From e64bfdb394e05430dab72db0edf10d2b371bca3f Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 16 Nov 2022 15:39:13 +1300 Subject: [PATCH] API Stop using deprecated API --- _config.php | 5 ++- code/Controllers/CMSMain.php | 3 +- code/Controllers/CMSPageHistoryController.php | 6 ++-- code/Controllers/SilverStripeNavigator.php | 2 +- .../SiteTreeFileFormFactoryExtension.php | 4 +-- composer.json | 1 + templates/BreadcrumbsTemplate.ss | 2 +- tests/php/Controllers/CMSBatchActionsTest.php | 2 +- tests/php/Controllers/CMSMainTest.php | 4 +++ .../CMSPageHistoryControllerTest.php | 34 ++++++++++++++----- tests/php/Model/RedirectorPageTest.php | 2 +- tests/php/Model/SiteTreeTest.php | 22 +++++++----- tests/php/Model/VirtualPageTest.php | 4 +-- ...archFormTest.php => ZZZSearchFormTest.php} | 2 +- ...archFormTest.yml => ZZZSearchFormTest.yml} | 0 .../Tasks/MigrateSiteTreeLinkingTaskTest.php | 2 -- 16 files changed, 62 insertions(+), 33 deletions(-) rename tests/php/Search/{SearchFormTest.php => ZZZSearchFormTest.php} (99%) rename tests/php/Search/{SearchFormTest.yml => ZZZSearchFormTest.yml} (100%) diff --git a/_config.php b/_config.php index 50511c6e..d19bd89d 100644 --- a/_config.php +++ b/_config.php @@ -37,5 +37,8 @@ ShortcodeParser::get('default')->register( CMSMenu::remove_menu_class(CMSMain::class); CMSMenu::remove_menu_class(CMSPageEditController::class); CMSMenu::remove_menu_class(CMSPageSettingsController::class); -CMSMenu::remove_menu_class(CMSPageHistoryController::class); +if (class_exists(CMSPageHistoryController::class)) { + // this class will be removed in CMS 5 + CMSMenu::remove_menu_class(CMSPageHistoryController::class); +} CMSMenu::remove_menu_class(CMSPageAddController::class); diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 424e9eb1..2107c61c 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -72,6 +72,7 @@ use SilverStripe\Versioned\Versioned; use SilverStripe\View\ArrayData; use SilverStripe\View\Requirements; use Translatable; +use SilverStripe\VersionedAdmin\Controllers\CMSPageHistoryViewerController; /** * The main "content" area of the CMS. @@ -411,7 +412,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr { if ($id = $this->currentPageID()) { return $this->LinkWithSearch( - Controller::join_links(CMSPageHistoryController::singleton()->Link('show'), $id) + Controller::join_links(CMSPageHistoryViewerController::singleton()->Link('show'), $id) ); } else { return null; diff --git a/code/Controllers/CMSPageHistoryController.php b/code/Controllers/CMSPageHistoryController.php index 7ffcc88d..0520ecdb 100644 --- a/code/Controllers/CMSPageHistoryController.php +++ b/code/Controllers/CMSPageHistoryController.php @@ -63,7 +63,9 @@ class CMSPageHistoryController extends CMSMain public function __construct() { parent::__construct(); - Deprecation::notice('4.3.0', 'Use silverstripe/versioned-admin instead', Deprecation::SCOPE_CLASS); + Deprecation::withNoReplacement(function () { + Deprecation::notice('4.3.0', 'Use silverstripe/versioned-admin instead', Deprecation::SCOPE_CLASS); + }); } public function getResponseNegotiator() @@ -308,7 +310,7 @@ class CMSPageHistoryController extends CMSMain $compareModeChecked = ($action == "compare"); if ($page) { - $versions = $page->allVersions(); + $versions = $page->Versions(); $versionID = (!$versionID) ? $page->Version : $versionID; if ($versions) { diff --git a/code/Controllers/SilverStripeNavigator.php b/code/Controllers/SilverStripeNavigator.php index dce05372..9373efdd 100644 --- a/code/Controllers/SilverStripeNavigator.php +++ b/code/Controllers/SilverStripeNavigator.php @@ -66,7 +66,7 @@ class SilverStripeNavigator extends ViewableData } ksort($items); - // Drop the keys and let the ArrayList handle the numbering, so $First, $Last and others work properly. + // Drop the keys and let the ArrayList handle the numbering, so $IsFirst, $IsLast and others work properly. return new ArrayList(array_values($items ?? [])); } diff --git a/code/Model/SiteTreeFileFormFactoryExtension.php b/code/Model/SiteTreeFileFormFactoryExtension.php index e20c95ec..59773030 100644 --- a/code/Model/SiteTreeFileFormFactoryExtension.php +++ b/code/Model/SiteTreeFileFormFactoryExtension.php @@ -18,12 +18,10 @@ use SilverStripe\Versioned\RecursivePublishable; * Uses tracking provided by {@see SiteTreeFileExtension} to generate this. * * @property File $owner + * @deprecated 4.12.0 Use UsedOnTable instead */ class SiteTreeFileFormFactoryExtension extends DataExtension { - /** - * @deprecated 4.12.0 Use UsedOnTable instead - */ public function __construct() { Deprecation::notice('4.12.0', 'Use UsedOnTable instead', Deprecation::SCOPE_CLASS); diff --git a/composer.json b/composer.json index e3186a66..278ea854 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "silverstripe/reports": "^4.7@dev", "silverstripe/siteconfig": "^4.7@dev", "silverstripe/versioned": "^1.7@dev", + "silverstripe/versioned-admin": "^1.7@dev", "silverstripe/vendor-plugin": "^1.0", "php": "^7.4 || ^8.0" }, diff --git a/templates/BreadcrumbsTemplate.ss b/templates/BreadcrumbsTemplate.ss index a2ccd5a9..912382aa 100755 --- a/templates/BreadcrumbsTemplate.ss +++ b/templates/BreadcrumbsTemplate.ss @@ -1,4 +1,4 @@ <%-- Loop is all on one line to prevent whitespace bug in older versions of IE --%> <% if $Pages %> - <% loop $Pages %><% if $Last %>$MenuTitle.XML<% else %><% if not Up.Unlinked %><% end_if %>$MenuTitle.XML<% if not Up.Unlinked %><% end_if %> $Up.Delimiter.RAW <% end_if %><% end_loop %> + <% loop $Pages %><% if $IsLast %>$MenuTitle.XML<% else %><% if not Up.Unlinked %><% end_if %>$MenuTitle.XML<% if not Up.Unlinked %><% end_if %> $Up.Delimiter.RAW <% end_if %><% end_loop %> <% end_if %> diff --git a/tests/php/Controllers/CMSBatchActionsTest.php b/tests/php/Controllers/CMSBatchActionsTest.php index 9a079b80..3ec33d56 100644 --- a/tests/php/Controllers/CMSBatchActionsTest.php +++ b/tests/php/Controllers/CMSBatchActionsTest.php @@ -26,7 +26,7 @@ class CMSBatchActionsTest extends SapphireTest $this->logInWithPermission('ADMIN'); // Tests assume strict hierarchy is enabled - Config::inst()->update(SiteTree::class, 'enforce_strict_hierarchy', true); + Config::inst()->set(SiteTree::class, 'enforce_strict_hierarchy', true); // published page $published = $this->objFromFixture(SiteTree::class, 'published'); diff --git a/tests/php/Controllers/CMSMainTest.php b/tests/php/Controllers/CMSMainTest.php index f61158f4..c8a8bfc5 100644 --- a/tests/php/Controllers/CMSMainTest.php +++ b/tests/php/Controllers/CMSMainTest.php @@ -25,6 +25,7 @@ use SilverStripe\Security\Member; use SilverStripe\Security\Security; use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\Versioned\Versioned; +use SilverStripe\Dev\Deprecation; class CMSMainTest extends FunctionalTest { @@ -123,6 +124,9 @@ class CMSMainTest extends FunctionalTest */ public function testPublish() { + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $page1 = $this->objFromFixture(Page::class, "page1"); $page2 = $this->objFromFixture(Page::class, "page2"); $this->logInAs('admin'); diff --git a/tests/php/Controllers/CMSPageHistoryControllerTest.php b/tests/php/Controllers/CMSPageHistoryControllerTest.php index 40d564b5..4100436c 100755 --- a/tests/php/Controllers/CMSPageHistoryControllerTest.php +++ b/tests/php/Controllers/CMSPageHistoryControllerTest.php @@ -12,6 +12,7 @@ use SilverStripe\Forms\FieldGroup; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\HTMLReadonlyField; +use SilverStripe\Dev\Deprecation; use SilverStripe\Forms\TextField; class CMSPageHistoryControllerTest extends FunctionalTest @@ -32,10 +33,12 @@ class CMSPageHistoryControllerTest extends FunctionalTest { parent::setUp(); - Injector::inst()->registerService( - new CMSPageHistoryController(), - CMSPageHistoryController::class - ); + Deprecation::withNoReplacement(function () { + Injector::inst()->registerService( + new CMSPageHistoryController(), + CMSPageHistoryController::class + ); + }); $this->loginWithPermission('ADMIN'); @@ -62,6 +65,9 @@ class CMSPageHistoryControllerTest extends FunctionalTest public function testGetEditForm() { + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $controller = new CMSPageHistoryController(); $controller->setRequest(Controller::curr()->getRequest()); @@ -108,7 +114,10 @@ class CMSPageHistoryControllerTest extends FunctionalTest */ public function testVersionsForm() { - $this->get('admin/pages/legacyhistory/show/'. $this->page->ID); + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } + $this->get('admin/pages/legacyhistory/show/' . $this->page->ID); $form = $this->cssParser()->getBySelector('#Form_VersionsForm'); @@ -127,7 +136,10 @@ class CMSPageHistoryControllerTest extends FunctionalTest public function testVersionsFormTableContainsInformation() { - $this->get('admin/pages/legacyhistory/show/'. $this->page->ID); + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } + $this->get('admin/pages/legacyhistory/show/' . $this->page->ID); $form = $this->cssParser()->getBySelector('#Form_VersionsForm'); $rows = $form[0]->xpath("fieldset/table/tbody/tr"); @@ -153,7 +165,10 @@ class CMSPageHistoryControllerTest extends FunctionalTest public function testVersionsFormSelectsUnpublishedCheckbox() { - $this->get('admin/pages/legacyhistory/show/'. $this->page->ID); + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } + $this->get('admin/pages/legacyhistory/show/' . $this->page->ID); $checkbox = $this->cssParser()->getBySelector('#Form_VersionsForm_ShowUnpublished'); $this->assertThat($checkbox[0], $this->logicalNot($this->isNull())); @@ -162,7 +177,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest $this->assertThat($checked, $this->logicalNot($this->stringContains('checked'))); // viewing an unpublished - $this->get('admin/pages/legacyhistory/show/'.$this->page->ID .'/'.$this->versionUnpublishedCheck); + $this->get('admin/pages/legacyhistory/show/' . $this->page->ID . '/' . $this->versionUnpublishedCheck); $checkbox = $this->cssParser()->getBySelector('#Form_VersionsForm_ShowUnpublished'); $this->assertThat($checkbox[0], $this->logicalNot($this->isNull())); @@ -171,6 +186,9 @@ class CMSPageHistoryControllerTest extends FunctionalTest public function testTransformReadonly() { + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } /** @var CMSPageHistoryController $history */ $history = new CMSPageHistoryController(); $history->setRequest(Controller::curr()->getRequest()); diff --git a/tests/php/Model/RedirectorPageTest.php b/tests/php/Model/RedirectorPageTest.php index b49998c8..fa007731 100644 --- a/tests/php/Model/RedirectorPageTest.php +++ b/tests/php/Model/RedirectorPageTest.php @@ -33,7 +33,7 @@ class RedirectorPageTest extends FunctionalTest $file->publishSingle(); } - Director::config()->update('alternate_base_url', 'http://www.mysite.com/'); + Director::config()->set('alternate_base_url', 'http://www.mysite.com/'); // Ensure all pages are published /** @var Page $page */ diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index 86880f7c..a56740f3 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -39,6 +39,7 @@ use SilverStripe\View\Parsers\URLSegmentFilter; use SilverStripe\View\Shortcodes\EmbedShortcodeProvider; use TractorCow\Fluent\Extension\FluentSiteTreeExtension; use const RESOURCES_DIR; +use SilverStripe\Dev\Deprecation; class SiteTreeTest extends SapphireTest { @@ -430,7 +431,7 @@ class SiteTreeTest extends SapphireTest public function testNoCascadingDeleteWithoutID() { - Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', true); + Config::inst()->set('SiteTree', 'enforce_strict_hierarchy', true); $count = SiteTree::get()->count(); $this->assertNotEmpty($count); $obj = new SiteTree(); @@ -1253,27 +1254,27 @@ class SiteTreeTest extends SapphireTest $classCext->write(); $classB->ParentID = $page->ID; - $valid = $classB->doValidate(); + $valid = $classB->validate(); $this->assertTrue($valid->isValid(), "Does allow children on unrestricted parent"); $classB->ParentID = $classA->ID; - $valid = $classB->doValidate(); + $valid = $classB->validate(); $this->assertTrue($valid->isValid(), "Does allow child specifically allowed by parent"); $classC->ParentID = $classA->ID; - $valid = $classC->doValidate(); + $valid = $classC->validate(); $this->assertFalse($valid->isValid(), "Doesnt allow child on parents specifically restricting children"); $classB->ParentID = $classC->ID; - $valid = $classB->doValidate(); + $valid = $classB->validate(); $this->assertFalse($valid->isValid(), "Doesnt allow child on parents disallowing all children"); $classB->ParentID = $classCext->ID; - $valid = $classB->doValidate(); + $valid = $classB->validate(); $this->assertTrue($valid->isValid(), "Extensions of allowed classes are incorrectly reported as invalid"); $classCext->ParentID = $classD->ID; - $valid = $classCext->doValidate(); + $valid = $classCext->validate(); $this->assertFalse($valid->isValid(), "Doesnt allow child where only parent class is allowed on parent node, and asterisk prefixing is used"); } @@ -1655,7 +1656,7 @@ class SiteTreeTest extends SapphireTest */ public function testGetControllerNameFromConfig() { - Config::inst()->update(Page::class, 'controller_name', 'This\\Is\\A\\New\\Controller'); + Config::inst()->set(Page::class, 'controller_name', 'This\\Is\\A\\New\\Controller'); $class = new Page; $this->assertSame('This\\Is\\A\\New\\Controller', $class->getControllerName()); } @@ -1665,7 +1666,7 @@ class SiteTreeTest extends SapphireTest */ public function testGetControllerNameFromNamespaceMappingConfig() { - Config::inst()->update(SiteTree::class, 'namespace_mapping', [ + Config::inst()->merge(SiteTree::class, 'namespace_mapping', [ 'SilverStripe\\CMS\\Tests\\Page' => 'SilverStripe\\CMS\\Tests\\Controllers', ]); @@ -1678,6 +1679,9 @@ class SiteTreeTest extends SapphireTest */ public function testGetControllerNameWithUnderscoresIsSupported() { + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } $class = new SiteTreeTest_LegacyControllerName; $this->assertEquals(SiteTreeTest_LegacyControllerName_Controller::class, $class->getControllerName()); } diff --git a/tests/php/Model/VirtualPageTest.php b/tests/php/Model/VirtualPageTest.php index b4ee7ba5..39086e31 100644 --- a/tests/php/Model/VirtualPageTest.php +++ b/tests/php/Model/VirtualPageTest.php @@ -412,11 +412,11 @@ class VirtualPageTest extends FunctionalTest $classCVirtual->write(); $classBVirtual->ParentID = $classA->ID; - $valid = $classBVirtual->doValidate(); + $valid = $classBVirtual->validate(); $this->assertTrue($valid->isValid(), "Does allow child linked to virtual page type allowed by parent"); $classCVirtual->ParentID = $classA->ID; - $valid = $classCVirtual->doValidate(); + $valid = $classCVirtual->validate(); $this->assertFalse($valid->isValid(), "Doesn't allow child linked to virtual page type disallowed by parent"); } diff --git a/tests/php/Search/SearchFormTest.php b/tests/php/Search/ZZZSearchFormTest.php similarity index 99% rename from tests/php/Search/SearchFormTest.php rename to tests/php/Search/ZZZSearchFormTest.php index 3f8653ab..e278de4b 100644 --- a/tests/php/Search/SearchFormTest.php +++ b/tests/php/Search/ZZZSearchFormTest.php @@ -30,7 +30,7 @@ use TractorCow\Fluent\Extension\FluentSiteTreeExtension; class ZZZSearchFormTest extends FunctionalTest { - protected static $fixture_file = 'SearchFormTest.yml'; + protected static $fixture_file = 'ZZZSearchFormTest.yml'; protected static $illegal_extensions = [ SiteTree::class => [ diff --git a/tests/php/Search/SearchFormTest.yml b/tests/php/Search/ZZZSearchFormTest.yml similarity index 100% rename from tests/php/Search/SearchFormTest.yml rename to tests/php/Search/ZZZSearchFormTest.yml diff --git a/tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.php b/tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.php index 12f92ccd..2b3fdc75 100644 --- a/tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.php +++ b/tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.php @@ -12,8 +12,6 @@ class MigrateSiteTreeLinkingTaskTest extends SapphireTest { protected static $fixture_file = 'MigrateSiteTreeLinkingTaskTest.yml'; - protected static $use_draft_site = true; - public static function setUpBeforeClass(): void { parent::setUpBeforeClass();