Skip to content

Commit

Permalink
MDL-43557 events: fixed minor issues in existing events
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Apr 30, 2014
1 parent 4d9c1b5 commit 02a5a4b
Show file tree
Hide file tree
Showing 319 changed files with 2,569 additions and 1,935 deletions.
6 changes: 3 additions & 3 deletions admin/tool/capability/classes/event/report_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Event for when capability report is viewed.
* The tool_capability report viewed event.
*
* @package tool_capability
* @copyright 2014 Petr Skoda
Expand All @@ -24,7 +24,7 @@
namespace tool_capability\event;

/**
* Event triggered, when capability report is viewed.
* The tool_capability report viewed event class.
*
* @package tool_capability
* @since Moodle 2.7
Expand Down Expand Up @@ -59,7 +59,7 @@ public static function get_name() {
* @return string
*/
public function get_description() {
return "The user with id " . $this->userid . " viewed capability overview report";
return "The user with the id '$this->userid' viewed the capability overview report.";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion badges/classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function course_criteria_review(\core\event\course_completed $even
require_once($CFG->dirroot.'/lib/badgeslib.php');

$eventdata = $event->get_record_snapshot('course_completions', $event->objectid);
$userid = $event->other['relateduserid'];
$userid = $event->relateduserid;
$courseid = $event->courseid;

// Need to take into account that course can be a part of course_completion and courseset_completion criteria.
Expand Down
10 changes: 5 additions & 5 deletions blog/tests/bloglib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,15 @@ public function test_blog_association_created_event_validations() {
'objectid' => 3,
'other' => array('associateid' => 2 , 'blogid' => 3, 'subject' => 'blog subject')));
} catch (coding_exception $e) {
$this->assertContains('Invalid associatetype', $e->getMessage());
$this->assertContains('The \'associatetype\' value must be set in other and be a valid type.', $e->getMessage());
}
try {
\core\event\blog_association_created::create(array(
'contextid' => 1,
'objectid' => 3,
'other' => array('associateid' => 2 , 'blogid' => 3, 'associatetype' => 'random', 'subject' => 'blog subject')));
} catch (coding_exception $e) {
$this->assertContains('Invalid associatetype', $e->getMessage());
$this->assertContains('The \'associatetype\' value must be set in other and be a valid type.', $e->getMessage());
}
// Make sure associateid validations work.
try {
Expand All @@ -345,7 +345,7 @@ public function test_blog_association_created_event_validations() {
'objectid' => 3,
'other' => array('blogid' => 3, 'associatetype' => 'course', 'subject' => 'blog subject')));
} catch (coding_exception $e) {
$this->assertContains('Associate id must be set', $e->getMessage());
$this->assertContains('The \'associateid\' value must be set in other.', $e->getMessage());
}
// Make sure blogid validations work.
try {
Expand All @@ -354,7 +354,7 @@ public function test_blog_association_created_event_validations() {
'objectid' => 3,
'other' => array('associateid' => 3, 'associatetype' => 'course', 'subject' => 'blog subject')));
} catch (coding_exception $e) {
$this->assertContains('Blog id must be set', $e->getMessage());
$this->assertContains('The \'blogid\' value must be set in other.', $e->getMessage());
}
// Make sure blogid validations work.
try {
Expand All @@ -363,7 +363,7 @@ public function test_blog_association_created_event_validations() {
'objectid' => 3,
'other' => array('blogid' => 3, 'associateid' => 3, 'associatetype' => 'course')));
} catch (coding_exception $e) {
$this->assertContains('Subject must be set', $e->getMessage());
$this->assertContains('The \'subject\' value must be set in other.', $e->getMessage());
}
}

Expand Down
20 changes: 10 additions & 10 deletions calendar/tests/event_test.php → calendar/tests/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @copyright 2014 Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_calendar_event_testcase extends advanced_testcase {
class core_calendar_events_testcase extends advanced_testcase {

/**
* The test user.
Expand Down Expand Up @@ -126,7 +126,7 @@ public function test_calendar_event_created_validations() {
$this->fail("Event validation should not allow \\core\\event\\calendar_event_created to be triggered without
other['repeatid']");
} catch (coding_exception $e) {
$this->assertContains("Field other['repeatid'] must be set", $e->getMessage());
$this->assertContains('The \'repeatid\' value must be set in other.', $e->getMessage());
}

// Test not setting other['name'].
Expand All @@ -142,7 +142,7 @@ public function test_calendar_event_created_validations() {
$this->fail("Event validation should not allow \\core\\event\\calendar_event_created to be triggered without
other['name']");
} catch (coding_exception $e) {
$this->assertContains("Field other['name'] cannot be empty", $e->getMessage());
$this->assertContains('The \'name\' value must be set in other.', $e->getMessage());
}

// Test not setting other['timestart'].
Expand All @@ -158,7 +158,7 @@ public function test_calendar_event_created_validations() {
$this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
other['timestart']");
} catch (coding_exception $e) {
$this->assertContains("Field other['timestart'] cannot be empty", $e->getMessage());
$this->assertContains('The \'timestart\' value must be set in other.', $e->getMessage());
}
}

Expand Down Expand Up @@ -239,7 +239,7 @@ public function test_calendar_event_updated_validations() {
$this->fail("Event validation should not allow \\core\\event\\calendar_event_updated to be triggered without
other['repeatid']");
} catch (coding_exception $e) {
$this->assertContains("Field other['repeatid'] must be set", $e->getMessage());
$this->assertContains('The \'repeatid\' value must be set in other.', $e->getMessage());
}

// Test not setting other['name'].
Expand All @@ -255,7 +255,7 @@ public function test_calendar_event_updated_validations() {
$this->fail("Event validation should not allow \\core\\event\\calendar_event_updated to be triggered without
other['name']");
} catch (coding_exception $e) {
$this->assertContains("Field other['name'] cannot be empty", $e->getMessage());
$this->assertContains('The \'name\' value must be set in other.', $e->getMessage());
}

// Test not setting other['timestart'].
Expand All @@ -271,7 +271,7 @@ public function test_calendar_event_updated_validations() {
$this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
other['timestart']");
} catch (coding_exception $e) {
$this->assertContains("Field other['timestart'] cannot be empty", $e->getMessage());
$this->assertContains('The \'timestart\' value must be set in other.', $e->getMessage());
}
}

Expand Down Expand Up @@ -351,7 +351,7 @@ public function test_calendar_event_deleted_validations() {
$this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
other['repeatid']");
} catch (coding_exception $e) {
$this->assertContains("Field other['repeatid'] must be set", $e->getMessage());
$this->assertContains('The \'repeatid\' value must be set in other.', $e->getMessage());
}

// Test not setting other['name'].
Expand All @@ -367,7 +367,7 @@ public function test_calendar_event_deleted_validations() {
$this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
other['name']");
} catch (coding_exception $e) {
$this->assertContains("Field other['name'] cannot be empty", $e->getMessage());
$this->assertContains('The \'name\' value must be set in other.', $e->getMessage());
}

// Test not setting other['timestart'].
Expand All @@ -383,7 +383,7 @@ public function test_calendar_event_deleted_validations() {
$this->fail("Event validation should not allow \\core\\event\\calendar_event_deleted to be triggered without
other['timestart']");
} catch (coding_exception $e) {
$this->assertContains("Field other['timestart'] cannot be empty", $e->getMessage());
$this->assertContains('The \'timestart\' value must be set in other.', $e->getMessage());
}
}
}
4 changes: 2 additions & 2 deletions completion/completion_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public function mark_complete($timecomplete = null) {
array(
'objectid' => $data->id,
'userid' => $USER->id,
'relateduserid' => $data->userid,
'context' => context_course::instance($data->course),
'courseid' => $data->course,
'other' => array('relateduserid' => $data->userid)
'courseid' => $data->course
)
);
$event->add_record_snapshot('course_completions', $data);
Expand Down
18 changes: 8 additions & 10 deletions course/tests/courselib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ public function test_course_module_created_event_exceptions() {
$this->fail("Event validation should not allow \\core\\event\\course_module_created to be triggered without
other['instanceid']");
} catch (coding_exception $e) {
$this->assertContains("Field other['instanceid'] cannot be empty", $e->getMessage());
$this->assertContains("The 'instanceid' value must be set in other.", $e->getMessage());
}

// Test not setting modulename.
Expand All @@ -2031,7 +2031,7 @@ public function test_course_module_created_event_exceptions() {
$this->fail("Event validation should not allow \\core\\event\\course_module_created to be triggered without
other['modulename']");
} catch (coding_exception $e) {
$this->assertContains("Field other['modulename'] cannot be empty", $e->getMessage());
$this->assertContains("The 'modulename' value must be set in other.", $e->getMessage());
}

// Test not setting name.
Expand All @@ -2049,7 +2049,7 @@ public function test_course_module_created_event_exceptions() {
$this->fail("Event validation should not allow \\core\\event\\course_module_created to be triggered without
other['name']");
} catch (coding_exception $e) {
$this->assertContains("Field other['name'] cannot be empty", $e->getMessage());
$this->assertContains("The 'name' value must be set in other.", $e->getMessage());
}

}
Expand Down Expand Up @@ -2166,7 +2166,7 @@ public function test_course_module_updated_event_exceptions() {
$this->fail("Event validation should not allow \\core\\event\\course_module_updated to be triggered without
other['instanceid']");
} catch (coding_exception $e) {
$this->assertContains("Field other['instanceid'] cannot be empty", $e->getMessage());
$this->assertContains("The 'instanceid' value must be set in other.", $e->getMessage());
}

// Test not setting modulename.
Expand All @@ -2183,7 +2183,7 @@ public function test_course_module_updated_event_exceptions() {
$this->fail("Event validation should not allow \\core\\event\\course_module_updated to be triggered without
other['modulename']");
} catch (coding_exception $e) {
$this->assertContains("Field other['modulename'] cannot be empty", $e->getMessage());
$this->assertContains("The 'modulename' value must be set in other.", $e->getMessage());
}

// Test not setting name.
Expand All @@ -2201,7 +2201,7 @@ public function test_course_module_updated_event_exceptions() {
$this->fail("Event validation should not allow \\core\\event\\course_module_updated to be triggered without
other['name']");
} catch (coding_exception $e) {
$this->assertContains("Field other['name'] cannot be empty", $e->getMessage());
$this->assertContains("The 'name' value must be set in other.", $e->getMessage());
}

}
Expand Down Expand Up @@ -2269,7 +2269,7 @@ public function test_course_module_deleted_event_exceptions() {
$this->fail("Event validation should not allow \\core\\event\\course_module_deleted to be triggered without
other['instanceid']");
} catch (coding_exception $e) {
$this->assertContains("Field other['instanceid'] cannot be empty", $e->getMessage());
$this->assertContains("The 'instanceid' value must be set in other.", $e->getMessage());
}

// Test not setting modulename.
Expand All @@ -2286,7 +2286,7 @@ public function test_course_module_deleted_event_exceptions() {
$this->fail("Event validation should not allow \\core\\event\\course_module_deleted to be triggered without
other['modulename']");
} catch (coding_exception $e) {
$this->assertContains("Field other['modulename'] cannot be empty", $e->getMessage());
$this->assertContains("The 'modulename' value must be set in other.", $e->getMessage());
}
}

Expand Down Expand Up @@ -2468,8 +2468,6 @@ public function test_view_resources_list() {
$this->assertEquals(null, $event->objectid);
$this->assertEquals($course->id, $event->courseid);
$this->assertEquals($coursecontext->id, $event->contextid);
$expecteddesc = "User with id '$event->userid' viewed list of resources in course with id '$event->courseid'";
$this->assertEquals($expecteddesc, $event->get_description());
$expectedlegacydata = array(
array($course->id, "book", "view all", 'index.php?id=' . $course->id, ''),
array($course->id, "page", "view all", 'index.php?id=' . $course->id, ''),
Expand Down
26 changes: 20 additions & 6 deletions lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1756,9 +1756,16 @@ function role_assign($roleid, $userid, $contextid, $component = '', $itemid = 0,
reload_all_capabilities();
}

$event = \core\event\role_assigned::create(
array('context'=>$context, 'objectid'=>$ra->roleid, 'relateduserid'=>$ra->userid,
'other'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
$event = \core\event\role_assigned::create(array(
'context' => $context,
'objectid' => $ra->roleid,
'relateduserid' => $ra->userid,
'other' => array(
'id' => $ra->id,
'component' => $ra->component,
'itemid' => $ra->itemid
)
));
$event->add_record_snapshot('role_assignments', $ra);
$event->trigger();

Expand Down Expand Up @@ -1844,9 +1851,16 @@ function role_unassign_all(array $params, $subcontexts = false, $includemanual =
if (!empty($USER->id) && $USER->id == $ra->userid) {
reload_all_capabilities();
}
$event = \core\event\role_unassigned::create(
array('context'=>$context, 'objectid'=>$ra->roleid, 'relateduserid'=>$ra->userid,
'other'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
$event = \core\event\role_unassigned::create(array(
'context' => $context,
'objectid' => $ra->roleid,
'relateduserid' => $ra->userid,
'other' => array(
'id' => $ra->id,
'component' => $ra->component,
'itemid' => $ra->itemid
)
));
$event->add_record_snapshot('role_assignments', $ra);
$event->trigger();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/event/assessable_submitted.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class assessable_submitted extends \core\event\base {
abstract class assessable_submitted extends base {

/**
* Init method.
Expand Down
12 changes: 6 additions & 6 deletions lib/classes/event/assessable_uploaded.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
* @property-read array $other {
* Extra information about event.
*
* @type array pathnamehashes uploaded files path name hashes.
* @type string content string.
* - array pathnamehashes: uploaded files path name hashes.
* - string content: the content.
* }
*
* @package core
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class assessable_uploaded extends \core\event\base {
abstract class assessable_uploaded extends base {

/**
* Init method.
Expand All @@ -69,11 +69,11 @@ protected function init() {
protected function validate_data() {
parent::validate_data();
if ($this->contextlevel != CONTEXT_MODULE) {
throw new \coding_exception('Context passed must be module context.');
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
} else if (!isset($this->other['pathnamehashes']) || !is_array($this->other['pathnamehashes'])) {
throw new \coding_exception('pathnamehashes must be set in $other and must be an array.');
throw new \coding_exception('The \'pathnamehashes\' value must be set in other and must be an array.');
} else if (!isset($this->other['content']) || !is_string($this->other['content'])) {
throw new \coding_exception('content must be set in $other and must be a string.');
throw new \coding_exception('The \'content\' value must be set in other and must be a string.');
}
}

Expand Down
Loading

0 comments on commit 02a5a4b

Please sign in to comment.