You are here

protected function JSWebAssert::escapeHtml in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php \Drupal\FunctionalJavascriptTests\JSWebAssert::escapeHtml()

Escapes HTML for testing.

Drupal's Html::escape() uses the ENT_QUOTES flag with htmlspecialchars() to escape both single and double quotes. With JavascriptTestBase testing the browser is automatically converting " and ' to double and single quotes respectively therefore we can not escape them when testing for escaped HTML.

Parameters

$raw: The raw string to escape.

Return value

string The string with escaped HTML.

See also

Drupal\Component\Utility\Html::escape()

2 calls to JSWebAssert::escapeHtml()
JSWebAssert::assertEscaped in core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
Passes if the raw text IS found escaped on the loaded page.
JSWebAssert::assertNoEscaped in core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
Passes if the raw text IS NOT found escaped on the loaded page.

File

core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php, line 457

Class

JSWebAssert
Defines a class with methods for asserting presence of elements during tests.

Namespace

Drupal\FunctionalJavascriptTests

Code

protected function escapeHtml($raw) {
  return htmlspecialchars($raw, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
}