Skip to content

Commit

Permalink
Merge branch 'MDL-52895-master' of git://github.com/jleyva/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Feb 9, 2016
2 parents ba4fd38 + 0bf6c0b commit 37f77a1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
6 changes: 4 additions & 2 deletions mod/assign/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1544,13 +1544,15 @@ public function test_view_grading_table() {
// 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);
}

}
Expand Down
4 changes: 3 additions & 1 deletion mod/folder/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ public function test_view_folder() {
// 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);
}

}
Expand Down
8 changes: 6 additions & 2 deletions mod/imscp/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ public function test_view_imscp() {
// 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);
}

}
Expand Down Expand Up @@ -168,10 +170,12 @@ public function test_get_imscps_by_courses() {
$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']);
}
}
8 changes: 6 additions & 2 deletions mod/lti/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,13 @@ public function test_mod_lti_get_ltis_by_courses() {
$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']);
}

/**
Expand Down Expand Up @@ -264,13 +266,15 @@ public function test_view_lti() {
// 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);
}

}
Expand Down
4 changes: 3 additions & 1 deletion mod/page/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ public function test_view_page() {
// 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);
}

}
Expand Down
4 changes: 3 additions & 1 deletion mod/resource/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ public function test_view_resource() {
// 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);
}

}
Expand Down
4 changes: 3 additions & 1 deletion mod/url/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ public function test_view_url() {
// 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);
}

}
Expand Down

0 comments on commit 37f77a1

Please sign in to comment.