public function BigPipeTest::testNoJsDetection in Drupal 8
Same name and namespace in other branches
- 9 core/modules/big_pipe/tests/src/Functional/BigPipeTest.php \Drupal\Tests\big_pipe\Functional\BigPipeTest::testNoJsDetection()
Tests BigPipe's no-JS detection.
Covers:
File
- core/
modules/ big_pipe/ tests/ src/ Functional/ BigPipeTest.php, line 83
Class
- BigPipeTest
- Tests BigPipe's no-JS detection & response delivery (with and without JS).
Namespace
Drupal\Tests\big_pipe\FunctionalCode
public function testNoJsDetection() {
$no_js_to_js_markup = '<script>document.cookie = "' . BigPipeStrategy::NOJS_COOKIE . '=1; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"</script>';
// 1. No session (anonymous).
$this
->drupalGet(Url::fromRoute('<front>'));
$this
->assertSessionCookieExists(FALSE);
$this
->assertBigPipeNoJsCookieExists(FALSE);
$this
->assertNoRaw('<noscript><meta http-equiv="Refresh" content="0; URL=');
$this
->assertNoRaw($no_js_to_js_markup);
// 2. Session (authenticated).
$this
->drupalLogin($this->rootUser);
$this
->assertSessionCookieExists(TRUE);
$this
->assertBigPipeNoJsCookieExists(FALSE);
$this
->assertRaw('<noscript><meta http-equiv="Refresh" content="0; URL=' . base_path() . 'big_pipe/no-js?destination=' . base_path() . 'user/1" />' . "\n" . '</noscript>');
$this
->assertNoRaw($no_js_to_js_markup);
$this
->assertBigPipeNoJsMetaRefreshRedirect();
$this
->assertBigPipeNoJsCookieExists(TRUE);
$this
->assertNoRaw('<noscript><meta http-equiv="Refresh" content="0; URL=');
$this
->assertRaw($no_js_to_js_markup);
$this
->drupalLogout();
// Close the prior connection and remove the collected state.
$this
->getSession()
->reset();
// 3. Session (anonymous).
$this
->drupalGet(Url::fromRoute('user.login', [], [
'query' => [
'trigger_session' => 1,
],
]));
$this
->drupalGet(Url::fromRoute('user.login'));
$this
->assertSessionCookieExists(TRUE);
$this
->assertBigPipeNoJsCookieExists(FALSE);
$this
->assertRaw('<noscript><meta http-equiv="Refresh" content="0; URL=' . base_path() . 'big_pipe/no-js?destination=' . base_path() . 'user/login" />' . "\n" . '</noscript>');
$this
->assertNoRaw($no_js_to_js_markup);
$this
->assertBigPipeNoJsMetaRefreshRedirect();
$this
->assertBigPipeNoJsCookieExists(TRUE);
$this
->assertNoRaw('<noscript><meta http-equiv="Refresh" content="0; URL=');
$this
->assertRaw($no_js_to_js_markup);
// Close the prior connection and remove the collected state.
$this
->getSession()
->reset();
// Edge case: route with '_no_big_pipe' option.
$this
->drupalGet(Url::fromRoute('no_big_pipe'));
$this
->assertSessionCookieExists(FALSE);
$this
->assertBigPipeNoJsCookieExists(FALSE);
$this
->assertNoRaw('<noscript><meta http-equiv="Refresh" content="0; URL=');
$this
->assertNoRaw($no_js_to_js_markup);
$this
->drupalLogin($this->rootUser);
$this
->drupalGet(Url::fromRoute('no_big_pipe'));
$this
->assertSessionCookieExists(TRUE);
$this
->assertBigPipeNoJsCookieExists(FALSE);
$this
->assertNoRaw('<noscript><meta http-equiv="Refresh" content="0; URL=');
$this
->assertNoRaw($no_js_to_js_markup);
}