mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-49502 forum: Unit tests for forum_view
This commit is contained in:
parent
449a6304d4
commit
ebfa74c799
@ -1256,6 +1256,45 @@ class mod_forum_lib_testcase extends advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
public function test_forum_view() {
|
||||
global $CFG;
|
||||
|
||||
$CFG->enablecompletion = 1;
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Setup test data.
|
||||
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
|
||||
$forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
|
||||
array('completion' => 2, 'completionview' => 1));
|
||||
$context = context_module::instance($forum->cmid);
|
||||
$cm = get_coursemodule_from_instance('forum', $forum->id);
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
|
||||
$this->setAdminUser();
|
||||
forum_view($forum, $course, $cm, $context);
|
||||
|
||||
$events = $sink->get_events();
|
||||
// 2 additional events thanks to completion.
|
||||
$this->assertCount(3, $events);
|
||||
$event = array_pop($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\mod_forum\event\course_module_viewed', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new \moodle_url('/mod/forum/view.php', array('f' => $forum->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
$this->assertEventContextNotUsed($event);
|
||||
$this->assertNotEmpty($event->get_name());
|
||||
|
||||
// Check completion status.
|
||||
$completion = new completion_info($course);
|
||||
$completiondata = $completion->get_data($cm);
|
||||
$this->assertEquals(1, $completiondata->completionstate);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new course, forum, and user with a number of discussions and replies.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user