class FieldFilteredMarkupTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Field/FieldFilteredMarkupTest.php \Drupal\Tests\Core\Field\FieldFilteredMarkupTest
- 8.9.x core/tests/Drupal/Tests/Core/Field/FieldFilteredMarkupTest.php \Drupal\Tests\Core\Field\FieldFilteredMarkupTest
- 10 core/tests/Drupal/Tests/Core/Field/FieldFilteredMarkupTest.php \Drupal\Tests\Core\Field\FieldFilteredMarkupTest
@coversDefaultClass \Drupal\Core\Field\FieldFilteredMarkup @group Field
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Field\FieldFilteredMarkupTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of FieldFilteredMarkupTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Field/ FieldFilteredMarkupTest.php, line 16
Namespace
Drupal\Tests\Core\FieldView source
class FieldFilteredMarkupTest extends UnitTestCase {
/**
* @covers ::create
* @dataProvider providerTestCreate
*/
public function testCreate($string, $expected, $instance_of_check) : void {
$filtered_string = FieldFilteredMarkup::create($string);
if ($instance_of_check) {
$this->assertInstanceOf(FieldFilteredMarkup::class, $filtered_string);
}
$this->assertSame($expected, (string) $filtered_string);
}
/**
* Provides data for testCreate().
*/
public static function providerTestCreate() {
$data = [];
$data[] = [
'',
'',
FALSE,
];
// Certain tags are filtered.
$data[] = [
'<script>test string</script>',
'test string',
TRUE,
];
// Certain tags are not filtered.
$data[] = [
'<em>test string</em>',
'<em>test string</em>',
TRUE,
];
// HTML will be normalized.
$data[] = [
'<em>test string',
'<em>test string</em>',
TRUE,
];
// Even safe strings will be escaped.
$safe_string = (new Prophet())->prophesize(MarkupInterface::class);
$safe_string->__toString()
->willReturn('<script>test string</script>');
$data[] = [
$safe_string->reveal(),
'test string',
TRUE,
];
return $data;
}
/**
* @covers ::displayAllowedTags
*/
public function testDisplayAllowedTags() : void {
$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());
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
FieldFilteredMarkupTest::providerTestCreate | public static | function | Provides data for testCreate(). | |
FieldFilteredMarkupTest::testCreate | public | function | @covers ::create @dataProvider providerTestCreate |
|
FieldFilteredMarkupTest::testDisplayAllowedTags | public | function | @covers ::displayAllowedTags | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUp | protected | function | 358 | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.