diff --git a/modules/stanford_decoupled/src/Plugin/Filter/SuCleanHtml.php b/modules/stanford_decoupled/src/Plugin/Filter/SuCleanHtml.php index bb760401..c3a60bb3 100644 --- a/modules/stanford_decoupled/src/Plugin/Filter/SuCleanHtml.php +++ b/modules/stanford_decoupled/src/Plugin/Filter/SuCleanHtml.php @@ -74,7 +74,7 @@ public function process($text, $langcode) { } } - return new FilterProcessResult($text); + return new FilterProcessResult(trim($text)); } /** diff --git a/modules/stanford_decoupled/tests/src/Unit/Plugin/Filter/SuCleanHtmlTest.php b/modules/stanford_decoupled/tests/src/Unit/Plugin/Filter/SuCleanHtmlTest.php index 5e8cf339..7f5bea1b 100644 --- a/modules/stanford_decoupled/tests/src/Unit/Plugin/Filter/SuCleanHtmlTest.php +++ b/modules/stanford_decoupled/tests/src/Unit/Plugin/Filter/SuCleanHtmlTest.php @@ -14,10 +14,25 @@ */ class SuCleanHtmlTest extends UnitTestCase { + public function filterDataProvider() { + return [ + [ + "\r\n\n\n
foo
\n\n\n
\r\nbar\r\n\r\nbaz
\r\n", + '
foo
bar baz
', + ], + [ + 'foobar
foobar
foobarfoobarbaz', + 'foobar
foobar
foobarfoobarbaz', + ], + ]; + } + /** * Test the clean html filter. + * + * @dataProvider filterDataProvider */ - public function testFilter() { + public function testFilter($html, $expected) { $config = []; $definition = ['provider' => 'stanford_profile_helper']; @@ -36,9 +51,9 @@ public function testFilter() { $container->set('entity_type.manager', $entity_type_manager); $filter = SuCleanHtml::create($container, $config, 'foo', $definition); - $result = $filter->process("\r\n\n\n
foo
\n\n\n
\r\nbar\r\n\r\nbaz
\r\n", NULL); + $result = $filter->process($html, NULL); - $this->assertEquals('
foo
bar baz
', (string) $result); + $this->assertEquals($expected, (string) $result); } }