Skip to content

Commit

Permalink
MDL-39638 behat: New step to collapse nodes based on the expand nodes
Browse files Browse the repository at this point in the history
Also updating steps with a collapse behaviour.
  • Loading branch information
David Monllao committed May 16, 2013
1 parent 5e1bdac commit c4509f8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion admin/tests/behat/upload_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Feature: Upload users
| Section 1 | math102 | S1 |
| Section 3 | math102 | S3 |
And I log in as "admin"
And I expand "Front page settings" node
And I collapse "Front page settings" node
And I expand "Site administration" node
And I expand "Users" node
And I expand "Accounts" node
Expand Down
2 changes: 1 addition & 1 deletion cohort/tests/behat/add_cohort.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +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 expand "Front page settings" node
And I collapse "Front page settings" node
And I expand "Site administration" node
And I expand "Users" node
And I expand "Accounts" node
Expand Down
2 changes: 1 addition & 1 deletion cohort/tests/behat/behat_cohort.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function i_add_user_to_cohort($username, $cohortidnumber) {
$steps = array_merge(
array(
new Given('I am on homepage'),
new Given('I expand "Front page settings" node'),
new Given('I collapse "Front page settings" node'),
new Given('I expand "Site administration" node'),
new Given('I expand "Users" node'),
new Given('I expand "Accounts" node'),
Expand Down
2 changes: 1 addition & 1 deletion cohort/tests/behat/upload_cohort_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +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 expand "Course administration" node
And I collapse "Course administration" node
And I expand "Site administration" node
And I expand "Users" node
And I expand "Accounts" node
Expand Down
40 changes: 36 additions & 4 deletions lib/tests/behat/behat_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

require_once(__DIR__ . '/../../behat/behat_base.php');

use Behat\Behat\Context\Step\Given as Given,
Behat\Mink\Exception\ExpectationException as ExpectationException;

/**
* Steps definitions to navigate through the navigation tree nodes.
*
Expand All @@ -41,7 +44,7 @@ class behat_navigation extends behat_base {
* Expands the selected node of the navigation tree that matches the text.
* @Given /^I expand "(?P<nodetext_string>(?:[^"]|\\")*)" node$/
*
* @throws ElementNotFoundException Thrown by behat_base::find
* @throws ExpectationException
* @param string $nodetext
*/
public function i_expand_node($nodetext) {
Expand All @@ -54,18 +57,47 @@ public function i_expand_node($nodetext) {
}

$xpath = "//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/child::li" .
"/child::li[contains(concat(' ', normalize-space(@class), ' '), ' collapsed ')]" .
"/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')]" .
"/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]" .
"|" .
"//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/descendant::li[not(contains(concat(' ', normalize-space(@class), ' '), ' collapsed'))]" .
"/descendant::li" .
"/descendant::li[contains(concat(' ', normalize-space(@class), ' '), ' collapsed')]" .
"/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')]" .
"/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]";

$node = $this->find('xpath', $xpath);
$exception = new ExpectationException('The "' . $nodetext . '" node can not be expanded', $this->getSession());
$node = $this->find('xpath', $xpath, $exception);
$node->click();
}

/**
* Collapses the selected node of the navigation tree that matches the text.
*
* @Given /^I collapse "(?P<nodetext_string>(?:[^"]|\\")*)" node$/
* @throws ExpectationException
* @param string $nodetext
*/
public function i_collapse_node($nodetext) {

// No collapsible nodes with non-JS browsers.
if (!$this->running_javascript()) {
return false;
}

$xpath = "//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/child::li[not(contains(concat(' ', normalize-space(@class), ' '), ' collapsed '))]" .
"/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')]" .
"/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]" .
"|" .
"//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/descendant::li[not(contains(concat(' ', normalize-space(@class), ' '), ' collapsed'))]" .
"/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')]" .
"/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]";

$exception = new ExpectationException('The "' . $nodetext . '" node can not be collapsed', $this->getSession());
$node = $this->find('xpath', $xpath, $exception);
$node->click();
}
}
2 changes: 1 addition & 1 deletion lib/tests/behat/behat_permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function i_set_the_following_system_permissions_of_role($rolename, $table

return array(
new Given('I am on homepage'),
new Given('I expand "Front page settings" node'),
new Given('I collapse "Front page settings" node'),
new Given('I expand "Site administration" node'),
new Given('I expand "Users" node'),
new Given('I expand "Permissions" node'),
Expand Down

0 comments on commit c4509f8

Please sign in to comment.