function BigPipeTest::testBigPipeMultiOccurrencePlaceholders

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

Tests BigPipe with a multi-occurrence placeholder.

File

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

Class

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

Namespace

Drupal\Tests\big_pipe\Functional

Code

public function testBigPipeMultiOccurrencePlaceholders() {
    $this->drupalLogin($this->rootUser);
    $this->assertSessionCookieExists(TRUE);
    $this->assertBigPipeNoJsCookieExists(FALSE);
    // By not calling performMetaRefresh() here, we simulate JavaScript being
    // enabled, because as far as the BigPipe module is concerned, JavaScript is
    // enabled in the browser as long as the BigPipe no-JS cookie is *not* set.
    // @see setUp()
    // @see performMetaRefresh()
    $this->drupalGet(Url::fromRoute('big_pipe_test_multi_occurrence'));
    $big_pipe_placeholder_id = 'callback=Drupal%5CCore%5CRender%5CElement%5CStatusMessages%3A%3ArenderMessages&args%5B0%5D&token=_HAdUpwWmet0TOTe2PSiJuMntExoshbm1kh2wQzzzAA';
    $expected_placeholder_replacement = '<script type="application/vnd.drupal-ajax" data-big-pipe-replacement-for-placeholder-with-id="' . $big_pipe_placeholder_id . '">';
    $this->assertRaw('The count is 1.');
    $this->assertNoRaw('The count is 2.');
    $this->assertNoRaw('The count is 3.');
    $raw_content = $this->getSession()
        ->getPage()
        ->getContent();
    $this->assertTrue(substr_count($raw_content, $expected_placeholder_replacement) == 1, 'Only one placeholder replacement was found for the duplicate #lazy_builder arrays.');
    // 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(TRUE);
    $this->drupalGet(Url::fromRoute('big_pipe_test_multi_occurrence'));
    $this->assertRaw('The count is 1.');
    $this->assertNoRaw('The count is 2.');
    $this->assertNoRaw('The count is 3.');
}

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