Skip to content

Commit

Permalink
MDL-60567 competencies: test list_competencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Oct 27, 2017
1 parent f09f01f commit 1518ce9
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions competency/tests/external_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2803,4 +2803,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 1518ce9

Please sign in to comment.