From 2a8ec1ce68b2bae35bdf153183959661f75be941 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Thu, 4 Sep 2014 11:06:48 +0200 Subject: [PATCH] MDL-46588 web services: Unit tests added --- lib/tests/externallib_test.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/tests/externallib_test.php b/lib/tests/externallib_test.php index f0a2a04cee4..369c342b466 100644 --- a/lib/tests/externallib_test.php +++ b/lib/tests/externallib_test.php @@ -147,6 +147,28 @@ class core_externallib_testcase extends advanced_testcase { $fetchedcontext = test_exernal_api::get_context_wrapper(array("contextlevel" => "course", "instanceid" => $course->id)); $this->assertEquals($realcontext, $fetchedcontext); + // Passing empty values. + try { + $fetchedcontext = test_exernal_api::get_context_wrapper(array("contextid" => 0)); + $this->fail('Exception expected from get_context_wrapper()'); + } catch (moodle_exception $e) { + $this->assertInstanceOf('invalid_parameter_exception', $e); + } + + try { + $fetchedcontext = test_exernal_api::get_context_wrapper(array("instanceid" => 0)); + $this->fail('Exception expected from get_context_wrapper()'); + } catch (moodle_exception $e) { + $this->assertInstanceOf('invalid_parameter_exception', $e); + } + + try { + $fetchedcontext = test_exernal_api::get_context_wrapper(array("contextid" => null)); + $this->fail('Exception expected from get_context_wrapper()'); + } catch (moodle_exception $e) { + $this->assertInstanceOf('invalid_parameter_exception', $e); + } + // Passing wrong level. $this->setExpectedException('invalid_parameter_exception'); $fetchedcontext = test_exernal_api::get_context_wrapper(array("contextlevel" => "random", "instanceid" => $course->id));