Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / permissions_by_term / tests / src / Behat / Context / PermissionsByTermContext.php
index 4b2539c6128b0a0b1ca293ab008d39b2fc70f183..27b76c406c441a72559850bc3d95266d50da3d1d 100644 (file)
@@ -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()");
+  }
+
 }