MDL-64820 forum: add new classes for rendering to local namespace
[moodle.git] / mod / forum / tests / entities_discussion_test.php
CommitLineData
47d38303
RW
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * The discussion entity tests.
19 *
20 * @package mod_forum
21 * @copyright 2019 Ryan Wyllie <ryan@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27use mod_forum\local\entities\discussion as discussion_entity;
28use mod_forum\local\entities\post as post_entity;
29
30/**
31 * The discussion entity tests.
32 *
33 * @package mod_forum
34 * @copyright 2019 Ryan Wyllie <ryan@moodle.com>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
37class mod_forum_entities_discussion_testcase extends advanced_testcase {
38 /**
39 * Test the entity returns expected values.
40 */
41 public function test_entity() {
42 $this->resetAfterTest();
43
44 // In the past to ensure the time started is true.
45 $time = time() + 10;
46 $discussion = new discussion_entity(
47 1,
48 2,
49 3,
50 'test discussion',
51 4,
52 5,
53 6,
54 false,
55 $time,
56 $time,
57 0,
58 0,
59 false
60 );
61 $firstpost = new post_entity(
62 4,
63 1,
64 0,
65 1,
66 time(),
67 time(),
68 true,
69 'post subject',
70 'post message',
71 1,
72 true,
73 false,
74 0,
75 false,
76 false
77 );
78 $notfirstpost = new post_entity(
79 1,
80 1,
81 0,
82 1,
83 time(),
84 time(),
85 true,
86 'post subject',
87 'post message',
88 1,
89 true,
90 false,
91 0,
92 false,
93 false
94 );
95
96 $this->assertEquals(1, $discussion->get_id());
97 $this->assertEquals(2, $discussion->get_course_id());
98 $this->assertEquals(3, $discussion->get_forum_id());
99 $this->assertEquals('test discussion', $discussion->get_name());
100 $this->assertEquals(4, $discussion->get_first_post_id());
101 $this->assertEquals(5, $discussion->get_user_id());
102 $this->assertEquals(6, $discussion->get_group_id());
103 $this->assertEquals(false, $discussion->is_assessed());
104 $this->assertEquals($time, $discussion->get_time_modified());
105 $this->assertEquals($time, $discussion->get_user_modified());
106 $this->assertEquals(0, $discussion->get_time_start());
107 $this->assertEquals(0, $discussion->get_time_end());
108 $this->assertEquals(false, $discussion->is_pinned());
109 $this->assertEquals(true, $discussion->is_first_post($firstpost));
110 $this->assertEquals(false, $discussion->is_first_post($notfirstpost));
111 $this->assertEquals(true, $discussion->has_started());
112 $this->assertEquals(true, $discussion->has_group());
113 }
114}