function BigPipeTest::assertBigPipeNoJsMetaRefreshRedirect
Same name in other branches
- 9 core/modules/big_pipe/tests/src/Functional/BigPipeTest.php \Drupal\Tests\big_pipe\Functional\BigPipeTest::assertBigPipeNoJsMetaRefreshRedirect()
- 8.9.x core/modules/big_pipe/tests/src/Functional/BigPipeTest.php \Drupal\Tests\big_pipe\Functional\BigPipeTest::assertBigPipeNoJsMetaRefreshRedirect()
- 10 core/modules/big_pipe/tests/src/Functional/BigPipeTest.php \Drupal\Tests\big_pipe\Functional\BigPipeTest::assertBigPipeNoJsMetaRefreshRedirect()
Calls ::performMetaRefresh() and asserts the responses.
@internal
1 call to BigPipeTest::assertBigPipeNoJsMetaRefreshRedirect()
- BigPipeTest::testNoJsDetection in core/
modules/ big_pipe/ tests/ src/ Functional/ BigPipeTest.php - Tests BigPipe's no-JS detection.
File
-
core/
modules/ big_pipe/ tests/ src/ Functional/ BigPipeTest.php, line 513
Class
- BigPipeTest
- Tests BigPipe's no-JS detection & response delivery (with and without JS).
Namespace
Drupal\Tests\big_pipe\FunctionalCode
protected function assertBigPipeNoJsMetaRefreshRedirect() : void {
$original_url = $this->getSession()
->getCurrentUrl();
// 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->assertEquals($original_url, $this->getSession()
->getCurrentUrl(), 'Redirected back to the original location.');
// First response: redirect.
$this->assertEquals(302, $statuses[0], 'The first response was a 302 (redirect).');
$this->assertStringStartsWith('big_pipe_nojs=1', $headers[0]['Set-Cookie'][0], 'The first response sets the big_pipe_nojs cookie.');
$this->assertEquals($original_url, $headers[0]['Location'][0], 'The first response redirected back to the original page.');
$this->assertEmpty(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.');
// Second response: redirect followed.
$this->assertEquals(200, $statuses[1], 'The second response was a 200.');
$this->assertEmpty(array_diff([
'cookies:big_pipe_nojs',
'session.exists',
], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0])), 'The second response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.');
$this->assertEquals('no-store, content="BigPipe/1.0"', $headers[1]['Surrogate-Control'][0], 'The second response has a "Surrogate-Control" header.');
// Check that the <meta> refresh is absent, only one redirect ever happens.
$this->assertSession()
->responseNotContains('<noscript><meta http-equiv="Refresh" content="0; URL=');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.