From 4a5e22cc60d8faeb0a8bdf5ab54906389fb2f3b9 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 20 Dec 2022 14:41:32 +1300 Subject: [PATCH] MNT Update unit test to handle HTML5Value --- tests/php/Model/SiteTreeTest.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index 71bb02ab..2f6c305d 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -39,6 +39,8 @@ use SilverStripe\View\Parsers\URLSegmentFilter; use SilverStripe\View\Shortcodes\EmbedShortcodeProvider; use TractorCow\Fluent\Extension\FluentSiteTreeExtension; use const RESOURCES_DIR; +use SilverStripe\View\Parsers\HTMLValue; +use SilverStripe\HTML5\HTML5Value; class SiteTreeTest extends SapphireTest { @@ -2023,10 +2025,20 @@ class SiteTreeTest extends SapphireTest */ public function testSanitiseExtraMeta(string $extraMeta, string $expected, string $message): void { + // If using HTML5Value then the 'somethingdodgy' test won't be converted to valid html + // However if using the default HTMLValue, then it will be converted to valid html + $isDodgyAndUsingHTML5 = strpos($expected, 'somethingdodgy') !== false && + (HTMLValue::create() instanceof HTML5Value); + if ($isDodgyAndUsingHTML5) { + $this->expectException(ValidationException::class); + $this->expectExceptionMessage('Custom Meta Tags does not contain valid HTML'); + } $siteTree = new SiteTree(); $siteTree->ExtraMeta = $extraMeta; $siteTree->write(); - $this->assertSame($expected, $siteTree->ExtraMeta, $message); + if (!$isDodgyAndUsingHTML5) { + $this->assertSame($expected, $siteTree->ExtraMeta, $message); + } } public function provideSanitiseExtraMeta(): array