MDL-65032 mod_forum: Behat test for locking
[moodle.git] / mod / forum / tests / entities_forum_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 forum 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
27global $CFG;
28require_once($CFG->dirroot . '/rating/lib.php');
29
30use mod_forum\local\entities\discussion as discussion_entity;
31use mod_forum\local\entities\forum as forum_entity;
32
33/**
34 * The forum entity tests.
35 *
36 * @package mod_forum
37 * @copyright 2019 Ryan Wyllie <ryan@moodle.com>
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 */
40class mod_forum_entities_forum_testcase extends advanced_testcase {
41 /**
42 * Test the entity returns expected values.
43 */
44 public function test_entity() {
45 $this->resetAfterTest();
46
47 $time = time() - 10;
48 $discussion = new discussion_entity(
49 1,
50 2,
51 3,
52 'test discussion',
53 4,
54 5,
55 6,
56 false,
57 $time,
58 $time,
59 0,
60 0,
f5b4320e
P
61 false,
62 0
47d38303
RW
63 );
64
65 $past = time() - 100;
66 $course = $this->getDataGenerator()->create_course();
67 $forum = $this->getDataGenerator()->create_module('forum', ['course' => $course->id]);
68 $coursemodule = get_coursemodule_from_instance('forum', $forum->id);
69 $context = context_module::instance($coursemodule->id);
70 $effectivegroupmode = NOGROUPS;
71 $id = 1;
72 $courseid = 2;
73 $type = 'standard';
74 $name = 'test forum';
75 $intro = 'this is the intro';
76 $introformat = FORMAT_MOODLE;
77 $assessed = RATING_AGGREGATE_NONE;
78 $assesstimestart = 0;
79 $assesstimefinish = 0;
80 $scale = 0;
81 $maxbytes = 200;
82 $maxattachments = 5;
7c1d857d 83 $forcesubscribe = 0;
47d38303
RW
84 $trackingtype = 1;
85 $rsstype = 0;
86 $rssarticles = 0;
87 $timemodified = $past;
88 $warnafter = 0;
89 $blockafter = 0;
90 $blockperiod = 0;
91 $completiondiscussions = 0;
92 $completionreplies = 0;
93 $completionposts = 0;
94 $displaywordcount = false;
95 $lockdiscussionafter = 0;
cbf63d8e
SR
96 $duedate = 0;
97 $cutoffdate = 0;
47d38303
RW
98
99 $forum = new forum_entity(
100 $context,
101 $coursemodule,
102 $course,
103 $effectivegroupmode,
104 $id,
105 $courseid,
106 $type,
107 $name,
108 $intro,
109 $introformat,
110 $assessed,
111 $assesstimestart,
112 $assesstimefinish,
113 $scale,
114 $maxbytes,
115 $maxattachments,
116 $forcesubscribe,
117 $trackingtype,
118 $rsstype,
119 $rssarticles,
120 $timemodified,
121 $warnafter,
122 $blockafter,
123 $blockperiod,
124 $completiondiscussions,
125 $completionreplies,
126 $completionposts,
127 $displaywordcount,
cbf63d8e
SR
128 $lockdiscussionafter,
129 $duedate,
130 $cutoffdate
47d38303
RW
131 );
132
133 $this->assertEquals($context, $forum->get_context());
134 $this->assertEquals($coursemodule, $forum->get_course_module_record());
135 $this->assertEquals($coursemodule, $forum->get_course_module_record());
136 $this->assertEquals($effectivegroupmode, $forum->get_effective_group_mode());
137 $this->assertEquals(false, $forum->is_in_group_mode());
138 $this->assertEquals($course, $forum->get_course_record());
139 $this->assertEquals($id, $forum->get_id());
140 $this->assertEquals($courseid, $forum->get_course_id());
141 $this->assertEquals($name, $forum->get_name());
142 $this->assertEquals($intro, $forum->get_intro());
143 $this->assertEquals($introformat, $forum->get_intro_format());
144 $this->assertEquals($assessed, $forum->get_rating_aggregate());
145 // Rating aggregate is set to none.
146 $this->assertEquals(false, $forum->has_rating_aggregate());
147 $this->assertEquals($assesstimestart, $forum->get_assess_time_start());
148 $this->assertEquals($assesstimefinish, $forum->get_assess_time_finish());
149 $this->assertEquals($scale, $forum->get_scale());
150 $this->assertEquals($maxbytes, $forum->get_max_bytes());
151 $this->assertEquals($maxattachments, $forum->get_max_attachments());
7c1d857d 152 $this->assertEquals($forcesubscribe, $forum->get_subscription_mode());
47d38303
RW
153 $this->assertEquals($trackingtype, $forum->get_tracking_type());
154 $this->assertEquals($rsstype, $forum->get_rss_type());
155 $this->assertEquals($rssarticles, $forum->get_rss_articles());
156 $this->assertEquals($timemodified, $forum->get_time_modified());
157 $this->assertEquals($warnafter, $forum->get_warn_after());
158 $this->assertEquals($blockafter, $forum->get_block_after());
159 $this->assertEquals($blockperiod, $forum->get_block_period());
160 $this->assertEquals(false, $forum->has_blocking_enabled());
161 $this->assertEquals($completiondiscussions, $forum->get_completion_discussions());
162 $this->assertEquals($completionreplies, $forum->get_completion_replies());
163 $this->assertEquals($completionposts, $forum->get_completion_posts());
164 $this->assertEquals($displaywordcount, $forum->should_display_word_count());
165 $this->assertEquals($lockdiscussionafter, $forum->get_lock_discussions_after());
166 $this->assertEquals(false, $forum->has_lock_discussions_after());
167 $this->assertEquals(false, $forum->is_discussion_locked($discussion));
cbf63d8e
SR
168 $this->assertEquals(false, $forum->has_due_date());
169 $this->assertEquals(false, $forum->is_due_date_reached());
170 $this->assertEquals(false, $forum->has_cutoff_date());
171 $this->assertEquals(false, $forum->is_cutoff_date_reached());
47d38303
RW
172 }
173}