Skip to content
Permalink
Browse files

MDL-53167 search: Adding unit tests for external API change

  • Loading branch information...
merrill-oakland committed Apr 12, 2016
1 parent 427e3cb commit 935ee1c6c6d3c08231e34de71d4819fedf226478
Showing with 22 additions and 1 deletion.
  1. +1 −1 course/externallib.php
  2. +21 −0 course/tests/externallib_test.php
@@ -2221,7 +2221,7 @@ public static function search_courses($criterianame,
foreach ($courses as $course) {
if (!empty($limittoenrolled)) {
// Filter out not enrolled courses.
if (empty($enrolled[$course->id])) {
if (!isset($enrolled[$course->id])) {
$totalcount--;
continue;
}
@@ -652,6 +652,14 @@ public function test_search_courses () {
// Now as a normal user.
$user = self::getDataGenerator()->create_user();
// Add a 3rd, hidden, course we shouldn't see, even when enrolled as student.
$coursedata3['fullname'] = 'HIDDEN COURSE';
$coursedata3['visible'] = 0;
$course3 = self::getDataGenerator()->create_course($coursedata3);
$this->getDataGenerator()->enrol_user($user->id, $course3->id, 'student');
$this->getDataGenerator()->enrol_user($user->id, $course2->id, 'student');
$this->setUser($user);
$results = core_course_external::search_courses('search', 'FIRST');
@@ -660,6 +668,19 @@ public function test_search_courses () {
$this->assertEquals(1, $results['total']);
$this->assertEquals($coursedata1['fullname'], $results['courses'][0]['fullname']);
// Check that we can see both without the limit to enrolled setting.
$results = core_course_external::search_courses('search', 'COURSE', 0, 0, array(), 0);
$results = external_api::clean_returnvalue(core_course_external::search_courses_returns(), $results);
$this->assertCount(2, $results['courses']);
$this->assertEquals(2, $results['total']);
// Check that we only see our enrolled course when limiting.
$results = core_course_external::search_courses('search', 'COURSE', 0, 0, array(), 1);
$results = external_api::clean_returnvalue(core_course_external::search_courses_returns(), $results);
$this->assertCount(1, $results['courses']);
$this->assertEquals(1, $results['total']);
$this->assertEquals($coursedata2['fullname'], $results['courses'][0]['fullname']);
// Search by block (use news_items default block). Should fail (only admins allowed).
$this->setExpectedException('required_capability_exception');
$results = core_course_external::search_courses('blocklist', $blockid);

0 comments on commit 935ee1c

Please sign in to comment.
You can’t perform that action at this time.