function BigPipeTest::testNoJsDetection

Same name in other branches
  1. 9 core/modules/big_pipe/tests/src/Functional/BigPipeTest.php \Drupal\Tests\big_pipe\Functional\BigPipeTest::testNoJsDetection()
  2. 8.9.x core/modules/big_pipe/tests/src/Functional/BigPipeTest.php \Drupal\Tests\big_pipe\Functional\BigPipeTest::testNoJsDetection()
  3. 10 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 79

Class

BigPipeTest
Tests BigPipe's no-JS detection & response delivery (with and without JS).

Namespace

Drupal\Tests\big_pipe\Functional

Code

public function testNoJsDetection() : void {
    $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('0');
    $this->assertBigPipeNoJsCookieExists('0');
    $this->assertSession()
        ->responseNotContains('<noscript><meta http-equiv="Refresh" content="0; URL=');
    $this->assertSession()
        ->responseNotContains($no_js_to_js_markup);
    // 2. Session (authenticated).
    $this->drupalLogin($this->rootUser);
    $this->assertSessionCookieExists('1');
    $this->assertBigPipeNoJsCookieExists('0');
    $this->assertSession()
        ->responseContains('<noscript><meta http-equiv="Refresh" content="0; URL=' . base_path() . 'big_pipe/no-js?destination=' . UrlHelper::encodePath(base_path() . 'user/1?check_logged_in=1') . '" />' . "\n" . '</noscript>');
    $this->assertSession()
        ->responseNotContains($no_js_to_js_markup);
    $this->assertBigPipeNoJsMetaRefreshRedirect();
    $this->assertBigPipeNoJsCookieExists('1');
    $this->assertSession()
        ->responseNotContains('<noscript><meta http-equiv="Refresh" content="0; URL=');
    $this->assertSession()
        ->responseContains($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('1');
    $this->assertBigPipeNoJsCookieExists('0');
    $this->assertSession()
        ->responseContains('<noscript><meta http-equiv="Refresh" content="0; URL=' . base_path() . 'big_pipe/no-js?destination=' . base_path() . 'user/login" />' . "\n" . '</noscript>');
    $this->assertSession()
        ->responseNotContains($no_js_to_js_markup);
    $this->assertBigPipeNoJsMetaRefreshRedirect();
    $this->assertBigPipeNoJsCookieExists('1');
    $this->assertSession()
        ->responseNotContains('<noscript><meta http-equiv="Refresh" content="0; URL=');
    $this->assertSession()
        ->responseContains($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('0');
    $this->assertBigPipeNoJsCookieExists('0');
    $this->assertSession()
        ->responseNotContains('<noscript><meta http-equiv="Refresh" content="0; URL=');
    $this->assertSession()
        ->responseNotContains($no_js_to_js_markup);
    $this->drupalLogin($this->rootUser);
    $this->drupalGet(Url::fromRoute('no_big_pipe'));
    $this->assertSessionCookieExists('1');
    $this->assertBigPipeNoJsCookieExists('0');
    $this->assertSession()
        ->responseNotContains('<noscript><meta http-equiv="Refresh" content="0; URL=');
    $this->assertSession()
        ->responseNotContains($no_js_to_js_markup);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.