Skip to content

Commit

Permalink
Merge branch 'MDL-40666-master' of git://github.com/danpoltawski/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Jul 23, 2013
2 parents 1315808 + fb5ce7d commit 18474f8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cohort/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public static function get_cohorts_returns() {
return new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_NUMBER, 'ID of the cohort'),
'id' => new external_value(PARAM_INT, 'ID of the cohort'),
'name' => new external_value(PARAM_RAW, 'cohort name'),
'idnumber' => new external_value(PARAM_RAW, 'cohort idnumber'),
'description' => new external_value(PARAM_RAW, 'cohort description'),
Expand All @@ -280,7 +280,7 @@ public static function update_cohorts_parameters() {
'cohorts' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_NUMBER, 'ID of the cohort'),
'id' => new external_value(PARAM_INT, 'ID of the cohort'),
'categorytype' => new external_single_structure(
array(
'type' => new external_value(PARAM_TEXT, 'the name of the field: id (numeric value
Expand Down
34 changes: 30 additions & 4 deletions cohort/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ public function test_get_cohorts() {
// Check we retrieve the good total number of enrolled cohorts + no error on capability.
$this->assertEquals(2, count($returnedcohorts));

// Call the external function.
$returnedcohorts = core_cohort_external::get_cohorts(array(
$cohort1->id, $cohort2->id));

foreach ($returnedcohorts as $enrolledcohort) {
if ($enrolledcohort['idnumber'] == $cohort1->idnumber) {
$this->assertEquals($cohort1->name, $enrolledcohort['name']);
Expand Down Expand Up @@ -207,6 +203,36 @@ public function test_update_cohorts() {
core_cohort_external::update_cohorts(array($cohort1));
}

/**
* Verify handling of 'id' param.
*/
public function test_update_cohorts_invalid_id_param() {
$this->resetAfterTest(true);
$cohort = self::getDataGenerator()->create_cohort();

$cohort1 = array(
'id' => 'THIS IS NOT AN ID',
'name' => 'Changed cohort name',
'categorytype' => array('type' => 'id', 'value' => '1'),
'idnumber' => $cohort->idnumber,
);

try {
core_cohort_external::update_cohorts(array($cohort1));
$this->fail('Expecting invalid_parameter_exception exception, none occured');
} catch (invalid_parameter_exception $e1) {
$this->assertContains('Invalid external api parameter: the value is "THIS IS NOT AN ID"', $e1->debuginfo);
}

$cohort1['id'] = 9.999; // Also not a valid id of a cohort.
try {
core_cohort_external::update_cohorts(array($cohort1));
$this->fail('Expecting invalid_parameter_exception exception, none occured');
} catch (invalid_parameter_exception $e2) {
$this->assertContains('Invalid external api parameter: the value is "9.999"', $e2->debuginfo);
}
}

/**
* Test update_cohorts without permission on the dest category.
*/
Expand Down
9 changes: 9 additions & 0 deletions cohort/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This files describes API changes in /cohort/ information provided here is intended
especially for developers.

=== 2.6 ===
* Webservice core_cohort_update_cohorts was incorrectly specifiying float as the parameter type
for cohort id. This field is actually int and input is now reported and processed as such.
* Webservice core_cohort_get_cohorts was incorrectly specifiying float as the return
type for cohort id. The actual return type is int and is now reported as such.

2 changes: 1 addition & 1 deletion enrol/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static function get_enrolled_users_with_capability_returns() {
'users' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_NUMBER, 'ID of the user'),
'id' => new external_value(PARAM_INT, 'ID of the user'),
'username' => new external_value(PARAM_RAW, 'Username', VALUE_OPTIONAL),
'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL),
'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL),
Expand Down
3 changes: 3 additions & 0 deletions enrol/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ information provided here is intended especially for developers.
* Enrolment plugin which supports self enrolment should implement can_self_enrol()
* Enrolment plugin should implement get_enrol_info() to expose instance information
with webservice or external interface.
* Webservice core_enrol_get_enrolled_users_with_capability was incorrectly specifing
float as the return type for user id. int is the actual returned type and is now
reported as such.

=== 2.5 ===

Expand Down

0 comments on commit 18474f8

Please sign in to comment.