mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
MDL-72904 core_badges: Update behat tests
This commit is contained in:
parent
96dd6c9c94
commit
6d5ab2233a
@ -40,12 +40,11 @@ Feature: Add badges to the system
|
||||
And I should see "Alignments (0)"
|
||||
And I should not see "Create badge"
|
||||
And I should not see "Issuer details"
|
||||
And I follow "Overview"
|
||||
And I select "Overview" from the "jump" singleselect
|
||||
And I should see "Issuer details"
|
||||
And I should see "Test Badge Site"
|
||||
And I should see "testuser@example.com"
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I should see "Number of badges available: 1"
|
||||
And I should not see "There are no badges available."
|
||||
|
||||
@javascript @_file_upload
|
||||
@ -62,7 +61,6 @@ Feature: Add badges to the system
|
||||
And I press "Create badge"
|
||||
And I wait until the page is ready
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I should see "Number of badges available: 1"
|
||||
And I press "Add a new badge"
|
||||
And I set the following fields to these values:
|
||||
| Name | Test Badge 2 |
|
||||
@ -73,7 +71,7 @@ Feature: Add badges to the system
|
||||
| Image caption | Test caption image |
|
||||
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
|
||||
And I press "Create badge"
|
||||
And I follow "Related badges (0)"
|
||||
And I select "Related badges (0)" from the "jump" singleselect
|
||||
And I should see "This badge does not have any related badges."
|
||||
And I press "Add related badge"
|
||||
And I follow "Related badges"
|
||||
@ -97,7 +95,7 @@ Feature: Add badges to the system
|
||||
When I press "Create badge"
|
||||
Then I should see "Edit details"
|
||||
And I should see "Endorsement"
|
||||
And I follow "Endorsement"
|
||||
And I select "Endorsement" from the "jump" singleselect
|
||||
And I set the following fields to these values:
|
||||
| Endorser name | Endorser |
|
||||
| Email | endorsement@example.com |
|
||||
@ -121,7 +119,7 @@ Feature: Add badges to the system
|
||||
When I press "Create badge"
|
||||
Then I should see "Test Badge"
|
||||
And I should see "Endorsement"
|
||||
And I follow "Alignments (0)"
|
||||
And I select "Alignments (0)" from the "jump" singleselect
|
||||
And I should see "This badge does not have any external skills or standards specified."
|
||||
And I press "Add external skill or standard"
|
||||
And I set the following fields to these values:
|
||||
@ -158,7 +156,6 @@ Feature: Add badges to the system
|
||||
And I should see "Alignments (0)"
|
||||
And I should not see "Create badge"
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I should see "Number of badges available: 1"
|
||||
And I should not see "There are no badges available."
|
||||
# See buttons from the "Site badges" page.
|
||||
And I am on homepage
|
||||
@ -183,14 +180,14 @@ Feature: Add badges to the system
|
||||
| Image caption | Test caption image |
|
||||
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
|
||||
And I press "Create badge"
|
||||
When I follow "Edit details"
|
||||
When I select "Edit details" from the "jump" singleselect
|
||||
And I should see "Test badge with 'apostrophe' and other friends (&@#)"
|
||||
And I should not see "Issuer details"
|
||||
And I set the following fields to these values:
|
||||
| Name | Test badge renamed |
|
||||
| Version | secondversion |
|
||||
And I press "Save changes"
|
||||
And I follow "Overview"
|
||||
And I select "Overview" from the "jump" singleselect
|
||||
Then I should not see "Test badge with 'apostrophe' and other friends (&@#)"
|
||||
And I should not see "firstversion"
|
||||
And I should see "Test badge renamed"
|
||||
|
@ -63,7 +63,7 @@ Feature: Award badges
|
||||
And I am on "Course 1" course homepage
|
||||
And I navigate to "Badges > Manage badges" in current page administration
|
||||
And I follow "Course Badge 1"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
# Award course badge 1 to student 1.
|
||||
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
|
||||
@ -71,7 +71,7 @@ Feature: Award badges
|
||||
And I am on "Course 1" course homepage
|
||||
And I navigate to "Badges > Manage badges" in current page administration
|
||||
And I follow "Course Badge 1"
|
||||
And I follow "Recipients (1)"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
Then I should see "Recipients (1)"
|
||||
And I log out
|
||||
# Student 1 should have both badges.
|
||||
@ -152,7 +152,7 @@ Feature: Award badges
|
||||
And I press "Save"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Teacher 1 (teacher1@example.com)"
|
||||
And I press "Award badge"
|
||||
@ -181,7 +181,7 @@ Feature: Award badges
|
||||
And I press "Save"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
|
||||
And I press "Award badge"
|
||||
@ -284,7 +284,7 @@ Feature: Award badges
|
||||
And I press "Save"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
# Award course badge 1 to student 1.
|
||||
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
|
||||
@ -292,7 +292,7 @@ Feature: Award badges
|
||||
And I am on "Course 1" course homepage
|
||||
And I navigate to "Badges > Manage badges" in current page administration
|
||||
And I follow "Course Badge 1"
|
||||
And I follow "Recipients (1)"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
Then I should see "Recipients (1)"
|
||||
# Add course badge 2.
|
||||
And I am on "Course 1" course homepage
|
||||
@ -310,7 +310,7 @@ Feature: Award badges
|
||||
And I press "Save"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
# Award course badge 2 to student 2.
|
||||
And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
|
||||
@ -318,7 +318,7 @@ Feature: Award badges
|
||||
And I am on "Course 1" course homepage
|
||||
And I navigate to "Badges > Manage badges" in current page administration
|
||||
And I follow "Course Badge 2"
|
||||
And I follow "Recipients (1)"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
Then I should see "Recipients (1)"
|
||||
And I log out
|
||||
And I trigger cron
|
||||
@ -351,7 +351,7 @@ Feature: Award badges
|
||||
And I press "Save"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
|
||||
And I press "Award badge"
|
||||
@ -361,7 +361,7 @@ Feature: Award badges
|
||||
And I navigate to "Badges > Manage badges" in current page administration
|
||||
And I follow "Course Badge"
|
||||
Then I should see "Recipients (2)"
|
||||
And I follow "Recipients (2)"
|
||||
And I select "Recipients (2)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "existingrecipients[]" to "Student 2 (student2@example.com)"
|
||||
And I press "Revoke badge"
|
||||
|
@ -60,7 +60,7 @@ Feature: Backpack badges
|
||||
And I press "Save"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
|
||||
And I press "Award badge"
|
||||
@ -97,7 +97,7 @@ Feature: Backpack badges
|
||||
And I press "Save"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
|
||||
And I press "Award badge"
|
||||
|
147
badges/tests/behat/badge_navigation.feature
Normal file
147
badges/tests/behat/badge_navigation.feature
Normal file
@ -0,0 +1,147 @@
|
||||
@core @core_badges @_file_upload @javascript
|
||||
Feature: Test tertiary navigation as various users
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
| teacher | Teacher | 1 | teacher@example.com |
|
||||
| nonediting | Nonediting | 1 | nonediting@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 |
|
||||
| student1 | C1 | student |
|
||||
| nonediting | C1 | teacher |
|
||||
# Create system badge and define a criterion.
|
||||
And I log in as "admin"
|
||||
And I am on "Course 1" course homepage
|
||||
And I navigate to "Badges > Add a new badge" in current page administration
|
||||
And I set the following fields to these values:
|
||||
| Name | Testing course badge |
|
||||
| Version | 1.1 |
|
||||
| Language | Catalan |
|
||||
| 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 press "Create badge"
|
||||
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 press "Save"
|
||||
And I am on site homepage
|
||||
And I navigate to "Badges > Add a new badge" in site administration
|
||||
And I set the following fields to these values:
|
||||
| Name | Testing site badge |
|
||||
| Version | 1.1 |
|
||||
| Language | Catalan |
|
||||
| Description | Testing site 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 press "Create badge"
|
||||
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 press "Save"
|
||||
|
||||
Scenario Outline: Check navigation as different users in a course context
|
||||
Given I log in as "<user>"
|
||||
And I am on "Course 1" course homepage
|
||||
When I navigate to "Badges" in current page administration
|
||||
Then "Manage badges" "button" should exist
|
||||
And "Add a new badge" "button" <createbutton>
|
||||
And I should see "<activetab>" is active in secondary navigation
|
||||
And I click on "Manage badges" "button"
|
||||
And "Manage badges" "button" should not exist
|
||||
And "Back" "button" should exist
|
||||
And "Add a new badge" "button" <createbutton>
|
||||
And I should see "<activetab>" is active in secondary navigation
|
||||
And I click on "Back" "button"
|
||||
And "Back" "button" should not exist
|
||||
And "Manage badges" "button" should exist
|
||||
And "Add a new badge" "button" <createbutton>
|
||||
And I should see "<activetab>" is active in secondary navigation
|
||||
And I click on "Manage badges" "button"
|
||||
And I click on "Testing course badge" "link"
|
||||
And "Manage badges" "button" should not exist
|
||||
And "Add a new badge" "button" should not exist
|
||||
And "Back" "button" should exist
|
||||
And I should see "<activetab>" is active in secondary navigation
|
||||
And I click on "Back" "button"
|
||||
And "Back" "button" should exist
|
||||
And "Manage badges" "button" should not exist
|
||||
And "Add a new badge" "button" <createbutton>
|
||||
And I should see "<activetab>" is active in secondary navigation
|
||||
|
||||
Examples:
|
||||
| user | createbutton | activetab |
|
||||
| admin | should exist | More |
|
||||
| teacher | should exist | More |
|
||||
| nonediting | should not exist | Badges |
|
||||
|
||||
Scenario: Check navigation as a student
|
||||
Given I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
When I navigate to "Badges" in current page administration
|
||||
Then "Back" "button" should not exist
|
||||
And "Manage badges" "button" should not exist
|
||||
And "Add a new badge" "button" should not exist
|
||||
And I should see "Badges" is active in secondary navigation
|
||||
|
||||
Scenario: Check navigation as an admin in a site context
|
||||
Given I log in as "admin"
|
||||
When I navigate to "Badges > Manage badges" in site administration
|
||||
Then "Manage badges" "button" should not exist
|
||||
And "Add a new badge" "button" should exist
|
||||
And I should see "Site administration" is active in secondary navigation
|
||||
And I click on "Testing site badge" "link"
|
||||
And "Manage badges" "button" should not exist
|
||||
And "Add a new badge" "button" should not exist
|
||||
And "Back" "button" should exist
|
||||
And I should see "Site administration" is active in secondary navigation
|
||||
And I click on "Back" "button"
|
||||
And "Back" "button" should not exist
|
||||
And "Manage badges" "button" should not exist
|
||||
And "Add a new badge" "button" should exist
|
||||
|
||||
Scenario Outline: Check secondary navigation highlights after tertiary nav jumps in site admin
|
||||
Given I log in as "admin"
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I click on "Testing site badge" "link"
|
||||
When I select "<option>" from the "jump" singleselect
|
||||
Then I should see "Site administration" is active in secondary navigation
|
||||
|
||||
Examples:
|
||||
| option |
|
||||
| Overview |
|
||||
| Edit details |
|
||||
| Criteria |
|
||||
| Message |
|
||||
| Recipients (0) |
|
||||
| Endorsement |
|
||||
| Related badges (0) |
|
||||
| Alignments (0) |
|
||||
|
||||
Scenario Outline: Check secondary navigation highlights after tertiary nav jumps in course as admin
|
||||
Given I log in as "admin"
|
||||
And I am on "Course 1" course homepage
|
||||
And I navigate to "Badges" in current page administration
|
||||
And I click on "Manage badges" "button"
|
||||
And I click on "Testing course badge" "link"
|
||||
When I select "<option>" from the "jump" singleselect
|
||||
Then I should see "More" is active in secondary navigation
|
||||
|
||||
Examples:
|
||||
| option |
|
||||
| Overview |
|
||||
| Edit details |
|
||||
| Criteria |
|
||||
| Message |
|
||||
| Recipients (0) |
|
||||
| Endorsement |
|
||||
| Related badges (0) |
|
||||
| Alignments (0) |
|
@ -146,7 +146,7 @@ Feature: Award badges based on cohort
|
||||
And I press "Save"
|
||||
When I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "First User (first@example.com)"
|
||||
And I press "Award badge"
|
||||
@ -198,7 +198,7 @@ Feature: Award badges based on cohort
|
||||
And I set the field "update" to "Any"
|
||||
When I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (1)"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "First User (first@example.com)"
|
||||
And I press "Award badge"
|
||||
@ -255,7 +255,7 @@ Feature: Award badges based on cohort
|
||||
And I set the field "update" to "Any"
|
||||
When I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (1)"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "First User (first@example.com)"
|
||||
And I press "Award badge"
|
||||
@ -314,7 +314,7 @@ Feature: Award badges based on cohort
|
||||
And I set the field "update" to "All"
|
||||
When I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "First User (first@example.com)"
|
||||
And I press "Award badge"
|
||||
|
@ -30,14 +30,14 @@ Feature: Display badges
|
||||
Given I press "Enable access"
|
||||
And I press "Continue"
|
||||
# Award badge to student1.
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
|
||||
And I press "Award badge"
|
||||
# Check badge details are displayed.
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I follow "Testing system badge"
|
||||
And I follow "Recipients (1)"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
When I click on "View issued badge" "link" in the "Student 1" "table_row"
|
||||
Then I should see "Awarded to Student 1"
|
||||
And I should see "This badge has to be awarded by a user with the following role:"
|
||||
@ -55,14 +55,14 @@ Feature: Display badges
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
# Award badge to student1.
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
|
||||
And I press "Award badge"
|
||||
# Check badge details are displayed.
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I follow "Testing system badge"
|
||||
And I follow "Recipients (1)"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
When I click on "View issued badge" "link" in the "Student 1" "table_row"
|
||||
Then I should see "Awarded to Student 1"
|
||||
And I should see "Complete ALL of the listed requirements."
|
||||
@ -83,7 +83,7 @@ Feature: Display badges
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
# Check badge details are displayed.
|
||||
And I follow "Recipients (2)"
|
||||
And I select "Recipients (2)" from the "jump" singleselect
|
||||
When I click on "View issued badge" "link" in the "Student 1" "table_row"
|
||||
Then I should see "Awarded to Student 1"
|
||||
And I should see "Complete ANY of the listed requirements."
|
||||
@ -97,28 +97,28 @@ Feature: Display badges
|
||||
|
||||
Scenario: Display badge with expiration date but not expired yet
|
||||
# Set expired date to badge (future date).
|
||||
Given I follow "Edit details"
|
||||
Given I select "Edit details" from the "jump" singleselect
|
||||
When I click on "Relative date" "radio"
|
||||
And I set the field "expireperiod[number]" to "1"
|
||||
And I press "Save changes"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
# Award badge to student1.
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
|
||||
And I press "Award badge"
|
||||
# Check "Expires" date is displayed.
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I follow "Testing system badge"
|
||||
And I follow "Recipients (1)"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
And I click on "View issued badge" "link" in the "Student 1" "table_row"
|
||||
Then I should see "Expires"
|
||||
And I should not see "Expired"
|
||||
|
||||
Scenario: Display expired badge
|
||||
# Set expired date to badge (relative date 1 seconds after the date of issue it).
|
||||
Given I follow "Edit details"
|
||||
Given I select "Edit details" from the "jump" singleselect
|
||||
When I click on "Relative date" "radio"
|
||||
And I set the field "expireperiod[timeunit]" to "1"
|
||||
And I set the field "expireperiod[number]" to "1"
|
||||
@ -126,7 +126,7 @@ Feature: Display badges
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
# Award badge to student1.
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
|
||||
And I press "Award badge"
|
||||
@ -135,7 +135,7 @@ Feature: Display badges
|
||||
# Check "Expired" date is displayed.
|
||||
And I navigate to "Badges > Manage badges" in site administration
|
||||
And I follow "Testing system badge"
|
||||
And I follow "Recipients (1)"
|
||||
And I select "Recipients (1)" from the "jump" singleselect
|
||||
And I click on "View issued badge" "link" in the "Student 1" "table_row"
|
||||
Then I should see "Expired"
|
||||
And I should not see "Expires"
|
||||
|
141
badges/tests/output/manage_badge_action_bar_test.php
Normal file
141
badges/tests/output/manage_badge_action_bar_test.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core_badges\output;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
/**
|
||||
* Class manage_badge_action_bar_test
|
||||
*
|
||||
* Unit test for the badges tertiary navigation
|
||||
*
|
||||
* @coversDefaultClass \core_badges\output\manage_badge_action_bar
|
||||
* @package core_badges
|
||||
* @copyright 2021 onwards Peter Dias
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class manage_badge_action_bar_test extends \advanced_testcase {
|
||||
/**
|
||||
* Data provider for test_generate_badge_navigation
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function generate_badge_navigation_provider(): array {
|
||||
return [
|
||||
"Test tertiary nav as an editing teacher" => [
|
||||
"editingteacher", [
|
||||
'Overview',
|
||||
'Edit details',
|
||||
'Criteria',
|
||||
'Message',
|
||||
'Recipients (0)',
|
||||
'Endorsement',
|
||||
'Related badges (0)',
|
||||
'Alignments (0)'
|
||||
],
|
||||
],
|
||||
"Test tertiary nav as an non-editing teacher" => [
|
||||
"teacher", [
|
||||
'Overview',
|
||||
'Recipients (0)'
|
||||
],
|
||||
],
|
||||
"Test tertiary nav as an admin" => [
|
||||
"admin", [
|
||||
'Overview',
|
||||
'Edit details',
|
||||
'Criteria',
|
||||
'Message',
|
||||
'Recipients (0)',
|
||||
'Endorsement',
|
||||
'Related badges (0)',
|
||||
'Alignments (0)'
|
||||
]
|
||||
],
|
||||
"Test tertiary nav as a student" => [
|
||||
"student", [
|
||||
'Overview'
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the generate_badge_navigation function
|
||||
*
|
||||
* @dataProvider generate_badge_navigation_provider
|
||||
* @param string $role
|
||||
* @param array $expected
|
||||
* @covers ::generate_badge_navigation
|
||||
*/
|
||||
public function test_generate_badge_navigation(string $role, array $expected) {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$teacher = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
|
||||
if ($role != 'admin') {
|
||||
$user = $this->getDataGenerator()->create_and_enrol($course, $role);
|
||||
$this->setUser($user);
|
||||
} else {
|
||||
$this->setAdminUser();
|
||||
}
|
||||
|
||||
// Mock up a course badge.
|
||||
$now = time();
|
||||
$badge = new \stdClass();
|
||||
$badge->id = null;
|
||||
$badge->name = "Test badge course";
|
||||
$badge->description = "Testing badges course";
|
||||
$badge->type = BADGE_TYPE_COURSE;
|
||||
$badge->courseid = $course->id;
|
||||
$badge->timecreated = $now - 12;
|
||||
$badge->timemodified = $now - 12;
|
||||
$badge->usercreated = $teacher->id;
|
||||
$badge->usermodified = $teacher->id;
|
||||
$badge->issuername = "Test issuer";
|
||||
$badge->issuerurl = "http://issuer-url.domain.co.nz";
|
||||
$badge->issuercontact = "issuer@example.com";
|
||||
$badge->expiredate = null;
|
||||
$badge->expireperiod = null;
|
||||
$badge->messagesubject = "Test message subject for badge";
|
||||
$badge->message = "Test message body for badge";
|
||||
$badge->attachment = 1;
|
||||
$badge->notification = 0;
|
||||
$badge->status = BADGE_STATUS_ACTIVE;
|
||||
$badge->version = '1';
|
||||
$badge->language = 'en';
|
||||
$badge->imageauthorname = 'Image author';
|
||||
$badge->imageauthoremail = 'imageauthor@example.com';
|
||||
$badge->imageauthorurl = 'http://image-author-url.domain.co.nz';
|
||||
$badge->imagecaption = 'Caption';
|
||||
$coursebadgeid = $DB->insert_record('badge', $badge, true);
|
||||
$badge = new \core_badges\badge($coursebadgeid);
|
||||
|
||||
$context = \context_course::instance($course->id);
|
||||
$page = new \moodle_page();
|
||||
$page->set_context($context);
|
||||
$actionbar = new manage_badge_action_bar($badge, $page);
|
||||
|
||||
$rc = new \ReflectionClass(manage_badge_action_bar::class);
|
||||
$rcm = $rc->getMethod('generate_badge_navigation');
|
||||
$rcm->setAccessible(true);
|
||||
$content = $rcm->invoke($actionbar);
|
||||
$this->assertEquals($expected, array_values($content));
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ Feature: Enable Block Badges in a course
|
||||
And I press "Save"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Teacher 1 (teacher1@example.com)"
|
||||
And I press "Award badge"
|
||||
@ -45,7 +45,7 @@ Feature: Enable Block Badges in a course
|
||||
And I press "Save"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Teacher 1 (teacher1@example.com)"
|
||||
And I press "Award badge"
|
||||
|
@ -28,7 +28,7 @@ Feature: Enable Block Badges on the dashboard and view awarded badges
|
||||
And I press "Save"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Teacher 1 (teacher1@example.com)"
|
||||
And I press "Award badge"
|
||||
|
@ -33,7 +33,7 @@ Feature: Enable Block Badges on the frontpage and view awarded badges
|
||||
And I press "Save"
|
||||
And I press "Enable access"
|
||||
And I press "Continue"
|
||||
And I follow "Recipients (0)"
|
||||
And I select "Recipients (0)" from the "jump" singleselect
|
||||
And I press "Award badge"
|
||||
And I set the field "potentialrecipients[]" to "Teacher 1 (teacher1@example.com)"
|
||||
And I press "Award badge"
|
||||
|
@ -44,6 +44,18 @@ class behat_theme_boost_behat_navigation extends behat_navigation {
|
||||
$this->execute("behat_general::assert_element_contains_text",
|
||||
[$element, '.navbar .nav-link.active', 'css_element']);
|
||||
}
|
||||
/**
|
||||
* Checks whether a node is active in the secondary nav.
|
||||
*
|
||||
* @Given i should see :name is active in secondary navigation
|
||||
* @throws ElementNotFoundException
|
||||
* @param string $element The name of the nav elemnent to look for.
|
||||
* @return void
|
||||
*/
|
||||
public function i_should_see_is_active_in_secondary_navigation($element) {
|
||||
$this->execute("behat_general::assert_element_contains_text",
|
||||
[$element, '.secondary-navigation .nav-link.active', 'css_element']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the language selector menu is present in the navbar.
|
||||
|
168
theme/boost/tests/boostnavbar_test.php
Normal file
168
theme/boost/tests/boostnavbar_test.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace theme_boost;
|
||||
|
||||
/**
|
||||
* Test the boostnavbar file
|
||||
*
|
||||
* @package theme_boost
|
||||
* @copyright 2021 Peter Dias
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class boostnavbar_test extends \advanced_testcase {
|
||||
/**
|
||||
* Provider for test_remove_no_link_items
|
||||
* The setup and expected arrays are defined as an array of 'nodekey' => $hasaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function remove_no_link_items_provider(): array {
|
||||
return [
|
||||
'All nodes have links links including leaf node' => [
|
||||
[
|
||||
'node1' => true,
|
||||
'node2' => true,
|
||||
'node3' => true,
|
||||
],
|
||||
[
|
||||
'Home' => true,
|
||||
'Courses' => true,
|
||||
'tc_1' => true,
|
||||
'node1' => true,
|
||||
'node2' => true,
|
||||
'node3' => true,
|
||||
]
|
||||
],
|
||||
'Only some parent nodes have links. Leaf node has a link.' => [
|
||||
[
|
||||
'node1' => false,
|
||||
'node2' => true,
|
||||
'node3' => true,
|
||||
],
|
||||
[
|
||||
'Home' => true,
|
||||
'Courses' => true,
|
||||
'tc_1' => true,
|
||||
'node2' => true,
|
||||
'node3' => true,
|
||||
]
|
||||
],
|
||||
'All parent nodes do not have links. Leaf node has a link.' => [
|
||||
[
|
||||
'node1' => false,
|
||||
'node2' => false,
|
||||
'node3' => true,
|
||||
],
|
||||
[
|
||||
'Home' => true,
|
||||
'Courses' => true,
|
||||
'tc_1' => true,
|
||||
'node3' => true,
|
||||
]
|
||||
],
|
||||
'All parent nodes have links. Leaf node does not has a link.' => [
|
||||
[
|
||||
'node1' => true,
|
||||
'node2' => true,
|
||||
'node3' => false,
|
||||
],
|
||||
[
|
||||
'Home' => true,
|
||||
'Courses' => true,
|
||||
'tc_1' => true,
|
||||
'node1' => true,
|
||||
'node2' => true,
|
||||
'node3' => false,
|
||||
]
|
||||
],
|
||||
'All parent nodes do not have links. Leaf node does not has a link.' => [
|
||||
[
|
||||
'node1' => false,
|
||||
'node2' => false,
|
||||
'node3' => false,
|
||||
],
|
||||
[
|
||||
'Home' => true,
|
||||
'Courses' => true,
|
||||
'tc_1' => true,
|
||||
'node3' => false,
|
||||
]
|
||||
],
|
||||
'Some parent nodes do not have links. Leaf node does not has a link.' => [
|
||||
[
|
||||
'node1' => true,
|
||||
'node2' => false,
|
||||
'node3' => false,
|
||||
],
|
||||
[
|
||||
'Home' => true,
|
||||
'Courses' => true,
|
||||
'tc_1' => true,
|
||||
'node1' => true,
|
||||
'node3' => false,
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Test the remove_no_link_items function
|
||||
*
|
||||
* @dataProvider remove_no_link_items_provider
|
||||
* @param array $setup
|
||||
* @param array $expected
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function test_remove_no_link_items(array $setup, array $expected) {
|
||||
global $PAGE;
|
||||
|
||||
$this->resetAfterTest();
|
||||
// Unfortunate hack needed because people use global $PAGE around the place.
|
||||
$PAGE->set_url('/');
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$page = new \moodle_page();
|
||||
$page->set_course($course);
|
||||
$page->set_url(new \moodle_url('/course/view.php', array('id' => $course->id)));
|
||||
// A dummy url to use. We don't care where it's pointing to.
|
||||
$url = new \moodle_url('/');
|
||||
foreach ($setup as $node => $hasaction) {
|
||||
$page->navbar->add($node, $hasaction ? $url : null);
|
||||
}
|
||||
|
||||
$boostnavbar = $this->getMockBuilder(boostnavbar::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([])
|
||||
->getMock();
|
||||
|
||||
$rc = new \ReflectionClass(boostnavbar::class);
|
||||
$rcp = $rc->getProperty('items');
|
||||
$rcp->setAccessible(true);
|
||||
$rcp->setValue($boostnavbar, $page->navbar->get_items());
|
||||
|
||||
// Make the call to the function.
|
||||
$rcm = $rc->getMethod('remove_no_link_items');
|
||||
$rcm->setAccessible(true);
|
||||
$rcm->invoke($boostnavbar);
|
||||
|
||||
// Get the value for the class variable that the function modifies.
|
||||
$values = $rcp->getValue($boostnavbar);
|
||||
$actual = [];
|
||||
foreach ($values as $value) {
|
||||
$actual[$value->text] = $value->has_action();
|
||||
}
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@
|
||||
"blocks/tests/behat/move_blocks.feature",
|
||||
"course/format/tests/behat/course_courseindex.feature",
|
||||
"course/format/tests/behat/courseindex_keyboardnav.feature",
|
||||
"course/format/tests/behat/courseindex_completion.feature"
|
||||
"course/format/tests/behat/courseindex_completion.feature",
|
||||
"badges/tests/behat/badge_navigation.feature"
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user