class HtmlEscapedTextTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Component/Render/HtmlEscapedTextTest.php \Drupal\Tests\Component\Render\HtmlEscapedTextTest
Tests the HtmlEscapedText class.
@coversDefaultClass \Drupal\Component\Render\HtmlEscapedText @group utility
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Component\Render\HtmlEscapedTextTest
Expanded class hierarchy of HtmlEscapedTextTest
File
- core/
tests/ Drupal/ Tests/ Component/ Render/ HtmlEscapedTextTest.php, line 20 - Contains \Drupal\Tests\Component\Render\HtmlEscapedTextTest.
Namespace
Drupal\Tests\Component\RenderView source
class HtmlEscapedTextTest extends UnitTestCase {
/**
* @covers ::__toString
* @covers ::jsonSerialize
*
* @dataProvider providerToString
*/
public function testToString($text, $expected, $message) {
$escapeable_string = new HtmlEscapedText($text);
$this
->assertEquals($expected, (string) $escapeable_string, $message);
$this
->assertEquals($expected, $escapeable_string
->jsonSerialize());
}
/**
* Data provider for testToString().
*
* @see testToString()
*/
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,
'<script>',
'Escapes <script> even inside an object that implements MarkupInterface.',
);
$tests[] = array(
"<script>",
'<script>',
'Escapes <script>',
);
$tests[] = array(
'<>&"\'',
'<>&"'',
'Escapes reserved HTML characters.',
);
$specialchars = $this
->prophesize(MarkupInterface::class);
$specialchars
->__toString()
->willReturn('<>&"\'');
$specialchars = $specialchars
->reveal();
$tests[] = array(
$specialchars,
'<>&"'',
'Escapes reserved HTML characters even inside an object that implements MarkupInterface.',
);
return $tests;
}
/**
* @covers ::count
*/
public function testCount() {
$string = 'Can I please have a <em>kitten</em>';
$escapeable_string = new HtmlEscapedText($string);
$this
->assertEquals(strlen($string), $escapeable_string
->count());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HtmlEscapedTextTest:: |
function | Data provider for testToString(). | ||
HtmlEscapedTextTest:: |
public | function | @covers ::count | |
HtmlEscapedTextTest:: |
public | function | @covers ::__toString @covers ::jsonSerialize | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 259 |