From 1bfd51f16bf89ce754b7ac34a42d1d992d1b3202 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Mon, 13 Apr 2015 16:37:18 +0200 Subject: [PATCH 1/8] MDL-45131 calendar: Add validation for returned parameters in WS tests --- calendar/tests/externallib_test.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/calendar/tests/externallib_test.php b/calendar/tests/externallib_test.php index b8582abf9a3..8f500d9cdf7 100644 --- a/calendar/tests/externallib_test.php +++ b/calendar/tests/externallib_test.php @@ -328,6 +328,7 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase { $paramevents = array ('courseids' => array($course->id), 'groupids' => array($group->id)); $events = core_calendar_external::get_calendar_events($paramevents, $options); + $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events); $this->assertEquals(4, count($events['events'])); // site, user, group, one course event. $this->assertEquals(0, count($events['warnings'])); @@ -390,6 +391,7 @@ class core_calendar_externallib_testcase extends externallib_advanced_testcase { array('name' => 'user') ); $eventsret = core_calendar_external::create_calendar_events($events); + $eventsret = external_api::clean_returnvalue(core_calendar_external::create_calendar_events_returns(), $eventsret); // Check to see if things were created properly. $aftercount = $DB->count_records('event'); From 58611999f3ac0063fe87893a7bb0d8bf58b385b9 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Mon, 13 Apr 2015 16:37:29 +0200 Subject: [PATCH 2/8] MDL-45131 cohort: Add validation for returned parameters in WS tests --- cohort/tests/externallib_test.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cohort/tests/externallib_test.php b/cohort/tests/externallib_test.php index 0b0f3142945..3ca5fa21248 100644 --- a/cohort/tests/externallib_test.php +++ b/cohort/tests/externallib_test.php @@ -69,6 +69,7 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase { // Call the external function. $this->setCurrentTimeStart(); $createdcohorts = core_cohort_external::create_cohorts(array($cohort1, $cohort2)); + $createdcohorts = external_api::clean_returnvalue(core_cohort_external::create_cohorts_returns(), $createdcohorts); // Check we retrieve the good total number of created cohorts + no error on capability. $this->assertEquals(2, count($createdcohorts)); @@ -155,6 +156,7 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase { // Call the external function. $returnedcohorts = core_cohort_external::get_cohorts(array( $cohort1->id, $cohort2->id)); + $returnedcohorts = external_api::clean_returnvalue(core_cohort_external::get_cohorts_returns(), $returnedcohorts); // Check we retrieve the good total number of enrolled cohorts + no error on capability. $this->assertEquals(2, count($returnedcohorts)); @@ -173,6 +175,7 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase { // Call the external function. $returnedcohorts = core_cohort_external::get_cohorts(array( $cohort1->id, $cohort2->id)); + $returnedcohorts = external_api::clean_returnvalue(core_cohort_external::get_cohorts_returns(), $returnedcohorts); // Check we retrieve the good total number of enrolled cohorts + no error on capability. $this->assertEquals(2, count($returnedcohorts)); @@ -367,6 +370,7 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase { // Call the external function. $addcohortmembers = core_cohort_external::add_cohort_members(array($cohort1)); + $addcohortmembers = external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $addcohortmembers); // Check we retrieve the good total number of created cohorts + no error on capability. $this->assertEquals(1, count($addcohortmembers)); @@ -408,11 +412,14 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase { 'usertype' => array('type' => 'id', 'value' => $user1->id) ); $cohortmembers1 = core_cohort_external::add_cohort_members(array($cohortaddmember1)); + $cohortmembers1 = external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $cohortmembers1); + $cohortaddmember2 = array( 'cohorttype' => array('type' => 'id', 'value' => $cohort2->id), 'usertype' => array('type' => 'id', 'value' => $user2->id) ); $cohortmembers2 = core_cohort_external::add_cohort_members(array($cohortaddmember2)); + $cohortmembers2 = external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $cohortmembers2); // Check we retrieve no cohorts + no error on capability. $this->assertEquals(2, $DB->count_records_select('cohort_members', ' ((cohortid = :idcohort1 AND userid = :iduser1) From db4f496b52231356ea86e0ae7b331fa7ce6235a6 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Mon, 13 Apr 2015 16:37:49 +0200 Subject: [PATCH 3/8] MDL-45131 enrol: Add validation for returned parameters in WS tests --- enrol/self/tests/externallib_test.php | 3 +++ enrol/tests/externallib_test.php | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/enrol/self/tests/externallib_test.php b/enrol/self/tests/externallib_test.php index 343af57fd67..d4abbe2c62f 100644 --- a/enrol/self/tests/externallib_test.php +++ b/enrol/self/tests/externallib_test.php @@ -69,6 +69,7 @@ class enrol_self_external_testcase extends externallib_advanced_testcase { $this->assertCount(3, $enrolmentmethods); $instanceinfo1 = enrol_self_external::get_instance_info($instanceid1); + $instanceinfo1 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo1); $this->assertEquals($instanceid1, $instanceinfo1['id']); $this->assertEquals($course->id, $instanceinfo1['courseid']); @@ -78,6 +79,7 @@ class enrol_self_external_testcase extends externallib_advanced_testcase { $this->assertFalse(isset($instanceinfo1['enrolpassword'])); $instanceinfo2 = enrol_self_external::get_instance_info($instanceid2); + $instanceinfo2 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo2); $this->assertEquals($instanceid2, $instanceinfo2['id']); $this->assertEquals($course->id, $instanceinfo2['courseid']); $this->assertEquals('self', $instanceinfo2['type']); @@ -86,6 +88,7 @@ class enrol_self_external_testcase extends externallib_advanced_testcase { $this->assertFalse(isset($instanceinfo2['enrolpassword'])); $instanceinfo3 = enrol_self_external::get_instance_info($instanceid3); + $instanceinfo3 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo3); $this->assertEquals($instanceid3, $instanceinfo3['id']); $this->assertEquals($course->id, $instanceinfo3['courseid']); $this->assertEquals('self', $instanceinfo3['type']); diff --git a/enrol/tests/externallib_test.php b/enrol/tests/externallib_test.php index 5273bbb8d3d..b02656546b3 100644 --- a/enrol/tests/externallib_test.php +++ b/enrol/tests/externallib_test.php @@ -248,6 +248,8 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase { // Check if information is returned. $enrolmentmethods = core_enrol_external::get_course_enrolment_methods($course1->id); + $enrolmentmethods = external_api::clean_returnvalue(core_enrol_external::get_course_enrolment_methods_returns(), + $enrolmentmethods); // Enrolment information is currently returned by self enrolment plugin, so count == 1. // This should be changed as we implement get_enrol_info() for other enrolment plugins. $this->assertCount(1, $enrolmentmethods); @@ -264,6 +266,8 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase { 'customint6' => 1, 'password' => 'test')); $enrolmentmethods = core_enrol_external::get_course_enrolment_methods($course2->id); + $enrolmentmethods = external_api::clean_returnvalue(core_enrol_external::get_course_enrolment_methods_returns(), + $enrolmentmethods); $this->assertCount(1, $enrolmentmethods); $enrolmentmethod = $enrolmentmethods[0]; From 772f17a280360b785208811e8d2159690c3eff2c Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Mon, 13 Apr 2015 16:37:59 +0200 Subject: [PATCH 4/8] MDL-45131 files: Add validation for returned parameters in WS tests --- files/tests/externallib_test.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/files/tests/externallib_test.php b/files/tests/externallib_test.php index 3922c6494b6..0ebff4dc0be 100644 --- a/files/tests/externallib_test.php +++ b/files/tests/externallib_test.php @@ -61,6 +61,7 @@ class core_files_externallib_testcase extends advanced_testcase { // Call the api to create a file. $fileinfo = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent, $contextlevel, $instanceid); + $fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo); // Get the created draft item id. $itemid = $fileinfo['itemid']; @@ -76,6 +77,7 @@ class core_files_externallib_testcase extends advanced_testcase { // Call the api to create a file. $fileinfo = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent, $contextlevel, $instanceid); + $fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo); $file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename); $this->assertNotEmpty($file); @@ -88,6 +90,7 @@ class core_files_externallib_testcase extends advanced_testcase { $this->assertEmpty($file); $fileinfo = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent, $contextlevel, $instanceid); + $fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo); $file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename); $this->assertNotEmpty($file); @@ -142,7 +145,8 @@ class core_files_externallib_testcase extends advanced_testcase { $instanceid = null; // Make sure the file is created. - @core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent); + $fileinfo = @core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent); + $fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo); $browser = get_file_browser(); $file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename); $this->assertNotEmpty($file); @@ -165,7 +169,8 @@ class core_files_externallib_testcase extends advanced_testcase { $filename = "Simple4.txt"; $filecontent = base64_encode("Let us create a nice simple file"); - @core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent); + $fileinfo = @core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent); + $fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo); // Assert debugging called (deprecation warning). $this->assertDebuggingCalled(); @@ -249,6 +254,7 @@ class core_files_externallib_testcase extends advanced_testcase { // The first time is with a valid context ID. $filename = ''; $testfilelisting = core_files_external::get_files($context->id, $component, $filearea, $itemid, '/', $filename); + $testfilelisting = external_api::clean_returnvalue(core_files_external::get_files_returns(), $testfilelisting); // With the information that we have provided we should get an object exactly like the one below. $coursecontext = context_course::instance($course->id); @@ -304,6 +310,8 @@ class core_files_externallib_testcase extends advanced_testcase { $contextlevel = 'module'; $instanceid = $module->cmid; $testfilelisting = core_files_external::get_files($nocontext, $component, $filearea, $itemid, '/', $filename, $modified, $contextlevel, $instanceid); + $testfilelisting = external_api::clean_returnvalue(core_files_external::get_files_returns(), $testfilelisting); + $this->assertEquals($testfilelisting, $testdata); } } From 728b068e24d7690226a4b81220be868c1513c95e Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Mon, 13 Apr 2015 16:38:11 +0200 Subject: [PATCH 5/8] MDL-45131 message: Add validation for returned parameters in WS tests --- message/output/airnotifier/tests/externallib_test.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/message/output/airnotifier/tests/externallib_test.php b/message/output/airnotifier/tests/externallib_test.php index 028cf0b3dbe..95357c1941d 100644 --- a/message/output/airnotifier/tests/externallib_test.php +++ b/message/output/airnotifier/tests/externallib_test.php @@ -60,6 +60,7 @@ class message_airnotifier_external_testcase extends externallib_advanced_testcas // In a clean installation, it should be not configured. $configured = message_airnotifier_external::is_system_configured(); + $configured = external_api::clean_returnvalue(message_airnotifier_external::is_system_configured_returns(), $configured); $this->assertEquals(0, $configured); // Fake configuration. @@ -68,6 +69,7 @@ class message_airnotifier_external_testcase extends externallib_advanced_testcas $DB->set_field('message_processors', 'enabled', 1, array('name' => 'airnotifier')); $configured = message_airnotifier_external::is_system_configured(); + $configured = external_api::clean_returnvalue(message_airnotifier_external::is_system_configured_returns(), $configured); $this->assertEquals(1, $configured); } @@ -92,6 +94,8 @@ class message_airnotifier_external_testcase extends externallib_advanced_testcas $params = array($user1->id, $user2->id, $user3->id); $preferences = message_airnotifier_external::are_notification_preferences_configured($params); + $returnsdescription = message_airnotifier_external::are_notification_preferences_configured_returns(); + $preferences = external_api::clean_returnvalue($returnsdescription, $preferences); $expected = array( array( @@ -107,6 +111,7 @@ class message_airnotifier_external_testcase extends externallib_advanced_testcas // Now, remove one user. delete_user($user2); $preferences = message_airnotifier_external::are_notification_preferences_configured($params); + $preferences = external_api::clean_returnvalue($returnsdescription, $preferences); $this->assertEquals(1, count($preferences['users'])); $this->assertEquals($expected, $preferences['users']); $this->assertEquals(2, count($preferences['warnings'])); @@ -114,11 +119,13 @@ class message_airnotifier_external_testcase extends externallib_advanced_testcas // Now, remove one user1 preference (the user still has one prefernce for airnotifier). unset_user_preference('message_provider_moodle_instantmessage_loggedin', $user1); $preferences = message_airnotifier_external::are_notification_preferences_configured($params); + $preferences = external_api::clean_returnvalue($returnsdescription, $preferences); $this->assertEquals($expected, $preferences['users']); // Delete the last user1 preference. unset_user_preference('message_provider_moodle_instantmessage_loggedoff', $user1); $preferences = message_airnotifier_external::are_notification_preferences_configured($params); + $preferences = external_api::clean_returnvalue($returnsdescription, $preferences); $expected = array( array( 'userid' => $user1->id, From a1b54310e14de765d1c94b91577c36ab9b87bbe4 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Mon, 13 Apr 2015 16:38:19 +0200 Subject: [PATCH 6/8] MDL-45131 user: Add validation for returned parameters in WS tests --- user/tests/externallib_test.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/user/tests/externallib_test.php b/user/tests/externallib_test.php index 6913a007d27..633c6ff6e46 100644 --- a/user/tests/externallib_test.php +++ b/user/tests/externallib_test.php @@ -257,6 +257,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase { // Call the external function. $returnedusers = core_user_external::get_users_by_field($fieldtosearch, array($USER->{$fieldtosearch}, $user1->{$fieldtosearch}, $user2->{$fieldtosearch})); + $returnedusers = external_api::clean_returnvalue(core_user_external::get_users_by_field_returns(), $returnedusers); // Expected result differ following the searched field // Admin user in the PHPunit framework doesn't have an idnumber. @@ -338,6 +339,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase { // Call the external function. $returnedusers = core_user_external::get_users_by_field('username', array($USER->username, $user1->username, $user2->username)); + $returnedusers = external_api::clean_returnvalue(core_user_external::get_users_by_field_returns(), $returnedusers); // Only the own $USER username should be returned $this->assertEquals(1, count($returnedusers)); @@ -348,6 +350,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase { // Call the external function. $returnedusers = core_user_external::get_users_by_field('username', array($USER->username, $user1->username, $user2->username)); + $returnedusers = external_api::clean_returnvalue(core_user_external::get_users_by_field_returns(), $returnedusers); // Only the own $USER username should be returned still. $this->assertEquals(1, count($returnedusers)); @@ -705,6 +708,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase { // Call the files api to create a file. $draftfile = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent, $contextlevel, $instanceid); + $draftfile = external_api::clean_returnvalue(core_files_external::upload_returns(), $draftfile); $draftid = $draftfile['itemid']; // Make sure the file was created. @@ -761,6 +765,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase { $device['pushid'] = 'different than before'; $warnings = core_user_external::add_user_device($device['appid'], $device['name'], $device['model'], $device['platform'], $device['version'], $device['pushid'], $device['uuid']); + $warnings = external_api::clean_returnvalue(core_user_external::add_user_device_returns(), $warnings); $this->assertEquals(1, $DB->count_records('user_devices')); $updated = $DB->get_record('user_devices', array('pushid' => $device['pushid'])); @@ -771,6 +776,7 @@ class core_user_externallib_testcase extends externallib_advanced_testcase { $device['pushid'] = 'new different than before'; $warnings = core_user_external::add_user_device($device['appid'], $device['name'], $device['model'], $device['platform'], $device['version'], $device['pushid'], $device['uuid']); + $warnings = external_api::clean_returnvalue(core_user_external::add_user_device_returns(), $warnings); $this->assertEquals(2, $DB->count_records('user_devices')); } From 43d75763327b85e27d69508cd36bf998d53f5968 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Mon, 13 Apr 2015 16:37:37 +0200 Subject: [PATCH 7/8] MDL-45131 course: Add validation for returned parameters in WS tests --- course/tests/externallib_test.php | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index a0c29f497e5..6327667466f 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -243,6 +243,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { // Retrieve categories from parent. $categories = core_course_external::get_categories(array( array('key' => 'parent', 'value' => $category3->id)), 1); + $categories = external_api::clean_returnvalue(core_course_external::get_categories_returns(), $categories); + $this->assertEquals(2, count($categories)); // Retrieve all categories. @@ -739,6 +741,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $courses = array($course1, $course2); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $COURSE = $origcourse; // Restore $COURSE. Instead of using the OLD one set by the previous line. // Check that right number of courses were created. @@ -796,6 +800,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $this->unassignUserCapability('moodle/course:update', $contextid, $roleid); self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(1, count($updatedcoursewarnings['warnings'])); // Try update course category without capability. @@ -807,6 +813,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $course1['categoryid'] = $category2->id; $courses = array($course1); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(1, count($updatedcoursewarnings['warnings'])); // Try update course fullname without capability. @@ -816,10 +824,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $this->setUser($user); self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(0, count($updatedcoursewarnings['warnings'])); $course1['fullname'] = 'Testing fullname without permission'; $courses = array($course1); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(1, count($updatedcoursewarnings['warnings'])); // Try update course shortname without capability. @@ -829,10 +841,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $this->setUser($user); self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(0, count($updatedcoursewarnings['warnings'])); $course1['shortname'] = 'Testing shortname without permission'; $courses = array($course1); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(1, count($updatedcoursewarnings['warnings'])); // Try update course idnumber without capability. @@ -842,10 +858,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $this->setUser($user); self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(0, count($updatedcoursewarnings['warnings'])); $course1['idnumber'] = 'NEWIDNUMBER'; $courses = array($course1); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(1, count($updatedcoursewarnings['warnings'])); // Try update course summary without capability. @@ -855,10 +875,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $this->setUser($user); self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(0, count($updatedcoursewarnings['warnings'])); $course1['summary'] = 'New summary'; $courses = array($course1); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(1, count($updatedcoursewarnings['warnings'])); // Try update course with invalid summary format. @@ -867,10 +891,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $this->setUser($user); self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(0, count($updatedcoursewarnings['warnings'])); $course1['summaryformat'] = 10; $courses = array($course1); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(1, count($updatedcoursewarnings['warnings'])); // Try update course visibility without capability. @@ -881,10 +909,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $course1['summaryformat'] = FORMAT_MOODLE; $courses = array($course1); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(0, count($updatedcoursewarnings['warnings'])); $course1['visible'] = 0; $courses = array($course1); $updatedcoursewarnings = core_course_external::update_courses($courses); + $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), + $updatedcoursewarnings); $this->assertEquals(1, count($updatedcoursewarnings['warnings'])); } @@ -1188,4 +1220,5 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { // Import from course1 to course2, with invalid option core_course_external::import_course($course1->id, $course2->id, -1);; } + } From 19ddaeb78284a6a5c370e282ef6ebe9585f1ba7e Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Thu, 16 Apr 2015 10:23:18 +0200 Subject: [PATCH 8/8] MDL-45131 notes: Add validation for returned parameters in WS tests --- notes/tests/externallib_test.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/notes/tests/externallib_test.php b/notes/tests/externallib_test.php index 72af7f91e1f..aa2334c0902 100644 --- a/notes/tests/externallib_test.php +++ b/notes/tests/externallib_test.php @@ -119,11 +119,13 @@ class core_notes_externallib_testcase extends externallib_advanced_testcase { // Call without required capability. $creatednotes = core_notes_external::create_notes($cnotes); + $creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes); $dnotes3 = array($creatednotes[0]['noteid']); $this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid); $this->setExpectedException('required_capability_exception'); $deletednotes = core_notes_external::delete_notes($dnotes3); + $deletednotes = external_api::clean_returnvalue(core_notes_external::delete_notes_returns(), $deletednotes); } public function test_get_notes() { @@ -230,6 +232,7 @@ class core_notes_externallib_testcase extends externallib_advanced_testcase { // Call without required capability. $creatednotes = core_notes_external::create_notes($notes1); + $creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes); $this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid); $this->setExpectedException('required_capability_exception'); $note2 = array(); @@ -239,5 +242,6 @@ class core_notes_externallib_testcase extends externallib_advanced_testcase { $note2['format'] = FORMAT_HTML; $notes2 = array($note2); $updatednotes = core_notes_external::update_notes($notes2); + $updatednotes = external_api::clean_returnvalue(core_notes_external::update_notes_returns(), $updatednotes); } }