You are here

function HtmlEscapedTextTest::providerToString in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Render/HtmlEscapedTextTest.php \Drupal\Tests\Component\Render\HtmlEscapedTextTest::providerToString()

Data provider for testToString().

See also

testToString()

File

core/tests/Drupal/Tests/Component/Render/HtmlEscapedTextTest.php, line 39
Contains \Drupal\Tests\Component\Render\HtmlEscapedTextTest.

Class

HtmlEscapedTextTest
Tests the HtmlEscapedText class.

Namespace

Drupal\Tests\Component\Render

Code

function providerToString() {

  // Checks that invalid multi-byte sequences are escaped.
  $tests[] = array(
    "",
    'Foo�barbaz',
    'Escapes invalid sequence "Foo\\xC0barbaz"',
  );
  $tests[] = array(
    "",
    '�"',
    'Escapes invalid sequence "\\xc2\\""',
  );
  $tests[] = array(
    "Fooÿñ",
    "Fooÿñ",
    'Does not escape valid sequence "Fooÿñ"',
  );

  // Checks that special characters are escaped.
  $script_tag = $this
    ->prophesize(MarkupInterface::class);
  $script_tag
    ->__toString()
    ->willReturn('<script>');
  $script_tag = $script_tag
    ->reveal();
  $tests[] = array(
    $script_tag,
    '&lt;script&gt;',
    'Escapes &lt;script&gt; even inside an object that implements MarkupInterface.',
  );
  $tests[] = array(
    "<script>",
    '&lt;script&gt;',
    'Escapes &lt;script&gt;',
  );
  $tests[] = array(
    '<>&"\'',
    '&lt;&gt;&amp;&quot;&#039;',
    'Escapes reserved HTML characters.',
  );
  $specialchars = $this
    ->prophesize(MarkupInterface::class);
  $specialchars
    ->__toString()
    ->willReturn('<>&"\'');
  $specialchars = $specialchars
    ->reveal();
  $tests[] = array(
    $specialchars,
    '&lt;&gt;&amp;&quot;&#039;',
    'Escapes reserved HTML characters even inside an object that implements MarkupInterface.',
  );
  return $tests;
}