Skip to content

Commit

Permalink
Merge pull request #2808 from creative-commoners/pulls/4.12/invalid-e…
Browse files Browse the repository at this point in the history
…xtra-meta

MNT Update unit test to detect invalid HTML
  • Loading branch information
GuySartorelli authored Dec 20, 2022
2 parents 0b6ee12 + 4a5e22c commit b673796
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/php/Model/SiteTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
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
{
Expand Down Expand Up @@ -2023,10 +2025,20 @@ public function testCMSEditLink()
*/
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
Expand Down

0 comments on commit b673796

Please sign in to comment.