FieldFilteredMarkupTest.php in Drupal 10
File
core/tests/Drupal/Tests/Core/Field/FieldFilteredMarkupTest.php
View source
<?php
namespace Drupal\Tests\Core\Field;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Component\Render\MarkupInterface;
class FieldFilteredMarkupTest extends UnitTestCase {
public function testCreate($string, $expected, $instance_of_check) {
$filtered_string = FieldFilteredMarkup::create($string);
if ($instance_of_check) {
$this
->assertInstanceOf(FieldFilteredMarkup::class, $filtered_string);
}
$this
->assertSame($expected, (string) $filtered_string);
}
public function providerTestCreate() {
$data = [];
$data[] = [
'',
'',
FALSE,
];
$data[] = [
'<script>teststring</script>',
'teststring',
TRUE,
];
$data[] = [
'<em>teststring</em>',
'<em>teststring</em>',
TRUE,
];
$data[] = [
'<em>teststring',
'<em>teststring</em>',
TRUE,
];
$safe_string = $this
->prophesize(MarkupInterface::class);
$safe_string
->__toString()
->willReturn('<script>teststring</script>');
$data[] = [
$safe_string
->reveal(),
'teststring',
TRUE,
];
return $data;
}
public function testdisplayAllowedTags() {
$expected = '<a> <b> <big> <code> <del> <em> <i> <ins> <pre> <q> <small> <span> <strong> <sub> <sup> <tt> <ol> <ul> <li> <p> <br> <img>';
$this
->assertSame($expected, FieldFilteredMarkup::displayAllowedTags());
}
}