From 4f190127b59e77bb11a33e2d2ba60089c4dde4ef Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Wed, 5 Jan 2022 21:03:26 +0100 Subject: [PATCH] MDL-73359 core_badges: Badge pages polish --- badges/index.php | 2 +- badges/renderer.php | 2 +- badges/tests/behat/add_badge.feature | 3 +- badges/tests/behat/nobadge_navigation.feature | 60 +++++++++++++++++++ badges/view.php | 7 ++- 5 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 badges/tests/behat/nobadge_navigation.feature diff --git a/badges/index.php b/badges/index.php index a389ea53baa..cdbbc4b0109 100644 --- a/badges/index.php +++ b/badges/index.php @@ -189,7 +189,7 @@ if ($totalcount) { echo $output->render($badges); } else { - echo $output->notification(get_string('nobadges', 'badges')); + echo $output->notification(get_string('nobadges', 'badges'), 'info'); } echo $OUTPUT->footer(); diff --git a/badges/renderer.php b/badges/renderer.php index 80bea0c31b1..4ab395b179c 100644 --- a/badges/renderer.php +++ b/badges/renderer.php @@ -380,7 +380,7 @@ class core_badges_renderer extends plugin_renderer_base { $localhtml .= $backpackconnect . $countmessage . $searchform; $localhtml .= $htmlpagingbar . $htmllist . $htmlpagingbar . $downloadall; } else { - $localhtml .= $searchform . $this->output->notification(get_string('nobadges', 'badges')); + $localhtml .= $searchform . $this->output->notification(get_string('nobadges', 'badges'), 'info'); } $localhtml .= html_writer::end_tag('div'); diff --git a/badges/tests/behat/add_badge.feature b/badges/tests/behat/add_badge.feature index 99c906844a2..a59459c7fe2 100644 --- a/badges/tests/behat/add_badge.feature +++ b/badges/tests/behat/add_badge.feature @@ -136,8 +136,7 @@ Feature: Add badges to the system And I add the "Navigation" block if not present When I click on "Site pages" "list_item" in the "Navigation" "block" And I click on "Site badges" "link" in the "Navigation" "block" - Then I should see "Manage badges" - And I should see "Add a new badge" + Then I should see "Add a new badge" # Add a badge. When I press "Add a new badge" And I set the following fields to these values: diff --git a/badges/tests/behat/nobadge_navigation.feature b/badges/tests/behat/nobadge_navigation.feature new file mode 100644 index 00000000000..2b1bcfce633 --- /dev/null +++ b/badges/tests/behat/nobadge_navigation.feature @@ -0,0 +1,60 @@ +@core @core_badges @_file_upload @javascript +Feature: Manage badges is not shown when there are no existing badges. + + Scenario: Check navigation at site level with no badges + Given I log in as "admin" + When I navigate to "Badges > Manage badges" in site administration + And I should see "There are no badges available" + Then "Manage badges" "button" should not exist + + Scenario: Check navigation at course level with no badges + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher | Teacher | 1 | teacher@example.com | + And the following "courses" exist: + | fullname | shortname | format | enablecompletion | + | Course 1 | C1 | topics | 1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher | C1 | editingteacher | + And I log in as "teacher" + And I am on "Course 1" course homepage + When I navigate to "Badges" in current page administration + Then "Manage badges" "button" should not exist + And I click on "Add a new badge" "button" + And I set the following fields to these values: + | Name | Testing course badge | + | Version | 1.1 | + | Language | Basque | + | Description | Testing course badge description | + | Image author | http://author.example.com | + | Image caption | Test caption image | + And I upload "badges/tests/behat/badge.png" file to "Image" filemanager + And I click on "Create badge" "button" + And I click on "Back" "button" + And I should see "Testing course badge" + And I click on "Back" "button" + And "Manage badges" "button" should exist +# Badge is not enabled so is not listed. + And I should not see "Testing course badge" + And I click on "Manage badges" "button" + And I click on "Edit" "link" in the "Testing course badge" "table_row" + And I click on "Add criteria" "button" + And I set the field "type" to "Manual issue by role" + And I expand all fieldsets + And I set the field "Teacher" to "1" + And I click on "Save" "button" + And I click on "Back" "button" + And I should see "Testing course badge" + And I click on "Back" "button" + And "Manage badges" "button" should exist +# Badge is not enabled yet so is not listed. + And I should not see "Testing course badge" + And I click on "Manage badges" "button" + And I click on "Enable access" "link" in the "Testing course badge" "table_row" + And I click on "Continue" "button" + And I should see "Testing course badge" + And I click on "Back" "button" + And "Manage badges" "button" should exist +# Badge is already enabled so is listed. + And I should see "Testing course badge" diff --git a/badges/view.php b/badges/view.php index 2c42e3dc8ac..7e2c79a76d3 100644 --- a/badges/view.php +++ b/badges/view.php @@ -97,6 +97,11 @@ $canmanage = has_any_capability(array('moodle/badges:viewawarded', 'moodle/badges:configuredetails', 'moodle/badges:deletebadge'), $context); +if ($canmanage) { + // Check there are non archived badges on the course. + $allbadgescount = count(badges_get_badges($type, $courseid)); + $canmanage = ($allbadgescount > 0); +} $actionbar = new \core_badges\output\standard_action_bar($PAGE, $type, $canmanage); echo $output->header(); echo $output->render_tertiary_navigation($actionbar); @@ -119,7 +124,7 @@ if ($totalcount) { echo $output->render($badges); } else { - echo $output->notification(get_string('nobadges', 'badges')); + echo $output->notification(get_string('nobadges', 'badges'), 'info'); } // Trigger event, badge listing viewed. $eventparams = array('context' => $PAGE->context, 'other' => $eventotherparams);