class FilterHtmlTest
Same name and namespace in other branches
- 11.x core/modules/filter/tests/src/Unit/FilterHtmlTest.php \Drupal\Tests\filter\Unit\FilterHtmlTest
- 10 core/modules/filter/tests/src/Unit/FilterHtmlTest.php \Drupal\Tests\filter\Unit\FilterHtmlTest
- 9 core/modules/filter/tests/src/Unit/FilterHtmlTest.php \Drupal\Tests\filter\Unit\FilterHtmlTest
- 9 core/modules/filter/tests/src/FunctionalJavascript/FilterHtmlTest.php \Drupal\Tests\filter\FunctionalJavascript\FilterHtmlTest
- 8.9.x core/modules/filter/tests/src/Unit/FilterHtmlTest.php \Drupal\Tests\filter\Unit\FilterHtmlTest
Tests Drupal\filter\Plugin\Filter\FilterHtml.
Attributes
#[CoversClass(FilterHtml::class)]
#[Group('filter')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\filter\Unit\FilterHtmlTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of FilterHtmlTest
File
-
core/
modules/ filter/ tests/ src/ Unit/ FilterHtmlTest.php, line 16
Namespace
Drupal\Tests\filter\UnitView source
class FilterHtmlTest extends UnitTestCase {
/**
* The filter to test.
*
* @var \Drupal\filter\Plugin\Filter\FilterHtml
*/
protected $filter;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$configuration['settings'] = [
'allowed_html' => '<a href> <p> <em> <strong> <cite> <blockquote> <code class="pretty boring align-*"> <ul alpaca-*="wooly-* strong"> <ol llama-*> <li> <dl> <dt> <dd> <br> <h3 id>',
'filter_html_help' => 1,
'filter_html_nofollow' => 0,
];
$this->filter = new FilterHtml($configuration, 'filter_html', [
'provider' => 'test',
]);
$this->filter
->setStringTranslation($this->getStringTranslationStub());
}
/**
* Tests filter attributes.
*
* @param string $html
* Input HTML.
* @param string $expected
* The expected output string.
*/
public function testFilterAttributes(string $html, string $expected) : void {
$this->assertSame($expected, $this->filter
->filterAttributes($html));
}
/**
* Provides data for testFilterAttributes.
*
* @return array
* An array of test data.
*/
public static function providerFilterAttributes() : array {
return [
[
'<a href="/blog" title="Blog">Blog</a>',
'<a href="/blog">Blog</a>',
],
[
'<p dir="rtl" />',
'<p dir="rtl"></p>',
],
[
'<p dir="bogus" />',
'<p></p>',
],
[
'<p id="first" />',
'<p></p>',
],
[
'<p id="first" lang="en">text</p>',
'<p lang="en">text</p>',
],
[
'<p style="display: none;" />',
'<p></p>',
],
[
'<code class="pretty invalid">foreach ($a as $b) {}</code>',
'<code class="pretty">foreach ($a as $b) {}</code>',
],
[
'<code class="boring pretty">foreach ($a as $b) {}</code>',
'<code class="boring pretty">foreach ($a as $b) {}</code>',
],
[
'<code class="boring pretty ">foreach ($a as $b) {}</code>',
'<code class="boring pretty">foreach ($a as $b) {}</code>',
],
[
'<code class="invalid alpaca">foreach ($a as $b) {}</code>',
'<code>foreach ($a as $b) {}</code>',
],
[
'<h3 class="big">a heading</h3>',
'<h3>a heading</h3>',
],
[
'<h3 id="first">a heading</h3>',
'<h3 id="first">a heading</h3>',
],
// Wildcard value. Case matters, so upper case doesn't match.
[
'<code class="align-left bold">foreach ($a as $b) {}</code>',
'<code class="align-left">foreach ($a as $b) {}</code>',
],
[
'<code class="align-right ">foreach ($a as $b) {}</code>',
'<code class="align-right">foreach ($a as $b) {}</code>',
],
[
'<code class="Align-right ">foreach ($a as $b) {}</code>',
'<code>foreach ($a as $b) {}</code>',
],
// Wildcard name, case is ignored.
[
'<ol style="display: none;" llama-wim="noble majestic"></ol>',
'<ol llama-wim="noble majestic"></ol>',
],
[
'<ol style="display: none;" LlamA-Wim="majestic"></ol>',
'<ol llama-wim="majestic"></ol>',
],
[
'<ol style="display: none;" llama-="noble majestic"></ol>',
'<ol llama-="noble majestic"></ol>',
],
// Both wildcard names and values.
[
'<ul style="display: none;" alpaca-wool="wooly-warm strong majestic"></ul>',
'<ul alpaca-wool="wooly-warm strong"></ul>',
],
];
}
/**
* Tests set configuration.
*/
public function testSetConfiguration() : void {
$configuration['settings'] = [
// New lines and spaces are replaced with a single space.
'allowed_html' => "<a> <br>\r\n <p>",
'filter_html_help' => 1,
'filter_html_nofollow' => 0,
];
$filter = new FilterHtml($configuration, 'filter_html', [
'provider' => 'test',
]);
$this->assertSame('<a> <br> <p>', $filter->getConfiguration()['settings']['allowed_html']);
}
}
Members
| Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
|---|---|---|---|---|---|---|
| DrupalTestCaseTrait::$root | protected | property | The Drupal root directory. | |||
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | 1 | ||
| DrupalTestCaseTrait::getDrupalRoot | Deprecated | protected static | function | Returns the Drupal root directory. | 1 | |
| DrupalTestCaseTrait::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |||
| DrupalTestCaseTrait::setUpRoot | final protected | function | Ensure that the $root property is set initially. | |||
| FilterHtmlTest::$filter | protected | property | The filter to test. | |||
| FilterHtmlTest::providerFilterAttributes | public static | function | Provides data for testFilterAttributes. | |||
| FilterHtmlTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
| FilterHtmlTest::testFilterAttributes | public | function | Tests filter attributes. | |||
| FilterHtmlTest::testSetConfiguration | public | function | Tests set configuration. | |||
| 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::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::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::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.