Merge pull request #2794 from creative-commoners/pulls/4/stop-depr

API Stop using deprecated API
This commit is contained in:
Sabina Talipova 2022-11-16 16:13:08 +13:00 committed by GitHub
commit 113f4e9dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 62 additions and 33 deletions

View File

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

View File

@ -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;

View File

@ -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) {

View File

@ -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 ?? []));
}

View File

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

View File

@ -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"
},

View File

@ -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 %>

View File

@ -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');

View File

@ -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');

View File

@ -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());

View File

@ -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 */

View File

@ -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());
}

View File

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

View File

@ -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 => [

View File

@ -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();