.../big_pipe/tests/src/Functional/BigPipeTest.php | 42 ++++++++-------------- core/tests/Drupal/Tests/BrowserTestBase.php | 2 +- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php index 016aa70..716cf73 100644 --- a/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php +++ b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php @@ -58,27 +58,13 @@ protected function setUp() { * This test disables the automatic refresh checking, each time it is * desired that this runs, a test case must explicitly call this. * - * @param bool $block_redirects - * Set to TRUE to block all redirects during the meta refresh. - * * @see setUp() - * - * @return int - * The number of refreshes done. */ - protected function performMetaRefresh($block_redirects = FALSE) { - if ($block_redirects) { - $this->getSession()->getDriver()->getClient()->followRedirects(FALSE); - } + protected function performMetaRefresh() { $this->maximumMetaRefreshCount = 1; $this->checkForMetaRefresh(); $this->maximumMetaRefreshCount = 0; - $count = $this->metaRefreshCount; $this->metaRefreshCount = 0; - if ($block_redirects) { - $this->getSession()->getDriver()->getClient()->followRedirects(TRUE); - } - return $count; } /** @@ -466,27 +452,29 @@ protected function assertCookieExists($cookie_name, $expected, $cookie_label) { */ protected function assertBigPipeNoJsMetaRefreshRedirect() { $original_url = $this->getSession()->getCurrentUrl(); - $this->performMetaRefresh(TRUE); + // Disable automatic following of redirects by the HTTP client, so that this + // test can analyze the response headers of each redirect response. + $this->getSession()->getDriver()->getClient()->followRedirects(FALSE); + $this->performMetaRefresh(); $headers[0] = $this->getSession()->getResponseHeaders(); + $statuses[0] = $this->getSession()->getStatusCode(); + $this->performMetaRefresh(); + $headers[1] = $this->getSession()->getResponseHeaders(); + $statuses[1] = $this->getSession()->getStatusCode(); + $this->getSession()->getDriver()->getClient()->followRedirects(TRUE); + + $this->assertEqual($original_url, $this->getSession()->getCurrentUrl(), 'Redirected back to the original location.'); + // First response: redirect. - $this->assertResponse(302); + $this->assertEqual(302, $statuses[0], 'The first response was a 302 (redirect).'); $this->assertIdentical(0, strpos($headers[0]['Set-Cookie'][0], 'big_pipe_nojs=1'), 'The first response sets the big_pipe_nojs cookie.'); $this->assertEqual($original_url, $headers[0]['Location'][0], 'The first response redirected back to the original page.'); $this->assertTrue(empty(array_diff(['cookies:big_pipe_nojs', 'session.exists'], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0]))), 'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.'); $this->assertFalse(isset($headers[0]['Surrogate-Control']), 'The first response has no "Surrogate-Control" header.'); - // Remove the big_pipe_nojs cookie so we can follow the full redirect. - $this->getSession()->setCookie('big_pipe_nojs', NULL); - - $this->drupalGet($original_url); - $count = $this->performMetaRefresh(FALSE); - $this->assertEquals($original_url, $this->getSession()->getCurrentUrl(), 'Redirected back to the original location.'); - $this->assertEqual(1, $count, 'One refresh was done following the refresh'); - $headers[1] = $this->getSession()->getResponseHeaders(); - // Second response: redirect followed. - $this->assertResponse(200); + $this->assertEqual(200, $statuses[1], 'The second response was a 200.'); $this->assertTrue(empty(array_diff(['cookies:big_pipe_nojs', 'session.exists'], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0]))), 'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.'); $this->assertEqual('no-store, content="BigPipe/1.0"', $headers[1]['Surrogate-Control'][0], 'The second response has a "Surrogate-Control" header.'); diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index bd50c23..b075b20 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -1407,7 +1407,7 @@ protected function getTestMethodCaller() { * 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]".