Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

API change the way ajax handlers are invoked to Doc Comments

  • Loading branch information...
commit e48151a332d7307536a651da5a387fc006516d75 1 parent fe6e6c9
@michalochman authored
Showing with 20 additions and 6 deletions.
  1. +20 −6 features/bootstrap/SilverStripe/Test/Behaviour/BasicContext.php
View
26 features/bootstrap/SilverStripe/Test/Behaviour/BasicContext.php
@@ -113,24 +113,38 @@ public function handleAjaxBeforeStep(StepEvent $event)
*
* Don't unregister handler if we're dealing with modal windows
*
+ * Below are the strings that are matched against step name
+ * that is possibly using AJAX
+ * @match go to
+ * @match follow
+ * @match press
+ * @match click
+ * @match submit
+ *
* @AfterStep ~@modal
*/
public function handleAjaxAfterStep(StepEvent $event)
{
- if (!preg_match('/(go to|follow|press|click|submit)/i', $event->getStep()->getText())) {
- return;
- }
+ $method = new \ReflectionMethod(__CLASS__, substr(__METHOD__, strpos(__METHOD__, '::') + 2));
+ if (preg_match_all('#\* @match (.+)#', $method->getDocComment(), $m)) {
+ array_walk($m[1], create_function('&$val', '$val = trim($val);'));
+ $matches = implode('|', array_filter($m[1]));
- $this->handleAjaxTimeout();
+ if (!preg_match('/(?:' . $matches . ')/i', $event->getStep()->getText())) {
+ return;
+ }
- $javascript = <<<JS
+ $this->handleAjaxTimeout();
+
+ $javascript = <<<JS
if ('undefined' !== typeof window.jQuery) {
window.jQuery(document).off('ajaxStart.ss.test.behaviour');
window.jQuery(document).off('ajaxComplete.ss.test.behaviour');
window.jQuery(document).off('ajaxSuccess.ss.test.behaviour');
}
JS;
- $this->getSession()->executeScript($javascript);
+ $this->getSession()->executeScript($javascript);
+ }
}
public function handleAjaxTimeout()

4 comments on commit e48151a

@chillu

So its only executed after scenarios flagged with @modal? Is that a built-in flag to behat?
"Modal" to me means a blocking UI, where a user is forced to take a specific action,
and can't interact with other elements. I don't see how that fits in this scenario here.

And those @modal scenarios are then further limited to only steps matching a certain naming convention?
My original concern is the same: Too much magic. Step definitions should be able to declare themselves
if they require special ajax treatment or not (rather than hiding it behind certain keywords in their naming).

Also: Can you please document new features like that in the README?

@michalochman

It's executed for scenarios NOT tagged @modal. This is a custom tag introduced by me that will prevent executing JS whenever modal dialogs come up to prevent runtime failures.

@michalochman

Step definitions should be able to declare themselves if they require special ajax treatment or not (rather than hiding it behind certain keywords in their naming).

How would you define steps then?

@michalochman

And here's @modal usage.

Please sign in to comment.
Something went wrong with that request. Please try again.