Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-37354-stable24' of git://github.com/mouneyrac/moodl…

…e into MOODLE_24_STABLE
  • Loading branch information...
commit c7e4ebf3f3ae908361df9feb39b4ebd9cddc611a 2 parents 70688fd + ada5df1
@stronk7 stronk7 authored
View
33 course/tests/externallib_test.php
@@ -76,6 +76,9 @@ public function test_create_categories() {
$createdcats = core_course_external::create_categories($categories);
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $createdcats = external_api::clean_returnvalue(core_course_external::create_categories_returns(), $createdcats);
+
// Initially confirm that base data was inserted correctly.
$this->assertEquals($category1->name, $createdcats[0]['name']);
$this->assertEquals($category2->name, $createdcats[1]['name']);
@@ -93,6 +96,9 @@ public function test_create_categories() {
$createdsubcats = core_course_external::create_categories($subcategories);
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $createdsubcats = external_api::clean_returnvalue(core_course_external::create_categories_returns(), $createdsubcats);
+
// Confirm that sub categories were inserted correctly.
$this->assertEquals($category3->name, $createdsubcats[0]['name']);
@@ -197,6 +203,9 @@ public function test_get_categories() {
array('key' => 'id', 'value' => $category1->id),
array('key' => 'visible', 'value' => 1)), 1);
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $categories = external_api::clean_returnvalue(core_course_external::get_categories_returns(), $categories);
+
// Check we retrieve the good total number of categories.
$this->assertEquals(2, count($categories));
@@ -214,6 +223,10 @@ public function test_get_categories() {
array('key' => 'id', 'value' => $category1->id),
array('key' => 'idnumber', 'value' => $category1->idnumber),
array('key' => 'visible', 'value' => 1)), 0);
+
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $categories = external_api::clean_returnvalue(core_course_external::get_categories_returns(), $categories);
+
$this->assertEquals(1, count($categories));
// Retrieve categories from parent.
@@ -223,6 +236,10 @@ public function test_get_categories() {
// Retrieve all categories.
$categories = core_course_external::get_categories();
+
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $categories = external_api::clean_returnvalue(core_course_external::get_categories_returns(), $categories);
+
$this->assertEquals($DB->count_records('course_categories'), count($categories));
// Call without required capability (it will fail cause of the search on idnumber).
@@ -354,6 +371,9 @@ public function test_create_courses() {
$createdcourses = core_course_external::create_courses($courses);
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $createdcourses = external_api::clean_returnvalue(core_course_external::create_courses_returns(), $createdcourses);
+
// Check that right number of courses were created.
$this->assertEquals(2, count($createdcourses));
@@ -492,6 +512,9 @@ public function test_get_courses () {
$courses = core_course_external::get_courses(array('ids' =>
array($course1->id, $course2->id)));
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $courses = external_api::clean_returnvalue(core_course_external::get_courses_returns(), $courses);
+
// Check we retrieve the good total number of categories.
$this->assertEquals(2, count($courses));
@@ -532,6 +555,10 @@ public function test_get_courses () {
// Get all courses in the DB
$courses = core_course_external::get_courses(array());
+
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $courses = external_api::clean_returnvalue(core_course_external::get_courses_returns(), $courses);
+
$this->assertEquals($DB->count_records('course'), count($courses));
}
@@ -559,6 +586,9 @@ public function test_get_course_contents() {
$courses = core_course_external::get_course_contents($course->id, array());
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $courses = external_api::clean_returnvalue(core_course_external::get_course_contents_returns(), $courses);
+
// Check that the course has the 3 created modules
$this->assertEquals(3, count($courses[0]['modules']));
}
@@ -602,6 +632,9 @@ public function test_duplicate_course() {
$duplicate = core_course_external::duplicate_course($course->id, $newcourse['fullname'],
$newcourse['shortname'], $newcourse['categoryid'], $newcourse['visible'], $newcourse['options']);
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $duplicate = external_api::clean_returnvalue(core_course_external::duplicate_course_returns(), $duplicate);
+
// Check that the course has been duplicated.
$this->assertEquals($newcourse['shortname'], $duplicate['shortname']);
}
View
9 enrol/tests/externallib_test.php
@@ -66,6 +66,9 @@ public function test_get_enrolled_users() {
// Call the external function.
$enrolledusers = core_enrol_external::get_enrolled_users($course->id);
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $enrolledusers = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $enrolledusers);
+
// Check we retrieve the good total number of enrolled users.
$this->assertEquals(3, count($enrolledusers));
@@ -109,6 +112,9 @@ public function test_get_users_courses() {
// Call the external function.
$enrolledincourses = core_enrol_external::get_users_courses($USER->id);
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $enrolledincourses = external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
+
// Check we retrieve the good total number of enrolled users.
$this->assertEquals(2, count($enrolledincourses));
}
@@ -156,6 +162,9 @@ public function test_get_enrolled_users_with_capability () {
$options = array();
$result = core_enrol_external::get_enrolled_users_with_capability($params, $options);
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $result = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_with_capability_returns(), $result);
+
// Check an array containing the expected user for the course capability is returned.
$expecteduserlist = $result[0];
$this->assertEquals($course1->id, $expecteduserlist['courseid']);
View
10 group/tests/externallib_test.php
@@ -66,6 +66,9 @@ public function test_create_groups() {
// Call the external function.
$groups = core_group_external::create_groups(array($group1, $group2));
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $groups = external_api::clean_returnvalue(core_group_external::create_groups_returns(), $groups);
+
// Checks against DB values
$this->assertEquals(2, count($groups));
foreach ($groups as $group) {
@@ -125,6 +128,9 @@ public function test_get_groups() {
// Call the external function.
$groups = core_group_external::get_groups(array($group1->id, $group2->id));
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $groups = external_api::clean_returnvalue(core_group_external::get_groups_returns(), $groups);
+
// Checks against DB values
$this->assertEquals(2, count($groups));
foreach ($groups as $group) {
@@ -151,7 +157,7 @@ public function test_get_groups() {
// Call without required capability
$this->unassignUserCapability('moodle/course:managegroups', $context->id, $roleid);
$this->setExpectedException('required_capability_exception');
- $froups = core_group_external::get_groups(array($group1->id, $group2->id));
+ $groups = core_group_external::get_groups(array($group1->id, $group2->id));
}
/**
@@ -201,4 +207,4 @@ public function test_delete_groups() {
$this->setExpectedException('required_capability_exception');
$froups = core_group_external::delete_groups(array($group3->id));
}
-}
+}
View
15 lib/external/tests/externallib_test.php
@@ -44,6 +44,10 @@ public function test_get_string() {
$returnedstring = core_external::get_string('addservice', 'webservice',
array(array('name' => 'name', 'value' => $service->name),
array('name' => 'id', 'value' => $service->id)));
+
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $returnedstring = external_api::clean_returnvalue(core_external::get_string_returns(), $returnedstring);
+
$corestring = get_string('addservice', 'webservice', $service);
$this->assertEquals($corestring, $returnedstring);
@@ -51,11 +55,19 @@ public function test_get_string() {
$acapname = 'A capability name';
$returnedstring = core_external::get_string('missingrequiredcapability', 'webservice',
array(array('value' => $acapname)));
+
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $returnedstring = external_api::clean_returnvalue(core_external::get_string_returns(), $returnedstring);
+
$corestring = get_string('missingrequiredcapability', 'webservice', $acapname);
$this->assertEquals($corestring, $returnedstring);
// String without parameters.
$returnedstring = core_external::get_string('missingpassword', 'webservice');
+
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $returnedstring = external_api::clean_returnvalue(core_external::get_string_returns(), $returnedstring);
+
$corestring = get_string('missingpassword', 'webservice');
$this->assertEquals($corestring, $returnedstring);
@@ -87,6 +99,9 @@ public function test_get_strings() {
array('stringid' => 'addaservice', 'component' => 'webservice')
));
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $returnedstrings = external_api::clean_returnvalue(core_external::get_strings_returns(), $returnedstrings);
+
foreach($returnedstrings as $returnedstring) {
$corestring = get_string($returnedstring['stringid'], $returnedstring['component'], $service);
$this->assertEquals($corestring, $returnedstring['string']);
View
5 message/tests/externallib_test.php
@@ -64,6 +64,9 @@ public function test_send_instant_messages() {
$sentmessages = core_message_external::send_instant_messages($messages);
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $sentmessages = external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
+
$themessage = $DB->get_record('message', array('id' => $sentmessages[0]['msgid']));
// Confirm that the message was inserted correctly.
@@ -72,4 +75,4 @@ public function test_send_instant_messages() {
$this->assertEquals($themessage->smallmessage, $message1['text']);
$this->assertEquals($sentmessages[0]['clientmsgid'], $message1['clientmsgid']);
}
-}
+}
View
15 mod/assign/tests/externallib_test.php
@@ -91,6 +91,9 @@ public function test_get_grades () {
$assignmentids[] = $assign->id;
$result = mod_assign_external::get_grades($assignmentids);
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $result = external_api::clean_returnvalue(mod_assign_external::get_grades_returns(), $result);
+
// Check that the correct grade information for the student is returned.
$this->assertEquals(1, count($result['assignments']));
$assignment = $result['assignments'][0];
@@ -158,6 +161,10 @@ public function test_get_assignments () {
));
$result = mod_assign_external::get_assignments();
+
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+
// Check the course and assignment are returned.
$this->assertEquals(1, count($result['courses']));
$course = $result['courses'][0];
@@ -169,6 +176,10 @@ public function test_get_assignments () {
$this->assertEquals('lightwork assignment', $assignment['name']);
$result = mod_assign_external::get_assignments(array($course1->id));
+
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+
$this->assertEquals(1, count($result['courses']));
$course = $result['courses'][0];
$this->assertEquals('Lightwork Course 1', $course['fullname']);
@@ -179,6 +190,10 @@ public function test_get_assignments () {
$this->assertEquals('lightwork assignment', $assignment['name']);
$result = mod_assign_external::get_assignments(array($course2->id));
+
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+
$this->assertEquals(0, count($result['courses']));
$this->assertEquals(1, count($result['warnings']));
}
View
3  notes/tests/externallib_test.php
@@ -59,6 +59,9 @@ public function test_create_notes() {
$creatednotes = core_notes_external::create_notes($notes);
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
+
$thenote = $DB->get_record('post', array('id' => $creatednotes[0]['noteid']));
// Confirm that base note data was inserted correctly.
View
17 user/tests/externallib_test.php
@@ -96,6 +96,9 @@ public function test_get_course_user_profiles() {
array('userid' => $user1->id, 'courseid' => $course->id),
array('userid' => $user2->id, 'courseid' => $course->id)));
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $enrolledusers = external_api::clean_returnvalue(core_user_external::get_course_user_profiles_returns(), $enrolledusers);
+
// Check we retrieve the good total number of enrolled users + no error on capability.
$this->assertEquals(3, count($enrolledusers));
@@ -109,6 +112,9 @@ public function test_get_course_user_profiles() {
array('userid' => $user1->id, 'courseid' => $course->id),
array('userid' => $user2->id, 'courseid' => $course->id)));
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $enrolledusers = external_api::clean_returnvalue(core_user_external::get_course_user_profiles_returns(), $enrolledusers);
+
foreach($enrolledusers as $enrolleduser) {
if ($enrolleduser['username'] == $user1->username) {
$this->assertEquals($user1->idnumber, $enrolleduser['idnumber']);
@@ -163,6 +169,9 @@ public function test_create_users() {
// Call the external function.
$createdusers = core_user_external::create_users(array($user1));
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $createdusers = external_api::clean_returnvalue(core_user_external::create_users_returns(), $createdusers);
+
// Check we retrieve the good total number of created users + no error on capability.
$this->assertEquals(1, count($createdusers));
@@ -261,6 +270,9 @@ public function test_get_users_by_id() {
$returnedusers = core_user_external::get_users_by_id(array(
$USER->id, $user1->id, $user2->id));
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $returnedusers = external_api::clean_returnvalue(core_user_external::get_users_by_id_returns(), $returnedusers);
+
// Check we retrieve the good total number of enrolled users + no error on capability.
$this->assertEquals(3, count($returnedusers));
@@ -272,6 +284,9 @@ public function test_get_users_by_id() {
$returnedusers = core_user_external::get_users_by_id(array(
$USER->id, $user1->id, $user2->id));
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $returnedusers = external_api::clean_returnvalue(core_user_external::get_users_by_id_returns(), $returnedusers);
+
foreach($returnedusers as $enrolleduser) {
if ($enrolleduser['username'] == $user1->username) {
$this->assertEquals($user1->idnumber, $enrolleduser['idnumber']);
@@ -344,4 +359,4 @@ public function test_update_users() {
$this->setExpectedException('required_capability_exception');
core_user_external::update_users(array($user1));
}
-}
+}
View
3  webservice/tests/externallib_test.php
@@ -81,6 +81,9 @@ public function test_get_site_info() {
$siteinfo = core_webservice_external::get_site_info();
+ // We need to execute the return values cleaning process to simulate the web service server.
+ $siteinfo = external_api::clean_returnvalue(core_webservice_external::get_site_info_returns(), $siteinfo);
+
$this->assertEquals('johnd', $siteinfo['username']);
$this->assertEquals('John', $siteinfo['firstname']);
$this->assertEquals('Doe', $siteinfo['lastname']);
Please sign in to comment.
Something went wrong with that request. Please try again.