You are here

public function BigPipeTest::testBigPipeMultiOccurrencePlaceholders in Drupal 9

Same name and namespace in other branches
  1. 8 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 297

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
    ->assertSession()
    ->pageTextContains('The count is 1.');
  $this
    ->assertSession()
    ->responseNotContains('The count is 2.');
  $this
    ->assertSession()
    ->responseNotContains('The count is 3.');
  $raw_content = $this
    ->getSession()
    ->getPage()
    ->getContent();
  $this
    ->assertSame(1, substr_count($raw_content, $expected_placeholder_replacement), '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
    ->assertSession()
    ->pageTextContains('The count is 1.');
  $this
    ->assertSession()
    ->responseNotContains('The count is 2.');
  $this
    ->assertSession()
    ->responseNotContains('The count is 3.');
}