function AjaxPageStateTest::testInvalidLibraryNameDoesNotInjectHtml

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/src/Functional/Render/AjaxPageStateTest.php \Drupal\Tests\system\Functional\Render\AjaxPageStateTest::testInvalidLibraryNameDoesNotInjectHtml()

Tests that an invalid library name does not inject HTML.

File

core/modules/system/tests/src/Functional/Render/AjaxPageStateTest.php, line 126

Class

AjaxPageStateTest
Performs tests for the effects of the ajax_page_state query parameter.

Namespace

Drupal\Tests\system\Functional\Render

Code

public function testInvalidLibraryNameDoesNotInjectHtml() : void {
  // Display all errors and warnings.
  $this->config('system.logging')
    ->set('error_level', ERROR_REPORTING_DISPLAY_ALL)
    ->save();
  // A value without an extension/name separator is discarded before it can
  // reach the asset system, where the raw value would be embedded in an
  // error message.
  $this->drupalGet('node', [
    'query' => [
      'ajax_page_state' => [
        'libraries' => UrlHelper::compressQueryParameter('<b>foo'),
      ],
    ],
  ]);
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertSession()
    ->responseNotContains('<b>foo');
  // A value with a separator but an unknown library name is resolved as
  // extension "core" and library "<b>foo", which does not exist and is
  // silently ignored, so it cannot generate error output either.
  $this->drupalGet('node', [
    'query' => [
      'ajax_page_state' => [
        'libraries' => UrlHelper::compressQueryParameter('core/<b>foo'),
      ],
    ],
  ]);
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertSession()
    ->responseNotContains('<b>foo');
}

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