From 0621e4e7cea27d6602f9082cabaf71670f531d42 Mon Sep 17 00:00:00 2001 From: Laurent David Date: Thu, 12 Sep 2024 09:44:28 +0200 Subject: [PATCH] MDL-82904 core_badges: Display empty column for unset criteria * In the report builder badges with unset criteria should have a empty value for the criteria column --- backup/util/ui/tests/behat/import_course.feature | 6 +++--- .../ui/tests/behat/restore_moodle2_courses.feature | 12 ++++++------ .../classes/reportbuilder/local/entities/badge.php | 4 +++- .../tests/reportbuilder/datasource/badges_test.php | 2 +- badges/tests/reportbuilder/datasource/users_test.php | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/backup/util/ui/tests/behat/import_course.feature b/backup/util/ui/tests/behat/import_course.feature index 5f849f5b711e6..8e9f31e62da8b 100644 --- a/backup/util/ui/tests/behat/import_course.feature +++ b/backup/util/ui/tests/behat/import_course.feature @@ -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" diff --git a/backup/util/ui/tests/behat/restore_moodle2_courses.feature b/backup/util/ui/tests/behat/restore_moodle2_courses.feature index 7da17b0abfca7..bca95e15c4b9f 100644 --- a/backup/util/ui/tests/behat/restore_moodle2_courses.feature +++ b/backup/util/ui/tests/behat/restore_moodle2_courses.feature @@ -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 "Criteria for this badge have not been set up yet" in the "Published course badge" "table_row" - And I "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" in the "Published course badge" "table_row" + And ".no-criteria-set" "css_element" 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 | diff --git a/badges/classes/reportbuilder/local/entities/badge.php b/badges/classes/reportbuilder/local/entities/badge.php index 526c441382c39..a205d5eed93ba 100644 --- a/badges/classes/reportbuilder/local/entities/badge.php +++ b/badges/classes/reportbuilder/local/entities/badge.php @@ -160,7 +160,9 @@ protected function get_all_columns(): array { return ''; } $badge = new \core_badges\badge($badgeid); - + if (empty($badge->criteria)) { + return ''; + } $renderer = $PAGE->get_renderer('core_badges'); return $renderer->print_badge_criteria($badge, 'short'); }); diff --git a/badges/tests/reportbuilder/datasource/badges_test.php b/badges/tests/reportbuilder/datasource/badges_test.php index 3644a16522de7..fa8ab22ae34ee 100644 --- a/badges/tests/reportbuilder/datasource/badges_test.php +++ b/badges/tests/reportbuilder/datasource/badges_test.php @@ -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); diff --git a/badges/tests/reportbuilder/datasource/users_test.php b/badges/tests/reportbuilder/datasource/users_test.php index b83f36f60f1ca..65af92adfcd15 100644 --- a/badges/tests/reportbuilder/datasource/users_test.php +++ b/badges/tests/reportbuilder/datasource/users_test.php @@ -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);