Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Stop using deprecated API #2794

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
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);
3 changes: 2 additions & 1 deletion code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
use Translatable;
use SilverStripe\VersionedAdmin\Controllers\CMSPageHistoryViewerController;

/**
* The main "content" area of the CMS.
Expand Down Expand Up @@ -411,7 +412,7 @@ public function LinkPageHistory()
{
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;
Expand Down
6 changes: 4 additions & 2 deletions code/Controllers/CMSPageHistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -308,7 +310,7 @@ public function VersionsForm()
$compareModeChecked = ($action == "compare");

if ($page) {
$versions = $page->allVersions();
$versions = $page->Versions();
$versionID = (!$versionID) ? $page->Version : $versionID;

if ($versions) {
Expand Down
2 changes: 1 addition & 1 deletion code/Controllers/SilverStripeNavigator.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getItems()
}
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 ?? []));
}

Expand Down
4 changes: 1 addition & 3 deletions code/Model/SiteTreeFileFormFactoryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
* 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);
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required to get CMS page history to work since we've migrated from the deprecated CMS class to the class in versioned-admin

"silverstripe/vendor-plugin": "^1.0",
"php": "^7.4 || ^8.0"
},
Expand Down
2 changes: 1 addition & 1 deletion templates/BreadcrumbsTemplate.ss
Original file line number Diff line number Diff line change
@@ -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 %><a href="$Link" class="breadcrumb-$Pos"><% end_if %>$MenuTitle.XML<% if not Up.Unlinked %></a><% end_if %> $Up.Delimiter.RAW <% end_if %><% end_loop %>
<% loop $Pages %><% if $IsLast %>$MenuTitle.XML<% else %><% if not Up.Unlinked %><a href="$Link" class="breadcrumb-$Pos"><% end_if %>$MenuTitle.XML<% if not Up.Unlinked %></a><% end_if %> $Up.Delimiter.RAW <% end_if %><% end_loop %>
<% end_if %>
2 changes: 1 addition & 1 deletion tests/php/Controllers/CMSBatchActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function setUp(): void
$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');
Expand Down
4 changes: 4 additions & 0 deletions tests/php/Controllers/CMSMainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use SilverStripe\Security\Security;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Dev\Deprecation;

class CMSMainTest extends FunctionalTest
{
Expand Down Expand Up @@ -123,6 +124,9 @@ public function testChildFilter()
*/
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');
Expand Down
34 changes: 26 additions & 8 deletions tests/php/Controllers/CMSPageHistoryControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\HTMLReadonlyField;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\TextField;

class CMSPageHistoryControllerTest extends FunctionalTest
Expand All @@ -32,10 +33,12 @@ protected function setUp(): void
{
parent::setUp();

Injector::inst()->registerService(
new CMSPageHistoryController(),
CMSPageHistoryController::class
);
Deprecation::withNoReplacement(function () {
Injector::inst()->registerService(
new CMSPageHistoryController(),
CMSPageHistoryController::class
);
});

$this->loginWithPermission('ADMIN');

Expand All @@ -62,6 +65,9 @@ protected function setUp(): void

public function testGetEditForm()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$controller = new CMSPageHistoryController();
$controller->setRequest(Controller::curr()->getRequest());

Expand Down Expand Up @@ -108,7 +114,10 @@ public function testGetEditForm()
*/
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');

Expand All @@ -127,7 +136,10 @@ public function testVersionsForm()

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");

Expand All @@ -153,7 +165,10 @@ public function testVersionsFormTableContainsInformation()

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()));
Expand All @@ -162,7 +177,7 @@ public function testVersionsFormSelectsUnpublishedCheckbox()
$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()));
Expand All @@ -171,6 +186,9 @@ public function testVersionsFormSelectsUnpublishedCheckbox()

public function testTransformReadonly()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
/** @var CMSPageHistoryController $history */
$history = new CMSPageHistoryController();
$history->setRequest(Controller::curr()->getRequest());
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Model/RedirectorPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function setUp(): void
$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 */
Expand Down
22 changes: 13 additions & 9 deletions tests/php/Model/SiteTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use SilverStripe\View\Shortcodes\EmbedShortcodeProvider;
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
use const RESOURCES_DIR;
use SilverStripe\Dev\Deprecation;

class SiteTreeTest extends SapphireTest
{
Expand Down Expand Up @@ -430,7 +431,7 @@ public function testRestoreToStage()

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();
Expand Down Expand Up @@ -1253,27 +1254,27 @@ public function testAllowedChildrenValidation()
$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");
}

Expand Down Expand Up @@ -1655,7 +1656,7 @@ public function testGetControllerName()
*/
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());
}
Expand All @@ -1665,7 +1666,7 @@ public function testGetControllerNameFromConfig()
*/
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',
]);

Expand All @@ -1678,6 +1679,9 @@ public function testGetControllerNameFromNamespaceMappingConfig()
*/
public function testGetControllerNameWithUnderscoresIsSupported()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$class = new SiteTreeTest_LegacyControllerName;
$this->assertEquals(SiteTreeTest_LegacyControllerName_Controller::class, $class->getControllerName());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Model/VirtualPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,11 @@ public function testAllowedChildrenLimitedOnVirtualPages()
$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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class ZZZSearchFormTest extends FunctionalTest
{

protected static $fixture_file = 'SearchFormTest.yml';
protected static $fixture_file = 'ZZZSearchFormTest.yml';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to remove the warning that the filename did not match the class name


protected static $illegal_extensions = [
SiteTree::class => [
Expand Down
2 changes: 0 additions & 2 deletions tests/php/Tasks/MigrateSiteTreeLinkingTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class MigrateSiteTreeLinkingTaskTest extends SapphireTest
{
protected static $fixture_file = 'MigrateSiteTreeLinkingTaskTest.yml';

protected static $use_draft_site = true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed because FunctionalTest::use_draft_site is deprecated. This never actually needed to be set true for the unit test to pass.


public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
Expand Down