mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Fix quoting in getRegionObj()
Based on work by @jeffreyguo. See https://github.com/silverstripe-labs/silverstripe-behat-extension/pull/53/commits
This commit is contained in:
parent
2dbd92b16b
commit
3fe596be63
@ -131,22 +131,33 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex
|
|||||||
/**
|
/**
|
||||||
* Returns MinkElement based off region defined in .yml file.
|
* Returns MinkElement based off region defined in .yml file.
|
||||||
* Also supports direct CSS selectors and regions identified by a "data-title" attribute.
|
* Also supports direct CSS selectors and regions identified by a "data-title" attribute.
|
||||||
|
* When using the "data-title" attribute, ensure not to include double quotes.
|
||||||
*
|
*
|
||||||
* @param String $region Region name or CSS selector
|
* @param String $region Region name or CSS selector
|
||||||
* @return MinkElement|null
|
* @return MinkElement|null
|
||||||
*/
|
*/
|
||||||
public function getRegionObj($region) {
|
public function getRegionObj($region) {
|
||||||
// Try to find regions directly by CSS selector
|
// Try to find regions directly by CSS selector.
|
||||||
$regionObj = $this->getSession()->getPage()->find('css',
|
$regionObj = $this->getSession()->getPage()->find(
|
||||||
$this->getSession()->getSelectorsHandler()->xpathLiteral($region));
|
'css',
|
||||||
|
// Escape CSS selector
|
||||||
|
(false !== strpos($region, "'")) ? str_replace("'", "\'", $region) : $region
|
||||||
|
);
|
||||||
if($regionObj) {
|
if($regionObj) {
|
||||||
return $regionObj;
|
return $regionObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to region identified by data-tilte
|
// Fall back to region identified by data-title.
|
||||||
$regionObj = $this->getSession()->getPage()->find('css', '[data-title="' . $region . '"]');
|
// Only apply if no double quotes exist in search string,
|
||||||
if($regionObj) {
|
// which would break the CSS selector.
|
||||||
return $regionObj;
|
if(false === strpos($region, '"')) {
|
||||||
|
$regionObj = $this->getSession()->getPage()->find(
|
||||||
|
'css',
|
||||||
|
'[data-title="' . $region . '"]'
|
||||||
|
);
|
||||||
|
if($regionObj) {
|
||||||
|
return $regionObj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for named region
|
// Look for named region
|
||||||
|
Loading…
Reference in New Issue
Block a user