MDL-57487 mod_forum: final deprecation xxx_print_overview

Apart from deprecating forum_print_overview, the following method
has been also deprecated because it's not used anymore:
- forum_filter_user_groups_discussions
This commit is contained in:
Sara Arjona 2019-06-12 20:03:32 +02:00
parent 99a80e133a
commit b18015c687
2 changed files with 6 additions and 452 deletions

View file

@ -2524,273 +2524,6 @@ class mod_forum_lib_testcase extends advanced_testcase {
$this->assertArrayHasKey('forumdiscussions', $nodes->getValue($tree));
}
public function test_print_overview() {
$this->resetAfterTest();
$course1 = self::getDataGenerator()->create_course();
$course2 = self::getDataGenerator()->create_course();
// Create an author user.
$author = self::getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($author->id, $course1->id);
$this->getDataGenerator()->enrol_user($author->id, $course2->id);
// Create a viewer user.
$viewer = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
$this->getDataGenerator()->enrol_user($viewer->id, $course1->id);
$this->getDataGenerator()->enrol_user($viewer->id, $course2->id);
// Create two forums - one in each course.
$record = new stdClass();
$record->course = $course1->id;
$forum1 = self::getDataGenerator()->create_module('forum', (object) array('course' => $course1->id));
$forum2 = self::getDataGenerator()->create_module('forum', (object) array('course' => $course2->id));
// A standard post in the forum.
$record = new stdClass();
$record->course = $course1->id;
$record->userid = $author->id;
$record->forum = $forum1->id;
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
$this->setUser($viewer->id);
$courses = array(
$course1->id => clone $course1,
$course2->id => clone $course2,
);
foreach ($courses as $courseid => $course) {
$courses[$courseid]->lastaccess = 0;
}
$results = array();
forum_print_overview($courses, $results);
$this->assertDebuggingCalledCount(2);
// There should be one entry for course1, and no others.
$this->assertCount(1, $results);
// There should be one entry for a forum in course1.
$this->assertCount(1, $results[$course1->id]);
$this->assertArrayHasKey('forum', $results[$course1->id]);
}
public function test_print_overview_groups() {
$this->resetAfterTest();
$course1 = self::getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
// Create an author user.
$author = self::getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($author->id, $course1->id);
// Create two viewer users - one in each group.
$viewer1 = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
$this->getDataGenerator()->enrol_user($viewer1->id, $course1->id);
$this->getDataGenerator()->create_group_member(array('userid' => $viewer1->id, 'groupid' => $group1->id));
$viewer2 = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
$this->getDataGenerator()->enrol_user($viewer2->id, $course1->id);
$this->getDataGenerator()->create_group_member(array('userid' => $viewer2->id, 'groupid' => $group2->id));
// Create a forum.
$record = new stdClass();
$record->course = $course1->id;
$forum1 = self::getDataGenerator()->create_module('forum', (object) array(
'course' => $course1->id,
'groupmode' => SEPARATEGROUPS,
));
// A post in the forum for group1.
$record = new stdClass();
$record->course = $course1->id;
$record->userid = $author->id;
$record->forum = $forum1->id;
$record->groupid = $group1->id;
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
$course1->lastaccess = 0;
$courses = array($course1->id => $course1);
// As viewer1 (same group as post).
$this->setUser($viewer1->id);
$results = array();
forum_print_overview($courses, $results);
$this->assertDebuggingCalledCount(2);
// There should be one entry for course1.
$this->assertCount(1, $results);
// There should be one entry for a forum in course1.
$this->assertCount(1, $results[$course1->id]);
$this->assertArrayHasKey('forum', $results[$course1->id]);
$this->setUser($viewer2->id);
$results = array();
forum_print_overview($courses, $results);
$this->assertDebuggingCalledCount(2);
// There should be one entry for course1.
$this->assertCount(0, $results);
}
/**
* @dataProvider print_overview_timed_provider
*/
public function test_print_overview_timed($config, $hasresult) {
$this->resetAfterTest();
$course1 = self::getDataGenerator()->create_course();
// Create an author user.
$author = self::getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($author->id, $course1->id);
// Create a viewer user.
$viewer = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
$this->getDataGenerator()->enrol_user($viewer->id, $course1->id);
// Create a forum.
$record = new stdClass();
$record->course = $course1->id;
$forum1 = self::getDataGenerator()->create_module('forum', (object) array('course' => $course1->id));
// A timed post with a timestart in the past (24 hours ago).
$record = new stdClass();
$record->course = $course1->id;
$record->userid = $author->id;
$record->forum = $forum1->id;
if (isset($config['timestartmodifier'])) {
$record->timestart = time() + $config['timestartmodifier'];
}
if (isset($config['timeendmodifier'])) {
$record->timeend = time() + $config['timeendmodifier'];
}
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
$course1->lastaccess = 0;
$courses = array($course1->id => $course1);
// As viewer, check the forum_print_overview result.
$this->setUser($viewer->id);
$results = array();
forum_print_overview($courses, $results);
$this->assertDebuggingCalledCount(2);
if ($hasresult) {
// There should be one entry for course1.
$this->assertCount(1, $results);
// There should be one entry for a forum in course1.
$this->assertCount(1, $results[$course1->id]);
$this->assertArrayHasKey('forum', $results[$course1->id]);
} else {
// There should be no entries for any course.
$this->assertCount(0, $results);
}
}
/**
* @dataProvider print_overview_timed_provider
*/
public function test_print_overview_timed_groups($config, $hasresult) {
$this->resetAfterTest();
$course1 = self::getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
// Create an author user.
$author = self::getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($author->id, $course1->id);
// Create two viewer users - one in each group.
$viewer1 = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
$this->getDataGenerator()->enrol_user($viewer1->id, $course1->id);
$this->getDataGenerator()->create_group_member(array('userid' => $viewer1->id, 'groupid' => $group1->id));
$viewer2 = self::getDataGenerator()->create_user((object) array('trackforums' => 1));
$this->getDataGenerator()->enrol_user($viewer2->id, $course1->id);
$this->getDataGenerator()->create_group_member(array('userid' => $viewer2->id, 'groupid' => $group2->id));
// Create a forum.
$record = new stdClass();
$record->course = $course1->id;
$forum1 = self::getDataGenerator()->create_module('forum', (object) array(
'course' => $course1->id,
'groupmode' => SEPARATEGROUPS,
));
// A post in the forum for group1.
$record = new stdClass();
$record->course = $course1->id;
$record->userid = $author->id;
$record->forum = $forum1->id;
$record->groupid = $group1->id;
if (isset($config['timestartmodifier'])) {
$record->timestart = time() + $config['timestartmodifier'];
}
if (isset($config['timeendmodifier'])) {
$record->timeend = time() + $config['timeendmodifier'];
}
$this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
$course1->lastaccess = 0;
$courses = array($course1->id => $course1);
// As viewer1 (same group as post).
$this->setUser($viewer1->id);
$results = array();
forum_print_overview($courses, $results);
$this->assertDebuggingCalledCount(2);
if ($hasresult) {
// There should be one entry for course1.
$this->assertCount(1, $results);
// There should be one entry for a forum in course1.
$this->assertCount(1, $results[$course1->id]);
$this->assertArrayHasKey('forum', $results[$course1->id]);
} else {
// There should be no entries for any course.
$this->assertCount(0, $results);
}
$this->setUser($viewer2->id);
$results = array();
forum_print_overview($courses, $results);
$this->assertDebuggingCalledCount(2);
// There should be one entry for course1.
$this->assertCount(0, $results);
}
public function print_overview_timed_provider() {
return array(
'timestart_past' => array(
'discussionconfig' => array(
'timestartmodifier' => -86000,
),
'hasresult' => true,
),
'timestart_future' => array(
'discussionconfig' => array(
'timestartmodifier' => 86000,
),
'hasresult' => false,
),
'timeend_past' => array(
'discussionconfig' => array(
'timeendmodifier' => -86000,
),
'hasresult' => false,
),
'timeend_future' => array(
'discussionconfig' => array(
'timeendmodifier' => 86000,
),
'hasresult' => true,
),
);
}
/**
* Test test_pinned_discussion_with_group.
*/