Commit 60eed402 authored by Robert Lyon's avatar Robert Lyon
Browse files

Fixing behat test to check for all select options



Change-Id: I329aa72c649fdc148184b474cb234df2cae25801
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 5470b39d
......@@ -181,6 +181,43 @@ class BehatForms extends BehatBase {
}
}
/**
* Checks, that given select box contains the specified options.
*
* @Then /^the "(?P<select_string>(?:[^"]|\\")*)" select box should contain all "(?P<option_string>(?:[^"]|\\")*)"$/
* @throws ExpectationException
* @throws ElementNotFoundException Thrown by BehatBase::find
* @param string $select The select element name
* @param string $option The option text/value. Separated by | (pipe).
*/
public function the_select_box_should_contain_all($select, $option) {
$selectnode = $this->find_field($select);
$optionsarr = array(); // Array of passed value/text options to test.
// Can pass multiple comma separated, with valuable commas escaped with backslash.
foreach (preg_split('/\|/', $option) as $opt) {
$optionsarr[] = trim($opt);
}
// Now get all the values and texts in the select.
$options = $selectnode->findAll('xpath', '//option');
$values = array();
foreach ($options as $opt) {
$values[trim($opt->getValue())] = trim($opt->getText());
}
foreach ($optionsarr as $opt) {
// Verify every option is a valid text or value.
if (!in_array($opt, $values) && !array_key_exists($opt, $values)) {
throw new ExpectationException(
'The select box "' . $select . '" does not contain the option "' . $opt . '"',
$this->getSession()
);
}
}
}
/**
* Checks, that given select box contains the specified option.
*
......
......@@ -28,52 +28,19 @@ Background:
And I press "Reply"
And I log out
Scenario Outline: Selection options to filter messages as an admin (Bug 1433342)
# First make sure each user has a message
# Then test for activity types
Scenario: Selection options to filter messages (Bug 1433342)
# First check what options an admin has
Given I log in as "admin" with password "Password1"
When I follow "Inbox"
And I select "<types>" from "Activity type:"
Examples:
| types |
| Administration messages |
| Contact us |
| Feedback |
| Feedback on annotations |
| Group message |
| Institution message |
| Message from other users |
| New forum post |
| New page access |
| Objectionable content |
| Objectionable content in forum |
| Repeat virus upload |
| System message |
| Virus flag release |
| Watchlist |
And the "Activity type:" select box should contain all "Administration messages | Contact us | Feedback | Feedback on annotations | Group message | Institution message | Message from other users | New forum post | New page access | Objectionable content | Objectionable content in forum | Repeat virus upload | System message | Virus flag release | Watchlist"
And I log out
Scenario Outline: Selecting options to filter messages as a student (Bug 1433342)
# Then check what options a normal user has
Given I log in as "userA" with password "Password1"
And I follow "Groups"
And I follow "Create group"
And I fill in "Group name" with "Jurassic Park"
And I press "Save group"
And I am on homepage
And I fill in "Group name" with "Jurassic Park"
And I press "Save group"
And I am on homepage
When I follow "Inbox"
And I select "<types>" from "Activity type"
Examples:
| types |
| Feedback |
| Feedback on annotations |
| Group message |
| Institution message |
| Message from other users |
| New forum post |
| New page access |
| Objectionable content in forum |
| System message |
| Watchlist |
And the "Activity type:" select box should contain all "Feedback | Feedback on annotations | Group message | Institution message | Message from other users | New forum post | New page access | Objectionable content in forum | System message | Watchlist"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment