Permalink
Browse files

Merge branch '44711-25-r3' of git://github.com/samhemelryk/moodle int…

…o MOODLE_25_STABLE
  • Loading branch information...
stronk7 committed May 21, 2014
2 parents acbaec5 + 84cdd9b commit d3e6508d5b1d2600b6906c466913c252f1900541
Showing with 32 additions and 141 deletions.
  1. +0 −33 blocks/navigation/tests/behat/view_my_courses.feature
  2. +32 −108 lib/tests/behat/behat_navigation.php
@@ -69,36 +69,3 @@ Feature: View my courses in navigation block
And I wait "2" seconds
And I should see "c331" in the "Navigation" "block"
And I should not see "c332" in the "Navigation" "block"
@javascript
Scenario: I can expand categories and courses as guest
Given I set the following administration settings values:
| Show my course categories | 1 |
| Show all courses | 1 |
And I log out
And I expand "Courses" node
And I should see "cat1" in the "Navigation" "block"
And I should see "cat2" in the "Navigation" "block"
And I should see "cat3" in the "Navigation" "block"
And I should not see "cat31" in the "Navigation" "block"
And I should not see "cat32" in the "Navigation" "block"
And I should not see "cat331" in the "Navigation" "block"
And I should not see "c1" in the "Navigation" "block"
And I should not see "c2" in the "Navigation" "block"
And I should not see "c31" in the "Navigation" "block"
And I should not see "c32" in the "Navigation" "block"
When I expand "cat3" node
And I expand "cat31" node
And I expand "cat1" node
And I should see "c1" in the "Navigation" "block"
And I expand "c1" node
Then I should see "cat1" in the "Navigation" "block"
And I should see "cat2" in the "Navigation" "block"
And I should see "cat3" in the "Navigation" "block"
And I should see "cat31" in the "Navigation" "block"
And I should see "cat32" in the "Navigation" "block"
And I should not see "cat331" in the "Navigation" "block"
And I should see "c1" in the "Navigation" "block"
And I should not see "c2" in the "Navigation" "block"
And I should see "c31" in the "Navigation" "block"
And I should not see "c32" in the "Navigation" "block"
@@ -40,107 +40,12 @@
*/
class behat_navigation extends behat_base {
/**
* Helper function to get a navigation nodes text element given its text from within the navigation block.
*
* This function finds the node with the given text from within the navigation block.
* It checks to make sure the node is visible, and then returns it.
*
* @param string $text
* @param bool $branch Set this true if you're only interested in the node if its a branch.
* @param null|bool $collapsed Set this to true or false if you want the node to either be collapsed or not.
* If its left as null then we don't worry about it.
* @param null|string|Exception|false $exception The exception to throw if the node is not found.
* @return \Behat\Mink\Element\NodeElement
*/
protected function get_node_text_node($text, $branch = false, $collapsed = null, $exception = null) {
if ($exception === null) {
$exception = new ExpectationException('The "' . $text . '" node could not be found', $this->getSession());
} else if (is_string($exception)) {
$exception = new ExpectationException($exception, $this->getSession());
}
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($text);
$hasblocktree = "[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]";
$hasbranch = "[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]";
$hascollapsed = "li[contains(concat(' ', normalize-space(@class), ' '), ' collapsed ') or @data-exandable='1']";
$notcollapsed = "li[not(contains(concat(' ', normalize-space(@class), ' '), ' collapsed '))]";
$match = "[normalize-space(.)={$nodetextliteral}]";
// Avoid problems with quotes.
$isbranch = ($branch) ? $hasbranch : '';
if ($collapsed === true) {
$iscollapsed = $hascollapsed;
} else if ($collapsed === false) {
$iscollapsed = $notcollapsed;
} else {
$iscollapsed = 'li';
}
// First check root nodes.
$xpath = "//ul{$hasblocktree}/$hascollapsed/p{$isbranch}/span{$match}|";
// Next search for the node containing the text within a link.
$xpath .= "//ul{$hasblocktree}//{$notcollapsed}/ul/{$iscollapsed}/p{$isbranch}/a{$match}|";
// Finally search for the node containing the text within a span.
$xpath .= "//ul{$hasblocktree}//{$notcollapsed}/ul/{$iscollapsed}/p{$isbranch}/span{$match}";
$node = $this->find('xpath', $xpath, $exception);
return $node;
}
/**
* Returns true if the navigation node with the given text is expandable.
*
* @Given /^navigation node "([^"]*)" should be expandable$/
*
* @throws ExpectationException
* @param string $nodetext
* @return bool
*/
public function navigation_node_should_be_expandable($nodetext) {
if (!$this->running_javascript()) {
// Nodes are only expandable when JavaScript is enabled.
return false;
}
$node = $this->get_node_text_node($nodetext, true);
$node = $node->getParent();
if ($node->hasAttribute('data-expandable') && $node->getAttribute('data-expandable')) {
return true;
}
throw new ExpectationException('The "' . $nodetext . '" node is not expandable', $this->getSession());
}
/**
* Returns true if the navigation node with the given text is not expandable.
*
* @Given /^navigation node "([^"]*)" should not be expandable$/
*
* @throws ExpectationException
* @param string $nodetext
* @return bool
*/
public function navigation_node_should_not_be_expandable($nodetext) {
if (!$this->running_javascript()) {
// Nodes are only expandable when JavaScript is enabled.
return false;
}
$node = $this->get_node_text_node($nodetext);
$node = $node->getParent();
if ($node->hasAttribute('data-expandable') && $node->getAttribute('data-expandable')) {
throw new ExpectationException('The "' . $nodetext . '" node is expandable', $this->getSession());
}
return true;
}
/**
* Expands the selected node of the navigation tree that matches the text.
* @Given /^I expand "(?P<nodetext_string>(?:[^"]|\\")*)" node$/
*
* @throws ExpectationException
* @param string $nodetext
* @return bool|void
*/
public function i_expand_node($nodetext) {
@@ -150,12 +55,23 @@ public function i_expand_node($nodetext) {
if (!$this->running_javascript()) {
return false;
}
$node = $this->get_node_text_node($nodetext, true, true, 'The "' . $nodetext . '" node can not be expanded');
// Check if the node is a link AND a branch.
if (strtolower($node->getTagName()) === 'a') {
// We just want to expand the node, we don't want to follow it.
$node = $node->getParent();
}
// Avoid problems with quotes.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($nodetext);
$xpath = "//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/child::li[contains(concat(' ', normalize-space(@class), ' '), ' collapsed ')]" .
"/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
"/child::span[normalize-space(.)=$nodetextliteral]" .
"|" .
"//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
"/descendant::li[not(contains(concat(' ', normalize-space(@class), ' '), ' collapsed '))]" .
"/descendant::li[contains(concat(' ', normalize-space(@class), ' '), ' collapsed ')]" .
"/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
"/child::span[normalize-space(.)=$nodetextliteral]";
$exception = new ExpectationException('The "' . $nodetext . '" node can not be expanded', $this->getSession());
$node = $this->find('xpath', $xpath, $exception);
$node->click();
}
@@ -165,7 +81,6 @@ public function i_expand_node($nodetext) {
* @Given /^I collapse "(?P<nodetext_string>(?:[^"]|\\")*)" node$/
* @throws ExpectationException
* @param string $nodetext
* @return bool|void
*/
public function i_collapse_node($nodetext) {
@@ -174,12 +89,21 @@ public function i_collapse_node($nodetext) {
return false;
}
$node = $this->get_node_text_node($nodetext, true, false, 'The "' . $nodetext . '" node can not be collapsed');
// Check if the node is a link AND a branch.
if (strtolower($node->getTagName()) === 'a') {
// We just want to expand the node, we don't want to follow it.
$node = $node->getParent();
}
// Avoid problems with quotes.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($nodetext);
$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[normalize-space(.)=$nodetextliteral]" .
"|" .
"//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[normalize-space(.)=$nodetextliteral]";
$exception = new ExpectationException('The "' . $nodetext . '" node can not be collapsed', $this->getSession());
$node = $this->find('xpath', $xpath, $exception);
$node->click();
}
}

0 comments on commit d3e6508

Please sign in to comment.