diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 3b706e60d6..a95beb0366 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -67,7 +67,6 @@ createUser as drupalCreateUser; } use XdebugRequestTrait; - use MetaRefreshTrait; /** * The database prefix of this test run. @@ -250,6 +249,20 @@ protected $originalShutdownCallbacks = []; /** + * The number of meta refresh redirects to follow, or NULL if unlimited. + * + * @var null|int + */ + protected $maximumMetaRefreshCount = NULL; + + /** + * The number of meta refresh redirects followed during ::drupalGet(). + * + * @var int + */ + protected $metaRefreshCount = 0; + + /** * Initializes Mink sessions. */ protected function initMink() { @@ -1385,4 +1398,26 @@ protected function getTestMethodCaller() { return $caller; } + /** + * Checks for meta refresh tag and if found call drupalGet() recursively. + * + * This function looks for the http-equiv attribute to be set to "Refresh" and + * is case-sensitive. + * + * @return string|false + * Either the new page content or FALSE. + */ + protected function checkForMetaRefresh() { + $refresh = $this->cssSelect('meta[http-equiv="Refresh"]'); + if (!empty($refresh) && (!isset($this->maximumMetaRefreshCount) || $this->metaRefreshCount < $this->maximumMetaRefreshCount)) { + // Parse the content attribute of the meta tag for the format: + // "[delay]: URL=[page_to_redirect_to]". + if (preg_match('/\d+;\s*URL=(?.*)/i', $refresh[0]->getAttribute('content'), $match)) { + $this->metaRefreshCount++; + return $this->drupalGet($this->getAbsoluteUrl(Html::decodeEntities($match['url']))); + } + } + return FALSE; + } + } diff --git a/core/tests/Drupal/Tests/Traits/Core/MetaRefreshTrait.php b/core/tests/Drupal/Tests/Traits/Core/MetaRefreshTrait.php deleted file mode 100644 index b891ec20de..0000000000 --- a/core/tests/Drupal/Tests/Traits/Core/MetaRefreshTrait.php +++ /dev/null @@ -1,48 +0,0 @@ -cssSelect('meta[http-equiv="Refresh"]'); - if (!empty($refresh) && (!isset($this->maximumMetaRefreshCount) || $this->metaRefreshCount < $this->maximumMetaRefreshCount)) { - // Parse the content attribute of the meta tag for the format: - // "[delay]: URL=[page_to_redirect_to]". - if (preg_match('/\d+;\s*URL=(?.*)/i', $refresh[0]->getAttribute('content'), $match)) { - $this->metaRefreshCount++; - return $this->drupalGet($this->getAbsoluteUrl(Html::decodeEntities($match['url']))); - } - } - return FALSE; - } - -}