Merge branch 'MDL-44440_master' of git://github.com/dmonllao/moodle

This commit is contained in:
Dan Poltawski
2014-03-10 13:45:26 +08:00
21 changed files with 235 additions and 84 deletions
+1 -5
View File
@@ -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"
@@ -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
@@ -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"
@@ -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
@@ -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"
@@ -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"
@@ -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
@@ -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
+47 -16
View File
@@ -69,21 +69,9 @@ class behat_auth extends behat_base {
// Wait for the homepage to be ready.
$this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
// 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.
// 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
// a DOM node that is not always there (at the moment clean is not even the
// default theme...).
$navbuttonjs = "return (
Y.one('.btn-navbar') &&
Y.one('.btn-navbar').getComputedStyle('display') !== 'none'
)";
// 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 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;
@@ -95,7 +83,50 @@ class behat_auth extends behat_base {
* @Given /^I log out$/
*/
public function i_log_out() {
return new When('I follow "' . get_string('logout') . '"');
$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 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
// a DOM node that is not always there (at the moment clean is not even the
// default theme...).
$navbuttonjs = "return (
Y.one('.btn-navbar') &&
Y.one('.btn-navbar').getComputedStyle('display') !== 'none'
)";
// Adding an extra click we need to show the 'Log in' link.
if (!$this->getSession()->getDriver()->evaluateScript($navbuttonjs)) {
return false;
}
return new Given('I click on ".btn-navbar" "css_element"');
}
}
+4 -4
View File
@@ -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:
@@ -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:
@@ -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"
+2 -6
View File
@@ -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 |
@@ -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 |
@@ -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
+1 -4
View File
@@ -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"
+1 -5
View File
@@ -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 |
+4 -5
View File
@@ -60,14 +60,13 @@ class behat_cohort extends behat_base {
// 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
);
@@ -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"
+1 -1
View File
@@ -89,7 +89,7 @@ XPATH
//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%)]
+156
View File
@@ -111,4 +111,160 @@ class behat_navigation extends behat_base {
$node = $this->find('xpath', $xpath, $exception);
$node->click();
}
/**
* Click link in navigation tree that matches the text in parentnode/s (seperated using greater-than character if more than one)
*
* @Given /^I navigate to "(?P<nodetext_string>(?:[^"]|\\")*)" node in "(?P<parentnodes_string>(?:[^"]|\\")*)"$/
*
* @throws ExpectationException
* @param string $nodetext navigation node to click.
* @param string $parentnodes comma seperated list of parent nodes.
* @return void
*/
public function i_navigate_to_node_in($nodetext, $parentnodes) {
// Site admin is different and needs special treatment.
$siteadminstr = get_string('administrationsite');
// Create array of all parentnodes.
$parentnodes = array_map('trim', explode('>', $parentnodes));
$countparentnode = count($parentnodes);
// If JS is disabled and Site administration is not expanded we
// should follow it, so all the lower-level nodes are available.
if (!$this->running_javascript()) {
if ($parentnodes[0] === $siteadminstr) {
// We don't know if there if Site admin is already expanded so
// don't wait, it is non-JS and we already waited for the DOM.
if ($siteadminlink = $this->getSession()->getPage()->find('named', array('link', "'" . $siteadminstr . "'"))) {
$siteadminlink->click();
}
}
}
// Expand first node, and get it.
$node = $this->get_top_navigation_node($parentnodes[0]);
// Expand parent, sub-parent nodes in navigation if js enabled.
if ($node->hasClass('collapsed') || ($node->hasAttribute('data-loaded') && $node->getAttribute('data-loaded') == 0)) {
$xpath = "/p[contains(concat(' ', normalize-space(@class), ' '), ' tree_item ')]/span";
$nodetoexpand = $node->find('xpath', $xpath);
if ($this->running_javascript()) {
$this->ensure_node_is_visible($nodetoexpand);
$nodetoexpand->click();
// Site administration node needs to be expanded.
if ($parentnodes[0] === $siteadminstr) {
$this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
}
}
}
// If sub-parent nodes then get to the last one.
if ($countparentnode > 1) {
for ($i = 1; $i < $countparentnode; $i++) {
$node = $this->get_navigation_node($parentnodes[$i], $node);
// Keep expanding all sub-parents if js enabled.
if ($this->running_javascript()) {
$xpath = "/p[contains(concat(' ', normalize-space(@class), ' '), ' tree_item ')]";
if ($node->hasClass('collapsed')) {
$nodetoexpand = $node->find('xpath', $xpath);
if ($this->running_javascript()) {
$this->ensure_node_is_visible($nodetoexpand);
$nodetoexpand->click();
}
}
}
}
}
// Finally, click on requested node under navigation.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($nodetext);
$xpath = "/ul/li/p[contains(concat(' ', normalize-space(@class), ' '), ' tree_item ')]" .
"/a[normalize-space(.)=" . $nodetextliteral . "]";
$node = $node->find('xpath', $xpath);
// Throw exception if no node found.
if (!$node) {
throw new ExpectationException('Navigation node "' . $nodetext . '" not found under "' .
$parentnodes . '"', $this->getSession());
}
if ($this->running_javascript()) {
$this->ensure_node_is_visible($node);
}
$node->click();
}
/**
* Helper function to get top navigation node in tree.
*
* @throws ExpectationException if note not found.
* @param string $nodetext name of top navigation node in tree.
* @return NodeElement
*/
protected function get_top_navigation_node($nodetext) {
// Avoid problems with quotes.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($nodetext);
$exception = new ExpectationException('Top navigation node "' . $nodetext . ' not found in "', $this->getSession());
// First find in navigation block.
$xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' content ')]" .
"/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
"/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
"[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
"/span[normalize-space(.)=" . $nodetextliteral ."]]" .
"|" .
"//div[contains(concat(' ', normalize-space(@class), ' '), ' content ')]/div" .
"/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
"/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
"[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
"/span[normalize-space(.)=" . $nodetextliteral ."]]" .
"|" .
"//div[contains(concat(' ', normalize-space(@class), ' '), ' content ')]/div" .
"/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/li[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
"/span[normalize-space(.)=" . $nodetextliteral ."]]";
$node = $this->find('xpath', $xpath, $exception);
return $node;
}
/**
* Helper function to get sub-navigation node.
*
* @throws ExpectationException if note not found.
* @param string $nodetext node to find.
* @param NodeElement $parentnode parent navigation node.
* @return NodeElement.
*/
protected function get_navigation_node($nodetext, $parentnode = null) {
// Avoid problems with quotes.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($nodetext);
$xpath = "/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
"[child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
"/child::span[normalize-space(.)=" . $nodetextliteral ."]]";
$node = $parentnode->find('xpath', $xpath);
if (!$node) {
$xpath = "/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
"[child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
"/child::a[normalize-space(.)=" . $nodetextliteral ."]]";
$node = $parentnode->find('xpath', $xpath);
}
if (!$node) {
throw new ExpectationException('Sub-navigation node "' . $nodetext . '" not found under "' .
$parentnode->getText() . '"', $this->getSession());
}
return $node;
}
}
+4 -5
View File
@@ -50,13 +50,12 @@ class behat_permissions extends behat_base {
*/
public function i_set_the_following_system_permissions_of_role($rolename, $table) {
$parentnodes = get_string('administrationsite') . ' > ' .
get_string('users', 'admin') . ' > ' .
get_string('permissions', 'role');
return 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('permissions', 'role') . '" node'),
new Given('I follow "' . get_string('defineroles', 'role') . '"'),
new Given('I navigate to "' . get_string('defineroles', 'role') . '" node in "' . $parentnodes . '"'),
new Given('I follow "Edit ' . $this->escape($rolename) . ' role"'),
new Given('I fill the capabilities form with the following permissions:', $table),
new Given('I press "' . get_string('savechanges') . '"')
@@ -59,7 +59,7 @@ Feature: A teacher can set one of 3 possible options for tracking read forum pos
And I follow "Test forum name"
And I follow "Track unread posts"
And I wait to be redirected
And I follow "1"
And I click on "1" "link" in the "Admin User" "table_row"
And I follow "Course 1"
And I should not see "1 unread post"
@@ -156,7 +156,7 @@ Feature: A teacher can set one of 3 possible options for tracking read forum pos
And I follow "Test forum name"
And I follow "Track unread posts"
And I wait to be redirected
And I follow "1"
And I click on "1" "link" in the "Admin User" "table_row"
And I follow "Course 1"
And I should not see "1 unread post"
@@ -10,12 +10,11 @@ Feature: Upload files
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And I log in as "admin"
And I follow "Admin User"
And I follow "My private files"
When I navigate to "My private files" node in "My profile"
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
Then I should see "1" elements in "Files" filemanager
And I should see "empty.txt" in the "div.fp-content" "css_element"
When I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager as:
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager as:
| Save as | empty_copy.txt |
Then I should see "2" elements in "Files" filemanager
And I should see "empty.txt"
+1 -4
View File
@@ -8,10 +8,7 @@ Feature: Enable/disable password field based on authentication selected.
Scenario: Verify the password field is enabled/disabled based on authentication selected, in user edit advanced page.
Given I log in as "admin"
And I follow "My home"
And I expand "Site administration" node
And I expand "Users" node
And I expand "Accounts" node
When I follow "Add a new user"
When I navigate to "Add a new user" node in "Site administration > Users > Accounts"
Then the "newpassword" "field" should be enabled
And I set the field "auth" to "Web services authentication"
And the "newpassword" "field" should be disabled