Graceful handling of regions which aren't CSS selectors

The dual use of regions (CSS selector and natural language name)
causes some difficulties in processing. Since the CSS selector
is tried first, we need to ensure the underlying logic
doesn't bail on invald selector syntax.

See https://github.com/silverstripe-labs/silverstripe-behat-extension/pull/84
This commit is contained in:
Ingo Schommer 2015-04-08 08:19:34 +12:00
parent b28b179df7
commit 0cdfb2e116

View File

@ -138,13 +138,17 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex
*/
public function getRegionObj($region) {
// Try to find regions directly by CSS selector.
$regionObj = $this->getSession()->getPage()->find(
'css',
// Escape CSS selector
(false !== strpos($region, "'")) ? str_replace("'", "\'", $region) : $region
);
if($regionObj) {
return $regionObj;
try {
$regionObj = $this->getSession()->getPage()->find(
'css',
// Escape CSS selector
(false !== strpos($region, "'")) ? str_replace("'", "\'", $region) : $region
);
if($regionObj) {
return $regionObj;
}
} catch(\Symfony\Component\CssSelector\Exception\SyntaxErrorException $e) {
// fall through to next case
}
// Fall back to region identified by data-title.