Merge branch 'MDL-37354-master' of git://github.com/mouneyrac/moodle

Conflicts:
	message/tests/externallib_test.php
This commit is contained in:
Eloy Lafuente (stronk7) 2013-01-15 21:50:31 +01:00
commit 493d8f781c
9 changed files with 105 additions and 4 deletions

View File

@ -76,6 +76,9 @@ class core_course_external_testcase extends externallib_advanced_testcase {
$createdcats = core_course_external::create_categories($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. // Initially confirm that base data was inserted correctly.
$this->assertEquals($category1->name, $createdcats[0]['name']); $this->assertEquals($category1->name, $createdcats[0]['name']);
$this->assertEquals($category2->name, $createdcats[1]['name']); $this->assertEquals($category2->name, $createdcats[1]['name']);
@ -93,6 +96,9 @@ class core_course_external_testcase extends externallib_advanced_testcase {
$createdsubcats = core_course_external::create_categories($subcategories); $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. // Confirm that sub categories were inserted correctly.
$this->assertEquals($category3->name, $createdsubcats[0]['name']); $this->assertEquals($category3->name, $createdsubcats[0]['name']);
@ -197,6 +203,9 @@ class core_course_external_testcase extends externallib_advanced_testcase {
array('key' => 'id', 'value' => $category1->id), array('key' => 'id', 'value' => $category1->id),
array('key' => 'visible', 'value' => 1)), 1); 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. // Check we retrieve the good total number of categories.
$this->assertEquals(2, count($categories)); $this->assertEquals(2, count($categories));
@ -214,6 +223,10 @@ class core_course_external_testcase extends externallib_advanced_testcase {
array('key' => 'id', 'value' => $category1->id), array('key' => 'id', 'value' => $category1->id),
array('key' => 'idnumber', 'value' => $category1->idnumber), array('key' => 'idnumber', 'value' => $category1->idnumber),
array('key' => 'visible', 'value' => 1)), 0); 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)); $this->assertEquals(1, count($categories));
// Retrieve categories from parent. // Retrieve categories from parent.
@ -223,6 +236,10 @@ class core_course_external_testcase extends externallib_advanced_testcase {
// Retrieve all categories. // Retrieve all categories.
$categories = core_course_external::get_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)); $this->assertEquals($DB->count_records('course_categories'), count($categories));
// Call without required capability (it will fail cause of the search on idnumber). // Call without required capability (it will fail cause of the search on idnumber).
@ -354,6 +371,9 @@ class core_course_external_testcase extends externallib_advanced_testcase {
$createdcourses = core_course_external::create_courses($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. // Check that right number of courses were created.
$this->assertEquals(2, count($createdcourses)); $this->assertEquals(2, count($createdcourses));
@ -492,6 +512,9 @@ class core_course_external_testcase extends externallib_advanced_testcase {
$courses = core_course_external::get_courses(array('ids' => $courses = core_course_external::get_courses(array('ids' =>
array($course1->id, $course2->id))); 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. // Check we retrieve the good total number of categories.
$this->assertEquals(2, count($courses)); $this->assertEquals(2, count($courses));
@ -532,6 +555,10 @@ class core_course_external_testcase extends externallib_advanced_testcase {
// Get all courses in the DB // Get all courses in the DB
$courses = core_course_external::get_courses(array()); $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)); $this->assertEquals($DB->count_records('course'), count($courses));
} }
@ -559,6 +586,9 @@ class core_course_external_testcase extends externallib_advanced_testcase {
$courses = core_course_external::get_course_contents($course->id, array()); $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 // Check that the course has the 3 created modules
$this->assertEquals(3, count($courses[0]['modules'])); $this->assertEquals(3, count($courses[0]['modules']));
} }
@ -602,6 +632,9 @@ class core_course_external_testcase extends externallib_advanced_testcase {
$duplicate = core_course_external::duplicate_course($course->id, $newcourse['fullname'], $duplicate = core_course_external::duplicate_course($course->id, $newcourse['fullname'],
$newcourse['shortname'], $newcourse['categoryid'], $newcourse['visible'], $newcourse['options']); $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. // Check that the course has been duplicated.
$this->assertEquals($newcourse['shortname'], $duplicate['shortname']); $this->assertEquals($newcourse['shortname'], $duplicate['shortname']);
} }

View File

@ -66,6 +66,9 @@ class core_enrol_external_testcase extends externallib_advanced_testcase {
// Call the external function. // Call the external function.
$enrolledusers = core_enrol_external::get_enrolled_users($course->id); $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. // Check we retrieve the good total number of enrolled users.
$this->assertEquals(3, count($enrolledusers)); $this->assertEquals(3, count($enrolledusers));
@ -109,6 +112,9 @@ class core_enrol_external_testcase extends externallib_advanced_testcase {
// Call the external function. // Call the external function.
$enrolledincourses = core_enrol_external::get_users_courses($USER->id); $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. // Check we retrieve the good total number of enrolled users.
$this->assertEquals(2, count($enrolledincourses)); $this->assertEquals(2, count($enrolledincourses));
} }
@ -156,6 +162,9 @@ class core_enrol_external_testcase extends externallib_advanced_testcase {
$options = array(); $options = array();
$result = core_enrol_external::get_enrolled_users_with_capability($params, $options); $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. // Check an array containing the expected user for the course capability is returned.
$expecteduserlist = $result[0]; $expecteduserlist = $result[0];
$this->assertEquals($course1->id, $expecteduserlist['courseid']); $this->assertEquals($course1->id, $expecteduserlist['courseid']);

View File

@ -66,6 +66,9 @@ class core_group_external_testcase extends externallib_advanced_testcase {
// Call the external function. // Call the external function.
$groups = core_group_external::create_groups(array($group1, $group2)); $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 // Checks against DB values
$this->assertEquals(2, count($groups)); $this->assertEquals(2, count($groups));
foreach ($groups as $group) { foreach ($groups as $group) {
@ -125,6 +128,9 @@ class core_group_external_testcase extends externallib_advanced_testcase {
// Call the external function. // Call the external function.
$groups = core_group_external::get_groups(array($group1->id, $group2->id)); $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 // Checks against DB values
$this->assertEquals(2, count($groups)); $this->assertEquals(2, count($groups));
foreach ($groups as $group) { foreach ($groups as $group) {
@ -151,7 +157,7 @@ class core_group_external_testcase extends externallib_advanced_testcase {
// Call without required capability // Call without required capability
$this->unassignUserCapability('moodle/course:managegroups', $context->id, $roleid); $this->unassignUserCapability('moodle/course:managegroups', $context->id, $roleid);
$this->setExpectedException('required_capability_exception'); $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 @@ class core_group_external_testcase extends externallib_advanced_testcase {
$this->setExpectedException('required_capability_exception'); $this->setExpectedException('required_capability_exception');
$froups = core_group_external::delete_groups(array($group3->id)); $froups = core_group_external::delete_groups(array($group3->id));
} }
} }

View File

@ -44,6 +44,10 @@ class core_external_testcase extends externallib_advanced_testcase {
$returnedstring = core_external::get_string('addservice', 'webservice', $returnedstring = core_external::get_string('addservice', 'webservice',
array(array('name' => 'name', 'value' => $service->name), array(array('name' => 'name', 'value' => $service->name),
array('name' => 'id', 'value' => $service->id))); 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); $corestring = get_string('addservice', 'webservice', $service);
$this->assertEquals($corestring, $returnedstring); $this->assertEquals($corestring, $returnedstring);
@ -51,11 +55,19 @@ class core_external_testcase extends externallib_advanced_testcase {
$acapname = 'A capability name'; $acapname = 'A capability name';
$returnedstring = core_external::get_string('missingrequiredcapability', 'webservice', $returnedstring = core_external::get_string('missingrequiredcapability', 'webservice',
array(array('value' => $acapname))); 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); $corestring = get_string('missingrequiredcapability', 'webservice', $acapname);
$this->assertEquals($corestring, $returnedstring); $this->assertEquals($corestring, $returnedstring);
// String without parameters. // String without parameters.
$returnedstring = core_external::get_string('missingpassword', 'webservice'); $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'); $corestring = get_string('missingpassword', 'webservice');
$this->assertEquals($corestring, $returnedstring); $this->assertEquals($corestring, $returnedstring);
@ -87,6 +99,9 @@ class core_external_testcase extends externallib_advanced_testcase {
array('stringid' => 'addaservice', 'component' => 'webservice') 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) { foreach($returnedstrings as $returnedstring) {
$corestring = get_string($returnedstring['stringid'], $returnedstring['component'], $service); $corestring = get_string($returnedstring['stringid'], $returnedstring['component'], $service);
$this->assertEquals($corestring, $returnedstring['string']); $this->assertEquals($corestring, $returnedstring['string']);

View File

@ -86,6 +86,9 @@ class core_message_external_testcase extends externallib_advanced_testcase {
$sentmessages = core_message_external::send_instant_messages($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'])); $themessage = $DB->get_record('message', array('id' => $sentmessages[0]['msgid']));
// Confirm that the message was inserted correctly. // Confirm that the message was inserted correctly.
@ -373,5 +376,4 @@ class core_message_external_testcase extends externallib_advanced_testcase {
$this->setExpectedException('moodle_exception'); $this->setExpectedException('moodle_exception');
$results = core_message_external::search_contacts(''); $results = core_message_external::search_contacts('');
} }
} }

View File

@ -91,6 +91,9 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
$assignmentids[] = $assign->id; $assignmentids[] = $assign->id;
$result = mod_assign_external::get_grades($assignmentids); $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. // Check that the correct grade information for the student is returned.
$this->assertEquals(1, count($result['assignments'])); $this->assertEquals(1, count($result['assignments']));
$assignment = $result['assignments'][0]; $assignment = $result['assignments'][0];
@ -158,6 +161,10 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
)); ));
$result = mod_assign_external::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. // Check the course and assignment are returned.
$this->assertEquals(1, count($result['courses'])); $this->assertEquals(1, count($result['courses']));
$course = $result['courses'][0]; $course = $result['courses'][0];
@ -169,6 +176,10 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('lightwork assignment', $assignment['name']); $this->assertEquals('lightwork assignment', $assignment['name']);
$result = mod_assign_external::get_assignments(array($course1->id)); $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'])); $this->assertEquals(1, count($result['courses']));
$course = $result['courses'][0]; $course = $result['courses'][0];
$this->assertEquals('Lightwork Course 1', $course['fullname']); $this->assertEquals('Lightwork Course 1', $course['fullname']);
@ -179,6 +190,10 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
$this->assertEquals('lightwork assignment', $assignment['name']); $this->assertEquals('lightwork assignment', $assignment['name']);
$result = mod_assign_external::get_assignments(array($course2->id)); $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(0, count($result['courses']));
$this->assertEquals(1, count($result['warnings'])); $this->assertEquals(1, count($result['warnings']));
} }

View File

@ -59,6 +59,9 @@ class core_notes_external_testcase extends externallib_advanced_testcase {
$creatednotes = core_notes_external::create_notes($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'])); $thenote = $DB->get_record('post', array('id' => $creatednotes[0]['noteid']));
// Confirm that base note data was inserted correctly. // Confirm that base note data was inserted correctly.

View File

@ -254,6 +254,9 @@ class core_user_external_testcase extends externallib_advanced_testcase {
array('userid' => $user1->id, 'courseid' => $course->id), array('userid' => $user1->id, 'courseid' => $course->id),
array('userid' => $user2->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. // Check we retrieve the good total number of enrolled users + no error on capability.
$this->assertEquals(3, count($enrolledusers)); $this->assertEquals(3, count($enrolledusers));
@ -267,6 +270,9 @@ class core_user_external_testcase extends externallib_advanced_testcase {
array('userid' => $user1->id, 'courseid' => $course->id), array('userid' => $user1->id, 'courseid' => $course->id),
array('userid' => $user2->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) { foreach($enrolledusers as $enrolleduser) {
if ($enrolleduser['username'] == $user1->username) { if ($enrolleduser['username'] == $user1->username) {
$this->assertEquals($user1->idnumber, $enrolleduser['idnumber']); $this->assertEquals($user1->idnumber, $enrolleduser['idnumber']);
@ -321,6 +327,9 @@ class core_user_external_testcase extends externallib_advanced_testcase {
// Call the external function. // Call the external function.
$createdusers = core_user_external::create_users(array($user1)); $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. // Check we retrieve the good total number of created users + no error on capability.
$this->assertEquals(1, count($createdusers)); $this->assertEquals(1, count($createdusers));
@ -419,6 +428,9 @@ class core_user_external_testcase extends externallib_advanced_testcase {
$returnedusers = core_user_external::get_users_by_id(array( $returnedusers = core_user_external::get_users_by_id(array(
$USER->id, $user1->id, $user2->id)); $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. // Check we retrieve the good total number of enrolled users + no error on capability.
$this->assertEquals(3, count($returnedusers)); $this->assertEquals(3, count($returnedusers));
@ -430,6 +442,9 @@ class core_user_external_testcase extends externallib_advanced_testcase {
$returnedusers = core_user_external::get_users_by_id(array( $returnedusers = core_user_external::get_users_by_id(array(
$USER->id, $user1->id, $user2->id)); $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) { foreach($returnedusers as $enrolleduser) {
if ($enrolleduser['username'] == $user1->username) { if ($enrolleduser['username'] == $user1->username) {
$this->assertEquals($user1->idnumber, $enrolleduser['idnumber']); $this->assertEquals($user1->idnumber, $enrolleduser['idnumber']);
@ -502,4 +517,4 @@ class core_user_external_testcase extends externallib_advanced_testcase {
$this->setExpectedException('required_capability_exception'); $this->setExpectedException('required_capability_exception');
core_user_external::update_users(array($user1)); core_user_external::update_users(array($user1));
} }
} }

View File

@ -81,6 +81,9 @@ class core_webservice_external_testcase extends externallib_advanced_testcase {
$siteinfo = core_webservice_external::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('johnd', $siteinfo['username']);
$this->assertEquals('John', $siteinfo['firstname']); $this->assertEquals('John', $siteinfo['firstname']);
$this->assertEquals('Doe', $siteinfo['lastname']); $this->assertEquals('Doe', $siteinfo['lastname']);