From 1ee7c087d69eb814221a7bfa10113b385c3c5558 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Thu, 10 Oct 2024 15:00:26 -0700 Subject: [PATCH] more tests --- .../src/Plugin/Filter/SuCleanHtml.php | 2 +- .../Unit/Plugin/Filter/SuCleanHtmlTest.php | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) 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); } }