Update to mink 1.6 and remove custom fork

Add javascript-workaround for selecting hidden elements
This commit is contained in:
Damian Mooyman 2014-05-30 09:04:18 +12:00
parent e3ccf1c733
commit 0050149bfa
2 changed files with 105 additions and 35 deletions

View File

@ -1,38 +1,39 @@
{
"name": "silverstripe/behat-extension",
"type": "behat-extension",
"description": "SilverStripe framework extension for Behat",
"keywords": ["framework", "web", "bdd", "silverstripe"],
"homepage": "http://silverstripe.org",
"license": "MIT",
"authors": [
{
"name": "Michal Ochman",
"email": "ochman.d.michal@gmail.com"
},
{
"name": "Ingo Schommer",
"email": "ingo@silverstripe.com"
}
],
"name": "silverstripe/behat-extension",
"type": "behat-extension",
"description": "SilverStripe framework extension for Behat",
"keywords": ["framework", "web", "bdd", "silverstripe"],
"homepage": "http://silverstripe.org",
"license": "MIT",
"authors": [
{
"name": "Michal Ochman",
"email": "ochman.d.michal@gmail.com"
},
{
"name": "Ingo Schommer",
"email": "ingo@silverstripe.com"
}
],
"require": {
"php": ">=5.3.2",
"phpunit/phpunit": "3.7.*",
"behat/behat": "2.5.*@stable",
"behat/mink": "1.5.*@stable",
"behat/mink-extension": "1.3.*@stable",
"silverstripe/mink-selenium2-driver": "1.1.*-dev",
"symfony/dom-crawler": "*@stable",
"behat/mink-goutte-driver": "*",
"silverstripe/testsession": "*",
"silverstripe/framework": "~3.1"
},
"autoload": {
"psr-0": {
"SilverStripe\\BehatExtension": "src/"
}
},
"minimum-stability": "dev"
"require": {
"php": ">=5.3.2",
"phpunit/phpunit": "3.7.*",
"behat/behat": "2.5.*@stable",
"behat/mink": "1.6.*-dev",
"behat/mink-extension": "1.3.*-dev",
"behat/mink-selenium2-driver": "1.2.*-dev",
"symfony/dom-crawler": "*@stable",
"fabpot/goutte": "1.*@stable",
"behat/mink-goutte-driver": "1.1.*-dev",
"silverstripe/testsession": "*",
"silverstripe/framework": "~3.1"
},
"autoload": {
"psr-0": {
"SilverStripe\\BehatExtension": "src/"
}
},
"minimum-stability": "dev"
}

View File

@ -412,4 +412,73 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex
$this->testSessionEnvironment->applyState($state);
}
/**
* Selects option in select field with specified id|name|label|value.
*
* @override /^(?:|I )select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/
*/
public function selectOption($select, $option) {
// Find field
$field = $this
->getSession()
->getPage()
->findField($this->fixStepArgument($select));
// If field is visible then select it as per normal
if($field && $field->isVisible()) {
parent::selectOption($select, $option);
} else {
$this->selectOptionWithJavascript($select, $option);
}
}
/**
* Selects option in select field with specified id|name|label|value using javascript
* This method uses javascript to allow selection of options that may be
* overridden by javascript libraries, and thus hide the element.
*
* @When /^(?:|I )select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)" with javascript$/
*/
public function selectOptionWithJavascript($select, $option) {
$select = $this->fixStepArgument($select);
$option = $this->fixStepArgument($option);
$page = $this->getSession()->getPage();
// Find field
$field = $page->findField($select);
if (null === $field) {
throw $page->elementNotFound('form field', 'id|name|label|value', $select);
}
// Find option
$opt = $field->find('named', array(
'option', $this->getSession()->getSelectorsHandler()->xpathLiteral($option)
));
if (null === $opt) {
throw $field->elementNotFound('select option', 'value|text', $option);
}
// Merge new option in with old handling both multiselect and single select
$value = $field->getValue();
$newValue = $opt->getAttribute('value');
if(is_array($value)) {
if(!in_array($newValue, $value)) $value[] = $newValue;
} else {
$value = $newValue;
}
$valueEncoded = json_encode($value);
// Inject this value via javascript
$fieldID = $field->getAttribute('ID');
$script = <<<EOS
(function($) {
$("#$fieldID")
.val($valueEncoded)
.trigger('liszt:updated')
.trigger('chosen:updated');
})(jQuery);
EOS;
$this->getSession()->getDriver()->executeScript($script);
}
}