Skip to content

Commit

Permalink
MDL-46588 web services: Unit tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Sep 12, 2014
1 parent 98dece2 commit 60ac6e2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ public function test_get_context_from_params() {
$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));
Expand Down

0 comments on commit 60ac6e2

Please sign in to comment.