From 4a5e22cc60d8faeb0a8bdf5ab54906389fb2f3b9 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 20 Dec 2022 14:41:32 +1300 Subject: [PATCH 1/4] 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 71bb02abc2..2f6c305d45 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -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 { @@ -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 From 9811579203df35e40273f4502b5e3e9afa5a1987 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 12 Jan 2023 13:55:37 +1300 Subject: [PATCH 2/4] FIX Behat test --- tests/behat/features/edit-a-page.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/behat/features/edit-a-page.feature b/tests/behat/features/edit-a-page.feature index 1d12d47e43..98e48aee3e 100644 --- a/tests/behat/features/edit-a-page.feature +++ b/tests/behat/features/edit-a-page.feature @@ -54,7 +54,7 @@ Feature: Edit a page Then the rendered HTML should contain "/about-modified-us" # Add metadata - When I click on the "#ui-accordion-Form_EditForm_Metadata-header-0" element + When I click on the ".ui-accordion-header" element And I wait for 1 second And I fill in "Meta Description" with "MyMetaDesc" From 75eae7f2bf89ced8ae0eef0adeb6bda11113cd78 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 17 Jan 2023 12:26:42 +1300 Subject: [PATCH 3/4] API Deprecate legacy tasks --- code/Tasks/MigrateSiteTreeLinkingTask.php | 12 ++++++++++++ code/Tasks/RemoveOrphanedPagesTask.php | 12 ++++++++++++ code/Tasks/SiteTreeMaintenanceTask.php | 13 +++++++++++++ tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.php | 4 ++++ tests/php/Tasks/RemoveOrphanedPagesTaskTest.php | 4 ++++ 5 files changed, 45 insertions(+) diff --git a/code/Tasks/MigrateSiteTreeLinkingTask.php b/code/Tasks/MigrateSiteTreeLinkingTask.php index 0687e5e687..e9acaeacf1 100644 --- a/code/Tasks/MigrateSiteTreeLinkingTask.php +++ b/code/Tasks/MigrateSiteTreeLinkingTask.php @@ -5,6 +5,7 @@ use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\BuildTask; use SilverStripe\Dev\Debug; +use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DB; use SilverStripe\Versioned\Versioned; @@ -12,6 +13,8 @@ /** * Updates legacy SiteTree link tracking into new polymorphic many_many relation. * This should be done for any site upgrading to 4.2.0 + * + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ class MigrateSiteTreeLinkingTask extends BuildTask { @@ -21,6 +24,15 @@ class MigrateSiteTreeLinkingTask extends BuildTask protected $description = 'Updates legacy SiteTree link tracking into new polymorphic many_many relation'; + public function __construct() + { + Deprecation::notice( + '4.13.0', + 'Will be removed without equivalent functionality to replace it', + Deprecation::SCOPE_CLASS + ); + } + public function run($request) { // Ensure legacy table exists diff --git a/code/Tasks/RemoveOrphanedPagesTask.php b/code/Tasks/RemoveOrphanedPagesTask.php index c422e74740..47e4d9f5bc 100644 --- a/code/Tasks/RemoveOrphanedPagesTask.php +++ b/code/Tasks/RemoveOrphanedPagesTask.php @@ -18,6 +18,7 @@ use SilverStripe\Security\Permission; use SilverStripe\Security\Security; use SilverStripe\View\Requirements; +use SilverStripe\Dev\Deprecation; /** * Identify "orphaned" pages which point to a parent @@ -36,6 +37,8 @@ * before and after orphan removal. * * @author Ingo Schommer (@silverstripe.com), SilverStripe Ltd. + * + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ class RemoveOrphanedPagesTask extends Controller { @@ -65,6 +68,15 @@ class RemoveOrphanedPagesTask extends Controller protected $orphanedSearchClass = SiteTree::class; + public function __construct() + { + Deprecation::notice( + '4.13.0', + 'Will be removed without equivalent functionality to replace it', + Deprecation::SCOPE_CLASS + ); + } + protected function init() { parent::init(); diff --git a/code/Tasks/SiteTreeMaintenanceTask.php b/code/Tasks/SiteTreeMaintenanceTask.php index 2a5c54a64c..0977b8dbc8 100644 --- a/code/Tasks/SiteTreeMaintenanceTask.php +++ b/code/Tasks/SiteTreeMaintenanceTask.php @@ -6,13 +6,26 @@ use SilverStripe\Control\Controller; use SilverStripe\ORM\DB; use SilverStripe\ORM\DataObject; +use SilverStripe\Dev\Deprecation; +/** + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it + */ class SiteTreeMaintenanceTask extends Controller { private static $allowed_actions = [ '*' => 'ADMIN' ]; + public function __construct() + { + Deprecation::notice( + '4.13.0', + 'Will be removed without equivalent functionality to replace it', + Deprecation::SCOPE_CLASS + ); + } + public function makelinksunique() { $table = DataObject::singleton(SiteTree::class)->baseTable(); diff --git a/tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.php b/tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.php index 2b3fdc75fe..f7b6f8a043 100644 --- a/tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.php +++ b/tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.php @@ -7,6 +7,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DB; +use SilverStripe\Dev\Deprecation; class MigrateSiteTreeLinkingTaskTest extends SapphireTest { @@ -34,6 +35,9 @@ public static function setUpBeforeClass(): void protected function setUp(): void { + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } parent::setUp(); // Manually bootstrap all Content blocks with soft coded IDs (raw sql to avoid save hooks) diff --git a/tests/php/Tasks/RemoveOrphanedPagesTaskTest.php b/tests/php/Tasks/RemoveOrphanedPagesTaskTest.php index dc3450b655..63108c9dce 100644 --- a/tests/php/Tasks/RemoveOrphanedPagesTaskTest.php +++ b/tests/php/Tasks/RemoveOrphanedPagesTaskTest.php @@ -5,6 +5,7 @@ use SilverStripe\CMS\Tasks\RemoveOrphanedPagesTask; use SilverStripe\Versioned\Versioned; use SilverStripe\Dev\FunctionalTest; +use SilverStripe\Dev\Deprecation; /** *

Fixture tree

@@ -40,6 +41,9 @@ class RemoveOrphanedPagesTaskTest extends FunctionalTest protected function setUp(): void { + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } parent::setUp(); $parent1_published = $this->objFromFixture('Page', 'parent1_published'); From b5a25e49f6f9a18b097ca133136d8829d79274f9 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 26 Jan 2023 15:23:46 +1300 Subject: [PATCH 4/4] MNT Update unit test to work with both HTML4Value and HTML5Value --- tests/php/Model/SiteTreeTest.php | 49 +++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index 9927c95800..007337787e 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -40,6 +40,9 @@ use TractorCow\Fluent\Extension\FluentSiteTreeExtension; use const RESOURCES_DIR; use SilverStripe\Dev\Deprecation; +use SilverStripe\HTML5\HTML5Value; +use SilverStripe\View\Parsers\HTMLValue; +use SilverStripe\View\Parsers\HTML4Value; class SiteTreeTest extends SapphireTest { @@ -2060,12 +2063,50 @@ public function provideSanitiseExtraMeta(): array '', '', 'Multiple attributes are removed' - ], + ] + ]; + } + + /** + * @dataProvider provideSanatiseInvalidExtraMeta + */ + public function testSanatiseInvalidExtraMetaHTML4Value(string $extraMeta, string $expected): void + { + Injector::inst()->registerService(HTML4Value::create(), HTMLValue::class); + $siteTree = new SiteTree(); + $siteTree->ExtraMeta = $extraMeta; + $siteTree->write(); + $this->assertSame( + $expected, + $siteTree->ExtraMeta, + 'Invalid HTML is converted to valid HTML and parsed' + ); + } + + /** + * @dataProvider provideSanatiseInvalidExtraMeta + */ + public function testSanatiseInvalidExtraMetaHTML5Value(string $extraMeta): void + { + // HTML5Value comes from the module silverstripe/html5 + if (!class_exists(HTML5Value::class)) { + $this->markTestSkipped('HTML5Value class does not exist'); + } + Injector::inst()->registerService(HTML5Value::create(), HTMLValue::class); + $this->expectException(ValidationException::class); + $this->expectExceptionMessage('Custom Meta Tags does not contain valid HTML'); + $siteTree = new SiteTree(); + $siteTree->ExtraMeta = $extraMeta; + $siteTree->write(); + } + + public function provideSanatiseInvalidExtraMeta(): array + { + return [ [ '', - 'Invalid HTML is converted to valid HTML and parsed' - ], + '' + ] ]; } }