Skip to content

Commit

Permalink
Merge pull request #140 from open-sausages/pulls/4.0/ui-button-refresh
Browse files Browse the repository at this point in the history
Update behat extension for updated button styling
  • Loading branch information
chillu authored Jan 10, 2017
2 parents f417b4b + eaa17cf commit a0ad8b3
Showing 1 changed file with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions src/SilverStripe/BehatExtension/Context/BasicContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Behat\Behat\Event\StepEvent;
use Behat\Behat\Event\ScenarioEvent;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Element\NodeElement;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Filesystem;

Expand Down Expand Up @@ -359,20 +360,57 @@ public function stepIWaitFor($secs)
}

/**
* @Given /^I press the "([^"]*)" button$/
* Find visible button with the given text.
* Supports data-text-alternate property.
*
* @param string $text
* @return NodeElement|null
*/
public function stepIPressTheButton($button)
protected function findNamedButton($title)
{
$page = $this->getSession()->getPage();
$els = $page->findAll('named', array('link_or_button', "'$button'"));
// See https://mathiasbynens.be/notes/css-escapes
$escapedTitle = addcslashes($title, '!"#$%&\'()*+,-./:;<=>?@[\]^`{|}~');
$matchedEl = null;
foreach ($els as $el) {
if ($el->isVisible()) {
$matchedEl = $el;
$searches = [
['named', ['link_or_button', "'{$title}'"]],
['css', "button[data-text-alternate='{$escapedTitle}']"],
];
foreach ($searches as list($type, $arg)) {
$buttons = $page->findAll($type, $arg);
foreach ($buttons as $el) {
if ($el->isVisible()) {
return $el;
}
}
}
assertNotNull($matchedEl, sprintf('%s button not found', $button));
$matchedEl->click();
return null;
}

/**
* Example: I should see a "Submit" button
* Example: I should not see a "Delete" button
*
* @Given /^I should( not? |\s*)see (?:a|an|the) "([^"]*)" button$/
*/
public function iShouldSeeAButton($negative, $text)
{
$matchedEl = $this->findNamedButton($text);
if (trim($negative)) {
assertNull($matchedEl, sprintf('%s button found', $text));
} else {
assertNotNull($matchedEl, sprintf('%s button not found', $text));
}
}

/**
* @Given /^I press the "([^"]*)" button$/
*/
public function stepIPressTheButton($text)
{
$button = $this->findNamedButton($text);
assertNotNull($button, "{$text} button not found");
$button->click();
}

/**
Expand Down

0 comments on commit a0ad8b3

Please sign in to comment.