mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Step transformations rather than special case step overrides
This commit is contained in:
parent
fd9e84006f
commit
8418bea0f8
@ -132,7 +132,6 @@ class FixtureContext extends BehatContext
|
|||||||
$class = $this->convertTypeToClass($type);
|
$class = $this->convertTypeToClass($type);
|
||||||
if(is_a($class, 'File', true)) {
|
if(is_a($class, 'File', true)) {
|
||||||
$fields = $this->prepareAsset($class, $id);
|
$fields = $this->prepareAsset($class, $id);
|
||||||
var_dump($fields);
|
|
||||||
} else {
|
} else {
|
||||||
$fields = array();
|
$fields = array();
|
||||||
}
|
}
|
||||||
@ -263,6 +262,29 @@ class FixtureContext extends BehatContext
|
|||||||
$yamlFixture->writeInto($this->getFixtureFactory());
|
$yamlFixture->writeInto($this->getFixtureFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces fixture references in values with their respective database IDs,
|
||||||
|
* with the notation "=><class>.<identifier>". Example: "=>Page.My Page".
|
||||||
|
*
|
||||||
|
* @Transform /^([^"]+)$/
|
||||||
|
*/
|
||||||
|
public function lookupFixtureReference($string)
|
||||||
|
{
|
||||||
|
if(preg_match('/^=>/', $string)) {
|
||||||
|
list($className, $identifier) = explode('.', preg_replace('/^=>/', '', $string), 2);
|
||||||
|
$id = $this->fixtureFactory->getId($className, $identifier);
|
||||||
|
if(!$id) {
|
||||||
|
throw new \InvalidArgumentException(sprintf(
|
||||||
|
'Cannot resolve reference "%s", no matching fixture found',
|
||||||
|
$string
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return $id;
|
||||||
|
} else {
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function prepareAsset($class, $identifier, $data = null) {
|
protected function prepareAsset($class, $identifier, $data = null) {
|
||||||
if(!$data) $data = array();
|
if(!$data) $data = array();
|
||||||
$relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier;
|
$relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier;
|
||||||
|
@ -263,53 +263,4 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex
|
|||||||
return new Step\Given($step);
|
return new Step\Given($step);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @Given /^((?:I )fill in =>(.+?) for "([^"]*)")$/
|
|
||||||
*/
|
|
||||||
public function iFillInFor($step, $reference, $field)
|
|
||||||
{
|
|
||||||
if (false === strpos($reference, '.')) {
|
|
||||||
throw new \Exception('Fixture reference should be in following format: =>ClassName.identifier');
|
|
||||||
}
|
|
||||||
|
|
||||||
list($className, $identifier) = explode('.', $reference);
|
|
||||||
$id = $this->idFromFixture($className, $identifier);
|
|
||||||
//$step = preg_replace('#=>(.+?) for "([^"]*)"#', '"'.$id.'" for "'.$field.'"', $step);
|
|
||||||
|
|
||||||
// below is not working, because Selenium can't interact with hidden inputs
|
|
||||||
// return new Step\Given($step);
|
|
||||||
|
|
||||||
// TODO: investigate how to simplify this and make universal
|
|
||||||
$javascript = <<<JAVASCRIPT
|
|
||||||
if ('undefined' !== typeof window.jQuery) {
|
|
||||||
window.jQuery('input[name="$field"]').val($id);
|
|
||||||
}
|
|
||||||
JAVASCRIPT;
|
|
||||||
$this->getSession()->executeScript($javascript);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Given /^((?:I )fill in "([^"]*)" with =>(.+))$/
|
|
||||||
*/
|
|
||||||
public function iFillInWith($step, $field, $reference)
|
|
||||||
{
|
|
||||||
if (false === strpos($reference, '.')) {
|
|
||||||
throw new \Exception('Fixture reference should be in following format: =>ClassName.identifier');
|
|
||||||
}
|
|
||||||
|
|
||||||
list($className, $identifier) = explode('.', $reference);
|
|
||||||
$id = $this->idFromFixture($className, $identifier);
|
|
||||||
//$step = preg_replace('#"([^"]*)" with =>(.+)#', '"'.$field.'" with "'.$id.'"', $step);
|
|
||||||
|
|
||||||
// below is not working, because Selenium can't interact with hidden inputs
|
|
||||||
// return new Step\Given($step);
|
|
||||||
|
|
||||||
// TODO: investigate how to simplify this and make universal
|
|
||||||
$javascript = <<<JAVASCRIPT
|
|
||||||
if ('undefined' !== typeof window.jQuery) {
|
|
||||||
window.jQuery('input[name="$field"]').val($id);
|
|
||||||
}
|
|
||||||
JAVASCRIPT;
|
|
||||||
$this->getSession()->executeScript($javascript);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user