Skip to content

Commit

Permalink
Merge branch 'MDL-43849_master' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jul 8, 2014
2 parents 59ba5a5 + bfce1e4 commit 7a26204
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
8 changes: 4 additions & 4 deletions enrol/meta/tests/plugin_test.php
Expand Up @@ -443,7 +443,7 @@ public function test_sync() {
/**
* Test user_enrolment_created event.
*/
public function test_user_enrolment_created_observer() {
public function test_user_enrolment_created_event() {
global $DB;

$this->resetAfterTest();
Expand Down Expand Up @@ -478,9 +478,9 @@ public function test_user_enrolment_created_observer() {
}

/**
* Test user_enrolment_deleted observer.
* Test user_enrolment_deleted event.
*/
public function test_user_enrolment_deleted_observer() {
public function test_user_enrolment_deleted_event() {
global $DB;

$this->resetAfterTest(true);
Expand Down Expand Up @@ -514,7 +514,7 @@ public function test_user_enrolment_deleted_observer() {
/**
* Test user_enrolment_updated event.
*/
public function test_user_enrolment_updated_observer() {
public function test_user_enrolment_updated_event() {
global $DB;

$this->resetAfterTest(true);
Expand Down
69 changes: 69 additions & 0 deletions mod/forum/tests/events_test.php
Expand Up @@ -2693,4 +2693,73 @@ public function test_forum_subscription_page_context_valid() {
$this->assertEquals($context, $event->get_context());

}

/**
* Test mod_forum_observer methods.
*/
public function test_observers() {
global $DB, $CFG;

require_once($CFG->dirroot . '/mod/forum/lib.php');

$forumgen = $this->getDataGenerator()->get_plugin_generator('mod_forum');

$course = $this->getDataGenerator()->create_course();
$trackedrecord = array('course' => $course->id, 'type' => 'general', 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
$untrackedrecord = array('course' => $course->id, 'type' => 'general');
$trackedforum = $this->getDataGenerator()->create_module('forum', $trackedrecord);
$untrackedforum = $this->getDataGenerator()->create_module('forum', $untrackedrecord);

// Used functions don't require these settings; adding
// them just in case there are APIs changes in future.
$user = $this->getDataGenerator()->create_user(array(
'maildigest' => 1,
'trackforums' => 1
));

$manplugin = enrol_get_plugin('manual');
$manualenrol = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual'));
$student = $DB->get_record('role', array('shortname' => 'student'));

// The role_assign observer does it's job adding the forum_subscriptions record.
$manplugin->enrol_user($manualenrol, $user->id, $student->id);

// They are not required, but in a real environment they are supposed to be required;
// adding them just in case there are APIs changes in future.
set_config('forum_trackingtype', 1);
set_config('forum_trackreadposts', 1);

$record = array();
$record['course'] = $course->id;
$record['forum'] = $trackedforum->id;
$record['userid'] = $user->id;
$discussion = $forumgen->create_discussion($record);

$record = array();
$record['discussion'] = $discussion->id;
$record['userid'] = $user->id;
$post = $forumgen->create_post($record);

forum_tp_add_read_record($user->id, $post->id);
forum_set_user_maildigest($trackedforum, 2, $user);
forum_tp_stop_tracking($untrackedforum->id, $user->id);

$this->assertEquals(1, $DB->count_records('forum_subscriptions'));
$this->assertEquals(1, $DB->count_records('forum_digests'));
$this->assertEquals(1, $DB->count_records('forum_track_prefs'));
$this->assertEquals(1, $DB->count_records('forum_read'));

// The course_module_created observer does it's job adding a subscription.
$forumrecord = array('course' => $course->id, 'type' => 'general', 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
$extraforum = $this->getDataGenerator()->create_module('forum', $forumrecord);
$this->assertEquals(2, $DB->count_records('forum_subscriptions'));

$manplugin->unenrol_user($manualenrol, $user->id);

$this->assertEquals(0, $DB->count_records('forum_digests'));
$this->assertEquals(0, $DB->count_records('forum_subscriptions'));
$this->assertEquals(0, $DB->count_records('forum_track_prefs'));
$this->assertEquals(0, $DB->count_records('forum_read'));
}

}

0 comments on commit 7a26204

Please sign in to comment.