Skip to content

Commit

Permalink
Merge branch 'MDL-40123_25' of git://github.com/dmonllao/moodle into …
Browse files Browse the repository at this point in the history
…MOODLE_25_STABLE
  • Loading branch information
stronk7 committed Jul 22, 2013
2 parents e024b71 + 2ab6b4d commit 2f956f4
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions lib/tests/behat/behat_forms.php
Expand Up @@ -110,34 +110,31 @@ protected function expand_all_fields() {
// behat_base::find() throws an exception if there are no elements, we should not fail a test because of this.
try {

// Expand fieldsets.
$fieldsets = $this->find_all('css', 'fieldset.collapsed a.fheader');

// We are supposed to have fieldsets here, otherwise exception.

// Funny thing about this, with find_all() we specify a pattern and each element matching the pattern is added to the array
// with of xpaths with a [0], [1]... sufix, but when we click on an element it does not matches the specified xpath
// anymore (is not collapsed) so [1] becomes [0], that's why we always click on the first XPath match, will be always the next one.
$iterations = count($fieldsets);
for ($i = 0; $i < $iterations; $i++) {
$fieldsets[0]->click();
}
// Expand fieldsets link.
$collapseexpandlink = $this->find('xpath', "//div[@class='collapsible-actions']" .
"/descendant::a[contains(concat(' ', @class, ' '), ' collapseexpand ')]" .
"[not(contains(concat(' ', @class, ' '), ' collapse-all '))]"
);
$collapseexpandlink->click();

} catch (ElementNotFoundException $e) {
// We continue if there are not expanded fields.
// We continue if there are not expandable fields.
}

// Different try & catch as we can have expanded fieldsets with advanced fields on them.
try {

// Show all fields.
$showmorestr = get_string('showmore', 'form');
$showmores = $this->find_all('xpath', "//a[normalize-space(.)='" . $showmorestr . "']" .
"[contains(concat(' ', normalize-space(@class), ' '), ' moreless-toggler ')]");
// Expand all fields xpath.
$showmorexpath = "//a[normalize-space(.)='" . get_string('showmore', 'form') . "']" .
"[contains(concat(' ', normalize-space(@class), ' '), ' moreless-toggler')]";

// We are supposed to have 'show more's here, otherwise exception.
// We don't wait here as we already waited when getting the expand fieldsets links.
$showmores = $this->getSession()->getPage()->findAll('xpath', $showmorexpath);

// Same funny case, after clicking on the element the [1] showmore link becomes the [0].
// Funny thing about this, with findAll() we specify a pattern and each element matching the pattern is added to the array
// with of xpaths with a [0], [1]... sufix, but when we click on an element it does not matches the specified xpath
// anymore (now is a "Show less..." link) so [1] becomes [0], that's why we always click on the first XPath match,
// will be always the next one.
$iterations = count($showmores);
for ($i = 0; $i < $iterations; $i++) {
$showmores[0]->click();
Expand Down

0 comments on commit 2f956f4

Please sign in to comment.