This commit is contained in:
Jun Pataleta 2022-07-13 13:02:07 +08:00
commit 50598298ba
3 changed files with 41 additions and 4 deletions

View File

@ -92,6 +92,43 @@ class badges_test extends core_reportbuilder_testcase {
}, $content));
}
/**
* Test datasource using course/user entities that each contain tags
*/
public function test_datasource_course_user_tags(): void {
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course(['tags' => ['horse']]);
$user = $this->getDataGenerator()->create_user(['interests' => ['pie']]);
// Create course badge, issue to user.
$badge = $this->create_badge(['name' => 'Course badge', 'type' => BADGE_TYPE_COURSE, 'courseid' => $course->id]);
$badge->issue($user->id, true);
/** @var core_reportbuilder_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
// Create our report.
$report = $generator->create_report(['name' => 'Badges', 'source' => badges::class, 'default' => 0]);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'badge:name']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'course:fullname']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'course:tags']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullname']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:interests']);
$content = $this->get_custom_report_content($report->get('id'));
$this->assertCount(1, $content);
$this->assertEquals([
$badge->name,
$course->fullname,
'horse',
fullname($user),
'pie',
], array_values($content[0]));
}
/**
* Helper method to create a badge
*

View File

@ -60,8 +60,8 @@ class course extends base {
return [
'course' => 'c',
'context' => 'cctx',
'tag_instance' => 'ti',
'tag' => 't',
'tag_instance' => 'cti',
'tag' => 'ct',
];
}

View File

@ -59,8 +59,8 @@ class user extends base {
return [
'user' => 'u',
'context' => 'uctx',
'tag_instance' => 'ti',
'tag' => 't',
'tag_instance' => 'uti',
'tag' => 'ut',
];
}