X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fpermissions_by_term%2Ftests%2Fsrc%2FBehat%2FContext%2FPermissionsByTermContext.php;fp=web%2Fmodules%2Fcontrib%2Fpermissions_by_term%2Ftests%2Fsrc%2FBehat%2FContext%2FPermissionsByTermContext.php;h=27b76c406c441a72559850bc3d95266d50da3d1d;hp=4b2539c6128b0a0b1ca293ab008d39b2fc70f183;hb=059867c3f96750652c80f39e44c442a58c2549ee;hpb=f8fc16ae6b862bef59baaad5d051dd37b7ff11b2 diff --git a/web/modules/contrib/permissions_by_term/tests/src/Behat/Context/PermissionsByTermContext.php b/web/modules/contrib/permissions_by_term/tests/src/Behat/Context/PermissionsByTermContext.php index 4b2539c61..27b76c406 100644 --- a/web/modules/contrib/permissions_by_term/tests/src/Behat/Context/PermissionsByTermContext.php +++ b/web/modules/contrib/permissions_by_term/tests/src/Behat/Context/PermissionsByTermContext.php @@ -14,6 +14,8 @@ use Drupal\taxonomy\Entity\Vocabulary; */ class PermissionsByTermContext extends RawDrupalContext { + private const MAX_DURATION_SECONDS = 1200; + public function __construct() { $driver = new DrupalDriver(DRUPAL_ROOT, ''); $driver->setCoreFromVersion(); @@ -22,18 +24,6 @@ class PermissionsByTermContext extends RawDrupalContext { $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. * @@ -224,4 +214,35 @@ class PermissionsByTermContext extends RawDrupalContext { $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()"); + } + }