From aae0baf8395196cfc5638494853e82a83da84805 Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Thu, 31 Aug 2017 20:07:33 +1000 Subject: [PATCH] Issue #2905818 by Wim Leers, Lendude: Make sure \Drupal\Tests\BrowserTestBase::checkForMetaRefresh is case insensitive --- .../test_page_test/src/Controller/Test.php | 15 +++++++++++++++ .../test_page_test/test_page_test.routing.yml | 8 ++++++++ .../FunctionalTests/BrowserTestBaseTest.php | 18 ++++++++++++++++++ core/tests/Drupal/Tests/BrowserTestBase.php | 4 ++-- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php b/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php index 2de84e95936..e754eaf0c25 100644 --- a/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php +++ b/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php @@ -1,6 +1,9 @@ 'foo|bar|baz']; } + /** + * Loads a page that does a redirect. + * + * Drupal uses Symfony's RedirectResponse for generating redirects. That class + * uses a lower-case 'http-equiv="refresh"'. + * + * @see \Symfony\Component\HttpFoundation\RedirectResponse + */ + public function metaRefresh() { + return new RedirectResponse(Url::fromRoute('test_page_test.test_page', [], ['absolute' => TRUE])->toString(), 302); + } + } diff --git a/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml b/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml index 5d84695f8b9..e64a88d003a 100644 --- a/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml +++ b/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml @@ -82,3 +82,11 @@ test_page_test.field_xpath: _form: '\Drupal\test_page_test\Form\TestForm' requirements: _access: 'TRUE' + +test_page_test.meta_refresh: + path: '/test-meta-refresh' + defaults: + _title: 'Page with a redirect' + _controller: '\Drupal\test_page_test\Controller\Test::metaRefresh' + requirements: + _access: 'TRUE' diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index 4a0e1956bfa..c9f621a796f 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -605,4 +605,22 @@ class BrowserTestBaseTest extends BrowserTestBase { $this->assertEquals('Australia/Sydney', $value); } + /** + * Tests the ::checkForMetaRefresh() method. + */ + public function testCheckForMetaRefresh() { + // Disable following redirects in the client. + $this->getSession()->getDriver()->getClient()->followRedirects(FALSE); + // Set the maximumMetaRefreshCount to zero to make sure the redirect doesn't + // happen when doing a drupalGet. + $this->maximumMetaRefreshCount = 0; + $this->drupalGet('test-meta-refresh'); + $this->assertNotEmpty($this->cssSelect('meta[http-equiv="refresh"]')); + // Allow one redirect to happen. + $this->maximumMetaRefreshCount = 1; + $this->checkForMetaRefresh(); + // Check that we are now on the test page. + $this->assertSession()->pageTextContains('Test page text.'); + } + } diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 08d083f3e02..a5ec84ed3bc 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -1267,13 +1267,13 @@ abstract class BrowserTestBase extends TestCase { * 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. + * is case-insensitive. * * @return string|false * Either the new page content or FALSE. */ protected function checkForMetaRefresh() { - $refresh = $this->cssSelect('meta[http-equiv="Refresh"]'); + $refresh = $this->cssSelect('meta[http-equiv="Refresh"], 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]".