Permalink
Browse files

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

…e into MOODLE_23_STABLE
  • Loading branch information...
2 parents 5a3aaea + 96ace84 commit 5d112775e98fb3042d5ab544598d17d7e12bb2c1 @stronk7 stronk7 committed Jan 15, 2013
Showing with 49 additions and 1 deletion.
  1. +33 −0 course/tests/externallib_test.php
  2. +16 −1 user/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).
@@ -343,6 +360,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));
@@ -475,6 +495,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));
@@ -508,6 +531,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));
}
@@ -535,6 +562,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']));
}
@@ -578,6 +608,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']);
}
@@ -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));
}
-}
+}

0 comments on commit 5d11277

Please sign in to comment.