forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-63729 badges: Return new fields in badge table in WS
- Loading branch information
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,12 @@ public function setUp() { | |
$badge->attachment = 1; | ||
$badge->notification = 0; | ||
$badge->status = BADGE_STATUS_ACTIVE; | ||
$badge->version = '1'; | ||
$badge->language = 'en'; | ||
$badge->imageauthorname = 'Image author'; | ||
$badge->imageauthoremail = '[email protected]'; | ||
$badge->imageauthorurl = 'http://image-author-url.domain.co.nz'; | ||
$badge->imagecaption = 'Caption'; | ||
|
||
$badgeid = $DB->insert_record('badge', $badge, true); | ||
$badge = new badge($badgeid); | ||
|
@@ -116,15 +122,26 @@ public function test_get_my_user_badges() { | |
|
||
$this->setUser($this->student); | ||
|
||
$badges = (array) badges_get_user_badges($this->student->id); | ||
$expectedbadges = array(); | ||
|
||
foreach ($badges as $badge) { | ||
$context = ($badge->type == BADGE_TYPE_SITE) ? context_system::instance() : context_course::instance($badge->courseid); | ||
$badge->badgeurl = moodle_url::make_webservice_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', | ||
'f1')->out(false); | ||
|
||
$expectedbadges[] = (array) $badge; | ||
} | ||
|
||
$result = core_badges_external::get_user_badges(); | ||
$result = external_api::clean_returnvalue(core_badges_external::get_user_badges_returns(), $result); | ||
$this->assertCount(2, $result['badges']); | ||
$this->assertEquals($expectedbadges, $result['badges']); | ||
|
||
// Pagination and filtering. | ||
$result = core_badges_external::get_user_badges(0, $this->course->id, 0, 1, '', true); | ||
$result = external_api::clean_returnvalue(core_badges_external::get_user_badges_returns(), $result); | ||
$this->assertCount(1, $result['badges']); | ||
$this->assertEquals($this->course->id, $result['badges'][0]['courseid']); | ||
$this->assertEquals($expectedbadges[1], $result['badges'][0]); | ||
} | ||
|
||
/** | ||
|