Permalink
Browse files

MDL-39638 behat: New step to collapse nodes based on the expand nodes

Also updating steps with a collapse behaviour.
  • Loading branch information...
dmonllao authored and stronk7 committed May 13, 2013
1 parent 2ab5928 commit 18003f2adb4b649681104d4314effb8626253713
@@ -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
@@ -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
@@ -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'),
@@ -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
@@ -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.
*
@@ -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) {
@@ -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();
+ }
}
@@ -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'),

0 comments on commit 18003f2

Please sign in to comment.