diff --git a/mod/assign/tests/externallib_test.php b/mod/assign/tests/externallib_test.php index 0dd6de1c140..78fa73e5565 100644 --- a/mod/assign/tests/externallib_test.php +++ b/mod/assign/tests/externallib_test.php @@ -1544,13 +1544,15 @@ class mod_assign_external_testcase extends externallib_advanced_testcase { // Test user with no capabilities. // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles. assign_capability('mod/assign:view', CAP_PROHIBIT, $teacherrole->id, $context->id); + // Empty all the caches that may be affected by this change. accesslib_clear_all_caches_for_unit_testing(); + course_modinfo::clear_instance_cache(); try { mod_assign_external::view_grading_table($assign->id); - $this->fail('Exception expected due to missing capability.'); + $this->fail('Exception expected due to missing view capability.'); } catch (moodle_exception $e) { - $this->assertEquals('nopermissions', $e->errorcode); + $this->assertEquals('requireloginerror', $e->errorcode); } } diff --git a/mod/folder/tests/externallib_test.php b/mod/folder/tests/externallib_test.php index 14c3cb50dfc..17f0ba92da4 100644 --- a/mod/folder/tests/externallib_test.php +++ b/mod/folder/tests/externallib_test.php @@ -99,13 +99,15 @@ class mod_folder_external_testcase extends externallib_advanced_testcase { // Test user with no capabilities. // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles. assign_capability('mod/folder:view', CAP_PROHIBIT, $studentrole->id, $context->id); + // Empty all the caches that may be affected by this change. accesslib_clear_all_caches_for_unit_testing(); + course_modinfo::clear_instance_cache(); try { mod_folder_external::view_folder($folder->id); $this->fail('Exception expected due to missing capability.'); } catch (moodle_exception $e) { - $this->assertEquals('nopermissions', $e->errorcode); + $this->assertEquals('requireloginerror', $e->errorcode); } } diff --git a/mod/imscp/tests/externallib_test.php b/mod/imscp/tests/externallib_test.php index 4a2904f037f..14b5c68c89e 100644 --- a/mod/imscp/tests/externallib_test.php +++ b/mod/imscp/tests/externallib_test.php @@ -99,13 +99,15 @@ class mod_imscp_external_testcase extends externallib_advanced_testcase { // Test user with no capabilities. // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles. assign_capability('mod/imscp:view', CAP_PROHIBIT, $studentrole->id, $context->id); + // Empty all the caches that may be affected by this change. accesslib_clear_all_caches_for_unit_testing(); + course_modinfo::clear_instance_cache(); try { mod_imscp_external::view_imscp($imscp->id); $this->fail('Exception expected due to missing capability.'); } catch (moodle_exception $e) { - $this->assertEquals('nopermissions', $e->errorcode); + $this->assertEquals('requireloginerror', $e->errorcode); } } @@ -168,10 +170,12 @@ class mod_imscp_external_testcase extends externallib_advanced_testcase { $contextcourse1 = context_course::instance($course1->id); // Prohibit capability = mod:imscp:view on Course1 for students. assign_capability('mod/imscp:view', CAP_PROHIBIT, $studentrole->id, $contextcourse1->id); + // Empty all the caches that may be affected by this change. accesslib_clear_all_caches_for_unit_testing(); + course_modinfo::clear_instance_cache(); $imscps = mod_imscp_external::get_imscps_by_courses(array($course1->id)); $imscps = external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps); - $this->assertFalse(isset($imscps['imscps'][0]['intro'])); + $this->assertCount(0, $imscps['imscps']); } } diff --git a/mod/lti/tests/externallib_test.php b/mod/lti/tests/externallib_test.php index 0fab2260393..51cd7b91d42 100644 --- a/mod/lti/tests/externallib_test.php +++ b/mod/lti/tests/externallib_test.php @@ -209,11 +209,13 @@ class mod_lti_external_testcase extends externallib_advanced_testcase { $contextcourse1 = context_course::instance($this->course->id); // Prohibit capability = mod:lti:view on Course1 for students. assign_capability('mod/lti:view', CAP_PROHIBIT, $this->studentrole->id, $contextcourse1->id); + // Empty all the caches that may be affected by this change. accesslib_clear_all_caches_for_unit_testing(); + course_modinfo::clear_instance_cache(); $ltis = mod_lti_external::get_ltis_by_courses(array($this->course->id)); $ltis = external_api::clean_returnvalue(mod_lti_external::get_ltis_by_courses_returns(), $ltis); - $this->assertFalse(isset($ltis['ltis'][0]['intro'])); + $this->assertCount(0, $ltis['ltis']); } /** @@ -264,13 +266,15 @@ class mod_lti_external_testcase extends externallib_advanced_testcase { // Test user with no capabilities. // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles. assign_capability('mod/lti:view', CAP_PROHIBIT, $this->studentrole->id, $this->context->id); + // Empty all the caches that may be affected by this change. accesslib_clear_all_caches_for_unit_testing(); + course_modinfo::clear_instance_cache(); try { mod_lti_external::view_lti($this->lti->id); $this->fail('Exception expected due to missing capability.'); } catch (moodle_exception $e) { - $this->assertEquals('nopermissions', $e->errorcode); + $this->assertEquals('requireloginerror', $e->errorcode); } } diff --git a/mod/page/tests/externallib_test.php b/mod/page/tests/externallib_test.php index 128e363c4ed..075af6e9971 100644 --- a/mod/page/tests/externallib_test.php +++ b/mod/page/tests/externallib_test.php @@ -98,13 +98,15 @@ class mod_page_external_testcase extends externallib_advanced_testcase { // Test user with no capabilities. // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles. assign_capability('mod/page:view', CAP_PROHIBIT, $studentrole->id, $context->id); + // Empty all the caches that may be affected by this change. accesslib_clear_all_caches_for_unit_testing(); + course_modinfo::clear_instance_cache(); try { mod_page_external::view_page($page->id); $this->fail('Exception expected due to missing capability.'); } catch (moodle_exception $e) { - $this->assertEquals('nopermissions', $e->errorcode); + $this->assertEquals('requireloginerror', $e->errorcode); } } diff --git a/mod/resource/tests/externallib_test.php b/mod/resource/tests/externallib_test.php index 6b79da136f5..8ce41c4fc1c 100644 --- a/mod/resource/tests/externallib_test.php +++ b/mod/resource/tests/externallib_test.php @@ -99,13 +99,15 @@ class mod_resource_external_testcase extends externallib_advanced_testcase { // Test user with no capabilities. // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles. assign_capability('mod/resource:view', CAP_PROHIBIT, $studentrole->id, $context->id); + // Empty all the caches that may be affected by this change. accesslib_clear_all_caches_for_unit_testing(); + course_modinfo::clear_instance_cache(); try { mod_resource_external::view_resource($resource->id); $this->fail('Exception expected due to missing capability.'); } catch (moodle_exception $e) { - $this->assertEquals('nopermissions', $e->errorcode); + $this->assertEquals('requireloginerror', $e->errorcode); } } diff --git a/mod/url/tests/externallib_test.php b/mod/url/tests/externallib_test.php index dd8cd6e1990..686c4227466 100644 --- a/mod/url/tests/externallib_test.php +++ b/mod/url/tests/externallib_test.php @@ -98,13 +98,15 @@ class mod_url_external_testcase extends externallib_advanced_testcase { // Test user with no capabilities. // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles. assign_capability('mod/url:view', CAP_PROHIBIT, $studentrole->id, $context->id); + // Empty all the caches that may be affected by this change. accesslib_clear_all_caches_for_unit_testing(); + course_modinfo::clear_instance_cache(); try { mod_url_external::view_url($url->id); $this->fail('Exception expected due to missing capability.'); } catch (moodle_exception $e) { - $this->assertEquals('nopermissions', $e->errorcode); + $this->assertEquals('requireloginerror', $e->errorcode); } }