Skip to content

Commit

Permalink
API Stop using deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 3, 2022
1 parent 7a7c751 commit 236d7af
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 30 deletions.
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);
4 changes: 4 additions & 0 deletions code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,12 @@ public function LinkPageSettings()
}
}

/**
* @deprecated 4.12.0 Will be removed without equivalent functionality to replace it
*/
public function LinkPageHistory()
{
Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it');
if ($id = $this->currentPageID()) {
return $this->LinkWithSearch(
Controller::join_links(CMSPageHistoryController::singleton()->Link('show'), $id)
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
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
38 changes: 27 additions & 11 deletions tests/php/Controllers/CMSPageHistoryControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace SilverStripe\CMS\Tests\Controllers;

use Page;
use SilverStripe\CMS\Controllers\CMSPageHistoryController;
use SilverStripe\CMS\Tests\Controllers\CMSPageHistoryControllerTest\HistoryController;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Control\Controller;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\HTMLReadonlyField;
use SilverStripe\Forms\TextField;
use SilverStripe\CMS\Controllers\CMSPageHistoryController;
use SilverStripe\CMS\Tests\Controllers\CMSPageHistoryControllerTest\HistoryController;

class CMSPageHistoryControllerTest extends FunctionalTest
{
Expand Down Expand Up @@ -62,6 +63,9 @@ protected function setUp(): void

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

Expand Down Expand Up @@ -108,7 +112,10 @@ public function testGetEditForm()
*/
public function testVersionsForm()
{
$this->get('admin/pages/legacyhistory/show/'. $this->page->ID);
if (Deprecation::get_is_enabled()) {
$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 +134,10 @@ public function testVersionsForm()

public function testVersionsFormTableContainsInformation()
{
$this->get('admin/pages/legacyhistory/show/'. $this->page->ID);
if (Deprecation::get_is_enabled()) {
$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 +163,10 @@ public function testVersionsFormTableContainsInformation()

public function testVersionsFormSelectsUnpublishedCheckbox()
{
$this->get('admin/pages/legacyhistory/show/'. $this->page->ID);
if (Deprecation::get_is_enabled()) {
$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 +175,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 +184,9 @@ public function testVersionsFormSelectsUnpublishedCheckbox()

public function testTransformReadonly()
{
if (Deprecation::get_is_enabled()) {
$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
18 changes: 9 additions & 9 deletions tests/php/Model/SiteTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,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 +1253,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 +1655,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 +1665,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 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
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;

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

0 comments on commit 236d7af

Please sign in to comment.