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()
- 10 core/modules/big_pipe/tests/src/Functional/BigPipeTest.php \Drupal\Tests\big_pipe\Functional\BigPipeTest::assertBigPipeNoJsMetaRefreshRedirect()
- 11.x core/modules/big_pipe/tests/src/Functional/BigPipeTest.php \Drupal\Tests\big_pipe\Functional\BigPipeTest::assertBigPipeNoJsMetaRefreshRedirect()
Calls ::performMetaRefresh() and asserts the responses.
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 466
Class
- BigPipeTest
- Tests BigPipe's no-JS detection & response delivery (with and without JS).
Namespace
Drupal\Tests\big_pipe\FunctionalCode
protected function assertBigPipeNoJsMetaRefreshRedirect() {
$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->assertEqual($original_url, $this->getSession()
->getCurrentUrl(), 'Redirected back to the original location.');
// First response: redirect.
$this->assertEqual(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->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.');
// Second response: redirect followed.
$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.');
$this->assertNoRaw('<noscript><meta http-equiv="Refresh" content="0; URL=', 'Once the BigPipe no-JS cookie is set, the <meta> refresh is absent: only one redirect ever happens.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.