Skip to content

Commit

Permalink
MDL-82904 core_badges: Display empty column for unset criteria
Browse files Browse the repository at this point in the history
* In the report builder badges with unset criteria should have a empty
value for the criteria column
  • Loading branch information
laurentdavid committed Oct 14, 2024
1 parent fc29add commit 0621e4e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions backup/util/ui/tests/behat/import_course.feature
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ Feature: Import course's contents into another course
And I should see "Unpublished course badge"
And I should see "Unpublished without criteria course badge"
# Badges exist and the criteria have been restored too.
And I should not see "Criteria for this badge have not been set up yet" in the "Published course badge" "table_row"
And I should not see "Criteria for this badge have not been set up yet" in the "Unpublished course badge" "table_row"
And I should see "Criteria for this badge have not been set up yet" in the "Unpublished without criteria course badge" "table_row"
And ".no-criteria-set" "css_element" should not exist in the "Published course badge" "table_row"
And ".no-criteria-set" "css_element" should not exist in the "Unpublished course badge" "table_row"
And ".no-criteria-set" "css_element" should exist in the "Unpublished without criteria course badge" "table_row"
12 changes: 6 additions & 6 deletions backup/util/ui/tests/behat/restore_moodle2_courses.feature
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ Feature: Restore Moodle 2 course backups
And I should see "Unpublished course badge"
And I should see "Unpublished without criteria course badge"
# If activities were included, the criteria have been restored too; otherwise no criteria have been set up for badges.
And I <shouldornotsee> "Criteria for this badge have not been set up yet" in the "Published course badge" "table_row"
And I <shouldornotsee> "Criteria for this badge have not been set up yet" in the "Unpublished course badge" "table_row"
And I should see "Criteria for this badge have not been set up yet" in the "Unpublished without criteria course badge" "table_row"
And ".no-criteria-set" "css_element" <shouldornotexist> in the "Published course badge" "table_row"
And ".no-criteria-set" "css_element" <shouldornotexist> in the "Unpublished course badge" "table_row"
And ".no-criteria-set" "css_element" should exist in the "Unpublished without criteria course badge" "table_row"

Examples:
| includeactivities | shouldornotsee |
| 0 | should see |
| 1 | should not see |
| includeactivities | shouldornotexist |
| 0 | should exist |
| 1 | should not exist |
4 changes: 3 additions & 1 deletion badges/classes/reportbuilder/local/entities/badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ protected function get_all_columns(): array {
return '';
}
$badge = new \core_badges\badge($badgeid);

if (empty($badge->criteria)) {
return '<span class="no-criteria-set d-none"></span>';
}
$renderer = $PAGE->get_renderer('core_badges');
return $renderer->print_badge_criteria($badge, 'short');
});
Expand Down
2 changes: 1 addition & 1 deletion badges/tests/reportbuilder/datasource/badges_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function test_datasource_non_default_columns(): void {
$this->assertEquals($badgetwo->name, $badgename);
$this->assertEmpty($fullname);
$this->assertEquals($expectedbadgetwolink, $namewithlink);
$this->assertEquals('Criteria for this badge have not been set up yet.', $criteria);
$this->assertStringContainsString('no-criteria-set', $criteria);
$this->assertStringContainsString('Image caption', $image);
$this->assertEquals('English', $language);
$this->assertEquals(2, $version);
Expand Down
2 changes: 1 addition & 1 deletion badges/tests/reportbuilder/datasource/users_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function test_datasource_non_default_columns(): void {
$this->assertEquals(fullname($user), $fullname);
$this->assertEquals($badgecourse->name, $badgename);
$this->assertEquals($expectedbadgecourselink, $namewithlink);
$this->assertEquals('Criteria for this badge have not been set up yet.', $criteria);
$this->assertStringContainsString('no-criteria-set', $criteria);
$this->assertStringContainsString('Image caption', $image);
$this->assertEquals('English', $language);
$this->assertEquals(2, $version);
Expand Down

0 comments on commit 0621e4e

Please sign in to comment.