View source
<?php
namespace Drupal\Tests\nbsp\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\filter\FilterPluginCollection;
use Drupal\filter\FilterProcessResult;
class NbspCleanerFilterTest extends KernelTestBase {
public static $modules = [
'system',
'filter',
'nbsp',
];
protected $filters;
protected function setUp() {
parent::setUp();
$this
->installConfig([
'system',
]);
$manager = $this->container
->get('plugin.manager.filter');
$bag = new FilterPluginCollection($manager, []);
$this->filters = $bag
->getAll();
}
public function testCleanerFilter($input, $expected) {
$filter = $this->filters['nbsp_cleaner_filter'];
$result = $filter
->process($input, 'und');
$this
->assertInstanceOf(FilterProcessResult::class, $result);
$this
->assertEquals($expected, $result
->getProcessedText());
}
public function providerTexts() {
return [
[
'',
'',
],
[
'<p>Maecenas cursus posuere</p>',
'<p>Maecenas cursus posuere</p>',
],
[
'<p>Maecenas<span class="nbsp"> </span>cursus posuere</p>',
'<p>Maecenas cursus posuere</p>',
],
[
'<p>Maecenas<span class="nbsp"> </span>cursus<span class="nbsp"> </span>posuere</p>',
'<p>Maecenas cursus posuere</p>',
],
[
'<p>Maecenas<div class="nbsp"> </div>cursus posuere</p>',
'<p>Maecenas</p><div class="nbsp"> </div>cursus posuere',
],
[
'<p>Maecenas<span> </span>cursus posuere</p>',
'<p>Maecenas<span> </span>cursus posuere</p>',
],
];
}
}