class HtmlTitleFilterTest in HTML Title 8
@coversDefaultClass \Drupal\html_title\HtmlTitleFilter
@group html_title
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\Render\RendererTestBase
- class \Drupal\Tests\html_title\Unit\HtmlTitleFilterTest
- class \Drupal\Tests\Core\Render\RendererTestBase
Expanded class hierarchy of HtmlTitleFilterTest
File
- tests/
src/ Unit/ HtmlTitleFilterTest.php, line 16
Namespace
Drupal\Tests\html_title\UnitView source
class HtmlTitleFilterTest extends RendererTestBase {
/**
* The availability manager.
*
* @var \Drupal\html_title\HtmlTitleFilter
*/
protected $htmlTitleFilter;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$config_factory = $this
->createMock(ConfigFactoryInterface::class);
$config = $this
->createMock(Config::class);
$config_factory
->method('get')
->willReturn($config);
$config
->method('get')
->willReturn('<br> <sub> <sup>');
$this->htmlTitleFilter = new HtmlTitleFilter($config_factory, $this->renderer);
}
/**
* Tests HtmlTitleFilter::decodeToText().
*
* @param string|array $input
* The input passed to decodeToText().
* @param string $expected
* The expected result from calling the function.
*
* @see HtmlTitleFilter::decodeToText()
*
* @dataProvider providerDecodeToText
*/
public function testDecodeToText($input, string $expected) {
$this
->assertEquals($expected, $this->htmlTitleFilter
->decodeToText($input));
}
/**
* Data provider for testDecodeToText().
*
* @see testDecodeToText()
*/
public function providerDecodeToText() {
return [
[
'test <sup>sup</sup>-tag',
'test <sup>sup</sup>-tag',
],
[
'test <p>p</p>-tag',
'test p-tag',
],
[
'test &',
'test &',
],
[
'test without tags',
'test without tags',
],
[
'test <br> br-tag',
'test <br> br-tag',
],
[
'test <sub>sub</sub>-tag',
'test <sub>sub</sub>-tag',
],
[
'test multiple tags: <sup>sup</sup>-tag, <sub>sub</sub>-tag and <br> br-tag',
'test multiple tags: <sup>sup</sup>-tag, <sub>sub</sub>-tag and <br> br-tag',
],
[
'test multiple tags: <sup>sup</sup>-tag, <sub>sub</sub>-tag and <br> br-tag <p>p</p>-tag',
'test multiple tags: <sup>sup</sup>-tag, <sub>sub</sub>-tag and <br> br-tag p-tag',
],
// The html title filter service should also works with renderable arrays.
[
[
'#markup' => '<p>Test renderable <sub>array</sub></p>',
],
'Test renderable <sub>array</sub>',
],
];
}
/**
* Tests HtmlTitleFilter::decodeToText().
*
* @param string|array $input
* The input passed to decodeToText().
* @param \Drupal\Core\Render\Markup $expected
* The expected result from calling the function.
*
* @see HtmlTitleFilter::decodeToMarkup()
*
* @dataProvider providerDecodeToMarkup
*/
public function testDecodeToMarkup($input, Markup $expected) {
$this
->assertEquals($expected, $this->htmlTitleFilter
->decodeToMarkup($input));
}
/**
* Data provider for testDecodeToText().
*
* @see testDecodeToMarkup()
*/
public function providerDecodeToMarkup() {
return [
[
'test <sup>sup</sup>-tag',
Markup::create('test <sup>sup</sup>-tag'),
],
[
'test <p>p</p>-tag',
Markup::create('test p-tag'),
],
[
'test &',
Markup::create('test &'),
],
[
'test without tags',
Markup::create('test without tags'),
],
[
'test <br> br-tag',
Markup::create('test <br> br-tag'),
],
[
'test <sub>sub</sub>-tag',
Markup::create('test <sub>sub</sub>-tag'),
],
[
'test multiple tags: <sup>sup</sup>-tag, <sub>sub</sub>-tag and <br> br-tag',
Markup::create('test multiple tags: <sup>sup</sup>-tag, <sub>sub</sub>-tag and <br> br-tag'),
],
[
'test multiple tags: <sup>sup</sup>-tag, <sub>sub</sub>-tag, <br> br-tag and <p>p</p>-tag',
Markup::create('test multiple tags: <sup>sup</sup>-tag, <sub>sub</sub>-tag, <br> br-tag and p-tag'),
],
// The html title filter service should also works with renderable arrays.
[
[
'#markup' => '<p>Test renderable <sub>array</sub></p>',
],
Markup::create('Test renderable <sub>array</sub>'),
],
];
}
/**
* Tests HtmlTitleFilter::getAllowHtmlTags().
*
* @see HtmlTitleFilter::getAllowHtmlTags()
*/
public function testGetAllowedHtmlTags() {
$this
->assertEquals([
'br',
'sub',
'sup',
], $this->htmlTitleFilter
->getAllowHtmlTags());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HtmlTitleFilterTest:: |
protected | property | The availability manager. | |
HtmlTitleFilterTest:: |
public | function | Data provider for testDecodeToText(). | |
HtmlTitleFilterTest:: |
public | function | Data provider for testDecodeToText(). | |
HtmlTitleFilterTest:: |
protected | function |
Overrides RendererTestBase:: |
|
HtmlTitleFilterTest:: |
public | function | Tests HtmlTitleFilter::decodeToText(). | |
HtmlTitleFilterTest:: |
public | function | Tests HtmlTitleFilter::decodeToText(). | |
HtmlTitleFilterTest:: |
public | function | Tests HtmlTitleFilter::getAllowHtmlTags(). | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | The mocked controller resolver. | |
RendererTestBase:: |
protected | property | The simulated "current" user role, for use in tests with cache contexts. | |
RendererTestBase:: |
protected | property | The mocked element info. | |
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | The tested placeholder generator. | 1 |
RendererTestBase:: |
protected | property | The tested render cache. | |
RendererTestBase:: |
protected | property | The tested renderer. | |
RendererTestBase:: |
protected | property | The mocked renderer configuration. | |
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | The mocked theme manager. | |
RendererTestBase:: |
protected | function | Asserts a render cache item. | |
RendererTestBase:: |
protected | function | Generates a random context value for the placeholder tests. | |
RendererTestBase:: |
protected | function | Sets up a memory-based render cache back-end. | |
RendererTestBase:: |
protected | function | Sets up a request object on the request stack. | |
RendererTestBase:: |
protected | function | Sets up a render cache back-end that is asserted to be never used. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed 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. |