Merge branch 'MDL-45075-25' of git://github.com/andrewnicols/moodle into MOODLE_25_STABLE
This commit is contained in:
@@ -123,4 +123,118 @@ class mod_forum_lib_testcase extends advanced_testcase {
|
||||
$this->assertContains($course->shortname, array($course1->shortname, $course2->shortname));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user