From 0cdfb2e11675f2b071771fc645bc79da4f30fafa Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 8 Apr 2015 08:19:34 +1200 Subject: [PATCH] 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 --- .../Context/SilverStripeContext.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php index 4b9aa964..552cbc3b 100644 --- a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php +++ b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php @@ -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.