first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,412 @@
@tool @tool_behat @javascript
Feature: Set up contextual data for tests
In order to write tests quickly
As a developer
I need to fill the database with fixtures
Scenario: Add a bunch of users
Given the following "users" exist:
| username | password | firstname | lastname |
| testuser | testuser | | |
| testuser2 | testuser2 | TestFirstname | TestLastname |
And I log in as "testuser"
And I log out
When I log in as "testuser2"
Then I should see "TestFirstname"
Scenario: Add a bunch of courses and categories
Given the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
| Cat 2 | CAT1 | CAT2 |
| Cat 3 | CAT1 | CAT3 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | COURSE1 | CAT3 |
| Course 2 | COURSE2 | CAT3 |
| Course 3 | COURSE3 | 0 |
When I log in as "admin"
And I am on site homepage
Then I should see "Course 1"
And I should see "Course 2"
And I should see "Course 3"
And I go to the courses management page
And I follow "Cat 1"
And I should see "Cat 2"
And I should see "Cat 3"
And I follow "Cat 3"
And I should see "Course 1"
And I should see "Course 2"
And I follow "Cat 2"
And I should see "No courses in this category"
And I follow "Category 1"
And I should see "Course 3"
Scenario: Add a bunch of groups and groupings
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| Group 2 | C1 | G2 |
And the following "groupings" exist:
| name | course | idnumber |
| Grouping 1 | C1 | GG1 |
| Grouping 2 | C1 | GG2 |
When I log in as "admin"
And I am on the "Course 1" "groups" page
Then I should see "Group 1"
And I should see "Group 2"
And I set the field "Participants tertiary navigation" to "Groupings"
And I should see "Grouping 1"
And I should see "Grouping 2"
Scenario: Role overrides
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| teacher1 | C1 | editingteacher |
And the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| mod/forum:editanypost | Allow | student | Course | C1 |
| mod/forum:replynews | Prevent | editingteacher | Course | C1 |
When I log in as "admin"
And I am on the "Course 1" "permissions" page
And I set the field "Advanced role override" to "Student (1)"
Then "mod/forum:editanypost" capability has "Allow" permission
And I press "Cancel"
And I set the field "Advanced role override" to "Teacher (1)"
And "mod/forum:replynews" capability has "Prevent" permission
And I press "Cancel"
Scenario: Add course enrolments
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
When I am on the "Course 1" course page logged in as student1
Then I should see "New section"
Scenario: Add role assigns
Given the following "roles" exist:
| name | shortname | description | archetype |
| Custom editing teacher | custom1 | My custom role 1 | editingteacher |
| Custom student | custom2 | | |
And the following "users" exist:
| username | firstname | lastname | email |
| user1 | User | 1 | user1@example.com |
| user2 | User | 2 | user2@example.com |
| user3 | User | 3 | user3@example.com |
| user4 | User | 4 | user4@example.com |
| user5 | User | 5 | user5@example.com |
And the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | CAT1 |
And the following "course enrolments" exist:
| user | course | role |
| user4 | C1 | custom1 |
| user2 | C1 | student |
| user3 | C1 | editingteacher |
And the following "role assigns" exist:
| user | role | contextlevel | reference |
| user1 | manager | System | |
| user2 | editingteacher | Category | CAT1 |
| user5 | custom2 | System | |
When I log in as "user1"
And I am on site homepage
Then edit mode should be available on the current page
And I am on the "Course 1" course page logged in as user2
Then edit mode should be available on the current page
And I am on the "Course 1" course page logged in as user3
Then edit mode should be available on the current page
And I am on the "Course 1" course page logged in as user4
Then edit mode should be available on the current page
And I log out
And I log in as "user5"
And I should see "You are logged in as"
And I am on "Course 1" course homepage
And I should see "You cannot enrol yourself in this course."
Scenario: Add modules
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And I enable "chat" "mod" plugin
And I enable "survey" "mod" plugin
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| assign | Test assignment name | Test assignment description | C1 | assign1 |
| book | Test book name | Test book description | C1 | book1 |
| chat | Test chat name | Test chat description | C1 | chat1 |
| choice | Test choice name | Test choice description | C1 | choice1 |
| data | Test database name | Test database description | C1 | data1 |
| feedback | Test feedback name | Test feedback description | C1 | feedback1 |
| folder | Test folder name | Test folder description | C1 | folder1 |
| forum | Test forum name | Test forum description | C1 | forum1 |
| glossary | Test glossary name | Test glossary description | C1 | glossary1 |
| imscp | Test imscp name | Test imscp description | C1 | imscp1 |
| label | Test label name | Test label description | C1 | label1 |
| lesson | Test lesson name | Test lesson description | C1 | lesson1 |
| lti | Test lti name | Test lti description | C1 | lti1 |
| page | Test page name | Test page description | C1 | page1 |
| quiz | Test quiz name | Test quiz description | C1 | quiz1 |
| resource | Test resource name | Test resource description | C1 | resource1 |
| scorm | Test scorm name | Test scorm description | C1 | scorm1 |
| survey | Test survey name | Test survey description | C1 | survey1 |
| url | Test url name | Test url description | C1 | url1 |
| wiki | Test wiki name | Test wiki description | C1 | wiki1 |
| workshop | Test workshop name | Test workshop description | C1 | workshop1 |
And the following "scales" exist:
| name | scale |
| Test Scale 1 | Disappointing, Good, Very good, Excellent |
And the following "activities" exist:
| activity | name | intro | course | idnumber | grade |
| assign | Test assignment name with scale | Test assignment description | C1 | assign1 | Test Scale 1 |
When I am on the "Course 1" course page logged in as admin
Then I should see "Test assignment name"
# Assignment 2.2 module type is disabled by default
# And I should see "Test assignment22 name"
And I should see "Test book name"
And I should see "Test chat name"
And I should see "Test choice name"
And I should see "Test database name"
# Feedback module type is disabled by default
# And I should see "Test feedback name"
And I should see "Test folder name"
And I should see "Test forum name"
And I should see "Test glossary name"
And I should see "Test imscp name"
# We don't see label name, we see only description:
And I should see "Test label description"
And I should see "Test lesson name"
And I should see "Test lti name"
And I should see "Test page name"
And I should see "Test quiz name"
And I should see "Test resource name"
And I should see "Test scorm name"
And I should see "Test survey name"
And I should see "Test url name"
And I should see "Test wiki name"
And I should see "Test workshop name"
And I follow "Test assignment name"
And I should see "Test assignment description"
And I am on "Course 1" course homepage
And I follow "Test assignment name with scale"
And I follow "Settings"
And the field "Type" matches value "Scale"
Scenario: Add relations between users and groups
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| Group 2 | C1 | G2 |
And the following "groupings" exist:
| name | course | idnumber |
| Grouping 1 | C1 | GG1 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| student2 | C1 | student |
And the following "group members" exist:
| user | group |
| student1 | G1 |
| student2 | G2 |
And the following "grouping groups" exist:
| grouping | group |
| GG1 | G1 |
When I log in as "admin"
And I am on the "Course 1" "groups" page
Then the "groups" select box should contain "Group 1 (1)"
And the "groups" select box should contain "Group 2 (1)"
And I set the field "groups" to "Group 1 (1)"
And the "members" select box should contain "Student 1 (student1@example.com)"
And I set the field "groups" to "Group 2 (1)"
And the "members" select box should contain "Student 2 (student2@example.com)"
Scenario: Add cohorts and cohort members with data generator
Given the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
And the following "cohorts" exist:
| name | idnumber |
| System cohort A | CHSA |
And the following "cohorts" exist:
| name | idnumber | contextlevel | reference |
| System cohort B | CHSB | System | |
| Cohort in category | CHC | Category | CAT1 |
| Empty cohort | CHE | Category | CAT1 |
And the following "cohort members" exist:
| user | cohort |
| student1 | CHSA |
| student2 | CHSB |
| student1 | CHSB |
| student1 | CHC |
When I log in as "admin"
And I navigate to "Users > Accounts > Cohorts" in site administration
Then the following should exist in the "reportbuilder-table" table:
| Name | Cohort size |
| System cohort A | 1 |
| System cohort B | 2 |
And I should not see "Cohort in category"
And I am on course index
And I follow "Cat 1"
And I navigate to "Cohorts" in current page administration
And I should not see "System cohort"
And the following should exist in the "reportbuilder-table" table:
| Name | Cohort size |
| Cohort in category | 1 |
| Empty cohort | 0 |
Scenario: Add grade categories with data generator
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "grade categories" exist:
| fullname | course |
| Grade category 1 | C1 |
And the following "grade categories" exist:
| fullname | course | gradecategory |
| Grade sub category 2 | C1 | Grade category 1 |
When I am on the "Course 1" "grades > Grader report > View" page logged in as "admin"
Then I should see "Grade category 1"
And I should see "Grade sub category 2"
Scenario: Add a bunch of grade items
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "grade categories" exist:
| fullname | course |
| Grade category 1 | C1 |
And the following "grade categories" exist:
| fullname | course | gradecategory |
| Grade sub category 2 | C1 | Grade category 1 |
And the following "grade items" exist:
| itemname | course |
| Test Grade Item 1 | C1 |
And the following "grade items" exist:
| itemname | course | gradecategory |
| Test Grade Item 2 | C1 | Grade category 1 |
| Test Grade Item 3 | C1 | Grade sub category 2 |
When I am on the "Course 1" "grades > gradebook setup" page logged in as "admin"
Then I should see "Test Grade Item 1"
And I click on grade item menu "Test Grade Item 1" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I expand all fieldsets
And I should see "Course 1"
And I click on "Cancel" "button" in the "Edit grade item" "dialogue"
And I should see "Grade category 1"
And I should see "Test Grade Item 2"
And I click on grade item menu "Test Grade Item 2" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I expand all fieldsets
And I should see "Grade category 1"
And I click on "Cancel" "button" in the "Edit grade item" "dialogue"
And I should see "Grade sub category 2"
And I should see "Test Grade Item 3"
And I click on grade item menu "Test Grade Item 3" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I expand all fieldsets
And I should see "Grade sub category 2"
And I click on "Cancel" "button" in the "Edit grade item" "dialogue"
Scenario: Add a bunch of scales
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "scales" exist:
| name | scale |
| Test Scale 1 | Disappointing, Good, Very good, Excellent |
When I am on the "Course 1" "grades > scales" page logged in as admin
Then I should see "Test Scale 1"
And I should see "Disappointing, Good, Very good, Excellent"
Scenario: Add a bunch of outcomes
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "scales" exist:
| name | scale |
| Test Scale 1 | Disappointing, Good, Very good, Excellent |
And the following "grade outcomes" exist:
| fullname | shortname | scale |
| Grade outcome 1 | OT1 | Test Scale 1 |
And the following "grade outcomes" exist:
| fullname | shortname | course | scale |
| Grade outcome 2 | OT2 | C1 | Test Scale 1 |
And the following config values are set as admin:
| enableoutcomes | 1 |
When I am on the "Course 1" "grades > outcomes" page logged in as admin
Then I should see "Grade outcome 1" in the "#addoutcomes" "css_element"
And I should see "Grade outcome 2" in the "#removeoutcomes" "css_element"
And I press "Manage outcomes"
And the following should exist in the "generaltable" table:
| Full name | Short name | Scale |
| Grade outcome 2 | OT2 | Test Scale 1 |
Scenario: Add a bunch of outcome grade items
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "scales" exist:
| name | scale |
| Test Scale 1 | Disappointing, Good, Very good, Excellent |
And the following "grade outcomes" exist:
| fullname | shortname | course | scale |
| Grade outcome 1 | OT1 | C1 | Test Scale 1 |
And the following "grade categories" exist:
| fullname | course |
| Grade category 1 | C1 |
And the following "grade items" exist:
| itemname | course | outcome | gradecategory |
| Test Outcome Grade Item 1 | C1 | OT1 | Grade category 1 |
And the following config values are set as admin:
| enableoutcomes | 1 |
When I am on the "Course 1" "grades > gradebook setup" page logged in as "admin"
Then I should see "Test Outcome Grade Item 1"
And I click on grade item menu "Test Outcome Grade Item 1" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I click on "Show more..." "link" in the "Edit outcome item" "dialogue"
And the field "Outcome" matches value "Grade outcome 1"
And I should see "Grade category 1" in the "Grade category" "form_row"
And I press "Cancel"
Scenario: Add a block
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| online_users | Course | C1 | course-view-* | site-pre |
When I am on the "Course 1" course page logged in as admin
Then I should see "Online users"
@@ -0,0 +1,25 @@
@tool @tool_behat
Feature: Transform date time string arguments
In order to write tests with relative date and time
As a user
I need to apply some transformations to the steps arguments
Scenario: Set date in table and check date with specific format
Given I am on site homepage
And the following "users" exist:
| username | firstname | lastname |
| teacher1 | Teacher | 1 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "activities" exist:
| activity | course | idnumber | name | intro | duedate |
| assign | C1 | assign1 | Test assignment name | Test assignment description | ##yesterday## |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Test assignment name"
And I should see "##yesterday##%d %B %Y##"
And I log out
@@ -0,0 +1,90 @@
@tool @tool_behat
Feature: Edit capabilities
In order to extend and restrict moodle features
As an admin or a teacher
I need to allow/deny the existing capabilities at different levels
Background:
Given the following "users" exist:
| username | firstname | lastname |
| teacher1 | Teacher | 1 |
| tutor | Teaching | Assistant |
| student | Student | One |
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| tutor | C1 | teacher |
| student | C1 | student |
Scenario: Default system capabilities modification
Given I log in as "admin"
And I navigate to "Users > Permissions > Define roles" in site administration
And I click on "Edit Teacher role" "link"
And I fill the capabilities form with the following permissions:
| capability | permission |
| block/mnet_hosts:myaddinstance | Allow |
| moodle/site:messageanyuser | Inherit |
| moodle/grade:managesharedforms | Prevent |
| moodle/course:request | Prohibit |
And I press "Save changes"
When I follow "Edit Teacher role"
Then "block/mnet_hosts:myaddinstance" capability has "Allow" permission
And "moodle/site:messageanyuser" capability has "Not set" permission
And "moodle/grade:managesharedforms" capability has "Prevent" permission
And "moodle/course:request" capability has "Prohibit" permission
Scenario: Course capabilities overrides
Given I log in as "teacher1"
And I am on the "Course 1" "permissions" page
And I override the system permissions of "Student" role with:
| mod/forum:deleteanypost | Prohibit |
| mod/forum:editanypost | Prevent |
| mod/forum:addquestion | Allow |
When I set the field "Advanced role override" to "Student (3)"
# There are two select elements and go buttons and we want to press the second one.
And I click on "//div[@class='advancedoverride']/div/form/noscript/input" "xpath_element"
Then "mod/forum:deleteanypost" capability has "Prohibit" permission
And "mod/forum:editanypost" capability has "Prevent" permission
And "mod/forum:addquestion" capability has "Allow" permission
Scenario: Module capabilities overrides
Given the following "activity" exists:
| activity | forum |
| course | C1 |
| idnumber | 00001 |
| name | I'm the name |
And I am on the "I'm the name" "forum activity" page logged in as teacher1
And I navigate to "Permissions" in current page administration
And I override the system permissions of "Student" role with:
| mod/forum:deleteanypost | Prohibit |
| mod/forum:editanypost | Prevent |
| mod/forum:addquestion | Allow |
When I set the field "Advanced role override" to "Student (3)"
And I click on "//div[@class='advancedoverride']/div/form/noscript/input" "xpath_element"
Then "mod/forum:deleteanypost" capability has "Prohibit" permission
And "mod/forum:editanypost" capability has "Prevent" permission
And "mod/forum:addquestion" capability has "Allow" permission
@javascript
Scenario: Edit permissions escapes role names correctly
When I am on the "Course 1" "renameroles" page logged in as "admin"
And I set the following fields to these values:
| Your word for 'Teacher' | Teacher >= editing |
| Your word for 'Non-editing teacher' | Teacher < "editing" |
| Your word for 'Student' | Studier & 'learner' |
And I press "Save"
And I navigate to course participants
Then I should see "Teacher >= editing (Teacher)" in the "Teacher 1" "table_row"
And I should see "Teacher < \"editing\" (Non-editing teacher)" in the "Teaching Assistant" "table_row"
And I should see "Studier & 'learner' (Student)" in the "Student One" "table_row"
And I am on the "C1" "permissions" page
And I should see "Teacher >= editing (Teacher)" in the "mod/forum:replypost" "table_row"
And I should see "Teacher < \"editing\" (Non-editing teacher)" in the "mod/forum:replypost" "table_row"
And I should see "Studier & 'learner' (Student)" in the "mod/forum:replypost" "table_row"
And I follow "Prohibit"
And "Teacher >= editing (Teacher)" "button" in the "Prohibit role" "dialogue" should be visible
And "Teacher < \"editing\" (Non-editing teacher)" "button" in the "Prohibit role" "dialogue" should be visible
And "Studier & 'learner' (Student)" "button" in the "Prohibit role" "dialogue" should be visible
@@ -0,0 +1,34 @@
<?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/>.
/**
* Display environment used for running behat.
*
* This file is used for behat testing to ensure cli and apache
* version of environment is same.
*
* @package tool_behat
* @copyright 2016 onwards Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../../../../../../config.php');
// Only continue for behat site.
defined('BEHAT_SITE_RUNNING') || die();
require_once($CFG->libdir.'/behat/classes/util.php');
echo json_encode(behat_util::get_environment(), true);
@@ -0,0 +1,201 @@
@tool_behat
Feature: Verify that all form fields values can be get and set
In order to use behat steps definitions
As a test writer
I need to verify it all works in real moodle forms
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "users" exist:
| username | email | firstname | lastname |
| student1 | s1@example.com | Student | 1 |
| student2 | s2@example.com | Student | 2 |
| student3 | s3@example.com | Student | 3 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| admin | C1 | editingteacher |
And the following "groups" exist:
| name | description | course | idnumber |
| Group 1 | G1 description | C1 | G1 |
| Group 2 | G1 description | C1 | G2 |
And the following "group members" exist:
| user | group |
| student1 | G1 |
| student2 | G1 |
| student2 | G2 |
| student3 | G2 |
And the following "activities" exist:
| activity | course | idnumber | name | firstpagetitle | wikimode | visible |
| wiki | C1 | wiki1 | Test this one | Test this one | collaborative | 0 |
And I am on the "Course 1" "reset" page logged in as admin
# Select (multi-select) - Checking "the select box should contain".
And I expand all fieldsets
And the "Unenrol users" select box should contain "No roles"
And the "Unenrol users" select box should contain "Student"
And the "Unenrol users" select box should contain "Non-editing teacher"
And the "Unenrol users" select box should contain "Teacher"
And the "Unenrol users" select box should contain "Manager"
And the "Unenrol users" select box should contain "No roles, Student, Non-editing teacher, Teacher, Manager"
And the "Unenrol users" select box should contain "Manager, Teacher, Non-editing teacher, Student, No roles"
And the "Unenrol users" select box should not contain "President"
And the "Unenrol users" select box should not contain "Baker"
And the "Unenrol users" select box should not contain "President, Baker"
And I am on "Course 1" course homepage with editing mode on
And I am on the "Test this one" "wiki activity" page
And I press "Create page"
# Text (textarea & editor) & Select (multi-select) - Checking "I set the following fields to these values".
When I set the following fields to these values:
| HTML format | Student page contents |
And I press "Save"
Then I should see "Student page contents" in the "region-main" "region"
# Select (multi-select) - Checking "I set the field".
And I navigate to "Settings" in current page administration
And I expand all fieldsets
# Checkbox - Checking "I set the field" and "The field matches value" ticked.
And I set the field "Force format" to "1"
And I press "Save and return to course"
And I am on the "Test this one" "wiki activity editing" page
And I expand all fieldsets
And the field "Force format" matches value "1"
And the field "Force format" does not match value ""
# Checkbox - Checking "I set the field" and "The field matches value" unticked.
And I set the field "Force format" to ""
And I press "Save and return to course"
And I am on the "Test this one" "wiki activity editing" page
And I expand all fieldsets
And the field "Force format" matches value ""
And the field "Force format" does not match value "1"
# Checkbox - Checking "I set the following fields to these values:" and "The following fields match these values" ticked.
And I set the following fields to these values:
| Force format | 1 |
And I press "Save and return to course"
And I am on the "Test this one" "wiki activity editing" page
And I expand all fieldsets
And the following fields match these values:
| Force format | 1 |
And the following fields do not match these values:
| Force format | |
# Checkbox - Checking "I set the following fields to these values:" and "The following fields match these values" unticked.
And I set the following fields to these values:
| Force format | |
And I press "Save and return to course"
And I am on the "Test this one" "wiki activity editing" page
And I expand all fieldsets
And the following fields match these values:
| Force format | |
And the following fields do not match these values:
| Force format | 1 |
# Select (simple) - Checking "I set the following fields to these values:".
And I set the following fields to these values:
| Default format | NWiki |
# Select (simple) - Checking "I set the field".
And I set the field "Group mode" to "Separate groups"
And I press "Save and display"
And I navigate to "Settings" in current page administration
And the following fields match these values:
| Default format | NWiki |
| Group mode | Separate groups |
# All fields - Checking "the following fields do not match these values".
And the following fields do not match these values:
| Wiki name | Test this one baby |
| Default format | HTML |
And I press "Cancel"
# Radio - Checking "I set the field" and "the field matches value".
And the following "activity" exists:
| activity | choice |
| course | C1 |
| idnumber | choice1 |
| intro | Test choice description |
| name | Test choice name |
| choice1 | Option 1, Option 2, Option 3 |
| section | 1 |
| allowupdate | 1 |
And I am on "Course 1" course homepage
And I am on the "Test choice name" "choice activity editing" page
And I set the field "Option 1" to "one"
And I set the field "Option 2" to "two"
And I set the field "Option 3" to "three"
And I press "Save and return to course"
And I am on "Course 1" course homepage
And I am on the "Test choice name" "choice activity" page
And I set the field "one" to "1"
And I press "Save my choice"
And the field "one" matches value "1"
And the field "two" matches value ""
# Check if field xpath set/match works.
And I am on "Course 1" course homepage
And I navigate to "Settings" in current page administration
And I set the field with xpath "//input[@id='id_idnumber']" to "Course id number"
And the field with xpath "//input[@name='idnumber']" matches value "Course id number"
And the field with xpath "//input[@name='idnumber']" does not match value ""
And I press "Save and display"
And I navigate to "Settings" in current page administration
And the field "Course ID number" matches value "Course id number"
@javascript
Scenario: with JS enabled all form fields getters and setters works as expected
Given the following "activities" exist:
| activity | course | name |
| lesson | C1 | Test lesson |
Then I am on the "Course 1" "groups" page
# Select (multi-select & AJAX) - Checking "I set the field" and "select box should contain".
And I set the field "groups" to "Group 2"
And the "members" select box should contain "Student 2 (s2@example.com)"
And the "members" select box should contain "Student 3 (s3@example.com)"
And the "members" select box should not contain "Student 1 (s1@example.com)"
And I set the field "groups" to "Group 1"
And the "members" select box should contain "Student 1 (s1@example.com)"
And the "members" select box should contain "Student 2 (s2@example.com)"
And the "members" select box should not contain "Student 3 (s3@example.com)"
# Checkbox (AJAX) - Checking "I set the field" and "I set the following fields to these values".
And I am on the "Test lesson" "lesson activity editing" page
And I set the following fields to these values:
| available[enabled] | 1 |
And I set the field "deadline[enabled]" to "1"
# Checkbox (AJAX) - Checking "the field matches value" before saving.
And the field "available[enabled]" matches value "1"
And the "available[day]" "field" should be enabled
And the field "deadline[enabled]" matches value "1"
And I press "Save and display"
And I navigate to "Settings" in current page administration
And the field "available[enabled]" matches value "1"
And the "available[day]" "field" should be enabled
And the field "deadline[enabled]" matches value "1"
And I press "Cancel"
# Advanced checkbox requires real browser to allow uncheck to work. MDL-58681. MDL-55386.
# Advanced checkbox - Checking "I set the field" and "The field matches value" ticked.
And I am on the "Test choice name" "choice activity editing" page
And I set the field "Display description on course page" to "1"
And I press "Save and return to course"
And I am on the "Test choice name" "choice activity editing" page
And the field "Display description on course page" matches value "1"
And the field "Display description on course page" does not match value ""
# Advanced checkbox - Checking "I set the field" and "The field matches value" unticked.
And I set the field "Display description on course page" to ""
And I press "Save and return to course"
And I am on the "Test choice name" "choice activity editing" page
And the field "Display description on course page" matches value ""
And the field "Display description on course page" does not match value "1"
# Advanced checkbox - Checking "I set the following fields to these values:" and "The following fields match these values" ticked.
And I set the following fields to these values:
| Display description on course page | 1 |
And I press "Save and return to course"
And I am on the "Test choice name" "choice activity editing" page
And the following fields match these values:
| Display description on course page | 1 |
And the following fields do not match these values:
| Display description on course page | |
# Advanced checkbox - Checking "I set the following fields to these values:" and "The following fields match these values" unticked.
And I set the following fields to these values:
| Display description on course page | |
And I press "Save and return to course"
And I am on the "Test choice name" "choice activity editing" page
And the following fields match these values:
| Display description on course page | |
And the following fields do not match these values:
| Display description on course page | 1 |
@@ -0,0 +1,31 @@
@tool_behat
Feature: Behat steps for interacting with form work
In order to test my Moodle code
As a developer
I need the Behat steps for form elements to work reliably
@javascript
Scenario: Test fields in containers
Given the following "courses" exist:
| fullname | shortname | summary | summaryformat |
| Course 1 | C1 | Red | 1 |
When I log in as "admin"
And I am on "Course 1" course homepage
# Just get to any form.
And I navigate to "Settings" in current page administration
And I set the field "Course full name" in the "General" "fieldset" to "Frog"
And I set the following fields in the "Appearance" "fieldset" to these values:
| Show activity reports | Yes |
| Number of announcements | 1 |
And I set the following fields in the "Description" "fieldset" to these values:
| Course summary | Green |
Then the field "Show activity reports" in the "Appearance" "fieldset" matches value "Yes"
And the field "Show activity reports" in the "Appearance" "fieldset" does not match value "No"
And the following fields in the "region-main" "region" match these values:
| Course full name | Frog |
| Number of announcements | 1 |
| Course summary | Green |
And the following fields in the "region-main" "region" do not match these values:
| Course full name | Course 1 |
| Number of announcements | 5 |
| Course summary | Red |
@@ -0,0 +1,85 @@
@tool @tool_behat
Feature: Use core page resolvers for the I am on the page steps
In order to write tests correctly
As a developer
I need to have steps which take me straight to a page
Scenario Outline: When I am on an instance
Given the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "course" exists:
| fullname | Economics 101 |
| shortname | ECON101 |
| idnumber | 2021-econ101 |
And the following "activity" exists:
| course | ECON101 |
| activity | forum |
| name | Fundamentals of Economics |
| idnumber | fundamentalsofeconomics |
And I log in as "admin"
When I am on the <identifier> <type> page
Then I should see "<shouldsee>"
Examples:
| description | identifier | type | shouldsee |
| Course Category idnumber | CAT1 | category | Add a new course |
| Course Category name | "Cat 1" | Category | Add a new course |
| Course Full name | "Economics 101" | course | Fundamentals of Economics |
| Course Short name | ECON101 | COURSE | Fundamentals of Economics |
| Course idnumber | "2021-econ101" | Course | Fundamentals of Economics |
| Forum idnumber | fundamentalsofeconomics | Activity | Add discussion topic |
| Generic activity editing | fundamentalsofeconomics | "Activity editing" | Edit settings |
| Forum name | "Fundamentals of Economics" | "Forum activity" | Add discussion topic |
| Forum name editing | "Fundamentals of Economics" | "Forum activity editing" | Edit settings |
| Forum name permissions | "Fundamentals of Economics" | "Forum activity permissions" | Permissions in Forum: Fun |
| Forum name roles | "Fundamentals of Economics" | "Forum activity roles" | Assign roles in Forum: Fun |
Scenario Outline: When I am on an instance logged in as
Given the following "categories" exist:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
And the following "course" exists:
| fullname | Economics 101 |
| shortname | ECON101 |
| idnumber | 2021-econ101 |
And the following "activity" exists:
| course | ECON101 |
| activity | forum |
| name | Fundamentals of Economics |
| idnumber | fundamentalsofeconomics |
When I am on the <identifier> <type> page logged in as admin
Then I should see "<shouldsee>"
Examples:
| description | identifier | type | shouldsee |
| Course Category idnumber | CAT1 | category | Add a new course |
| Course Category name | "Cat 1" | Category | Add a new course |
| Course Full name | "Economics 101" | course | Fundamentals of Economics |
| Course Short name | ECON101 | COURSE | Fundamentals of Economics |
| Course idnumber | "2021-econ101" | Course | Fundamentals of Economics |
| Forum idnumber | fundamentalsofeconomics | Activity | Add discussion topic |
| Generic activity editing | fundamentalsofeconomics | "Activity editing" | Edit settings |
| Forum name | "Fundamentals of Economics" | "Forum activity" | Add discussion topic |
| Forum name editing | "Fundamentals of Economics" | "Forum activity editing" | Edit settings |
| Forum name permissions | "Fundamentals of Economics" | "Forum activity permissions" | Permissions in Forum: Fun |
| Forum name roles | "Fundamentals of Economics" | "Forum activity roles" | Assign roles in Forum: Fun |
Scenario Outline: When I am on a named page
Given I log in as "admin"
When I am on the <identifier> page
Then I should see "<shouldsee>"
Examples:
| description | identifier | shouldsee |
| Admin page | "Admin notifications" | Check for available updates |
| Home page | Homepage | Calendar |
Scenario Outline: When I am on a named page logged in as
When I am on the <identifier> page logged in as admin
Then I should see "<shouldsee>"
Examples:
| description | identifier | shouldsee |
| Admin page | "Admin notifications" | Check for available updates |
| Home page | Homepage | Calendar |
@@ -0,0 +1,30 @@
@tool_behat
Feature: Verify that the inplace editable field works as expected
In order to use behat step definitions
As a test write
I need to ensure that the inplace editable works in forms
Background:
Given the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
And the following "activities" exist:
| activity | course | name | idnumber |
| forum | C1 | My first forum | forum1 |
| assign | C1 | My first assignment | assign1 |
| quiz | C1 | My first quiz | quiz1 |
And I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
@javascript
Scenario: Using an inplace editable updates the name of an activity
When I set the field "Edit title" in the "My first assignment" "activity" to "Coursework submission"
Then I should see "Coursework submission"
And I should not see "My first assignment"
But I should see "My first forum"
And I should see "My first quiz"
And I set the field "Edit title" in the "Coursework submission" "activity" to "My first assignment"
And I should not see "Coursework submission"
But I should see "My first assignment"
And I should see "My first forum"
And I should see "My first quiz"
@@ -0,0 +1,52 @@
@tool_behat
Feature: Verify that keyboard steps work as expected
In order to use behat step definitions
As a test writer
I need to verify that the keyboard steps work as expected
@javascript
Scenario: Typing keys into a field causes them to be input
Given the following "users" exist:
| username | email | firstname | lastname | password |
| saffronr | saffron.rutledge@example.com | Saffron | Rutledge | flowerpower |
Given I click on "Log in" "link"
And I click on "Username" "field"
When I type "saffronr"
And I press the tab key
And I type "flowerpower"
And I press enter
Then I should see "You are logged in as Saffron Rutledge"
@javascript
Scenario: Using tab changes focus to the next or previous field
Given I click on "Log in" "link"
And I click on "Username" "field"
And the focused element is "Username" "field"
When I press the tab key
Then the focused element is "Password" "field"
And I press the shift tab key
And the focused element is "Username" "field"
@javascript
Scenario: Using the arrow keys allows me to navigate through menus
Given the following "users" exist:
| username | email | firstname | lastname |
| saffronr | saffron.rutledge@example.com | Saffron | Rutledge |
And I log in as "saffronr"
And I click on "User menu" "button" in the ".usermenu" "css_element"
When I press the up key
Then the focused element is "Log out" "link"
@javascript
Scenario: The escape key can be used to close a dialogue
Given the following "course" exists:
| fullname | C1|
| shortname | C1 |
And I log in as "admin"
And I am on "C1" course homepage
And I navigate to course participants
And I press "Enrol users"
And "Enrol users" "dialogue" should be visible
When I press the escape key
Then "Enrol users" "dialogue" should not be visible
@@ -0,0 +1,48 @@
@tool @tool_behat
Feature: List the system steps definitions
In order to create new tests
As a tests writer
I need to list and filter the system steps definitions
Background:
Given I am on homepage
And I log in as "admin"
And I navigate to "Development > Acceptance testing" in site administration
@javascript
Scenario: Accessing the list
Then I should see "Step definitions"
And I should not see "There aren't steps definitions matching this filter"
And I should not see "the following \"ELEMENT_STRING\" exist:"
And "entities1" "select" should exist
And the "entities1" select box should contain "users"
And the "entities1" select box should contain "mod_assign > submissions"
@javascript
Scenario: Filtering by type
Given I set the field "Type" to "Then. Checkings to ensure the outcomes are the expected ones"
When I press "Filter"
Then I should see "Checks, that page contains specified text."
And I should not see "Opens Moodle homepage."
@javascript
Scenario: Filtering by keyword
Given I set the field "Contains" to "homepage"
When I press "Filter"
Then I should see "Opens Moodle homepage."
@javascript
Scenario: Filtering by the multiple words pattern
Given I set the field "Contains" to "should exist"
When I press "Filter"
Then I should not see "There aren't steps definitions matching this filter"
And I should see "Checks the provided element and selector type exists in the current page."
And I should see "Checks that an element and selector type exists in another element and selector type on the current page."
@javascript
Scenario: Get required fields
Given I set the field "entities1" to "users"
And I should see "| username |"
When I set the field "entities1" to "mod_quiz > user overrides"
Then I should not see "| username |"
And I should see "| quiz | user |"
@@ -0,0 +1,110 @@
@tool_behat
Feature: Verify that the behat login and logout steps work as expected
In order to use behat login and log out steps
As a test writer
I need to verify that login and logout happen when the steps are used
Scenario: Log in as a user using the step
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
When I log in as "traverst1"
Then I should see "Thomas Travers"
@javascript
Scenario: Log in as a user using the step (javascript)
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
When I log in as "traverst1"
Then I should see "Thomas Travers"
Scenario: Log out using the log out step
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
And I am logged in as traverst1
When I log out
Then I should not see "Thomas Travers"
And I should see "You are not logged in"
@javascript
Scenario: Log out using the log out step (javascript)
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
And I am logged in as traverst1
When I log out
Then I should not see "Thomas Travers"
And I should see "You are not logged in"
Scenario: Log in step should automatically log user out if already logged in
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
| emeryj | Jane | Emery |
And I am logged in as traverst1
When I log in as "emeryj"
Then I should not see "Thomas Travers"
And I should see "Jane Emery"
@javascript
Scenario: Log in step should automatically log user out if already logged in (javascript)
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
| emeryj | Jane | Emery |
And I am logged in as traverst1
When I log in as "emeryj"
Then I should not see "Thomas Travers"
And I should see "Jane Emery"
Scenario: I am on page logged in as should redirect to correct page
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
And the following "course" exists:
| fullname | Life, the Universe, and Everything |
| shortname | hhgttg |
When I am on the hhgttg Course page logged in as traverst1
Then I should see "Thomas Travers"
And I should see "Life, the Universe, and Everything"
@javascript
Scenario: I am on page logged in as should redirect to correct page (javascript)
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
And the following "course" exists:
| fullname | Life, the Universe, and Everything |
| shortname | hhgttg |
When I am on the hhgttg Course page logged in as traverst1
Then I should see "Thomas Travers"
And I should see "Life, the Universe, and Everything"
Scenario: I am on page logged in as should redirect to correct page when automatically logging a user out
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
| emeryj | Jane | Emery |
And the following "course" exists:
| fullname | Life, the Universe, and Everything |
| shortname | hhgttg |
And I am logged in as emeryj
When I am on the hhgttg Course page logged in as traverst1
Then I should see "Thomas Travers"
And I should see "Life, the Universe, and Everything"
@javascript
Scenario: I am on page logged in as should redirect to correct page when automatically logging a user out (javacript)
Given the following "users" exist:
| username | firstname | lastname |
| traverst1 | Thomas | Travers |
| emeryj | Jane | Emery |
And the following "course" exists:
| fullname | Life, the Universe, and Everything |
| shortname | hhgttg |
And I am logged in as emeryj
When I am on the hhgttg Course page logged in as traverst1
Then I should see "Thomas Travers"
And I should see "Life, the Universe, and Everything"
@@ -0,0 +1,32 @@
@tool @tool_behat
Feature: Forms manipulation
In order to interact with Moodle
As a user
I need to set forms values
@javascript
Scenario: Basic forms manipulation
Given I log in as "admin"
And I open my profile in edit mode
When I set the field "First name" to "Field value"
And I set the field "Select a country" to "Japan"
And I set the field "New password" to "TestPass"
Then the field "First name" matches value "Field value"
And the "Select a country" select box should contain "Japan"
And the field "New password" matches value "TestPass"
@javascript
Scenario: Expand all fieldsets and advanced elements
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "activities" exist:
| activity | course | section | name |
| quiz | C1 | 1 | Quiz 1 |
And I am on the "Quiz 1" "quiz activity editing" page logged in as admin
When I expand all fieldsets
Then I should see "Close the quiz"
And I should see "Group mode"
And I should see "ID number"
And I should not see "Show more..." in the "region-main" "region"
And I should see "Show less..."
@@ -0,0 +1,58 @@
@tool @tool_behat
Feature: Transform steps arguments
In order to write tests with complex nasty arguments
As a tests writer
I need to apply some transformations to the steps arguments
Background:
Given I am on site homepage
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And I log in as "admin"
And I open my profile in edit mode
Scenario: Use nasty strings on steps arguments
When I set the field "Last name" to "$NASTYSTRING1"
And I set the field "Description" to "$NASTYSTRING2"
And I set the field "City/town" to "$NASTYSTRING3"
And I press "Update profile"
And I click on "Edit profile" "link" in the "region-main" "region"
Then I should not see "NASTYSTRING"
And the field "Last name" matches value "$NASTYSTRING1"
And the field "City/town" matches value "$NASTYSTRING3"
Scenario: Use nasty strings on table nodes
When I set the following fields to these values:
| Last name | $NASTYSTRING1 |
| Description | $NASTYSTRING2 |
| City/town | $NASTYSTRING3 |
And I press "Update profile"
And I click on "Edit profile" "link" in the "region-main" "region"
Then I should not see "NASTYSTRING"
And the field "Last name" matches value "$NASTYSTRING1"
And the field "City/town" matches value "$NASTYSTRING3"
Scenario: Use double quotes
When I set the following fields to these values:
| First name | va"lue1 |
| Description | va\"lue2 |
And I set the field "City/town" to "va\"lue3"
And I press "Update profile"
And I click on "Edit profile" "link" in the "region-main" "region"
Then I should not see "NASTYSTRING"
And the field "First name" matches value "va\"lue1"
And the field "Description" matches value "va\\"lue2"
And the field "City/town" matches value "va\"lue3"
Scenario: Nasty strings with other contents
When I set the field "First name" to "My Firstname $NASTYSTRING1"
And I set the following fields to these values:
| Last name | My Last name $NASTYSTRING2 |
And I press "Update profile"
And I click on "Edit profile" "link" in the "region-main" "region"
Then I should not see "NASTYSTRING"
And I should see "My Firstname"
And I should see "My Last name"
And the field "First name" matches value "My Firstname $NASTYSTRING1"
And the field "Last name" matches value "My Last name $NASTYSTRING2"
+34
View File
@@ -0,0 +1,34 @@
@tool_behat
Feature: Confirm that we can open multiple browser tabs
In order to use multiple browser tabs
As a test writer
I need the relevant Behat steps to work
@javascript @_switch_window
Scenario: Open multiple browser tabs
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
| Course 2 | C2 |
| Course 3 | C3 |
And I am on the "C1" "Course" page logged in as "admin"
# Open a new tab on the same page.
When I open a tab named "CourseViewer1" on the current page
And I should see "Course 1" in the "h1" "css_element"
And I am on the "C2" "Course" page
# Open new tab for specified page with identifier.
And I open a tab named "CourseViewer2" on the "C3" "Course" page
# And for a specified page without identifier.
And I open a tab named "CourseViewer4" on the "My courses" page
# Switch between all the tabs and confirm their different contents.
Then I should see "You're not enrolled in any course"
And I switch to "CourseViewer2" tab
And "Course 3" "heading" should exist
And I switch to "CourseViewer1" tab
And "Course 2" "heading" should exist
And I switch to the main tab
And "Course 1" "heading" should exist
@@ -0,0 +1,9 @@
@tool @tool_behat
Feature: Set up the testing environment
In order to execute automated acceptance tests
As a developer
I need to use the test environment instead of the regular environment
Scenario: Accessing the site
When I am on site homepage
Then I should see "Acceptance test site"
@@ -0,0 +1,191 @@
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Tests for behat_form_text class
*
* @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_behat;
use behat_form_text;
use Behat\Mink\Session;
use Behat\Mink\Element\NodeElement;
use core_string_manager_standard;
defined('MOODLE_INTERNAL') || die;
global $CFG;
require_once($CFG->libdir . '/behat/classes/behat_session_interface.php');
require_once($CFG->libdir . '/behat/classes/behat_session_trait.php');
require_once($CFG->libdir . '/behat/form_field/behat_form_text.php');
/**
* Tests for the behat_form_text class
*
* @package tool_behat
* @category test
* @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @covers \behat_form_text
* @covers \behat_form_field
*/
class behat_form_text_test extends \basic_testcase {
/**
* Data provider for the test_set_get_value() method.
*
* @return array of value and expectation pairs to be tested.
*/
public function provider_test_set_get_value() {
return [
'null' => [null, null],
'int' => [3, 3],
'float' => [3.14, 3.14],
'string' => ['hello', 'hello'],
'utf8' => ['你好', '你好'],
];
}
/**
* Test the set_value() and get_value() methods.
*
* @param mixed $value value to be set.
* @param mixed $expectation value to be checked.
* @dataProvider provider_test_set_get_value()
*/
public function test_set_get_value($value, $expectation): void {
$session = $this->createMock(Session::class);
$node = $this->createMock(NodeElement::class);
$node->method('getValue')->willReturn($value);
$field = new behat_form_text($session, $node);
$field->set_value($value);
$this->assertEquals($expectation, $field->get_value());
}
/**
* Data provider for the test_text_matches() method.
*
* @return array of decsep, value, match and result pairs to be tested.
*/
public function provider_test_matches() {
return [
'lazy true' => ['.', 'hello', 'hello', true],
'lazy false' => ['.', 'hello', 'bye', false],
'float true' => ['.', '3.14', '3.1400', true],
'float false' => ['.', '3.14', '3.1401', false],
'float and float string true' => ['.', 3.14, '3.1400', true],
'float and unrelated string false' => ['.', 3.14, 'hello', false],
'float hash decsep true' => ['#', '3#14', '3#1400', true],
'float hash decsep false' => ['#', '3#14', '3#1401', false],
'float and float string hash decsep true' => ['#', 3.14, '3.1400', true],
'float and unrelated string hash decsep false' => ['#', 3.14, 'hello', false],
'float custom-default decsep mix1 true' => ['#', '3#14', '3.1400', true],
'float custom-default decsep mix2 true' => ['#', '3.14', '3#1400', true],
'float 2-custom decsep mix1 false' => ['#', '3#14', '3,1400', false],
'float 2-custom decsep mix2 false' => [',', '3#14', '3,1400', false],
'float default-custom decsep mix1 false' => ['.', '3#14', '3.1400', false],
'float default-custom decsep mix2 false' => ['.', '3.14', '3#1400', false],
];
}
/**
* Test the matches() method.
*
* @param string $decsep decimal separator to use.
* @param mixed $value value to be set.
* @param mixed $match value to be matched.
* @param bool $result expected return status of the function.
* @dataProvider provider_test_matches()
*/
public function test_matches($decsep, $value, $match, $result): void {
global $CFG;
// Switch of string manager to avoid having to (slow) customise the lang file.
$origcustom = $CFG->config_php_settings['customstringmanager'] ?? null;
$CFG->config_php_settings['customstringmanager'] = '\tool_behat\phpunit_string_manager';
$manager = get_string_manager(true);
$manager->set_string('decsep', 'langconfig', $decsep);
$session = $this->createMock(Session::class);
$node = $this->createMock(NodeElement::class);
$node->method('getValue')->willReturn($value);
$field = new behat_form_text($session, $node);
$field->set_value($value);
$this->assertSame($result, $field->matches($match));
// Switch back to the original string manager.
if (is_null($origcustom)) {
unset($CFG->config_php_settings['customstringmanager']);
} else {
$CFG->config_php_settings['customstringmanager'] = $origcustom;
}
$manager = get_string_manager(true);
}
}
/**
* Customised values that will be used instead of standard manager one.
*
* If an existing component/identifier is found, return it instead of the real
* one from language files. Note this doesn't support place holders or another niceties.
*
* @package tool_behat
* @category test
* @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class phpunit_string_manager extends core_string_manager_standard {
/** @var array language customisations provided by the manager without asking for real contents */
protected $customstrings = [];
/**
* Get String returns a requested string
*
* @param string $identifier The identifier of the string to search for
* @param string $component The module the string is associated with
* @param string|object|array $a An object, string or number that can be used
* within translation strings
* @param string $lang moodle translation language, null means use current
* @return string The String !
*/
public function get_string($identifier, $component = '', $a = null, $lang = null) {
$key = trim($component) . '/' . trim($identifier);
if (isset($this->customstrings[$key])) {
return $this->customstrings[$key];
}
return parent::get_string($identifier, $component, $a, $lang);
}
/**
* Sets a custom string to be returned by the string manager instead of the language file one.
*
* @param string $identifier The identifier of the string to search for
* @param string $component The module the string is associated with
* @param string $value the contents of the language string to be returned by get_string()
*/
public function set_string($identifier, $component, $value) {
$key = trim($component) . '/' . trim($identifier);
$this->customstrings[$key] = $value;
}
}
@@ -0,0 +1,104 @@
<?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/>.
/**
* Unit tests for get_entity_generator web service
*
* @package tool_behat
* @copyright 2022 onwards Catalyst IT EU {@link https://catalyst-eu.net}
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_behat\external;
/**
* Tests for get_entity_generator web service
*
* @covers \tool_behat\external\get_entity_generator
*/
class get_entity_generator_test extends \advanced_testcase {
/**
* Log in as admin
*
* @return void
*/
public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
}
/**
* Get the generator for a core entity.
*
* @return void
*/
public function test_execute_core_entity(): void {
$generator = get_entity_generator::execute('users');
$this->assertEquals(['required' => ['username']], $generator);
}
/**
* Get the generator for the plugin entity.
*
* @return void
*/
public function test_execute_plugin_entity(): void {
$generator = get_entity_generator::execute('mod_book > chapters');
$this->assertEquals(['required' => ['book', 'title', 'content']], $generator);
}
/**
* Get the generator for an entity with no required fields.
*
* @return void
*/
public function test_execute_no_requried(): void {
$generator = get_entity_generator::execute('mod_forum > posts');
$this->assertEquals(['required' => []], $generator);
}
/**
* Attempt to get the generator for a core entity that does not exist.
*
* @return void
*/
public function test_execute_invalid_entity(): void {
$this->expectException('coding_exception');
get_entity_generator::execute('foo');
}
/**
* Attempt to get a generator form a plugin that does not exist.
*
* @return void
*/
public function test_execute_invalid_plugin(): void {
$this->expectException('coding_exception');
get_entity_generator::execute('foo > bar');
}
/**
* Attempt to get a generator for an entity that does not exist, from a plugin that does.
*
* @return void
*/
public function test_execute_invalid_plugin_entity(): void {
$this->expectException('coding_exception');
get_entity_generator::execute('mod_book > bar');
}
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');
/**
* Test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_test_context_1 extends behat_base {
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');
/**
* Test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_test_context_2 extends behat_base {
}
+9
View File
@@ -0,0 +1,9 @@
@behat_test @test1
Feature: Test feature 1
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
+8
View File
@@ -0,0 +1,8 @@
@behat_test @test2
Feature: Test feature 2
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,38 @@
<?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/>.
/**
* Theme test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../../../lib/behat/behat_base.php');
/**
* Default Theme test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_defaulttheme_test_context_1 extends behat_base {
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Theme test context 1 overriding test_1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../core/behat_test_context_1.php');
/**
* Theme test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_nofeatures_behat_test_context_2 extends behat_test_context_2 {
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Theme test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../../../lib/behat/behat_base.php');
/**
* Theme test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_nofeatures_test_context_1 extends behat_base {
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Theme test context 1 overriding test_1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../core/behat_test_context_1.php');
/**
* Theme test context 1
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_withfeatures_behat_test_context_1 extends behat_test_context_1 {
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* Theme test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../../../lib/behat/behat_base.php');
/**
* Theme test context 2
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_withfeatures_test_context_2 extends behat_base {
}
@@ -0,0 +1,9 @@
@behat_test @test1 @testtheme @commontag
Feature: Test feature 1
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,9 @@
@behat_test @test2 @testtheme @commontag
Feature: Test feature 2
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,9 @@
@behat_test @test3 @testtheme
Feature: Test feature 3
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,9 @@
@behat_test @test4 @testtheme
Feature: Test feature 4
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,9 @@
@behat_test @test5 @testtheme
Feature: Test feature 5
In order to test behat.yml in phpunit
As an user
I need to be able to include this feature
@javascript
Scenario: I should not be included in normal execution.
Given I pause scenario execution
@@ -0,0 +1,705 @@
<?php
// phpcs:ignoreFile
// @codeCoverageIgnoreStart
// 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/>.
/**
* Unit tests for behat manager.
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_behat;
use behat_config_util;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/' . $CFG->admin .'/tool/behat/locallib.php');
require_once($CFG->libdir . '/behat/classes/util.php');
require_once($CFG->libdir . '/behat/classes/behat_config_manager.php');
/**
* Behat manager tests.
*
* @package tool_behat
* @copyright 2016 Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manager_util_test extends \advanced_testcase {
/** @var array Fixtures features which are available. */
private $featurepaths = array(
'default' => array(
'test_1.feature',
'test_2.feature',
),
'withfeatures' => array(
'theme_test_1.feature',
'theme_test_2.feature',
'theme_test_3.feature',
'theme_test_4.feature',
'theme_test_5.feature',
),
'nofeatures' => array()
);
/** @var array Fixture contexts which are available */
private $contextspath = array(
'default' => array(
'behat_test_context_1',
'behat_test_context_2',
'behat_theme_defaulttheme_test_context_1'
),
'withfeatures' => array(
'behat_test_context_2',
'behat_theme_withfeatures_test_context_2',
'behat_theme_withfeatures_behat_test_context_1'
),
'nofeatures' => array(
'behat_test_context_1',
'behat_theme_nofeatures_test_context_1',
'behat_theme_nofeatures_behat_test_context_2'
),
);
/** @var array List of core features. */
private $corefeatures = array('test_1_core_fixtures_tests_behat_tool' => __DIR__.'/fixtures/core/test_1.feature',
'test_2_core_fixtures_tests_behat_tool' => __DIR__.'/fixtures/core/test_2.feature');
/** @var array List of core contexts. */
private $corecontexts = array('behat_test_context_1' => __DIR__.'/fixtures/core/behat_test_context_1.php',
'behat_test_context_2' => __DIR__.'/fixtures/core/behat_test_context_2.php');
/**
* Setup test.
*/
public function setUp(): void {
global $CFG;
$this->resetAfterTest();
$CFG->behat_wwwroot = 'http://example.com/behat';
}
/**
* Utility function to build mock object.
*
* @param behat_config_util $behatconfigutil
* @param bool $notheme
* @return mixed
*/
private function get_behat_config_util($behatconfigutil, $notheme = false) {
// Create a map of arguments to return values.
$map = array(
array('withfeatures', __DIR__.'/fixtures/theme/withfeatures'),
array('nofeatures', __DIR__.'/fixtures/theme/nofeatures'),
array('defaulttheme', __DIR__.'/fixtures/theme/defaulttheme'),
);
// List of themes is const for test.
if ($notheme) {
$themelist = array('defaulttheme');
} else {
$themelist = array('withfeatures', 'nofeatures', 'defaulttheme');
}
$thememap = [];
foreach ($themelist as $themename) {
$mock = $this->getMockBuilder('theme_config');
$mock->disableOriginalConstructor();
$thememap[] = [$themename, $mock->getMock()];
}
$behatconfigutil->expects($this->any())
->method('get_list_of_themes')
->will($this->returnValue($themelist));
// Theme directory for testing.
$behatconfigutil->expects($this->any())
->method('get_theme_test_directory')
->will($this->returnValueMap($map));
// Theme directory for testing.
$behatconfigutil->expects($this->any())
->method('get_theme_config')
->will($this->returnValueMap($thememap));
$behatconfigutil->expects($this->any())
->method('get_default_theme')
->will($this->returnValue('defaulttheme'));
return $behatconfigutil;
}
/**
* Behat config for single run.
*/
public function test_get_config_file_contents_with_single_run() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
// Two suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// Check features.
foreach ($this->featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Behat config for single run with no theme installed.
*/
public function test_get_config_file_contents_with_single_run_no_theme() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil, true);
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
// Two suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(1, $suites);
$featurepaths = array(
'default' => array(
'test_1.feature',
'test_2.feature',
)
);
$contextspath = array(
'default' => array(
'behat_test_context_1',
'behat_test_context_2',
'behat_theme_defaulttheme_test_context_1',
)
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 3 step definitions.
$this->assertCount(3, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Behat config for parallel run.
*/
public function test_get_config_file_contents_with_parallel_run() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
// Test first run out of 3.
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts, '', 3, 1);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is first feature file in first run.
$featurepaths = array(
'default' => array('test_1.feature'),
'withfeatures' => array('theme_test_1.feature', 'theme_test_2.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
// Test second run out of 3.
$config = $behatconfigutil->get_config_file_contents('', '', '', 3, 2);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is second feature file in first run.
$featurepaths = array(
'default' => array('test_2.feature'),
'withfeatures' => array('theme_test_3.feature', 'theme_test_4.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
// Test third run out of 3.
$config = $behatconfigutil->get_config_file_contents('', '', '', 3, 3);
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is second feature file in first run.
$featurepaths = array(
'default' => array(),
'withfeatures' => array('theme_test_5.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Behat config for parallel run.
*/
public function test_get_config_file_contents_with_parallel_run_optimize_tags() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
// Test first run out of 3.
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts, '@commontag', 3, 1);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is first feature file in first run.
$featurepaths = array(
'default' => array('test_1.feature'),
'withfeatures' => array('theme_test_1.feature', 'theme_test_3.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
// Test second run out of 3.
$config = $behatconfigutil->get_config_file_contents('', '', '@commontag', 3, 2);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is second feature file in first run.
$featurepaths = array(
'default' => array('test_2.feature'),
'withfeatures' => array('theme_test_2.feature', 'theme_test_4.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
// Test third run out of 3.
$config = $behatconfigutil->get_config_file_contents('', '', '', 3, 3);
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
// There is second feature file in first run.
$featurepaths = array(
'default' => array(),
'withfeatures' => array('theme_test_5.feature'),
'nofeatures' => array()
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Test if clean features key and path is returned.
* @dataProvider clean_features_path_list
*/
public function test_get_clean_feature_key_and_path($featurepath, $key, $cleanfeaturepath) {
global $CFG;
// This is a hack so directory name is correctly detected in tests.
//FIXME: MDL-55722 work out why this is necessary..
$oldroot = $CFG->dirroot;
$CFG->dirroot = 'C:';
$behatconfigutil = new behat_config_util();
// Fix expected directory path for OS.
$cleanfeaturepath = testing_cli_fix_directory_separator($cleanfeaturepath);
list($retkey, $retcleanfeaturepath) = $behatconfigutil->get_clean_feature_key_and_path($featurepath);
$this->assertEquals($key, $retkey);
$this->assertEquals($cleanfeaturepath, $retcleanfeaturepath);
//FIXME: MDL-55722 work out why this is necessary..
$CFG->dirroot = $oldroot;
}
public function clean_features_path_list() {
return array(
['/home/test/this/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_this_test', '/home/test/this/that/test/behat/mod_assign.feature'],
['/home/this/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_this_home', '/home/this/that/test/behat/mod_assign.feature'],
['/home/that/test/behat/mod_assign.feature', 'mod_assign_behat_test_that_home', '/home/that/test/behat/mod_assign.feature'],
['/home/test/behat/mod_assign.feature', 'mod_assign_behat_test_home', '/home/test/behat/mod_assign.feature'],
['mod_assign.feature', 'mod_assign', 'mod_assign.feature'],
['C:\test\this\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that_this_test', 'C:\test\this\that\test\behat\mod_assign.feature'],
['C:\this\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that_this', 'C:\this\that\test\behat\mod_assign.feature'],
['C:\that\test\behat\mod_assign.feature', 'mod_assign_behat_test_that', 'C:\that\test\behat\mod_assign.feature'],
['C:\test\behat\mod_assign.feature', 'mod_assign_behat_test', 'C:\test\behat\mod_assign.feature'],
['C:\mod_assign.feature', 'mod_assign', 'C:\mod_assign.feature'],
);
}
/**
* Behat config for blacklisted tags.
*/
public function test_get_config_file_contents_with_blacklisted_tags() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_blacklisted_tests_for_theme',
'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
// Blacklisted tags.
$map = array(
array('withfeatures', 'tags', array('@test1')),
array('nofeatures', 'tags', array('@test2')),
array('defaulttheme', 'tags', array()),
array('withfeatures', 'features', array()),
array('nofeatures', 'features', array()),
array('defaulttheme', 'features', array()),
array('withfeatures', 'contexts', array()),
array('nofeatures', 'contexts', array()),
array('defaulttheme', 'contexts', array())
);
$behatconfigutil->expects($this->any())
->method('get_blacklisted_tests_for_theme')
->will($this->returnValueMap($map));
$behatconfigutil->set_theme_suite_to_include_core_features(true);
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
$featurepaths = array(
'default' => array('test_1.feature', 'test_2.feature'),
'withfeatures' => array('test_2.feature', 'theme_test_1.feature', 'theme_test_2.feature', 'theme_test_3.feature',
'theme_test_4.feature', 'theme_test_5.feature'),
'nofeatures' => array('test_1.feature')
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($this->contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Behat config for blacklisted features.
*/
public function test_get_config_file_contents_with_blacklisted_features_contexts() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_blacklisted_tests_for_theme',
'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
// Blacklisted features and contexts.
$map = array(
array('withfeatures', 'tags', array()),
array('nofeatures', 'tags', array()),
array('defaulttheme', 'tags', array()),
array('withfeatures', 'features', array('admin/tool/behat/tests/fixtures/core/test_1.feature')),
array('nofeatures', 'features', array('admin/tool/behat/tests/fixtures/core/test_2.feature')),
array('defaulttheme', 'features', array()),
array('withfeatures', 'contexts', array('admin/tool/behat/tests/fixtures/core/behat_test_context_2.php')),
array('nofeatures', 'contexts', array('admin/tool/behat/tests/fixtures/core/behat_test_context_1.php')),
array('defaulttheme', 'contexts', array()),
);
$behatconfigutil->expects($this->any())
->method('get_blacklisted_tests_for_theme')
->will($this->returnValueMap($map));
$behatconfigutil->set_theme_suite_to_include_core_features(true);
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
// Three suites should be present.
$suites = $config['default']['suites'];
$this->assertCount(3, $suites);
$featurepaths = array(
'default' => array('test_1.feature', 'test_2.feature'),
'withfeatures' => array('test_2.feature', 'theme_test_1.feature', 'theme_test_2.feature', 'theme_test_3.feature',
'theme_test_4.feature', 'theme_test_5.feature'),
'nofeatures' => array('test_1.feature')
);
$contextspath = array(
'default' => array(
'behat_test_context_1',
'behat_test_context_2',
'behat_theme_defaulttheme_test_context_1',
),
'withfeatures' => array(
'behat_theme_withfeatures_test_context_2',
'behat_theme_withfeatures_behat_test_context_1'
),
'nofeatures' => array(
'behat_theme_nofeatures_test_context_1',
'behat_theme_nofeatures_behat_test_context_2'
),
);
// Check features.
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check contexts.
foreach ($contextspath as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['contexts']);
foreach ($paths as $key => $context) {
$this->assertTrue(in_array($context, $suites[$themename]['contexts']));
}
}
// There are 7 step definitions.
$this->assertCount(7, $config['default']['extensions']['Moodle\BehatExtension']['steps_definitions']);
}
/**
* Behat config for blacklisted tags.
*/
public function test_core_features_to_include_in_specified_theme() {
$mockbuilder = $this->getMockBuilder('behat_config_util');
$mockbuilder->onlyMethods(array('get_theme_test_directory', 'get_list_of_themes', 'get_default_theme', 'get_theme_config'));
$behatconfigutil = $mockbuilder->getMock();
$behatconfigutil = $this->get_behat_config_util($behatconfigutil);
// Check features when, no theme is specified.
$behatconfigutil->set_theme_suite_to_include_core_features('');
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
$suites = $config['default']['suites'];
foreach ($this->featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check features when all themes are specified.
$featurepaths = $this->featurepaths;
$featurepaths['withfeatures'] = array_merge ($featurepaths['default'], $featurepaths['withfeatures']);
$featurepaths['nofeatures'] = array_merge ($featurepaths['default'], $featurepaths['nofeatures']);
$behatconfigutil->set_theme_suite_to_include_core_features('ALL');
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
$suites = $config['default']['suites'];
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check features when all themes are specified.
$featurepaths = $this->featurepaths;
$featurepaths['withfeatures'] = array_merge ($featurepaths['default'], $featurepaths['withfeatures']);
$featurepaths['nofeatures'] = array_merge ($featurepaths['default'], $featurepaths['nofeatures']);
$behatconfigutil->set_theme_suite_to_include_core_features('withfeatures, nofeatures');
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
$suites = $config['default']['suites'];
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
// Check features when specified themes are passed..
$featurepaths = $this->featurepaths;
$featurepaths['nofeatures'] = array_merge ($featurepaths['default'], $featurepaths['nofeatures']);
$behatconfigutil->set_theme_suite_to_include_core_features('nofeatures');
$config = $behatconfigutil->get_config_file_contents($this->corefeatures, $this->corecontexts);
$suites = $config['default']['suites'];
foreach ($featurepaths as $themename => $paths) {
$this->assertCount(count($paths), $suites[$themename]['paths']);
foreach ($paths as $key => $feature) {
$this->assertStringContainsString($feature, $suites[$themename]['paths'][$key]);
}
}
}
}
// @codeCoverageIgnoreEnd