mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-45075 mod_forum: Add unit tests for forum subscription on forum creation
This commit is contained in:
parent
8e6775d8f9
commit
7bb7de44cf
@ -575,4 +575,118 @@ class mod_forum_lib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(true, isset($result[$forumoptional->id]));
|
||||
$this->assertEquals(true, isset($result[$forumforce->id]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test subscription using automatic subscription on create.
|
||||
*/
|
||||
public function test_forum_auto_subscribe_on_create() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$usercount = 5;
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$users = array();
|
||||
|
||||
for ($i = 0; $i < $usercount; $i++) {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$users[] = $user;
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
}
|
||||
|
||||
$options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE); // Automatic Subscription.
|
||||
$forum = $this->getDataGenerator()->create_module('forum', $options);
|
||||
|
||||
$result = forum_subscribed_users($course, $forum);
|
||||
$this->assertEquals($usercount, count($result));
|
||||
foreach ($users as $user) {
|
||||
$this->assertTrue(forum_is_subscribed($user->id, $forum));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test subscription using forced subscription on create.
|
||||
*/
|
||||
public function test_forum_forced_subscribe_on_create() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$usercount = 5;
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$users = array();
|
||||
|
||||
for ($i = 0; $i < $usercount; $i++) {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$users[] = $user;
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
}
|
||||
|
||||
$options = array('course' => $course->id, 'forcesubscribe' => FORUM_FORCESUBSCRIBE); // Forced subscription.
|
||||
$forum = $this->getDataGenerator()->create_module('forum', $options);
|
||||
|
||||
$result = forum_subscribed_users($course, $forum);
|
||||
$this->assertEquals($usercount, count($result));
|
||||
foreach ($users as $user) {
|
||||
$this->assertTrue(forum_is_subscribed($user->id, $forum));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test subscription using optional subscription on create.
|
||||
*/
|
||||
public function test_forum_optional_subscribe_on_create() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$usercount = 5;
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$users = array();
|
||||
|
||||
for ($i = 0; $i < $usercount; $i++) {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$users[] = $user;
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
}
|
||||
|
||||
$options = array('course' => $course->id, 'forcesubscribe' => FORUM_CHOOSESUBSCRIBE); // Subscription optional.
|
||||
$forum = $this->getDataGenerator()->create_module('forum', $options);
|
||||
|
||||
$result = forum_subscribed_users($course, $forum);
|
||||
// No subscriptions by default.
|
||||
$this->assertEquals(0, count($result));
|
||||
foreach ($users as $user) {
|
||||
$this->assertFalse(forum_is_subscribed($user->id, $forum));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test subscription using disallow subscription on create.
|
||||
*/
|
||||
public function test_forum_disallow_subscribe_on_create() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$usercount = 5;
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$users = array();
|
||||
|
||||
for ($i = 0; $i < $usercount; $i++) {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$users[] = $user;
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
}
|
||||
|
||||
$options = array('course' => $course->id, 'forcesubscribe' => FORUM_DISALLOWSUBSCRIBE); // Subscription prevented.
|
||||
$forum = $this->getDataGenerator()->create_module('forum', $options);
|
||||
|
||||
$result = forum_subscribed_users($course, $forum);
|
||||
// No subscriptions by default.
|
||||
$this->assertEquals(0, count($result));
|
||||
foreach ($users as $user) {
|
||||
$this->assertFalse(forum_is_subscribed($user->id, $forum));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user