Skip to content

Commit

Permalink
Merge branch 'MDL-44440_master' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Mar 10, 2014
2 parents c13c64b + 1f631c7 commit 7f42ee9
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 82 deletions.
6 changes: 1 addition & 5 deletions admin/tests/behat/upload_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ Feature: Upload users
| Section 1 | math102 | S1 |
| Section 3 | math102 | S3 |
And I log in as "admin"
And I collapse "Front page settings" node
And I expand "Site administration" node
And I expand "Users" node
And I expand "Accounts" node
And I follow "Upload users"
And I navigate to "Upload users" node in "Site administration > Users > Accounts"
When I upload "lib/tests/fixtures/upload_users.csv" file to "File" filemanager
And I press "Upload users"
Then I should see "Upload users preview"
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/behat/tests/behat/basic_actions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Feature: Page contents assertions
And I log in as "admin"
And I follow "Course 1"
When I dock "Administration" block
Then I should not see "Question bank" in the "region-pre" "region"
Then I should not see "Question bank" in the ".block-region" "css_element"
And I click on "//div[@id='dock']/descendant::h2[normalize-space(.)='Administration']" "xpath_element"

@javascript
Expand All @@ -50,4 +50,4 @@ Feature: Page contents assertions
| Course 1 | C1 | 0 |
And I log in as "admin"
When I dock "Administration" block
Then I should not see "Turn editing on" in the "region-pre" "region"
Then I should not see "Turn editing on" in the ".block-region" "css_element"
4 changes: 1 addition & 3 deletions admin/tool/behat/tests/behat/list_steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ Feature: List the system steps definitions
Background:
Given I am on homepage
And I log in as "admin"
And I expand "Site administration" node
And I expand "Development" node
And I follow "Acceptance testing"
And I navigate to "Acceptance testing" node in "Site administration > Development"

@javascript
Scenario: Accessing the list
Expand Down
3 changes: 1 addition & 2 deletions admin/tool/behat/tests/behat/manipulate_forms.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ Feature: Forms manipulation
@javascript
Scenario: Basic forms manipulation
Given I log in as "admin"
And I follow "Admin User"
And I follow "Edit profile"
And I navigate to "Edit profile" node in "My profile settings"
When I set the field "First name" to "Field value"
And I set the field "Text editor" to "Plain text area"
And I set the field "Unmask" to "1"
Expand Down
3 changes: 1 addition & 2 deletions admin/tool/behat/tests/behat/nasty_strings.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Feature: Transform steps arguments
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And I log in as "admin"
And I follow "Admin User"
And I follow "Edit profile"
And I navigate to "Edit profile" node in "My profile settings"

Scenario: Use nasty strings on steps arguments
When I set the field "Surname" to "$NASTYSTRING1"
Expand Down
4 changes: 1 addition & 3 deletions admin/tool/uploadcourse/tests/behat/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ Feature: An admin can create courses using a CSV file
| fullname | shortname | category |
| First course | C1 | 0 |
And I log in as "admin"
And I expand "Site administration" node
And I expand "Courses" node
And I follow "Upload courses"
And I navigate to "Upload courses" node in "Site administration > Courses"

@javascript
Scenario: Creation of unexisting courses
Expand Down
4 changes: 1 addition & 3 deletions admin/tool/uploadcourse/tests/behat/update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ Feature: An admin can update courses using a CSV file
| fullname | shortname | category |
| Some random name | C1 | 0 |
And I log in as "admin"
And I expand "Site administration" node
And I expand "Courses" node
And I follow "Upload courses"
And I navigate to "Upload courses" node in "Site administration > Courses"

@javascript
Scenario: Updating a course fullname
Expand Down
59 changes: 45 additions & 14 deletions auth/tests/behat/behat_auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,49 @@ public function i_log_in_as($username) {
// Wait for the homepage to be ready.
$this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);

// If it is needed, it expands the navigation bar with the 'Log in' link.
if ($clicknavbar = $this->get_expand_navbar_step()) {
array_unshift($steps, $clicknavbar);
}

return $steps;
}

/**
* Logs out of the system.
*
* @Given /^I log out$/
*/
public function i_log_out() {

$steps = array(new When('I follow "' . get_string('logout') . '"'));

// No need to check anything else if we run without JS.
if (!$this->running_javascript()) {
return $steps;
}

// If it is needed, it expands the navigation bar with the 'Log out' link.
if ($clicknavbar = $this->get_expand_navbar_step()) {
array_unshift($steps, $clicknavbar);
}

return $steps;
}

/**
* Returns a step to open the navigation bar if it is needed.
*
* The top log in and log out links are hidden when middle or small
* size windows (or devices) are used. This step returns a step definition
* clicking to expand the navbar if it is hidden.
*
* @return Given|bool A step definition or false if there is no need to show the navbar.
*/
protected function get_expand_navbar_step() {

// Checking if we need to click the navbar button to show the navigation menu, it
// is hidden by default when using clean theme and a medium or small size screen size.
// is hidden by default when using clean theme and a medium or small screen size.

// The DOM and the JS should be all ready and loaded. Running without spinning
// as this is a widely used step and we can not spend time here trying to see
Expand All @@ -82,20 +123,10 @@ public function i_log_in_as($username) {
)";

// Adding an extra click we need to show the 'Log in' link.
if ($this->getSession()->getDriver()->evaluateScript($navbuttonjs)) {
array_unshift($steps, new Given('I click on ".btn-navbar" "css_element"'));
if (!$this->getSession()->getDriver()->evaluateScript($navbuttonjs)) {
return false;
}

return $steps;
}

/**
* Logs out of the system.
*
* @Given /^I log out$/
*/
public function i_log_out() {
return new When('I follow "' . get_string('logout') . '"');
return new Given('I click on ".btn-navbar" "css_element"');
}

}
8 changes: 4 additions & 4 deletions auth/tests/behat/login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Feature: Authentication

Scenario: Log in with the predefined admin user with Javascript disabled
Given I log in as "admin"
Then I should see "You are logged in as Admin User"
Then I should see "You are logged in as Admin User" in the "page-footer" "region"

@javascript
Scenario: Log in with the predefined admin user with Javascript enabled
Given I log in as "admin"
Then I should see "You are logged in as Admin User"
Then I should see "You are logged in as Admin User" in the "page-footer" "region"

Scenario: Log in as an existing admin user filling the form
Given the following "users" exist:
Expand All @@ -22,7 +22,7 @@ Feature: Authentication
And I set the field "Username" to "testuser"
And I set the field "Password" to "testuser"
And I press "Log in"
Then I should see "You are logged in as"
Then I should see "You are logged in as" in the "page-footer" "region"

Scenario: Log in as an unexisting user filling the form
Given the following "users" exist:
Expand All @@ -38,4 +38,4 @@ Feature: Authentication
Scenario: Log out
Given I log in as "admin"
When I log out
Then I should see "You are not logged in"
Then I should see "You are not logged in" in the "page-footer" "region"
8 changes: 2 additions & 6 deletions badges/tests/behat/award_badge.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ Feature: Award badges
@javascript
Scenario: Award profile badge
Given I log in as "admin"
And I expand "Site administration" node
And I expand "Badges" node
And I follow "Add a new badge"
And I navigate to "Add a new badge" node in "Site administration > Badges"
And I set the following fields to these values:
| Name | Profile Badge |
| Description | Test badge description |
Expand Down Expand Up @@ -44,9 +42,7 @@ Feature: Award badges
| teacher | teacher | 1 | teacher1@asd.com |
| student | student | 1 | student1@asd.com |
And I log in as "admin"
And I expand "Site administration" node
And I expand "Badges" node
And I follow "Add a new badge"
And I navigate to "Add a new badge" node in "Site administration > Badges"
And I set the following fields to these values:
| Name | Site Badge |
| Description | Site badge description |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ Feature: Block activity modules

Background:
Given I log in as "admin"
And I expand "Site administration" node
And I expand "Plugins" node
And I expand "Activity modules" node
And I follow "Manage activities"
And I navigate to "Manage activities" node in "Site administration > Plugins > Activity modules"
And I click on "//a[@title=\"Show\"]" "xpath_element" in the "Feedback" "table_row"

Scenario: Add activities block on the frontpage
Expand Down
5 changes: 1 addition & 4 deletions blocks/tests/behat/manage_blocks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ Feature: Block appearances
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "admin"
And I expand "Site administration" node
And I expand "Appearance" node
And I expand "Themes" node
And I follow "Theme selector"
And I navigate to "Theme selector" node in "Site administration > Appearance > Themes"
And I click on "Change theme" "button" in the "Default" "table_row"
And I click on "Use theme" "button" in the "Afterburner" "table_row"
And I press "Continue"
Expand Down
6 changes: 1 addition & 5 deletions cohort/tests/behat/add_cohort.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ Feature: Add cohorts of users
| user3 | Third | User | third@user.com |
| user4 | Forth | User | forth@user.com |
And I log in as "admin"
And I collapse "Front page settings" node
And I expand "Site administration" node
And I expand "Users" node
And I expand "Accounts" node
And I follow "Cohorts"
And I navigate to "Cohorts" node in "Site administration > Users > Accounts"
And I press "Add"
And I set the following fields to these values:
| Name | Test cohort name |
Expand Down
9 changes: 4 additions & 5 deletions cohort/tests/behat/behat_cohort.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ public function i_add_user_to_cohort_members($user, $cohortidnumber) {

// With JS enabled we should expand a few tree nodes.
if ($this->running_javascript()) {
$parentnodes = get_string('administrationsite') . ' > ' .
get_string('users', 'admin') . ' > ' .
get_string('accounts', 'admin');
$steps = array_merge(
array(
new Given('I am on homepage'),
new Given('I collapse "' . get_string('frontpagesettings', 'admin') . '" node'),
new Given('I expand "' . get_string('administrationsite') . '" node'),
new Given('I expand "' . get_string('users', 'admin') . '" node'),
new Given('I expand "' . get_string('accounts', 'admin') . '" node'),
new Given('I follow "' . get_string('cohorts', 'cohort') . '"')
new Given('I navigate to "' . get_string('cohorts', 'cohort') . '" node in "' . $parentnodes . '"')
),
$steps
);
Expand Down
6 changes: 1 addition & 5 deletions cohort/tests/behat/upload_cohort_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ Feature: Upload users to a cohort
And I follow "Course 2"
And I add "Cohort sync" enrolment method with:
| Cohort | Cohort 2 |
And I collapse "Course administration" node
And I expand "Site administration" node
And I expand "Users" node
And I expand "Accounts" node
When I follow "Upload users"
When I navigate to "Upload users" node in "Site administration > Users > Accounts"
And I upload "lib/tests/fixtures/upload_users_cohorts.csv" file to "File" filemanager
And I press "Upload users"
And I press "Upload users"
Expand Down
2 changes: 1 addition & 1 deletion lib/behat/classes/behat_selectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class behat_selectors {
//div[contains(concat(' ', normalize-space(@class), ' '), concat(' ', %locator%, ' '))] | //div[contains(concat(' ', normalize-space(@class), ' '), ' block ')]/descendant::h2[normalize-space(.) = %locator%]/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' block ')]
XPATH
, 'region' => <<<XPATH
.//*[self::div | self::section | self::aside][./@id = %locator%]
//*[self::div | self::section | self::aside | self::header | self::footer][./@id = %locator%]
XPATH
, 'table_row' => <<<XPATH
.//tr[contains(normalize-space(.), %locator%)]
Expand Down
Loading

0 comments on commit 7f42ee9

Please sign in to comment.