From eac1383edb5f294352b9d38c681700841ef421dd Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Tue, 9 Sep 2014 09:22:20 +0200 Subject: [PATCH] MDL-46588 web services: Fixed system context instanceid eq 0 case --- lib/externallib.php | 2 +- lib/tests/externallib_test.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/externallib.php b/lib/externallib.php index 95039eecf0c..56144efcb3a 100644 --- a/lib/externallib.php +++ b/lib/externallib.php @@ -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']); diff --git a/lib/tests/externallib_test.php b/lib/tests/externallib_test.php index 369c342b466..1012a6d6053 100644 --- a/lib/tests/externallib_test.php +++ b/lib/tests/externallib_test.php @@ -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));