MDL-46588 web services: Fixed system context instanceid eq 0 case

This commit is contained in:
Juan Leyva 2014-09-09 09:22:20 +02:00
parent 60ac6e2915
commit eac1383edb
2 changed files with 6 additions and 1 deletions

View File

@ -379,7 +379,7 @@ class external_api {
$levels = context_helper::get_all_levels();
if (!empty($param['contextid'])) {
return context::instance_by_id($param['contextid'], IGNORE_MISSING);
} else if (!empty($param['contextlevel']) && !empty($param['instanceid'])) {
} else if (!empty($param['contextlevel']) && isset($param['instanceid'])) {
$contextlevel = "context_".$param['contextlevel'];
if (!array_search($contextlevel, $levels)) {
throw new invalid_parameter_exception('Invalid context level = '.$param['contextlevel']);

View File

@ -169,6 +169,11 @@ class core_externallib_testcase extends advanced_testcase {
$this->assertInstanceOf('invalid_parameter_exception', $e);
}
// Tests for context with instanceid equal to 0 (System context).
$realcontext = context_system::instance();
$fetchedcontext = test_exernal_api::get_context_wrapper(array("contextlevel" => "system", "instanceid" => 0));
$this->assertEquals($realcontext, $fetchedcontext);
// Passing wrong level.
$this->setExpectedException('invalid_parameter_exception');
$fetchedcontext = test_exernal_api::get_context_wrapper(array("contextlevel" => "random", "instanceid" => $course->id));