diff --git a/blocks/comments/tests/events_test.php b/blocks/comments/tests/events_test.php index 7cb8e881a5b7c..cb4a1c52f7b87 100644 --- a/blocks/comments/tests/events_test.php +++ b/blocks/comments/tests/events_test.php @@ -113,6 +113,7 @@ public function test_comment_created() { $this->assertEquals($context, $event->get_context()); $url = new moodle_url('/mod/wiki/view.php', array('id' => $this->wiki->id)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } /** @@ -178,5 +179,6 @@ public function test_comment_deleted() { $this->assertEquals($context, $event->get_context()); $url = new moodle_url('/mod/wiki/view.php', array('id' => $this->wiki->id)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } } diff --git a/blog/tests/bloglib_test.php b/blog/tests/bloglib_test.php index 0109fd44baa2c..b4af76451c8d8 100644 --- a/blog/tests/bloglib_test.php +++ b/blog/tests/bloglib_test.php @@ -183,6 +183,7 @@ public function test_blog_entry_created_event() { $this->assertEventLegacyLogData($arr, $event); $this->assertEquals("blog_entry_added", $event->get_legacy_eventname()); $this->assertEventLegacyData($blog, $event); + $this->assertEventContextNotUsed($event); } /** @@ -215,6 +216,7 @@ public function test_blog_entry_updated_event() { $this->assertEventLegacyData($blog, $event); $arr = array (SITEID, 'blog', 'update', 'index.php?userid=' . $this->userid . '&entryid=' . $blog->id, $blog->subject); $this->assertEventLegacyLogData($arr, $event); + $this->assertEventContextNotUsed($event); } /** @@ -249,6 +251,7 @@ public function test_blog_entry_deleted_event() { $blog->id); $this->assertEventLegacyLogData($arr, $event); $this->assertEventLegacyData($blog, $event); + $this->assertEventContextNotUsed($event); } @@ -301,6 +304,7 @@ public function test_blog_association_created_event() { $arr = array(SITEID, 'blog', 'add association', 'index.php?userid=' . $this->userid . '&entryid=' . $blog->id, $blog->subject, $this->cmid, $this->userid); $this->assertEventLegacyLogData($arr, $event); + $this->assertEventContextNotUsed($event); } /** @@ -381,6 +385,7 @@ public function test_blog_entries_viewed_event() { $this->assertEquals($url, $event->get_url()); $arr = array(SITEID, 'blog', 'view', $url2->out(), 'view blog entry'); $this->assertEventLegacyLogData($arr, $event); + $this->assertEventContextNotUsed($event); } /** @@ -416,6 +421,7 @@ public function test_blog_comment_created_event() { $this->assertEquals($this->postid, $event->other['itemid']); $url = new moodle_url('/blog/index.php', array('entryid' => $this->postid)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } /** @@ -452,6 +458,7 @@ public function test_blog_comment_deleted_event() { $this->assertEquals($this->postid, $event->other['itemid']); $url = new moodle_url('/blog/index.php', array('entryid' => $this->postid)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } } diff --git a/cohort/tests/cohortlib_test.php b/cohort/tests/cohortlib_test.php index 64f40c7e7b646..6392b84e80fc4 100644 --- a/cohort/tests/cohortlib_test.php +++ b/cohort/tests/cohortlib_test.php @@ -106,6 +106,7 @@ public function test_cohort_add_cohort_event() { $this->assertEquals($cohort->contextid, $event->contextid); $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $id)); $this->assertEventLegacyData($cohort, $event); + $this->assertEventContextNotUsed($event); } public function test_cohort_update_cohort() { @@ -176,6 +177,7 @@ public function test_cohort_update_cohort_event() { $this->assertEquals($updatedcohort->contextid, $event->contextid); $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $id)); $this->assertEventLegacyData($cohort, $event); + $this->assertEventContextNotUsed($event); } public function test_cohort_delete_cohort() { @@ -213,6 +215,7 @@ public function test_cohort_delete_cohort_event() { $this->assertEquals($cohort->id, $event->objectid); $this->assertEquals($cohort, $event->get_record_snapshot('cohort', $cohort->id)); $this->assertEventLegacyData($cohort, $event); + $this->assertEventContextNotUsed($event); } public function test_cohort_delete_category() { @@ -270,6 +273,7 @@ public function test_cohort_add_member_event() { $this->assertEquals($user->id, $event->relateduserid); $this->assertEquals($USER->id, $event->userid); $this->assertEventLegacyData((object) array('cohortid' => $cohort->id, 'userid' => $user->id), $event); + $this->assertEventContextNotUsed($event); } public function test_cohort_remove_member() { @@ -313,6 +317,7 @@ public function test_cohort_remove_member_event() { $this->assertEquals($user->id, $event->relateduserid); $this->assertEquals($USER->id, $event->userid); $this->assertEventLegacyData((object) array('cohortid' => $cohort->id, 'userid' => $user->id), $event); + $this->assertEventContextNotUsed($event); } public function test_cohort_is_member() { diff --git a/course/tests/courselib_test.php b/course/tests/courselib_test.php index 56ad60f30580f..f2f1a6936777a 100644 --- a/course/tests/courselib_test.php +++ b/course/tests/courselib_test.php @@ -1449,6 +1449,7 @@ public function test_course_created_event() { // as they have already been validated in the previous steps. Here we only want to make sure that when the // imsenterprise plugin creates a course an event is triggered. $this->assertInstanceOf('\core\event\course_created', $event); + $this->assertEventContextNotUsed($event); } /** @@ -1527,6 +1528,7 @@ public function test_course_updated_event() { $this->assertEventLegacyData($movedcoursehidden, $event); $expectedlog = array($movedcoursehidden->id, 'course', 'move', 'edit.php?id=' . $movedcoursehidden->id, $movedcoursehidden->id); $this->assertEventLegacyLogData($expectedlog, $event); + $this->assertEventContextNotUsed($event); } /** @@ -1572,6 +1574,7 @@ public function test_course_deleted_event() { $this->assertEventLegacyData($course, $event); $expectedlog = array(SITEID, 'course', 'delete', 'view.php?id=' . $course->id, $course->fullname . '(ID ' . $course->id . ')'); $this->assertEventLegacyLogData($expectedlog, $event); + $this->assertEventContextNotUsed($event); } /** @@ -1613,6 +1616,7 @@ public function test_course_content_deleted_event() { $course->context = $coursecontext; $course->options = array(); $this->assertEventLegacyData($course, $event); + $this->assertEventContextNotUsed($event); } /** @@ -1675,6 +1679,7 @@ public function test_course_category_deleted_event() { $this->assertEventLegacyData($category2, $event); $expectedlog = array(SITEID, 'category', 'delete', 'index.php', $category2->name . '(ID ' . $category2->id . ')'); $this->assertEventLegacyLogData($expectedlog, $event); + $this->assertEventContextNotUsed($event); } /** @@ -1740,6 +1745,7 @@ public function test_course_restored_event() { 'samesite' => $rc->is_samesite() ); $this->assertEventLegacyData($legacydata, $event); + $this->assertEventContextNotUsed($event); // Destroy the resource controller since we are done using it. $rc->destroy(); @@ -1794,6 +1800,7 @@ public function test_course_section_updated_event() { $sectionnum = $section->section; $expectedlegacydata = array($course->id, "course", "editsection", 'editsection.php?id=' . $id, $sectionnum); $this->assertEventLegacyLogData($expectedlegacydata, $event); + $this->assertEventContextNotUsed($event); } public function test_course_integrity_check() { @@ -1953,6 +1960,7 @@ public function test_course_module_created_event() { $arr = array($cm->course, "course", "add mod", "../mod/assign/view.php?id=$mod->id", "assign $cm->instance"); $this->assertEventLegacyLogData($arr, $event); + $this->assertEventContextNotUsed($event); } @@ -2058,7 +2066,7 @@ public function test_course_module_updated_event() { $arr = array($cm->course, "course", "update mod", "../mod/forum/view.php?id=$mod->id", "forum $cm->instance"); $this->assertEventLegacyLogData($arr, $event); - + $this->assertEventContextNotUsed($event); } /** diff --git a/enrol/meta/tests/plugin_test.php b/enrol/meta/tests/plugin_test.php index 05cb522847b6f..a23c14895d975 100644 --- a/enrol/meta/tests/plugin_test.php +++ b/enrol/meta/tests/plugin_test.php @@ -474,6 +474,7 @@ public function test_user_enrolment_created_observer() { $expectedlegacyeventdata->enrol = 'meta'; $expectedlegacyeventdata->courseid = $course2->id; $this->assertEventLegacyData($expectedlegacyeventdata, $event); + $this->assertEventContextNotUsed($event); } /** @@ -507,6 +508,7 @@ public function test_user_enrolment_deleted_observer() { $this->assertEquals(0, $DB->count_records('user_enrolments')); $this->assertInstanceOf('\core\event\user_enrolment_deleted', $event); $this->assertEquals('user_unenrolled', $event->get_legacy_eventname()); + $this->assertEventContextNotUsed($event); } /** @@ -546,5 +548,6 @@ public function test_user_enrolment_updated_observer() { $expectedlegacyeventdata->enrol = 'meta'; $expectedlegacyeventdata->courseid = $course2->id; $this->assertEventLegacyData($expectedlegacyeventdata, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/enrol/tests/enrollib_test.php b/enrol/tests/enrollib_test.php index 394eb6cb66f29..61a43922a982e 100644 --- a/enrol/tests/enrollib_test.php +++ b/enrol/tests/enrollib_test.php @@ -318,6 +318,7 @@ public function test_user_enrolment_created_event() { $this->assertEventLegacyData($expectedlegacyeventdata, $event); $expected = array($course1->id, 'course', 'enrol', '../enrol/users.php?id=' . $course1->id, $course1->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -359,5 +360,6 @@ public function test_user_enrolment_deleted_event() { $this->assertEventLegacyData($expectedlegacyeventdata, $event); $expected = array($course->id, 'course', 'unenrol', '../enrol/users.php?id=' . $course->id, $course->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/lib/phpunit/classes/advanced_testcase.php b/lib/phpunit/classes/advanced_testcase.php index 34b086e7e032d..04bd7917b5e36 100644 --- a/lib/phpunit/classes/advanced_testcase.php +++ b/lib/phpunit/classes/advanced_testcase.php @@ -343,6 +343,34 @@ public function assertEventLegacyLogData($expected, \core\event\base $event, $me $this->assertEquals($expected, $legacydata, $message); } + /** + * Assert that an event is not using event->contxet. + * While restoring context might not be valid and it should not be used by event url + * or description methods. + * + * @param \core\event\base $event the event object. + * @param string $message + * @return void + */ + public function assertEventContextNotUsed(\core\event\base $event, $message = '') { + // Save current event->context and set it to false. + $eventcontext = phpunit_event_mock::testable_get_event_context($event); + phpunit_event_mock::testable_set_event_context($event, false); + if ($message === '') { + $message = 'Event should not use context property of event in any method.'; + } + + // Test event methods should not use event->context. + $event->get_url(); + $event->get_description(); + $event->get_legacy_eventname(); + phpunit_event_mock::testable_get_legacy_eventdata($event); + phpunit_event_mock::testable_get_legacy_logdata($event); + + // Restore event->context. + phpunit_event_mock::testable_set_event_context($event, $eventcontext); + } + /** * Stores current time as the base for assertTimeCurrent(). * diff --git a/lib/phpunit/classes/event_mock.php b/lib/phpunit/classes/event_mock.php index 26b99d1564df8..578f300009682 100644 --- a/lib/phpunit/classes/event_mock.php +++ b/lib/phpunit/classes/event_mock.php @@ -37,6 +37,8 @@ abstract class phpunit_event_mock extends \core\event\base { /** * Returns the log data of the event. + * + * @param \core\event\base $event event to get legacy eventdata from. * @return array */ public static function testable_get_legacy_eventdata($event) { @@ -45,10 +47,31 @@ public static function testable_get_legacy_eventdata($event) { /** * Returns the log data of the event. + * + * @param \core\event\base $event event to get legacy logdata from. * @return array */ public static function testable_get_legacy_logdata($event) { return $event->get_legacy_logdata(); } + /** + * Returns event context. + * + * @param \core\event\base $event event to get context for. + * @return context event context + */ + public static function testable_get_event_context($event) { + return $event->context; + } + + /** + * Sets event context. + * + * @param \core\event\base $event event to set context for. + * @param context $context context to set. + */ + public static function testable_set_event_context($event, $context) { + $event->context = $context; + } } diff --git a/lib/tests/event_content_viewed_test.php b/lib/tests/event_content_viewed_test.php index 859173e98d761..7e5579ffccd72 100644 --- a/lib/tests/event_content_viewed_test.php +++ b/lib/tests/event_content_viewed_test.php @@ -75,6 +75,7 @@ public function test_event_attributes() { $result = $sink->get_events(); $event = $result[1]; $this->assertEventLegacyLogData(null, $event); + $this->assertEventContextNotUsed($event); } /** @@ -89,6 +90,7 @@ public function test_event_context_exception() { $pageevent = \core_tests\event\content_viewed::create(); $pageevent->set_page_detail(); $pageevent->trigger(); + $this->assertEventContextNotUsed($pageevent); } } diff --git a/lib/tests/event_course_module_instance_list_viewed.php b/lib/tests/event_course_module_instance_list_viewed.php index b129c7814d7d0..3789ab7625c3a 100644 --- a/lib/tests/event_course_module_instance_list_viewed.php +++ b/lib/tests/event_course_module_instance_list_viewed.php @@ -57,6 +57,7 @@ public function test_event_attributes() { $this->assertEventLegacyLogData($legacydata, $event); $url = new moodle_url('/mod/unittests/index.php', array('id' => $course->id)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } diff --git a/lib/tests/event_course_module_viewed.php b/lib/tests/event_course_module_viewed.php index 7977642d11a25..28e7bd144ad91 100644 --- a/lib/tests/event_course_module_viewed.php +++ b/lib/tests/event_course_module_viewed.php @@ -64,6 +64,7 @@ public function test_event_attributes() { $this->assertSame('feedback', $event->objecttable); $url = new moodle_url('/mod/feedback/view.php', array('id' => $cm->id)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } diff --git a/lib/tests/event_test.php b/lib/tests/event_test.php index a85276d5e893c..713fc14b649f6 100644 --- a/lib/tests/event_test.php +++ b/lib/tests/event_test.php @@ -749,4 +749,16 @@ public function test_iteration() { $this->assertSame($event->get_data(), $data); } + + /** + * @expectedException PHPUnit_Framework_Error_Notice + */ + public function test_context_not_used() { + $event = \core_tests\event\context_used_in_event::create(array('courseid' => 1, 'other' => array('sample' => 1, 'xx' => 10))); + $this->assertEventContextNotUsed($event); + + $eventcontext = phpunit_event_mock::testable_get_event_context($event); + phpunit_event_mock::testable_set_event_context($event, null); + $this->assertEventContextNotUsed($event); + } } diff --git a/lib/tests/events_test.php b/lib/tests/events_test.php index e298bcc4271f4..cd54a1c8668a1 100644 --- a/lib/tests/events_test.php +++ b/lib/tests/events_test.php @@ -51,6 +51,7 @@ public function test_course_category_created() { $this->assertEquals(context_coursecat::instance($category->id), $event->get_context()); $expected = array(SITEID, 'category', 'add', 'editcategory.php?id=' . $category->id, $category->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -139,6 +140,7 @@ public function test_course_category_updated() { $this->assertEquals(context_coursecat::instance($category2->id), $event->get_context()); $expected = array(SITEID, 'category', 'show', 'editcategory.php?id=' . $category2->id, $category2->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -170,5 +172,6 @@ public function test_email_failed() { $this->assertEquals(context_system::instance(), $event->get_context()); $expected = array(SITEID, 'library', 'mailer', qualified_me(), 'ERROR: The email failed to send!'); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/lib/tests/fixtures/event_fixtures.php b/lib/tests/fixtures/event_fixtures.php index a516184ff043b..a72532acd9927 100644 --- a/lib/tests/fixtures/event_fixtures.php +++ b/lib/tests/fixtures/event_fixtures.php @@ -258,3 +258,29 @@ protected function init() { class course_module_viewed_noinit extends \core\event\course_module_viewed { } +/** + * Event to test context used in event functions + */ +class context_used_in_event extends \core\event\base { + public function get_description() { + return $this->context->instanceid . " Description"; + } + + protected function init() { + $this->data['crud'] = 'u'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->context = \context_system::instance(); + } + + public function get_url() { + return new \moodle_url('/somepath/somefile.php', array('id' => $this->context->instanceid)); + } + + protected function get_legacy_eventdata() { + return array($this->data['courseid'], $this->context->instanceid); + } + + protected function get_legacy_logdata() { + return array($this->data['courseid'], 'core_unittest', 'view', 'unittest.php?id=' . $this->context->instanceid); + } +} diff --git a/lib/tests/moodlelib_test.php b/lib/tests/moodlelib_test.php index 5971a4a151bee..dbb4b80b6ed30 100644 --- a/lib/tests/moodlelib_test.php +++ b/lib/tests/moodlelib_test.php @@ -1889,6 +1889,7 @@ public function test_delete_user() { $this->assertSame($eventdata['other']['picture'], $user->picture); $this->assertSame($eventdata['other']['mnethostid'], $user->mnethostid); $this->assertEquals($user, $event->get_record_snapshot('user', $event->objectid)); + $this->assertEventContextNotUsed($event); // Try invalid params. $record = new stdClass(); @@ -2459,6 +2460,7 @@ public function test_complete_user_login() { $this->assertEquals('user', $event->objecttable); $this->assertEquals($user->id, $event->objectid); $this->assertEquals(context_system::instance()->id, $event->contextid); + $this->assertEventContextNotUsed($event); $user = $DB->get_record('user', array('id'=>$user->id)); @@ -2504,6 +2506,7 @@ public function test_require_logout() { $expectedlogdata = array(SITEID, 'user', 'logout', 'view.php?id='.$event->objectid.'&course='.SITEID, $event->objectid, 0, $event->objectid); $this->assertEventLegacyLogData($expectedlogdata, $event); + $this->assertEventContextNotUsed($event); } public function test_email_to_user() { @@ -2586,6 +2589,7 @@ public function test_user_updated_event() { $this->assertEquals(context_user::instance($user->id), $event->get_context()); $expectedlogdata = array(SITEID, 'user', 'update', 'view.php?id='.$user->id, ''); $this->assertEventLegacyLogData($expectedlogdata, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/assign/submission/comments/tests/events_test.php b/mod/assign/submission/comments/tests/events_test.php index 035760640eeab..76b2fa314d558 100644 --- a/mod/assign/submission/comments/tests/events_test.php +++ b/mod/assign/submission/comments/tests/events_test.php @@ -75,6 +75,7 @@ public function test_comment_created() { $this->assertEquals($context, $event->get_context()); $url = new moodle_url('/mod/assign/view.php', array('id' => $submission->id)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } /** @@ -112,5 +113,6 @@ public function test_comment_deleted() { $this->assertEquals($context, $event->get_context()); $url = new moodle_url('/mod/assign/view.php', array('id' => $submission->id)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/assign/submission/file/tests/events_test.php b/mod/assign/submission/file/tests/events_test.php index 1aaa8717e689e..a6816a3e3b57d 100644 --- a/mod/assign/submission/file/tests/events_test.php +++ b/mod/assign/submission/file/tests/events_test.php @@ -90,6 +90,7 @@ public function test_assessable_uploaded() { $expected->files = $files; $expected->pathnamehashes = array($fi->get_pathnamehash(), $fi2->get_pathnamehash()); $this->assertEventLegacyData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/assign/submission/onlinetext/tests/events_test.php b/mod/assign/submission/onlinetext/tests/events_test.php index ce2616d6caa03..a84343d674870 100644 --- a/mod/assign/submission/onlinetext/tests/events_test.php +++ b/mod/assign/submission/onlinetext/tests/events_test.php @@ -70,6 +70,7 @@ public function test_assessable_uploaded() { $expected->userid = $user->id; $expected->content = 'Submission text'; $this->assertEventLegacyData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/book/tests/events_test.php b/mod/book/tests/events_test.php index 81d5089410ffa..3f4dfc353a235 100644 --- a/mod/book/tests/events_test.php +++ b/mod/book/tests/events_test.php @@ -70,6 +70,7 @@ public function test_chapter_created() { $expected = array($course->id, 'book', 'add chapter', 'view.php?id='.$book->cmid.'&chapterid='.$chapter->id, $chapter->id, $book->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_chapter_updated() { @@ -102,6 +103,7 @@ public function test_chapter_updated() { $expected = array($course->id, 'book', 'update chapter', 'view.php?id='.$book->cmid.'&chapterid='.$chapter->id, $chapter->id, $book->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_chapter_deleted() { @@ -135,6 +137,7 @@ public function test_chapter_deleted() { $this->assertEquals($chapter->id, $event->objectid); $this->assertEquals($chapter, $event->get_record_snapshot('book_chapters', $chapter->id)); $this->assertEventLegacyLogData(array('1', 2, false), $event); + $this->assertEventContextNotUsed($event); } public function test_course_module_instance_list_viewed() { @@ -159,6 +162,7 @@ public function test_course_module_instance_list_viewed() { $this->assertEquals(context_course::instance($course->id), $event->get_context()); $expected = array($course->id, 'book', 'view all', 'index.php?id='.$course->id, ''); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_course_module_viewed() { @@ -187,6 +191,7 @@ public function test_course_module_viewed() { $this->assertEquals($book->id, $event->objectid); $expected = array($course->id, 'book', 'view', 'view.php?id=' . $book->cmid, $book->id, $book->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_chapter_viewed() { @@ -219,6 +224,7 @@ public function test_chapter_viewed() { $expected = array($course->id, 'book', 'view chapter', 'view.php?id=' . $book->cmid . '&chapterid=' . $chapter->id, $chapter->id, $book->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/book/tool/exportimscp/tests/events_test.php b/mod/book/tool/exportimscp/tests/events_test.php index 9ca78a2e6067e..e83d2f159ec63 100644 --- a/mod/book/tool/exportimscp/tests/events_test.php +++ b/mod/book/tool/exportimscp/tests/events_test.php @@ -67,6 +67,7 @@ public function test_book_exported() { $expected = array($course->id, 'book', 'exportimscp', 'tool/exportimscp/index.php?id=' . $book->cmid, $book->id, $book->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/book/tool/importhtml/tests/locallib_test.php b/mod/book/tool/importhtml/tests/locallib_test.php index 71909ab98c864..1ab755f4ac99b 100644 --- a/mod/book/tool/importhtml/tests/locallib_test.php +++ b/mod/book/tool/importhtml/tests/locallib_test.php @@ -70,6 +70,7 @@ public function test_import_chapters_events() { $this->assertEquals($context, $event->get_context()); $chapter = $event->get_record_snapshot('book_chapters', $event->objectid); $this->assertNotEmpty($chapter); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/book/tool/print/tests/events_test.php b/mod/book/tool/print/tests/events_test.php index 82620fdf4338e..bd3fd7d2b5411 100644 --- a/mod/book/tool/print/tests/events_test.php +++ b/mod/book/tool/print/tests/events_test.php @@ -66,6 +66,7 @@ public function test_book_printed() { $this->assertEquals($book->id, $event->objectid); $expected = array($course->id, 'book', 'print', 'tool/print/index.php?id=' . $book->cmid, $book->id, $book->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } @@ -98,6 +99,7 @@ public function test_chapter_printed() { $expected = array($course->id, 'book', 'print chapter', 'tool/print/index.php?id=' . $book->cmid . '&chapterid=' . $chapter->id, $chapter->id, $book->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/chat/tests/events_test.php b/mod/chat/tests/events_test.php index fe115e07b53c5..85a6558a9ab3f 100644 --- a/mod/chat/tests/events_test.php +++ b/mod/chat/tests/events_test.php @@ -89,6 +89,7 @@ public function test_message_sent() { $this->assertEquals($user2->id, $event->userid); $expected = array($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id, $user2->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); // Sending a message from the system should not trigger any event. $sink->clear(); @@ -132,6 +133,7 @@ public function test_sessions_viewed() { $this->assertEquals($chat, $event->get_record_snapshot('chat', $chat->id)); $expected = array($course->id, 'chat', 'report', "report.php?id=$chat->cmid", $chat->id, $chat->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_course_module_instance_list_viewed() { @@ -156,6 +158,7 @@ public function test_course_module_instance_list_viewed() { $this->assertEquals(context_course::instance($course->id), $event->get_context()); $expected = array($course->id, 'chat', 'view all', "index.php?id=$course->id", ''); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/choice/tests/events_test.php b/mod/choice/tests/events_test.php index b747e93b0beed..4b85263fed360 100644 --- a/mod/choice/tests/events_test.php +++ b/mod/choice/tests/events_test.php @@ -48,14 +48,7 @@ class mod_choice_events_testcase extends advanced_testcase { protected $context; /** - * Setup - * often - * used - * objects - * for - * the - * following - * tests. + * Setup often used objects for the following tests. */ protected function setup() { global $DB; @@ -65,7 +58,7 @@ protected function setup() { $this->course = $this->getDataGenerator()->create_course(); $this->choice = $this->getDataGenerator()->create_module('choice', array('course' => $this->course->id)); $this->cm = $DB->get_record('course_modules', array('id' => $this->choice->cmid)); - $this->context = context_module::instance($this->choice->id); + $this->context = context_module::instance($this->choice->cmid); } /** @@ -89,6 +82,7 @@ public function test_answer_submitted() { $this->assertEquals(3, $events[0]->other['optionid']); $expected = array($this->course->id, "choice", "choose", 'view.php?id=' . $this->cm->id, $this->choice->id, $this->cm->id); $this->assertEventLegacyLogData($expected, $events[0]); + $this->assertEventContextNotUsed($events[0]); $sink->close(); } @@ -110,6 +104,7 @@ public function test_answer_submitted_other_exception() { $this->setExpectedException('coding_exception'); $event = \mod_choice\event\answer_submitted::create($eventdata); $event->trigger(); + $this->assertEventContextNotUsed($event); } /** @@ -139,6 +134,7 @@ public function test_answer_updated() { $expected = array($this->course->id, "choice", "choose again", 'view.php?id=' . $this->cm->id, $this->choice->id, $this->cm->id); $this->assertEventLegacyLogData($expected, $events[0]); + $this->assertEventContextNotUsed($events[0]); $sink->close(); } @@ -161,6 +157,7 @@ public function test_answer_updated_other_exception() { $this->setExpectedException('coding_exception'); $event = \mod_choice\event\answer_updated::create($eventdata); $event->trigger(); + $this->assertEventContextNotUsed($event); } /** @@ -196,6 +193,7 @@ public function test_report_viewed() { $expected = array($this->course->id, "choice", "report", 'report.php?id=' . $this->context->instanceid, $this->choice->id, $this->context->instanceid); $this->assertEventLegacyLogData($expected, $event[0]); + $this->assertEventContextNotUsed($event[0]); $sink->close(); } @@ -230,6 +228,7 @@ public function test_course_module_viewed() { $expected = array($this->course->id, "choice", "view", 'view.php?id=' . $this->context->instanceid, $this->choice->id, $this->context->instanceid); $this->assertEventLegacyLogData($expected, $event[0]); + $this->assertEventContextNotUsed($event[0]); $sink->close(); } @@ -254,5 +253,6 @@ public function test_course_module_instance_list_viewed_viewed() { $this->assertEquals(context_course::instance($this->course->id), $event->get_context()); $expected = array($this->course->id, 'choice', 'view all', 'index.php?id=' . $this->course->id, ''); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/data/tests/lib_test.php b/mod/data/tests/lib_test.php index 1a42142906d87..247ded7165498 100644 --- a/mod/data/tests/lib_test.php +++ b/mod/data/tests/lib_test.php @@ -165,6 +165,7 @@ public function test_data_comment_created_event() { $this->assertEquals($context, $event->get_context()); $url = new moodle_url('/mod/data/view.php', array('id' => $module->id)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } /** @@ -228,5 +229,6 @@ public function test_data_comment_deleted_event() { $this->assertEquals($context, $event->get_context()); $url = new moodle_url('/mod/data/view.php', array('id' => $module->id)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/feedback/tests/events_test.php b/mod/feedback/tests/events_test.php index a23b6a57af9be..947541bdfc7a3 100644 --- a/mod/feedback/tests/events_test.php +++ b/mod/feedback/tests/events_test.php @@ -164,6 +164,7 @@ public function test_response_deleted_event() { $this->assertTrue($event->can_view()); $this->setAdminUser(); $this->assertTrue($event->can_view()); + $this->assertEventContextNotUsed($event); } /** @@ -182,6 +183,7 @@ public function test_response_deleted_event_exceptions() { 'objectid' => $this->eventfeedbackcompleted->id, 'other' => array('cmid' => $this->eventcm->id, 'anonymous' => 2) )); + $this->assertEventContextNotUsed($event); $this->fail("Event validation should not allow \\mod_feedback\\event\\response_deleted to be triggered without other['instanceid']"); } catch (coding_exception $e) { @@ -291,7 +293,7 @@ public function test_response_submitted_event() { $this->assertTrue($event->can_view()); $this->setAdminUser(); $this->assertTrue($event->can_view()); - + $this->assertEventContextNotUsed($event); } /** diff --git a/mod/folder/tests/events_test.php b/mod/folder/tests/events_test.php index 50fff0429c6f6..a7b54a4002711 100644 --- a/mod/folder/tests/events_test.php +++ b/mod/folder/tests/events_test.php @@ -66,5 +66,6 @@ public function test_folder_updated() { $this->assertEquals($folder->id, $event->objectid); $expected = array($course->id, 'folder', 'edit', 'edit.php?id=' . $folder->cmid, $folder->id, $folder->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/forum/tests/lib_test.php b/mod/forum/tests/lib_test.php index 3d03583b0e6dc..a6cb6b0aa79e7 100644 --- a/mod/forum/tests/lib_test.php +++ b/mod/forum/tests/lib_test.php @@ -73,6 +73,7 @@ public function test_forum_trigger_content_uploaded_event() { $expected->content = $fakepost->message; $expected->pathnamehashes = array($fi->get_pathnamehash()); $this->assertEventLegacyData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_forum_get_courses_user_posted_in() { diff --git a/mod/glossary/tests/events_test.php b/mod/glossary/tests/events_test.php index f7f2a73f424bf..45fc60eef8f3b 100644 --- a/mod/glossary/tests/events_test.php +++ b/mod/glossary/tests/events_test.php @@ -76,6 +76,7 @@ public function test_comment_created() { $this->assertEquals($context, $event->get_context()); $url = new moodle_url('/mod/glossary/view.php', array('id' => $glossary->id)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } /** @@ -120,5 +121,6 @@ public function test_comment_deleted() { $this->assertEquals($context, $event->get_context()); $url = new moodle_url('/mod/glossary/view.php', array('id' => $glossary->id)); $this->assertEquals($url, $event->get_url()); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/lesson/tests/events_test.php b/mod/lesson/tests/events_test.php index e0b202ccf8cf1..820ebedd485c5 100644 --- a/mod/lesson/tests/events_test.php +++ b/mod/lesson/tests/events_test.php @@ -80,6 +80,7 @@ public function test_essay_attempt_viewed() { $expected = array($this->course->id, 'lesson', 'view grade', 'essay.php?id=' . $this->lesson->properties()->cmid . '&mode=grade&attemptid=1', get_string('manualgrading', 'lesson'), $this->lesson->properties()->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -119,6 +120,7 @@ public function test_highscore_added() { $expected = array($this->course->id, 'lesson', 'update highscores', 'highscores.php?id=' . $this->lesson->properties()->cmid, 'noob', $this->lesson->properties()->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -147,6 +149,7 @@ public function test_highscores_viewed() { $expected = array($this->course->id, 'lesson', 'view highscores', 'highscores.php?id=' . $this->lesson->properties()->cmid, $this->lesson->properties()->name, $this->lesson->properties()->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -165,6 +168,7 @@ public function test_lesson_started() { $expected = array($this->course->id, 'lesson', 'start', 'view.php?id=' . $this->lesson->properties()->cmid, $this->lesson->properties()->id, $this->lesson->properties()->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -193,6 +197,7 @@ public function test_lesson_ended() { $expected = array($this->course->id, 'lesson', 'end', 'view.php?id=' . $this->lesson->properties()->cmid, $this->lesson->properties()->id, $this->lesson->properties()->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -228,5 +233,6 @@ public function test_essay_assessed() { $expected = array($this->course->id, 'lesson', 'update grade', 'essay.php?id=' . $this->lesson->properties()->cmid, $this->lesson->name, $this->lesson->properties()->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/quiz/tests/events_test.php b/mod/quiz/tests/events_test.php index 1743af0c37de1..d7d34b3ac4172 100644 --- a/mod/quiz/tests/events_test.php +++ b/mod/quiz/tests/events_test.php @@ -117,6 +117,7 @@ public function test_attempt_submitted() { $legacydata->submitterid = null; $legacydata->timefinish = $timefinish; $this->assertEventLegacyData($legacydata, $event); + $this->assertEventContextNotUsed($event); } public function test_attempt_becameoverdue() { @@ -150,6 +151,7 @@ public function test_attempt_becameoverdue() { $legacydata->quizid = $quizobj->get_quizid(); $legacydata->submitterid = null; // Should be the user, but PHP Unit complains... $this->assertEventLegacyData($legacydata, $event); + $this->assertEventContextNotUsed($event); } public function test_attempt_abandoned() { @@ -183,6 +185,7 @@ public function test_attempt_abandoned() { $legacydata->quizid = $quizobj->get_quizid(); $legacydata->submitterid = null; // Should be the user, but PHP Unit complains... $this->assertEventLegacyData($legacydata, $event); + $this->assertEventContextNotUsed($event); } public function test_attempt_started() { @@ -218,5 +221,6 @@ public function test_attempt_started() { $this->assertEquals($quizobj->get_context(), $event->get_context()); $this->assertEquals('quiz_attempt_started', $event->get_legacy_eventname()); $this->assertEventLegacyData($legacydata, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/resource/tests/events_test.php b/mod/resource/tests/events_test.php index 10a77a902a5d4..da21c0551a2a5 100644 --- a/mod/resource/tests/events_test.php +++ b/mod/resource/tests/events_test.php @@ -68,6 +68,7 @@ public function test_course_module_instance_list_viewed() { $this->assertEquals(context_course::instance($course->id), $event->get_context()); $expected = array($course->id, 'resource', 'view all', 'index.php?id='.$course->id, ''); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -99,5 +100,6 @@ public function test_course_module_viewed() { $this->assertEquals($resource->id, $event->objectid); $expected = array($course->id, 'resource', 'view', 'view.php?id=' . $resource->cmid, $resource->id, $resource->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/mod/scorm/tests/event_test.php b/mod/scorm/tests/event_test.php index d6ae74eb1bb75..dbcbd04bb1be8 100644 --- a/mod/scorm/tests/event_test.php +++ b/mod/scorm/tests/event_test.php @@ -80,6 +80,7 @@ public function test_attempt_deleted_event() { $expected = array($this->eventcourse->id, 'scorm', 'delete attempts', 'report.php?id=' . $this->eventcm->id, 4, $this->eventscorm->id); $this->assertEventLegacyLogData($expected, $events[0]); + $this->assertEventContextNotUsed($event); // Test event validations. $this->setExpectedException('coding_exception'); @@ -113,6 +114,7 @@ public function test_course_module_viewed_event() { $expected = array($this->eventcourse->id, 'scorm', 'pre-view', 'view.php?id=' . $this->eventcm->id, $this->eventscorm->id, $this->eventcm->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -136,6 +138,7 @@ public function test_course_module_instance_list_viewed_event() { // Check that the legacy log data is valid. $expected = array($this->eventcourse->id, 'scorm', 'view all', 'index.php?id=' . $this->eventcourse->id, ''); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -162,6 +165,7 @@ public function test_interactions_viewed_event() { $expected = array($this->eventcourse->id, 'scorm', 'userreportinteractions', 'report/userreportinteractions.php?id=' . $this->eventcm->id . '&user=5&attempt=' . 2, $this->eventscorm->id, $this->eventcm->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -216,6 +220,7 @@ public function test_report_viewed_event() { $expected = array($this->eventcourse->id, 'scorm', 'report', 'report.php?id=' . $this->eventcm->id . '&mode=basic', $this->eventscorm->id, $this->eventcm->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); // Test validations. $this->setExpectedException('coding_exception'); @@ -250,6 +255,7 @@ public function test_sco_launched_event() { $expected = array($this->eventcourse->id, 'scorm', 'launch', 'view.php?id=' . $this->eventcm->id, 'url_to_content_that_was_laoded.php', $this->eventcm->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); // Test validations. $this->setExpectedException('coding_exception'); @@ -285,6 +291,7 @@ public function test_tracks_viewed_event() { $expected = array($this->eventcourse->id, 'scorm', 'userreporttracks', 'report/userreporttracks.php?id=' . $this->eventcm->id . '&user=5&attempt=' . 2 . '&scoid=3', $this->eventscorm->id, $this->eventcm->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -352,6 +359,7 @@ public function test_user_report_viewed_event() { $expected = array($this->eventcourse->id, 'scorm', 'userreport', 'report/userreport.php?id=' . $this->eventcm->id . '&user=5&attempt=' . 2, $this->eventscorm->id, $this->eventcm->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** diff --git a/mod/wiki/tests/events_test.php b/mod/wiki/tests/events_test.php index 5917a40a03d08..9b0d3243ec97f 100644 --- a/mod/wiki/tests/events_test.php +++ b/mod/wiki/tests/events_test.php @@ -83,6 +83,7 @@ public function test_comment_created() { $this->assertInstanceOf('\mod_wiki\event\comment_created', $event); $this->assertEquals($context, $event->get_context()); $this->assertEquals($page->id, $event->other['itemid']); + $this->assertEventContextNotUsed($event); } /** @@ -111,6 +112,7 @@ public function test_comment_deleted() { $this->assertInstanceOf('\mod_wiki\event\comment_deleted', $event); $this->assertEquals($context, $event->get_context()); $this->assertEquals($page->id, $event->other['itemid']); + $this->assertEventContextNotUsed($event); } /** @@ -142,6 +144,7 @@ public function test_comment_viewed() { $this->assertEquals($context, $event->get_context()); $expected = array($this->course->id, 'wiki', 'comments', 'comments.php?pageid=' . $page->id, $page->id, $this->wiki->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -169,6 +172,7 @@ public function test_course_module_instance_list_viewed() { $this->assertEquals($context, $event->get_context()); $expected = array($this->course->id, 'wiki', 'view all', 'index.php?id=' . $this->course->id, ''); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -201,6 +205,7 @@ public function test_course_module_viewed() { $expected = array($this->course->id, 'wiki', 'view', 'view.php?id=' . $this->wiki->cmid, $this->wiki->id, $this->wiki->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -234,6 +239,7 @@ public function test_page_viewed() { $this->assertEquals($page->id, $event->objectid); $expected = array($this->course->id, 'wiki', 'view', 'view.php?pageid=' . $page->id, $page->id, $this->wiki->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -268,6 +274,7 @@ public function test_pretty_page_viewed() { $this->assertEquals($page->id, $event->objectid); $expected = array($this->course->id, 'wiki', 'view', 'prettyview.php?pageid=' . $page->id, $page->id, $this->wiki->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -294,6 +301,7 @@ public function test_page_created() { $expected = array($this->course->id, 'wiki', 'add page', 'view.php?pageid=' . $page->id, $page->id, $this->wiki->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -358,6 +366,7 @@ public function test_page_deleted() { $this->assertEquals($page2->id, $event->objectid); $expected = array($this->course->id, 'wiki', 'admin', 'admin.php?pageid=' . $page2->id, $page2->id, $this->wiki->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -385,6 +394,7 @@ public function test_page_updated() { $expected = array($this->course->id, 'wiki', 'edit', 'view.php?pageid=' . $page->id, $page->id, $this->wiki->cmid); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -423,6 +433,7 @@ public function test_page_diff_viewed() { $expected = array($this->course->id, 'wiki', 'diff', 'diff.php?pageid=' . $page->id . '&comparewith=' . 1 . '&compare=' . 2, $page->id, $this->wiki->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -456,6 +467,7 @@ public function test_page_history_viewed() { $this->assertEquals($page->id, $event->objectid); $expected = array($this->course->id, 'wiki', 'history', 'history.php?pageid=' . $page->id, $page->id, $this->wiki->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -493,6 +505,7 @@ public function test_page_map_viewed() { $this->assertEquals(0, $event->other['option']); $expected = array($this->course->id, 'wiki', 'map', 'map.php?pageid=' . $page->id, $page->id, $this->wiki->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -531,6 +544,7 @@ public function test_page_version_viewed() { $expected = array($this->course->id, 'wiki', 'history', 'viewversion.php?pageid=' . $page->id . '&versionid=1', $page->id, $this->wiki->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } /** @@ -557,5 +571,6 @@ public function test_page_version_restored() { $this->assertEquals($page->id, $event->other['pageid']); $expected = array($this->course->id, 'wiki', 'restore', 'view.php?pageid=' . $page->id, $page->id, $this->wiki->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } } diff --git a/notes/tests/events_test.php b/notes/tests/events_test.php index b5e043343d34c..5ec91c145481f 100644 --- a/notes/tests/events_test.php +++ b/notes/tests/events_test.php @@ -83,6 +83,7 @@ public function test_note_deleted_event() { $logurl->set_anchor('note-' . $this->eventnote->id); $arr = array($this->eventnote->courseid, 'notes', 'delete', $logurl, 'delete note'); $this->assertEventLegacyLogData($arr, $event); + $this->assertEventContextNotUsed($event); } /** @@ -113,7 +114,7 @@ public function test_note_created_event() { $logurl->set_anchor('note-' . $note->id); $arr = array($note->courseid, 'notes', 'add', $logurl, 'add note'); $this->assertEventLegacyLogData($arr, $event); - + $this->assertEventContextNotUsed($event); } /** @@ -144,7 +145,7 @@ public function test_note_updated_event() { $logurl->set_anchor('note-' . $note->id); $arr = array($note->courseid, 'notes', 'update', $logurl, 'update note'); $this->assertEventLegacyLogData($arr, $event); - + $this->assertEventContextNotUsed($event); } } diff --git a/webservice/tests/events_test.php b/webservice/tests/events_test.php index 7152077703d8a..955d49b1fcf82 100644 --- a/webservice/tests/events_test.php +++ b/webservice/tests/events_test.php @@ -63,6 +63,7 @@ public function test_function_called() { $this->assertEquals(context_system::instance(), $event->get_context()); $this->assertEquals('A function', $event->other['function']); $this->assertEventLegacyLogData($fakelogdata, $event); + $this->assertEventContextNotUsed($event); } public function test_login_failed() { @@ -101,6 +102,7 @@ public function test_login_failed() { $this->fail('The token cannot be allowed in \core\event\webservice_login_failed'); } catch (coding_exception $e) { } + $this->assertEventContextNotUsed($event); } public function test_service_created() { @@ -145,6 +147,7 @@ public function test_service_created() { $returnurl = $CFG->wwwroot . "/" . $CFG->admin . "/settings.php?section=externalservices"; $expected = array(SITEID, 'webservice', 'add', $returnurl, get_string('addservice', 'webservice', $service)); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_service_updated() { @@ -189,6 +192,7 @@ public function test_service_updated() { $returnurl = $CFG->wwwroot . "/" . $CFG->admin . "/settings.php?section=externalservices"; $expected = array(SITEID, 'webservice', 'edit', $returnurl, get_string('editservice', 'webservice', $service)); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_service_deleted() { @@ -233,6 +237,7 @@ public function test_service_deleted() { $returnurl = $CFG->wwwroot . "/" . $CFG->admin . "/settings.php?section=externalservices"; $expected = array(SITEID, 'webservice', 'delete', $returnurl, get_string('deleteservice', 'webservice', $service)); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_service_user_added() { @@ -261,6 +266,7 @@ public function test_service_user_added() { $expected = array(SITEID, 'core', 'assign', $CFG->admin . '/webservice/service_users.php?id=' . $params['objectid'], 'add', '', $params['relateduserid']); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_service_user_removed() { @@ -289,6 +295,7 @@ public function test_service_user_removed() { $expected = array(SITEID, 'core', 'assign', $CFG->admin . '/webservice/service_users.php?id=' . $params['objectid'], 'remove', '', $params['relateduserid']); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_token_created() { @@ -317,6 +324,7 @@ public function test_token_created() { $this->assertEquals(2, $event->relateduserid); $expected = array(SITEID, 'webservice', 'automatically create user token', '' , 'User ID: ' . 2); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } public function test_token_sent() { @@ -346,5 +354,6 @@ public function test_token_sent() { $this->assertEquals(1, $event->objectid); $expected = array(SITEID, 'webservice', 'sending requested user token', '' , 'User ID: ' . $user->id); $this->assertEventLegacyLogData($expected, $event); + $this->assertEventContextNotUsed($event); } }