function BigPipeTest::testBigPipeNoJs

Same name in other branches
  1. 9 core/modules/big_pipe/tests/src/Functional/BigPipeTest.php \Drupal\Tests\big_pipe\Functional\BigPipeTest::testBigPipeNoJs()
  2. 8.9.x core/modules/big_pipe/tests/src/Functional/BigPipeTest.php \Drupal\Tests\big_pipe\Functional\BigPipeTest::testBigPipeNoJs()
  3. 10 core/modules/big_pipe/tests/src/Functional/BigPipeTest.php \Drupal\Tests\big_pipe\Functional\BigPipeTest::testBigPipeNoJs()

Tests BigPipe-delivered HTML responses when JavaScript is disabled.

Covers:

See also

\Drupal\big_pipe_test\BigPipePlaceholderTestCases

File

core/modules/big_pipe/tests/src/Functional/BigPipeTest.php, line 242

Class

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

Namespace

Drupal\Tests\big_pipe\Functional

Code

public function testBigPipeNoJs() : void {
    // Simulate production.
    $this->config('system.logging')
        ->set('error_level', ERROR_REPORTING_HIDE)
        ->save();
    $this->drupalLogin($this->rootUser);
    $this->assertSessionCookieExists('1');
    $this->assertBigPipeNoJsCookieExists('0');
    // By calling performMetaRefresh() here, we simulate JavaScript being
    // disabled, because as far as the BigPipe module is concerned, it is
    // enabled in the browser when the BigPipe no-JS cookie is set.
    // @see setUp()
    // @see performMetaRefresh()
    $this->performMetaRefresh();
    $this->assertBigPipeNoJsCookieExists('1');
    $this->drupalGet(Url::fromRoute('big_pipe_test'));
    $this->assertBigPipeResponseHeadersPresent();
    $this->assertSession()
        ->responseHeaderNotContains('X-Drupal-Cache-Tags', 'cache_tag_set_in_lazy_builder');
    $this->setCsrfTokenSeedInTestEnvironment();
    $cases = $this->getTestCases();
    $this->assertBigPipeNoJsPlaceholders([
        $cases['edge_case__invalid_html']->bigPipeNoJsPlaceholder => $cases['edge_case__invalid_html']->embeddedHtmlResponse,
        $cases['html_attribute_value']->bigPipeNoJsPlaceholder => $cases['html_attribute_value']->embeddedHtmlResponse,
        $cases['html_attribute_value_subset']->bigPipeNoJsPlaceholder => $cases['html_attribute_value_subset']->embeddedHtmlResponse,
        $cases['html']->bigPipeNoJsPlaceholder => $cases['html']->embeddedHtmlResponse,
        $cases['edge_case__html_non_lazy_builder']->bigPipeNoJsPlaceholder => $cases['edge_case__html_non_lazy_builder']->embeddedHtmlResponse,
        $cases['exception__lazy_builder']->bigPipePlaceholderId => NULL,
        $cases['exception__embedded_response']->bigPipePlaceholderId => NULL,
    ]);
    // Verifying there are no BigPipe placeholders & replacements.
    $this->assertSession()
        ->responseHeaderEquals('BigPipe-Test-Placeholders', '<none>');
    // Verifying BigPipe start/stop signals are absent.
    $this->assertSession()
        ->responseNotContains(BigPipe::START_SIGNAL);
    $this->assertSession()
        ->responseNotContains(BigPipe::STOP_SIGNAL);
    // Verifying BigPipe assets are absent.
    $this->assertArrayNotHasKey('bigPipePlaceholderIds', $this->getDrupalSettings());
    $this->assertArrayNotHasKey('ajaxPageState', $this->getDrupalSettings());
    $this->assertSession()
        ->responseContains('</body>');
    // Verify that 4xx responses work fine. (4xx responses are handled by
    // subrequests to a route pointing to a controller with the desired output.)
    $this->drupalGet(Url::fromUri('base:non-existing-path'));
    // Simulate development.
    // Verifying BigPipe provides useful error output when an error occurs
    // while rendering a placeholder if verbose error logging is enabled.
    $this->config('system.logging')
        ->set('error_level', ERROR_REPORTING_DISPLAY_VERBOSE)
        ->save();
    $this->drupalGet(Url::fromRoute('big_pipe_test'));
    // The 'edge_case__html_exception' case throws an exception.
    $this->assertSession()
        ->pageTextContains('The website encountered an unexpected error. Try again later');
    $this->assertSession()
        ->pageTextContains('You are not allowed to say llamas are not cool!');
    $this->assertSession()
        ->responseNotContains('</body>');
    // The exception is expected. Do not interpret it as a test failure.
    unlink($this->root . '/' . $this->siteDirectory . '/error.log');
}

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