From ef394f5aa95c22c0ba2690adde1bfd7cac87014e Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Mon, 13 Apr 2015 16:37:29 +0200 Subject: [PATCH] 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 8f7f4ba8d2f..bedfab88368 100644 --- a/cohort/tests/externallib_test.php +++ b/cohort/tests/externallib_test.php @@ -66,6 +66,7 @@ class core_cohort_externallib_testcase extends externallib_advanced_testcase { // Call the external function. $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)); @@ -143,6 +144,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)); @@ -160,6 +162,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)); @@ -345,6 +348,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)); @@ -386,11 +390,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)