MDL-45075 mod_forum: Move user subscription to an observer
[moodle.git] / mod / forum / tests / lib_test.php
CommitLineData
62b3b997
FM
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 module forums tests
19 *
20 * @package mod_forum
21 * @copyright 2013 Frédéric Massart
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27class mod_forum_lib_testcase extends advanced_testcase {
28
29 public function test_forum_trigger_content_uploaded_event() {
30 $this->resetAfterTest();
31
32 $user = $this->getDataGenerator()->create_user();
33 $course = $this->getDataGenerator()->create_course();
34 $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
35 $context = context_module::instance($forum->cmid);
36
37 $this->setUser($user->id);
38 $fakepost = (object) array('id' => 123, 'message' => 'Yay!', 'discussion' => 100);
74b63eae 39 $cm = get_coursemodule_from_instance('forum', $forum->id);
62b3b997
FM
40
41 $fs = get_file_storage();
42 $dummy = (object) array(
43 'contextid' => $context->id,
44 'component' => 'mod_forum',
45 'filearea' => 'attachment',
46 'itemid' => $fakepost->id,
47 'filepath' => '/',
48 'filename' => 'myassignmnent.pdf'
49 );
50 $fi = $fs->create_file_from_string($dummy, 'Content of ' . $dummy->filename);
51
52 $data = new stdClass();
53 $sink = $this->redirectEvents();
54 forum_trigger_content_uploaded_event($fakepost, $cm, 'some triggered from value');
55 $events = $sink->get_events();
56
57 $this->assertCount(1, $events);
58 $event = reset($events);
59 $this->assertInstanceOf('\mod_forum\event\assessable_uploaded', $event);
60 $this->assertEquals($context->id, $event->contextid);
61 $this->assertEquals($fakepost->id, $event->objectid);
62 $this->assertEquals($fakepost->message, $event->other['content']);
63 $this->assertEquals($fakepost->discussion, $event->other['discussionid']);
64 $this->assertCount(1, $event->other['pathnamehashes']);
65 $this->assertEquals($fi->get_pathnamehash(), $event->other['pathnamehashes'][0]);
66 $expected = new stdClass();
67 $expected->modulename = 'forum';
68 $expected->name = 'some triggered from value';
69 $expected->cmid = $forum->cmid;
70 $expected->itemid = $fakepost->id;
71 $expected->courseid = $course->id;
72 $expected->userid = $user->id;
73 $expected->content = $fakepost->message;
74 $expected->pathnamehashes = array($fi->get_pathnamehash());
75 $this->assertEventLegacyData($expected, $event);
623a32e5 76 $this->assertEventContextNotUsed($event);
62b3b997
FM
77 }
78
de316687
DP
79 public function test_forum_get_courses_user_posted_in() {
80 $this->resetAfterTest();
81
82 $user1 = $this->getDataGenerator()->create_user();
83 $user2 = $this->getDataGenerator()->create_user();
84 $user3 = $this->getDataGenerator()->create_user();
85
86 $course1 = $this->getDataGenerator()->create_course();
87 $course2 = $this->getDataGenerator()->create_course();
88 $course3 = $this->getDataGenerator()->create_course();
89
90 // Create 3 forums, one in each course.
91 $record = new stdClass();
92 $record->course = $course1->id;
93 $forum1 = $this->getDataGenerator()->create_module('forum', $record);
94
95 $record = new stdClass();
96 $record->course = $course2->id;
97 $forum2 = $this->getDataGenerator()->create_module('forum', $record);
98
99 $record = new stdClass();
100 $record->course = $course3->id;
101 $forum3 = $this->getDataGenerator()->create_module('forum', $record);
102
72c2c0bb
DP
103 // Add a second forum in course 1.
104 $record = new stdClass();
105 $record->course = $course1->id;
106 $forum4 = $this->getDataGenerator()->create_module('forum', $record);
107
108 // Add discussions to course 1 started by user1.
de316687
DP
109 $record = new stdClass();
110 $record->course = $course1->id;
111 $record->userid = $user1->id;
112 $record->forum = $forum1->id;
113 $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
114
72c2c0bb
DP
115 $record = new stdClass();
116 $record->course = $course1->id;
117 $record->userid = $user1->id;
118 $record->forum = $forum4->id;
119 $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
120
121 // Add discussions to course2 started by user1.
de316687
DP
122 $record = new stdClass();
123 $record->course = $course2->id;
124 $record->userid = $user1->id;
125 $record->forum = $forum2->id;
126 $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
127
128 // Add discussions to course 3 started by user2.
129 $record = new stdClass();
130 $record->course = $course3->id;
131 $record->userid = $user2->id;
132 $record->forum = $forum3->id;
133 $discussion3 = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
134
135 // Add post to course 3 by user1.
136 $record = new stdClass();
137 $record->course = $course3->id;
138 $record->userid = $user1->id;
139 $record->forum = $forum3->id;
140 $record->discussion = $discussion3->id;
141 $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
142
143 // User 3 hasn't posted anything, so shouldn't get any results.
144 $user3courses = forum_get_courses_user_posted_in($user3);
145 $this->assertEmpty($user3courses);
146
147 // User 2 has only posted in course3.
148 $user2courses = forum_get_courses_user_posted_in($user2);
149 $this->assertCount(1, $user2courses);
150 $user2course = array_shift($user2courses);
151 $this->assertEquals($course3->id, $user2course->id);
152 $this->assertEquals($course3->shortname, $user2course->shortname);
153
154 // User 1 has posted in all 3 courses.
155 $user1courses = forum_get_courses_user_posted_in($user1);
156 $this->assertCount(3, $user1courses);
157 foreach ($user1courses as $course) {
158 $this->assertContains($course->id, array($course1->id, $course2->id, $course3->id));
159 $this->assertContains($course->shortname, array($course1->shortname, $course2->shortname,
160 $course3->shortname));
161
162 }
163
164 // User 1 has only started a discussion in course 1 and 2 though.
165 $user1courses = forum_get_courses_user_posted_in($user1, true);
166 $this->assertCount(2, $user1courses);
167 foreach ($user1courses as $course) {
168 $this->assertContains($course->id, array($course1->id, $course2->id));
169 $this->assertContains($course->shortname, array($course1->shortname, $course2->shortname));
170 }
171 }
bb78e249 172
20e6782f
EM
173 /**
174 * Test the logic in the forum_tp_can_track_forums() function.
175 */
176 public function test_forum_tp_can_track_forums() {
177 global $CFG;
178
179 $this->resetAfterTest();
180
181 $useron = $this->getDataGenerator()->create_user(array('trackforums' => 1));
182 $useroff = $this->getDataGenerator()->create_user(array('trackforums' => 0));
183 $course = $this->getDataGenerator()->create_course();
184 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OFF); // Off.
185 $forumoff = $this->getDataGenerator()->create_module('forum', $options);
186
bd8f5d45 187 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_FORCED); // On.
20e6782f
EM
188 $forumforce = $this->getDataGenerator()->create_module('forum', $options);
189
190 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OPTIONAL); // Optional.
191 $forumoptional = $this->getDataGenerator()->create_module('forum', $options);
192
193 // Allow force.
194 $CFG->forum_allowforcedreadtracking = 1;
195
196 // User on, forum off, should be off.
197 $result = forum_tp_can_track_forums($forumoff, $useron);
198 $this->assertEquals(false, $result);
199
200 // User on, forum on, should be on.
201 $result = forum_tp_can_track_forums($forumforce, $useron);
202 $this->assertEquals(true, $result);
203
204 // User on, forum optional, should be on.
205 $result = forum_tp_can_track_forums($forumoptional, $useron);
206 $this->assertEquals(true, $result);
207
208 // User off, forum off, should be off.
209 $result = forum_tp_can_track_forums($forumoff, $useroff);
210 $this->assertEquals(false, $result);
211
212 // User off, forum force, should be on.
213 $result = forum_tp_can_track_forums($forumforce, $useroff);
214 $this->assertEquals(true, $result);
215
216 // User off, forum optional, should be off.
217 $result = forum_tp_can_track_forums($forumoptional, $useroff);
218 $this->assertEquals(false, $result);
219
220 // Don't allow force.
221 $CFG->forum_allowforcedreadtracking = 0;
222
223 // User on, forum off, should be off.
224 $result = forum_tp_can_track_forums($forumoff, $useron);
225 $this->assertEquals(false, $result);
226
227 // User on, forum on, should be on.
228 $result = forum_tp_can_track_forums($forumforce, $useron);
229 $this->assertEquals(true, $result);
230
231 // User on, forum optional, should be on.
232 $result = forum_tp_can_track_forums($forumoptional, $useron);
233 $this->assertEquals(true, $result);
234
235 // User off, forum off, should be off.
236 $result = forum_tp_can_track_forums($forumoff, $useroff);
237 $this->assertEquals(false, $result);
238
239 // User off, forum force, should be off.
240 $result = forum_tp_can_track_forums($forumforce, $useroff);
241 $this->assertEquals(false, $result);
242
243 // User off, forum optional, should be off.
244 $result = forum_tp_can_track_forums($forumoptional, $useroff);
245 $this->assertEquals(false, $result);
246
247 }
248
249 /**
250 * Test the logic in the test_forum_tp_is_tracked() function.
251 */
252 public function test_forum_tp_is_tracked() {
253 global $CFG;
254
255 $this->resetAfterTest();
256
257 $useron = $this->getDataGenerator()->create_user(array('trackforums' => 1));
258 $useroff = $this->getDataGenerator()->create_user(array('trackforums' => 0));
259 $course = $this->getDataGenerator()->create_course();
260 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OFF); // Off.
261 $forumoff = $this->getDataGenerator()->create_module('forum', $options);
262
bd8f5d45 263 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_FORCED); // On.
20e6782f
EM
264 $forumforce = $this->getDataGenerator()->create_module('forum', $options);
265
266 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OPTIONAL); // Optional.
267 $forumoptional = $this->getDataGenerator()->create_module('forum', $options);
268
269 // Allow force.
270 $CFG->forum_allowforcedreadtracking = 1;
271
272 // User on, forum off, should be off.
273 $result = forum_tp_is_tracked($forumoff, $useron);
274 $this->assertEquals(false, $result);
275
276 // User on, forum force, should be on.
277 $result = forum_tp_is_tracked($forumforce, $useron);
278 $this->assertEquals(true, $result);
279
280 // User on, forum optional, should be on.
281 $result = forum_tp_is_tracked($forumoptional, $useron);
282 $this->assertEquals(true, $result);
283
284 // User off, forum off, should be off.
285 $result = forum_tp_is_tracked($forumoff, $useroff);
286 $this->assertEquals(false, $result);
287
288 // User off, forum force, should be on.
289 $result = forum_tp_is_tracked($forumforce, $useroff);
290 $this->assertEquals(true, $result);
291
292 // User off, forum optional, should be off.
293 $result = forum_tp_is_tracked($forumoptional, $useroff);
294 $this->assertEquals(false, $result);
295
296 // Don't allow force.
297 $CFG->forum_allowforcedreadtracking = 0;
298
299 // User on, forum off, should be off.
300 $result = forum_tp_is_tracked($forumoff, $useron);
301 $this->assertEquals(false, $result);
302
303 // User on, forum force, should be on.
304 $result = forum_tp_is_tracked($forumforce, $useron);
305 $this->assertEquals(true, $result);
306
307 // User on, forum optional, should be on.
308 $result = forum_tp_is_tracked($forumoptional, $useron);
309 $this->assertEquals(true, $result);
310
311 // User off, forum off, should be off.
312 $result = forum_tp_is_tracked($forumoff, $useroff);
313 $this->assertEquals(false, $result);
314
315 // User off, forum force, should be off.
316 $result = forum_tp_is_tracked($forumforce, $useroff);
317 $this->assertEquals(false, $result);
318
319 // User off, forum optional, should be off.
320 $result = forum_tp_is_tracked($forumoptional, $useroff);
321 $this->assertEquals(false, $result);
322
323 // Stop tracking so we can test again.
324 forum_tp_stop_tracking($forumforce->id, $useron->id);
325 forum_tp_stop_tracking($forumoptional->id, $useron->id);
326 forum_tp_stop_tracking($forumforce->id, $useroff->id);
327 forum_tp_stop_tracking($forumoptional->id, $useroff->id);
328
329 // Allow force.
330 $CFG->forum_allowforcedreadtracking = 1;
331
332 // User on, preference off, forum force, should be on.
333 $result = forum_tp_is_tracked($forumforce, $useron);
334 $this->assertEquals(true, $result);
335
336 // User on, preference off, forum optional, should be on.
337 $result = forum_tp_is_tracked($forumoptional, $useron);
338 $this->assertEquals(false, $result);
339
340 // User off, preference off, forum force, should be on.
341 $result = forum_tp_is_tracked($forumforce, $useroff);
342 $this->assertEquals(true, $result);
343
344 // User off, preference off, forum optional, should be off.
345 $result = forum_tp_is_tracked($forumoptional, $useroff);
346 $this->assertEquals(false, $result);
347
348 // Don't allow force.
349 $CFG->forum_allowforcedreadtracking = 0;
350
351 // User on, preference off, forum force, should be on.
352 $result = forum_tp_is_tracked($forumforce, $useron);
353 $this->assertEquals(false, $result);
354
355 // User on, preference off, forum optional, should be on.
356 $result = forum_tp_is_tracked($forumoptional, $useron);
357 $this->assertEquals(false, $result);
358
359 // User off, preference off, forum force, should be off.
360 $result = forum_tp_is_tracked($forumforce, $useroff);
361 $this->assertEquals(false, $result);
362
363 // User off, preference off, forum optional, should be off.
364 $result = forum_tp_is_tracked($forumoptional, $useroff);
365 $this->assertEquals(false, $result);
366 }
367
368 /**
369 * Test the logic in the forum_tp_get_course_unread_posts() function.
370 */
371 public function test_forum_tp_get_course_unread_posts() {
372 global $CFG;
373
374 $this->resetAfterTest();
375
376 $useron = $this->getDataGenerator()->create_user(array('trackforums' => 1));
377 $useroff = $this->getDataGenerator()->create_user(array('trackforums' => 0));
378 $course = $this->getDataGenerator()->create_course();
379 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OFF); // Off.
380 $forumoff = $this->getDataGenerator()->create_module('forum', $options);
381
bd8f5d45 382 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_FORCED); // On.
20e6782f
EM
383 $forumforce = $this->getDataGenerator()->create_module('forum', $options);
384
385 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OPTIONAL); // Optional.
386 $forumoptional = $this->getDataGenerator()->create_module('forum', $options);
387
388 // Add discussions to the tracking off forum.
389 $record = new stdClass();
390 $record->course = $course->id;
391 $record->userid = $useron->id;
392 $record->forum = $forumoff->id;
393 $discussionoff = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
394
395 // Add discussions to the tracking forced forum.
396 $record = new stdClass();
397 $record->course = $course->id;
398 $record->userid = $useron->id;
399 $record->forum = $forumforce->id;
400 $discussionforce = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
401
402 // Add post to the tracking forced discussion.
403 $record = new stdClass();
404 $record->course = $course->id;
405 $record->userid = $useroff->id;
406 $record->forum = $forumforce->id;
407 $record->discussion = $discussionforce->id;
408 $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
409
410 // Add discussions to the tracking optional forum.
411 $record = new stdClass();
412 $record->course = $course->id;
413 $record->userid = $useron->id;
414 $record->forum = $forumoptional->id;
415 $discussionoptional = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
416
417 // Allow force.
418 $CFG->forum_allowforcedreadtracking = 1;
419
420 $result = forum_tp_get_course_unread_posts($useron->id, $course->id);
421 $this->assertEquals(2, count($result));
422 $this->assertEquals(false, isset($result[$forumoff->id]));
423 $this->assertEquals(true, isset($result[$forumforce->id]));
424 $this->assertEquals(2, $result[$forumforce->id]->unread);
425 $this->assertEquals(true, isset($result[$forumoptional->id]));
426 $this->assertEquals(1, $result[$forumoptional->id]->unread);
427
428 $result = forum_tp_get_course_unread_posts($useroff->id, $course->id);
429 $this->assertEquals(1, count($result));
430 $this->assertEquals(false, isset($result[$forumoff->id]));
431 $this->assertEquals(true, isset($result[$forumforce->id]));
432 $this->assertEquals(2, $result[$forumforce->id]->unread);
433 $this->assertEquals(false, isset($result[$forumoptional->id]));
434
435 // Don't allow force.
436 $CFG->forum_allowforcedreadtracking = 0;
437
438 $result = forum_tp_get_course_unread_posts($useron->id, $course->id);
439 $this->assertEquals(2, count($result));
440 $this->assertEquals(false, isset($result[$forumoff->id]));
441 $this->assertEquals(true, isset($result[$forumforce->id]));
442 $this->assertEquals(2, $result[$forumforce->id]->unread);
443 $this->assertEquals(true, isset($result[$forumoptional->id]));
444 $this->assertEquals(1, $result[$forumoptional->id]->unread);
445
446 $result = forum_tp_get_course_unread_posts($useroff->id, $course->id);
447 $this->assertEquals(0, count($result));
448 $this->assertEquals(false, isset($result[$forumoff->id]));
449 $this->assertEquals(false, isset($result[$forumforce->id]));
450 $this->assertEquals(false, isset($result[$forumoptional->id]));
451
452 // Stop tracking so we can test again.
453 forum_tp_stop_tracking($forumforce->id, $useron->id);
454 forum_tp_stop_tracking($forumoptional->id, $useron->id);
455 forum_tp_stop_tracking($forumforce->id, $useroff->id);
456 forum_tp_stop_tracking($forumoptional->id, $useroff->id);
457
458 // Allow force.
459 $CFG->forum_allowforcedreadtracking = 1;
460
461 $result = forum_tp_get_course_unread_posts($useron->id, $course->id);
462 $this->assertEquals(1, count($result));
463 $this->assertEquals(false, isset($result[$forumoff->id]));
464 $this->assertEquals(true, isset($result[$forumforce->id]));
465 $this->assertEquals(2, $result[$forumforce->id]->unread);
466 $this->assertEquals(false, isset($result[$forumoptional->id]));
467
468 $result = forum_tp_get_course_unread_posts($useroff->id, $course->id);
469 $this->assertEquals(1, count($result));
470 $this->assertEquals(false, isset($result[$forumoff->id]));
471 $this->assertEquals(true, isset($result[$forumforce->id]));
472 $this->assertEquals(2, $result[$forumforce->id]->unread);
473 $this->assertEquals(false, isset($result[$forumoptional->id]));
474
475 // Don't allow force.
476 $CFG->forum_allowforcedreadtracking = 0;
477
478 $result = forum_tp_get_course_unread_posts($useron->id, $course->id);
479 $this->assertEquals(0, count($result));
480 $this->assertEquals(false, isset($result[$forumoff->id]));
481 $this->assertEquals(false, isset($result[$forumforce->id]));
482 $this->assertEquals(false, isset($result[$forumoptional->id]));
483
484 $result = forum_tp_get_course_unread_posts($useroff->id, $course->id);
485 $this->assertEquals(0, count($result));
486 $this->assertEquals(false, isset($result[$forumoff->id]));
487 $this->assertEquals(false, isset($result[$forumforce->id]));
488 $this->assertEquals(false, isset($result[$forumoptional->id]));
489 }
490
491 /**
492 * Test the logic in the test_forum_tp_get_untracked_forums() function.
493 */
494 public function test_forum_tp_get_untracked_forums() {
495 global $CFG;
496
497 $this->resetAfterTest();
498
499 $useron = $this->getDataGenerator()->create_user(array('trackforums' => 1));
500 $useroff = $this->getDataGenerator()->create_user(array('trackforums' => 0));
501 $course = $this->getDataGenerator()->create_course();
502 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OFF); // Off.
503 $forumoff = $this->getDataGenerator()->create_module('forum', $options);
504
bd8f5d45 505 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_FORCED); // On.
20e6782f
EM
506 $forumforce = $this->getDataGenerator()->create_module('forum', $options);
507
508 $options = array('course' => $course->id, 'trackingtype' => FORUM_TRACKING_OPTIONAL); // Optional.
509 $forumoptional = $this->getDataGenerator()->create_module('forum', $options);
510
511 // Allow force.
512 $CFG->forum_allowforcedreadtracking = 1;
513
514 // On user with force on.
515 $result = forum_tp_get_untracked_forums($useron->id, $course->id);
516 $this->assertEquals(1, count($result));
517 $this->assertEquals(true, isset($result[$forumoff->id]));
518
519 // Off user with force on.
520 $result = forum_tp_get_untracked_forums($useroff->id, $course->id);
521 $this->assertEquals(2, count($result));
522 $this->assertEquals(true, isset($result[$forumoff->id]));
523 $this->assertEquals(true, isset($result[$forumoptional->id]));
524
525 // Don't allow force.
526 $CFG->forum_allowforcedreadtracking = 0;
527
528 // On user with force off.
529 $result = forum_tp_get_untracked_forums($useron->id, $course->id);
530 $this->assertEquals(1, count($result));
531 $this->assertEquals(true, isset($result[$forumoff->id]));
532
533 // Off user with force off.
534 $result = forum_tp_get_untracked_forums($useroff->id, $course->id);
535 $this->assertEquals(3, count($result));
536 $this->assertEquals(true, isset($result[$forumoff->id]));
537 $this->assertEquals(true, isset($result[$forumoptional->id]));
538 $this->assertEquals(true, isset($result[$forumforce->id]));
539
540 // Stop tracking so we can test again.
541 forum_tp_stop_tracking($forumforce->id, $useron->id);
542 forum_tp_stop_tracking($forumoptional->id, $useron->id);
543 forum_tp_stop_tracking($forumforce->id, $useroff->id);
544 forum_tp_stop_tracking($forumoptional->id, $useroff->id);
545
546 // Allow force.
547 $CFG->forum_allowforcedreadtracking = 1;
548
549 // On user with force on.
550 $result = forum_tp_get_untracked_forums($useron->id, $course->id);
551 $this->assertEquals(2, count($result));
552 $this->assertEquals(true, isset($result[$forumoff->id]));
553 $this->assertEquals(true, isset($result[$forumoptional->id]));
554
555 // Off user with force on.
556 $result = forum_tp_get_untracked_forums($useroff->id, $course->id);
557 $this->assertEquals(2, count($result));
558 $this->assertEquals(true, isset($result[$forumoff->id]));
559 $this->assertEquals(true, isset($result[$forumoptional->id]));
560
561 // Don't allow force.
562 $CFG->forum_allowforcedreadtracking = 0;
563
564 // On user with force off.
565 $result = forum_tp_get_untracked_forums($useron->id, $course->id);
566 $this->assertEquals(3, count($result));
567 $this->assertEquals(true, isset($result[$forumoff->id]));
568 $this->assertEquals(true, isset($result[$forumoptional->id]));
569 $this->assertEquals(true, isset($result[$forumforce->id]));
570
571 // Off user with force off.
572 $result = forum_tp_get_untracked_forums($useroff->id, $course->id);
573 $this->assertEquals(3, count($result));
574 $this->assertEquals(true, isset($result[$forumoff->id]));
575 $this->assertEquals(true, isset($result[$forumoptional->id]));
576 $this->assertEquals(true, isset($result[$forumforce->id]));
577 }
62b3b997 578}