You are here

public function BigPipeRegressionTest::testMultipleClosingBodies_2678662 in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php \Drupal\Tests\big_pipe\FunctionalJavascript\BigPipeRegressionTest::testMultipleClosingBodies_2678662()
  2. 9 core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php \Drupal\Tests\big_pipe\FunctionalJavascript\BigPipeRegressionTest::testMultipleClosingBodies_2678662()

Ensure BigPipe works despite inline JS containing the string "</body>".

See also

https://www.drupal.org/node/2678662

File

core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php, line 46

Class

BigPipeRegressionTest
BigPipe regression tests.

Namespace

Drupal\Tests\big_pipe\FunctionalJavascript

Code

public function testMultipleClosingBodies_2678662() {
  $this
    ->assertTrue($this->container
    ->get('module_installer')
    ->install([
    'render_placeholder_message_test',
  ], TRUE), 'Installed modules.');
  $this
    ->drupalLogin($this
    ->drupalCreateUser());
  $this
    ->drupalGet(Url::fromRoute('big_pipe_regression_test.2678662'));

  // Confirm that AJAX behaviors were instantiated, if not, this points to a
  // JavaScript syntax error.
  $javascript = <<<JS
    (function(){
      return Object.keys(Drupal.ajax.instances).length > 0;
    }())
JS;
  $this
    ->assertJsCondition($javascript);

  // Besides verifying there is no JavaScript syntax error, also verify the
  // HTML structure.
  // The BigPipe stop signal is present just before the closing </body> and
  // </html> tags.
  $this
    ->assertSession()
    ->responseContains(BigPipe::STOP_SIGNAL . "\n\n\n</body></html>");
  $js_code_until_closing_body_tag = substr(BigPipeRegressionTestController::MARKER_2678662, 0, strpos(BigPipeRegressionTestController::MARKER_2678662, '</body>'));

  // The BigPipe start signal does NOT start at the closing </body> tag string
  // in an inline script.
  $this
    ->assertSession()
    ->responseNotContains($js_code_until_closing_body_tag . "\n" . BigPipe::START_SIGNAL);
}