*/
class PermissionsByTermContext extends RawDrupalContext {
+ private const MAX_DURATION_SECONDS = 1200;
+
public function __construct() {
$driver = new DrupalDriver(DRUPAL_ROOT, '');
$driver->setCoreFromVersion();
$driver->bootstrap();
}
- /**
- * @AfterSuite
- */
- public static function cleanDB() {
- $module_path = \Drupal::service('module_handler')->getModule('permissions_by_term')->getPath();
-
- $defaultSitesDirPath = \Drupal::service('stream_wrapper_manager')->getViaScheme(file_default_scheme())->realpath() . '/';
- unlink($defaultSitesDirPath . 'db.sqlite');
- copy($module_path . '/tests/src/Behat/fixtures/db.sqlite', $defaultSitesDirPath . 'db.sqlite');
- chmod($defaultSitesDirPath . '/db.sqlite', 0777);
- }
-
/**
* Creates one or more terms on an existing vocabulary.
*
$selectElement->selectOption($label);
}
+ /**
+ * @Then /^I should see text matching "([^"]*)" after a while$/
+ */
+ public function iShouldSeeTextAfterAWhile($text)
+ {
+ try {
+ $startTime = time();
+ do {
+ $content = $this->getSession()->getPage()->getText();
+ if (substr_count($content, $text) > 0) {
+ return true;
+ }
+ } while (time() - $startTime < self::MAX_DURATION_SECONDS);
+ throw new ResponseTextException(
+ sprintf('Could not find text %s after %s seconds', $text, self::MAX_DURATION_SECONDS),
+ $this->getSession()
+ );
+ } catch (StaleElementReference $e) {
+ return true;
+ }
+ }
+
+ /**
+ * @Then /^I click by selector "([^"]*)" via JavaScript$/
+ * @param string $selector
+ */
+ public function clickBySelector(string $selector)
+ {
+ $this->getSession()->executeScript("document.querySelector('" . $selector . "').click()");
+ }
+
}