Skip to content

Commit

Permalink
MDL-75152 reportbuilder: unique default tag aliases across entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Jul 5, 2022
1 parent 9ccda59 commit ec452a4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
37 changes: 37 additions & 0 deletions badges/tests/reportbuilder/datasource/badges_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,43 @@ public function test_datasource(): void {
}, $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
*
Expand Down
4 changes: 2 additions & 2 deletions reportbuilder/classes/local/entities/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ protected function get_default_table_aliases(): array {
return [
'course' => 'c',
'context' => 'cctx',
'tag_instance' => 'ti',
'tag' => 't',
'tag_instance' => 'cti',
'tag' => 'ct',
];
}

Expand Down
4 changes: 2 additions & 2 deletions reportbuilder/classes/local/entities/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ protected function get_default_table_aliases(): array {
return [
'user' => 'u',
'context' => 'uctx',
'tag_instance' => 'ti',
'tag' => 't',
'tag_instance' => 'uti',
'tag' => 'ut',
];
}

Expand Down

0 comments on commit ec452a4

Please sign in to comment.