Skip to content

Commit

Permalink
Merge branch 'MDL-60567-master' of git://github.com/damyon/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Dec 19, 2017
2 parents baa8c89 + 1518ce9 commit a4e7e6f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions competency/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,10 +841,10 @@ public static function list_competencies($filters, $sort, $order, $skip, $limit)
$validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber',
'parentid', 'competencyframeworkid');
foreach ($params['filters'] as $filter) {
if (!in_array($filter->column, $validcolumns)) {
if (!in_array($filter['column'], $validcolumns)) {
throw new invalid_parameter_exception('Filter column was invalid');
}
$safefilters[$filter->column] = $filter->value;
$safefilters[$filter['column']] = $filter['value'];
}

$context = null;
Expand Down
39 changes: 39 additions & 0 deletions competency/tests/external_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2801,4 +2801,43 @@ public function test_update_course_competency_settings() {
$result = external::update_course_competency_settings($course->id, array('pushratingstouserplans' => true));
}

/**
* Test that we can list competencies with a filter.
*
* @return void
*/
public function test_list_competencies_with_filter() {
$this->resetAfterTest(true);
$this->setAdminUser();
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');

$framework = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id')));
$c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id')));
$c3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id')));
$c4 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id')));
$c5 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id')));

// Test if removing competency from plan don't create sortorder holes.
$filters = [];
$sort = 'id';
$order = 'ASC';
$skip = 0;
$limit = 0;
$result = external::list_competencies($filters, $sort, $order, $skip, $limit);
$this->assertCount(5, $result);

$result = external::list_competencies($filters, $sort, $order, 2, $limit);
$this->assertCount(3, $result);
$result = external::list_competencies($filters, $sort, $order, 2, 2);
$this->assertCount(2, $result);

$filter = $result[0]->shortname;
$filters[0] = ['column' => 'shortname', 'value' => $filter];
$result = external::list_competencies($filters, $sort, $order, $skip, $limit);
$this->assertCount(1, $result);
$this->assertEquals($filter, $result[0]->shortname);
}

}

0 comments on commit a4e7e6f

Please sign in to comment.