Skip to content

Commit

Permalink
Graceful handling of regions which aren't CSS selectors
Browse files Browse the repository at this point in the history
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 #84
  • Loading branch information
chillu committed Apr 7, 2015
1 parent b28b179 commit 0cdfb2e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/SilverStripe/BehatExtension/Context/SilverStripeContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,17 @@ public function setRegionMap($regionMap){
*/
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.
Expand Down

0 comments on commit 0cdfb2e

Please sign in to comment.