MDL-65032 mod_forum: Behat test for locking
[moodle.git] / mod / forum / tests / entities_discussion_summary_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_summary 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\author as author_entity;
28use mod_forum\local\entities\discussion as discussion_entity;
29use mod_forum\local\entities\discussion_summary as discussion_summary_entity;
30use mod_forum\local\entities\post as post_entity;
31
32/**
33 * The discussion_summary entity tests.
34 *
35 * @package mod_forum
36 * @copyright 2019 Ryan Wyllie <ryan@moodle.com>
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 */
39class mod_forum_entities_discussion_summary_testcase extends advanced_testcase {
40 /**
41 * Test the entity returns expected values.
42 */
43 public function test_entity() {
44 $this->resetAfterTest();
45
46 $firstauthor = new author_entity(
47 1,
48 2,
49 'test',
50 'person',
51 'test person',
52 'test@example.com'
53 );
54 $lastauthor = new author_entity(
55 2,
56 3,
57 'test 2',
58 'person 2',
59 'test 2 person 2',
60 'test2@example.com'
61 );
62 $discussion = new discussion_entity(
63 1,
64 1,
65 1,
66 'test discussion',
67 1,
68 1,
69 0,
70 false,
71 time(),
72 time(),
73 0,
74 0,
f5b4320e
P
75 false,
76 0
47d38303
RW
77 );
78 $firstpost = 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,
bc4c7337 93 false,
47d38303
RW
94 false
95 );
96
97 $discussionsummary = new discussion_summary_entity($discussion, $firstpost, $firstauthor, $lastauthor);
98
99 $this->assertEquals($discussion, $discussionsummary->get_discussion());
100 $this->assertEquals($firstauthor, $discussionsummary->get_first_post_author());
101 $this->assertEquals($lastauthor, $discussionsummary->get_latest_post_author());
102 $this->assertEquals($firstpost, $discussionsummary->get_first_post());
103 }
104}