From 2219899c1070abc85cdaa6ab99f226b35e37b602 Mon Sep 17 00:00:00 2001 From: Mike Cochrane Date: Fri, 4 May 2018 01:04:18 +0000 Subject: [PATCH] MNT Use SiteTree instead of Page in tests --- tests/php/Controllers/CMSBatchActionsTest.php | 5 +- tests/php/Controllers/CMSMainTest.php | 67 ++-- tests/php/Controllers/CMSMainTest.yml | 6 +- tests/php/Controllers/CMSMainTest_ClassA.php | 4 +- tests/php/Controllers/CMSMainTest_ClassB.php | 4 +- .../Controllers/CMSMainTest_HiddenClass.php | 5 +- tests/php/Controllers/CMSMainTest_NotRoot.php | 4 +- .../CMSPageHistoryControllerTest.php | 24 +- .../CMSPageHistoryControllerTest.yml | 2 +- .../php/Controllers/CMSSiteTreeFilterTest.php | 37 +- .../php/Controllers/CMSSiteTreeFilterTest.yml | 12 +- tests/php/Controllers/CMSTreeTest.php | 12 +- .../ContentControllerPermissionsTest.php | 16 +- .../ContentControllerSearchExtensionTest.php | 6 +- .../php/Controllers/ContentControllerTest.php | 10 +- .../Controllers/ContentControllerTestPage.php | 4 +- .../ContentControllerTestPageController.php | 2 +- ...entControllerTestPageWithoutController.php | 5 +- .../ContentControllerTest_Page.php | 4 +- .../ContentControllerTest_PageController.php | 7 +- .../php/Controllers/ModelAsControllerTest.php | 40 +- .../php/Controllers/RootURLControllerTest.php | 2 +- .../php/Controllers/RootURLControllerTest.yml | 4 +- .../Controllers/SilverStripeNavigatorTest.php | 1 - tests/php/GraphQL/LinkablePluginTest.php | 4 +- tests/php/Model/RedirectorPageTest.php | 44 ++- tests/php/Model/RedirectorPageTest.yml | 4 +- tests/php/Model/SiteTreeActionsTest.php | 24 +- tests/php/Model/SiteTreeActionsTest_Page.php | 4 +- tests/php/Model/SiteTreeBacklinksTest.php | 187 ++++++--- tests/php/Model/SiteTreeBacklinksTest.yml | 4 +- tests/php/Model/SiteTreeBrokenLinksTest.php | 61 +-- tests/php/Model/SiteTreeBrokenLinksTest.yml | 4 +- .../php/Model/SiteTreeHTMLEditorFieldTest.php | 11 +- tests/php/Model/SiteTreeLinkTrackingTest.php | 10 +- tests/php/Model/SiteTreePermissionsTest.php | 140 ++++--- tests/php/Model/SiteTreePermissionsTest.yml | 6 +- tests/php/Model/SiteTreeTest.php | 369 ++++++++++-------- tests/php/Model/SiteTreeTest.yml | 26 +- tests/php/Model/SiteTreeTest_AdminDenied.php | 4 +- tests/php/Model/SiteTreeTest_ClassA.php | 8 +- tests/php/Model/SiteTreeTest_ClassB.php | 6 +- tests/php/Model/SiteTreeTest_ClassC.php | 4 +- tests/php/Model/SiteTreeTest_ClassCext.php | 2 +- tests/php/Model/SiteTreeTest_ClassD.php | 4 +- tests/php/Model/SiteTreeTest_ClassE.php | 4 +- tests/php/Model/SiteTreeTest_Conflicted.php | 4 +- .../SiteTreeTest_ConflictedController.php | 6 +- .../SiteTreeTest_LegacyControllerName.php | 4 +- ...eeTest_LegacyControllerName_Controller.php | 5 +- tests/php/Model/SiteTreeTest_NotRoot.php | 4 +- tests/php/Model/SiteTreeTest_PageNode.php | 4 +- .../Model/SiteTreeTest_PageNodeController.php | 4 +- tests/php/Model/VirtualPageTest.php | 41 +- tests/php/Model/VirtualPageTest.yml | 14 +- tests/php/Model/VirtualPageTest_ClassA.php | 4 +- .../VirtualPageTest_ClassAController.php | 6 +- tests/php/Model/VirtualPageTest_ClassB.php | 4 +- tests/php/Model/VirtualPageTest_ClassC.php | 4 +- tests/php/Model/VirtualPageTest_NotRoot.php | 4 +- .../Model/VirtualPageTest_PageExtension.php | 3 +- ...irtualPageTest_PageWithAllowedChildren.php | 4 +- tests/php/Reports/CmsReportsTest.php | 128 +++--- tests/php/Search/CMSMainSearchFormTest.php | 2 +- tests/php/Search/SearchFormTest.php | 2 - .../php/Tasks/RemoveOrphanedPagesTaskTest.php | 32 +- .../php/Tasks/RemoveOrphanedPagesTaskTest.yml | 20 +- 67 files changed, 849 insertions(+), 663 deletions(-) mode change 100755 => 100644 tests/php/Controllers/CMSPageHistoryControllerTest.php mode change 100755 => 100644 tests/php/Controllers/ContentControllerTest.php mode change 100755 => 100644 tests/php/Model/SiteTreeTest.yml diff --git a/tests/php/Controllers/CMSBatchActionsTest.php b/tests/php/Controllers/CMSBatchActionsTest.php index 9a079b80..dae4836d 100644 --- a/tests/php/Controllers/CMSBatchActionsTest.php +++ b/tests/php/Controllers/CMSBatchActionsTest.php @@ -16,7 +16,6 @@ use SilverStripe\Versioned\Versioned; */ class CMSBatchActionsTest extends SapphireTest { - protected static $fixture_file = 'CMSBatchActionsTest.yml'; protected function setUp(): void @@ -145,7 +144,7 @@ class CMSBatchActionsTest extends SapphireTest $result = json_decode($action->run($list) ?? '', true); $this->assertEquals( [ - $archivedxID => $archivedxID + $archivedxID => $archivedxID, ], $result['success'] ); @@ -168,7 +167,7 @@ class CMSBatchActionsTest extends SapphireTest // Order of archived is opposite to order items are passed in, as // these are sorted by level first $archivedID => $archivedID, - $archivedyID => $archivedyID + $archivedyID => $archivedyID, ], $result['success'] ); diff --git a/tests/php/Controllers/CMSMainTest.php b/tests/php/Controllers/CMSMainTest.php index f61158f4..2d61ebba 100644 --- a/tests/php/Controllers/CMSMainTest.php +++ b/tests/php/Controllers/CMSMainTest.php @@ -2,7 +2,6 @@ namespace SilverStripe\CMS\Tests\Controllers; -use Page; use Psr\SimpleCache\CacheInterface; use SilverStripe\Admin\CMSBatchActionHandler; use SilverStripe\CMS\Controllers\CMSMain; @@ -123,8 +122,8 @@ class CMSMainTest extends FunctionalTest */ public function testPublish() { - $page1 = $this->objFromFixture(Page::class, "page1"); - $page2 = $this->objFromFixture(Page::class, "page2"); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); + $page2 = $this->objFromFixture(SiteTree::class, 'page2'); $this->logInAs('admin'); $response = $this->get('admin/pages/publishall?confirm=1'); @@ -136,7 +135,9 @@ class CMSMainTest extends FunctionalTest // Some modules (e.g., cmsworkflow) will remove this action $actions = CMSBatchActionHandler::config()->batch_actions; if (isset($actions['publish'])) { - $response = $this->get('admin/pages/batchactions/publish?ajax=1&csvIDs=' . implode(',', [$page1->ID, $page2->ID])); + $response = $this->get( + 'admin/pages/batchactions/publish?ajax=1&csvIDs=' . implode(',', [$page1->ID, $page2->ID]) + ); $responseData = json_decode($response->getBody() ?? '', true); $this->assertArrayHasKey($page1->ID, $responseData['modified']); $this->assertArrayHasKey($page2->ID, $responseData['modified']); @@ -144,8 +145,8 @@ class CMSMainTest extends FunctionalTest // Get the latest version of the redirector page $pageID = $this->idFromFixture(RedirectorPage::class, 'page5'); - $latestID = DB::prepared_query('select max("Version") from "RedirectorPage_Versions" where "RecordID" = ?', [$pageID])->value(); - $dsCount = DB::prepared_query('select count("Version") from "RedirectorPage_Versions" where "RecordID" = ? and "Version"= ?', [$pageID, $latestID])->value(); + $latestID = DB::prepared_query('SELECT MAX("Version") FROM "RedirectorPage_Versions" WHERE "RecordID" = ?', [$pageID])->value(); + $dsCount = DB::prepared_query('SELECT COUNT("Version") FROM "RedirectorPage_Versions" WHERE "RecordID" = ? AND "Version"= ?', [$pageID, $latestID])->value(); $this->assertEquals(1, $dsCount, "Published page has no duplicate version records: it has " . $dsCount . " for version " . $latestID); } @@ -181,8 +182,8 @@ class CMSMainTest extends FunctionalTest $this->logInWithPermission('ADMIN'); Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', true); - $parentPage = $this->objFromFixture(Page::class, 'page3'); - $childPage = $this->objFromFixture(Page::class, 'page1'); + $parentPage = $this->objFromFixture(SiteTree::class, 'page3'); + $childPage = $this->objFromFixture(SiteTree::class, 'page1'); $parentPage->doUnpublish(); $childPage->doUnpublish(); @@ -204,7 +205,7 @@ class CMSMainTest extends FunctionalTest $this->logInWithPermission('ADMIN'); // Set up a page that is delete from live - $page = $this->objFromFixture(Page::class, 'page1'); + $page = $this->objFromFixture(SiteTree::class, 'page1'); $pageID = $page->ID; $page->publishRecursive(); $page->delete(); @@ -212,7 +213,7 @@ class CMSMainTest extends FunctionalTest $response = $this->get('admin/pages/edit/show/' . $pageID); $livePage = Versioned::get_one_by_stage(SiteTree::class, Versioned::LIVE, [ - '"SiteTree"."ID"' => $pageID + '"SiteTree"."ID"' => $pageID, ]); $this->assertInstanceOf(SiteTree::class, $livePage); $this->assertTrue($livePage->canDelete()); @@ -229,7 +230,7 @@ class CMSMainTest extends FunctionalTest $this->logInWithPermission('ADMIN'); // Set up a page that is delete from live - $page1 = $this->objFromFixture(Page::class, 'page1'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); $page1ID = $page1->ID; $page1->publishRecursive(); $page1->delete(); @@ -242,18 +243,18 @@ class CMSMainTest extends FunctionalTest $this->assertNull($cmsMain->getRecord('asdf')); // Pages that are on draft and aren't on draft should both work - $this->assertInstanceOf('Page', $cmsMain->getRecord($page1ID)); - $this->assertInstanceOf('Page', $cmsMain->getRecord($this->idFromFixture('Page', 'page2'))); + $this->assertInstanceOf(SiteTree::class, $cmsMain->getRecord($page1ID)); + $this->assertInstanceOf(SiteTree::class, $cmsMain->getRecord($this->idFromFixture(SiteTree::class, 'page2'))); // This functionality isn't actually used any more. $newPage = $cmsMain->getRecord('new-Page-5'); - $this->assertInstanceOf('Page', $newPage); + $this->assertInstanceOf(SiteTree::class, $newPage); $this->assertEquals('5', $newPage->ParentID); } public function testDeletedPagesSiteTreeFilter() { - $id = $this->idFromFixture('Page', 'page3'); + $id = $this->idFromFixture(SiteTree::class, 'page3'); $this->logInWithPermission('ADMIN'); $result = $this->get('admin/pages/getsubtree?filter=CMSSiteTreeFilter_DeletedPages&ajax=1&ID=' . $id); $this->assertEquals(200, $result->getStatusCode()); @@ -274,7 +275,7 @@ class CMSMainTest extends FunctionalTest 'admin/pages/add/AddForm', [ 'ParentID' => '0', - 'PageType' => 'Page', + 'PageType' => RedirectorPage::class, 'Locale' => 'en_US', 'action_doAdd' => 1, 'ajax' => 1, @@ -294,7 +295,7 @@ class CMSMainTest extends FunctionalTest 'admin/pages/add/AddForm', [ 'ParentID' => '0', - 'PageType' => 'Page', + 'PageType' => RedirectorPage::class, 'Locale' => 'en_US', 'action_doAdd' => 1, 'ajax' => 1, @@ -328,7 +329,7 @@ class CMSMainTest extends FunctionalTest 'PageType' => CMSMainTest_ClassA::class, 'Locale' => 'en_US', 'action_doAdd' => 1, - 'ajax' => 1 + 'ajax' => 1, ], [ 'X-Pjax' => 'CurrentForm,Breadcrumbs', @@ -348,7 +349,7 @@ class CMSMainTest extends FunctionalTest 'PageType' => CMSMainTest_ClassB::class, 'Locale' => 'en_US', 'action_doAdd' => 1, - 'ajax' => 1 + 'ajax' => 1, ], [ 'X-Pjax' => 'CurrentForm,Breadcrumbs', @@ -371,10 +372,10 @@ class CMSMainTest extends FunctionalTest 'admin/pages/add/AddForm', [ 'ParentID' => $newPageId, - 'PageType' => 'Page', + 'PageType' => RedirectorPage::class, 'Locale' => 'en_US', 'action_doAdd' => 1, - 'ajax' => 1 + 'ajax' => 1, ], [ 'X-Pjax' => 'CurrentForm,Breadcrumbs', @@ -389,8 +390,8 @@ class CMSMainTest extends FunctionalTest public function testBreadcrumbs() { - $page3 = $this->objFromFixture(Page::class, 'page3'); - $page31 = $this->objFromFixture(Page::class, 'page31'); + $page3 = $this->objFromFixture(SiteTree::class, 'page3'); + $page31 = $this->objFromFixture(SiteTree::class, 'page31'); $this->logInAs('admin'); $response = $this->get('admin/pages/edit/show/' . $page31->ID); @@ -416,7 +417,7 @@ class CMSMainTest extends FunctionalTest $this->assertEquals($page->Title, 'New Page'); $this->assertNotEquals($page->Sort, 0); - $this->assertInstanceOf('Page', $page); + $this->assertInstanceOf(SiteTree::class, $page); // Test failure try { @@ -445,10 +446,10 @@ class CMSMainTest extends FunctionalTest ); // Change state of tree - $page1 = $this->objFromFixture(Page::class, 'page1'); - $page3 = $this->objFromFixture(Page::class, 'page3'); - $page11 = $this->objFromFixture(Page::class, 'page11'); - $page12 = $this->objFromFixture(Page::class, 'page12'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); + $page3 = $this->objFromFixture(SiteTree::class, 'page3'); + $page11 = $this->objFromFixture(SiteTree::class, 'page11'); + $page12 = $this->objFromFixture(SiteTree::class, 'page12'); // Deleted $page1->doUnpublish(); $page1->delete(); @@ -468,7 +469,7 @@ class CMSMainTest extends FunctionalTest // Test deleted page filter $params = [ - 'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_StatusDeletedPages' + 'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_StatusDeletedPages', ]; $pages = $controller->getList($params); $this->assertEquals(1, $pages->count()); @@ -479,7 +480,7 @@ class CMSMainTest extends FunctionalTest // Test live, but not on draft filter $params = [ - 'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_StatusRemovedFromDraftPages' + 'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_StatusRemovedFromDraftPages', ]; $pages = $controller->getList($params); $this->assertEquals(1, $pages->count()); @@ -490,7 +491,7 @@ class CMSMainTest extends FunctionalTest // Test live pages filter $params = [ - 'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_PublishedPages' + 'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_PublishedPages', ]; $pages = $controller->getList($params); $this->assertEquals(2, $pages->count()); @@ -525,7 +526,7 @@ class CMSMainTest extends FunctionalTest $this->loginWithPermission('ADMIN'); // Get a associated with a fixture page. - $page = $this->objFromFixture(Page::class, 'page1'); + $page = $this->objFromFixture(SiteTree::class, 'page1'); $controller = CMSMain::create(); $controller->setRequest(Controller::curr()->getRequest()); $form = $controller->getEditForm($page->ID); @@ -553,7 +554,7 @@ class CMSMainTest extends FunctionalTest $form->loadDataFrom(['ClassName' => CMSMainTest_ClassB::class]); $result = $cms->save([ 'ID' => $page->ID, - 'ClassName' => CMSMainTest_ClassB::class + 'ClassName' => CMSMainTest_ClassB::class, ], $form); $this->assertEquals(200, $result->getStatusCode()); diff --git a/tests/php/Controllers/CMSMainTest.yml b/tests/php/Controllers/CMSMainTest.yml index f053d774..cef69d84 100644 --- a/tests/php/Controllers/CMSMainTest.yml +++ b/tests/php/Controllers/CMSMainTest.yml @@ -1,4 +1,4 @@ -Page: +SilverStripe\CMS\Model\SiteTree: page1: Title: Page 1 Sort: 1 @@ -10,11 +10,11 @@ Page: Sort: 3 page31: Title: Page 3.1 - Parent: =>Page.page3 + Parent: =>SilverStripe\CMS\Model\SiteTree.page3 Sort: 1 page32: Title: Page 3.2 - Parent: =>Page.page3 + Parent: =>SilverStripe\CMS\Model\SiteTree.page3 Sort: 2 page4: Title: Page 4 diff --git a/tests/php/Controllers/CMSMainTest_ClassA.php b/tests/php/Controllers/CMSMainTest_ClassA.php index e39b54cc..afa9e401 100644 --- a/tests/php/Controllers/CMSMainTest_ClassA.php +++ b/tests/php/Controllers/CMSMainTest_ClassA.php @@ -2,11 +2,11 @@ namespace SilverStripe\CMS\Tests\Controllers; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\TestOnly; use SilverStripe\ORM\ValidationException; -use Page; -class CMSMainTest_ClassA extends Page implements TestOnly +class CMSMainTest_ClassA extends SiteTree implements TestOnly { private static $table_name = 'CMSMainTest_ClassA'; diff --git a/tests/php/Controllers/CMSMainTest_ClassB.php b/tests/php/Controllers/CMSMainTest_ClassB.php index 3593df1b..30e44d0f 100644 --- a/tests/php/Controllers/CMSMainTest_ClassB.php +++ b/tests/php/Controllers/CMSMainTest_ClassB.php @@ -2,11 +2,11 @@ namespace SilverStripe\CMS\Tests\Controllers; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\TestOnly; use SilverStripe\ORM\ValidationException; -use Page; -class CMSMainTest_ClassB extends Page implements TestOnly +class CMSMainTest_ClassB extends SiteTree implements TestOnly { private static $table_name = 'CMSMainTest_ClassB'; diff --git a/tests/php/Controllers/CMSMainTest_HiddenClass.php b/tests/php/Controllers/CMSMainTest_HiddenClass.php index 4cf69be6..28189129 100644 --- a/tests/php/Controllers/CMSMainTest_HiddenClass.php +++ b/tests/php/Controllers/CMSMainTest_HiddenClass.php @@ -2,11 +2,10 @@ namespace SilverStripe\CMS\Tests\Controllers; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\TestOnly; use SilverStripe\ORM\HiddenClass; -use Page; -class CMSMainTest_HiddenClass extends Page implements TestOnly, HiddenClass +class CMSMainTest_HiddenClass extends SiteTree implements TestOnly, HiddenClass { - } diff --git a/tests/php/Controllers/CMSMainTest_NotRoot.php b/tests/php/Controllers/CMSMainTest_NotRoot.php index e08a1fd2..5b2af0da 100644 --- a/tests/php/Controllers/CMSMainTest_NotRoot.php +++ b/tests/php/Controllers/CMSMainTest_NotRoot.php @@ -2,10 +2,10 @@ namespace SilverStripe\CMS\Tests\Controllers; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\TestOnly; -use Page; -class CMSMainTest_NotRoot extends Page implements TestOnly +class CMSMainTest_NotRoot extends SiteTree implements TestOnly { private static $table_name = 'CMSMainTest_NotRoot'; diff --git a/tests/php/Controllers/CMSPageHistoryControllerTest.php b/tests/php/Controllers/CMSPageHistoryControllerTest.php old mode 100755 new mode 100644 index 40d564b5..13e48873 --- a/tests/php/Controllers/CMSPageHistoryControllerTest.php +++ b/tests/php/Controllers/CMSPageHistoryControllerTest.php @@ -2,16 +2,15 @@ namespace SilverStripe\CMS\Tests\Controllers; -use Page; use SilverStripe\CMS\Controllers\CMSPageHistoryController; -use SilverStripe\CMS\Tests\Controllers\CMSPageHistoryControllerTest\HistoryController; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\Controller; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\FunctionalTest; use SilverStripe\Forms\FieldGroup; use SilverStripe\Forms\FieldList; -use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\HTMLReadonlyField; +use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\TextField; class CMSPageHistoryControllerTest extends FunctionalTest @@ -40,7 +39,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest $this->loginWithPermission('ADMIN'); // creates a series of published, unpublished versions of a page - $this->page = new Page(); + $this->page = new SiteTree(); $this->page->URLSegment = "test"; $this->page->Content = "new content"; $this->page->write(); @@ -90,7 +89,12 @@ class CMSPageHistoryControllerTest extends FunctionalTest ); // check that compare mode updates the message - $form = $controller->getEditForm($this->page->ID, null, $this->versionPublishCheck, $this->versionPublishCheck2); + $form = $controller->getEditForm( + $this->page->ID, + null, + $this->versionPublishCheck, + $this->versionPublishCheck2 + ); $this->assertStringContainsString( sprintf("Comparing versions %s", $this->versionPublishCheck), $form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent() @@ -108,7 +112,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest */ public function testVersionsForm() { - $this->get('admin/pages/legacyhistory/show/'. $this->page->ID); + $this->get('admin/pages/legacyhistory/show/' . $this->page->ID); $form = $this->cssParser()->getBySelector('#Form_VersionsForm'); @@ -127,7 +131,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest public function testVersionsFormTableContainsInformation() { - $this->get('admin/pages/legacyhistory/show/'. $this->page->ID); + $this->get('admin/pages/legacyhistory/show/' . $this->page->ID); $form = $this->cssParser()->getBySelector('#Form_VersionsForm'); $rows = $form[0]->xpath("fieldset/table/tbody/tr"); @@ -135,7 +139,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest ['version' => $this->versionPublishCheck2, 'status' => 'published'], ['version' => $this->versionUnpublishedCheck2, 'status' => 'internal'], ['version' => $this->versionPublishCheck, 'status' => 'published'], - ['version' => $this->versionUnpublishedCheck, 'status' => 'internal'] + ['version' => $this->versionUnpublishedCheck, 'status' => 'internal'], ]; // goes the reverse order that we created in setUp() @@ -153,7 +157,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest public function testVersionsFormSelectsUnpublishedCheckbox() { - $this->get('admin/pages/legacyhistory/show/'. $this->page->ID); + $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 +166,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())); diff --git a/tests/php/Controllers/CMSPageHistoryControllerTest.yml b/tests/php/Controllers/CMSPageHistoryControllerTest.yml index 5f34208f..dad212df 100644 --- a/tests/php/Controllers/CMSPageHistoryControllerTest.yml +++ b/tests/php/Controllers/CMSPageHistoryControllerTest.yml @@ -1,4 +1,4 @@ -Page: +SilverStripe\CMS\Model\SiteTree: page1: Title: Page 1 Sort: 1 diff --git a/tests/php/Controllers/CMSSiteTreeFilterTest.php b/tests/php/Controllers/CMSSiteTreeFilterTest.php index b76688f2..8cc720a6 100644 --- a/tests/php/Controllers/CMSSiteTreeFilterTest.php +++ b/tests/php/Controllers/CMSSiteTreeFilterTest.php @@ -2,7 +2,6 @@ namespace SilverStripe\CMS\Tests\Controllers; -use Page; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Versioned\Versioned; use SilverStripe\CMS\Controllers\CMSSiteTreeFilter_Search; @@ -15,13 +14,12 @@ use SilverStripe\Dev\SapphireTest; class CMSSiteTreeFilterTest extends SapphireTest { - protected static $fixture_file = 'CMSSiteTreeFilterTest.yml'; public function testSearchFilterEmpty() { - $page1 = $this->objFromFixture('Page', 'page1'); - $page2 = $this->objFromFixture('Page', 'page2'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); + $page2 = $this->objFromFixture(SiteTree::class, 'page2'); $f = new CMSSiteTreeFilter_Search(); $results = $f->pagesIncluded(); @@ -32,8 +30,8 @@ class CMSSiteTreeFilterTest extends SapphireTest public function testSearchFilterByTitle() { - $page1 = $this->objFromFixture('Page', 'page1'); - $page2 = $this->objFromFixture('Page', 'page2'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); + $page2 = $this->objFromFixture(SiteTree::class, 'page2'); $f = new CMSSiteTreeFilter_Search(['Title' => 'Page 1']); $results = $f->pagesIncluded(); @@ -49,7 +47,7 @@ class CMSSiteTreeFilterTest extends SapphireTest public function testUrlSegmentFilter() { - $page = $this->objFromFixture(Page::class, 'page8'); + $page = $this->objFromFixture(SiteTree::class, 'page8'); $filter = CMSSiteTreeFilter_Search::create(['Term' => 'lake-wanaka+adventure']); $this->assertTrue($filter->isPageIncluded($page)); @@ -60,8 +58,8 @@ class CMSSiteTreeFilterTest extends SapphireTest public function testIncludesParentsForNestedMatches() { - $parent = $this->objFromFixture('Page', 'page3'); - $child = $this->objFromFixture('Page', 'page3b'); + $parent = $this->objFromFixture(SiteTree::class, 'page3'); + $child = $this->objFromFixture(SiteTree::class, 'page3b'); $f = new CMSSiteTreeFilter_Search(['Title' => 'Page 3b']); $results = $f->pagesIncluded(); @@ -78,11 +76,11 @@ class CMSSiteTreeFilterTest extends SapphireTest public function testChangedPagesFilter() { /** @var Page $unchangedPage */ - $unchangedPage = $this->objFromFixture('Page', 'page1'); + $unchangedPage = $this->objFromFixture(SiteTree::class, 'page1'); $unchangedPage->publishRecursive(); /** @var Page $changedPage */ - $changedPage = $this->objFromFixture('Page', 'page2'); + $changedPage = $this->objFromFixture(SiteTree::class, 'page2'); $changedPage->Title = 'Original'; $changedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $changedPage->Title = 'Changed'; @@ -121,7 +119,7 @@ class CMSSiteTreeFilterTest extends SapphireTest public function testDeletedPagesFilter() { - $deletedPage = $this->objFromFixture('Page', 'page2'); + $deletedPage = $this->objFromFixture(SiteTree::class, 'page2'); $deletedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $deletedPageID = $deletedPage->ID; $deletedPage->delete(); @@ -141,7 +139,7 @@ class CMSSiteTreeFilterTest extends SapphireTest public function testStatusDraftPagesFilter() { - $draftPage = $this->objFromFixture('Page', 'page4'); + $draftPage = $this->objFromFixture(SiteTree::class, 'page4'); $draftPage = Versioned::get_one_by_stage( SiteTree::class, 'Stage', @@ -164,20 +162,23 @@ class CMSSiteTreeFilterTest extends SapphireTest public function testDateFromToLastSameDate() { - $draftPage = $this->objFromFixture('Page', 'page4'); + $draftPage = $this->objFromFixture(SiteTree::class, 'page4'); // Grab the date $date = substr($draftPage->LastEdited ?? '', 0, 10); // Filter with that date $filter = new CMSSiteTreeFilter_Search([ 'LastEditedFrom' => $date, - 'LastEditedTo' => $date + 'LastEditedTo' => $date, ]); - $this->assertTrue($filter->isPageIncluded($draftPage), 'Using the same date for from and to should show find that page'); + $this->assertTrue( + $filter->isPageIncluded($draftPage), + 'Using the same date for from and to should show find that page' + ); } public function testStatusRemovedFromDraftFilter() { - $removedDraftPage = $this->objFromFixture('Page', 'page6'); + $removedDraftPage = $this->objFromFixture(SiteTree::class, 'page6'); $removedDraftPage->publishRecursive(); $removedDraftPage->deleteFromStage('Stage'); $removedDraftPage = Versioned::get_one_by_stage( @@ -202,7 +203,7 @@ class CMSSiteTreeFilterTest extends SapphireTest public function testStatusDeletedFilter() { - $deletedPage = $this->objFromFixture('Page', 'page7'); + $deletedPage = $this->objFromFixture(SiteTree::class, 'page7'); $deletedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $deletedPageID = $deletedPage->ID; diff --git a/tests/php/Controllers/CMSSiteTreeFilterTest.yml b/tests/php/Controllers/CMSSiteTreeFilterTest.yml index c90e520a..cb52063f 100644 --- a/tests/php/Controllers/CMSSiteTreeFilterTest.yml +++ b/tests/php/Controllers/CMSSiteTreeFilterTest.yml @@ -1,4 +1,4 @@ -Page: +SilverStripe\CMS\Model\SiteTree: page1: Title: Page 1 page2: @@ -15,19 +15,19 @@ Page: page7: Title: Page 7 page7a: - Parent: =>Page.page7 + Parent: =>SilverStripe\CMS\Model\SiteTree.page7 Title: Page 7a page2a: - Parent: =>Page.page2 + Parent: =>SilverStripe\CMS\Model\SiteTree.page2 Title: Page 2a page2b: - Parent: =>Page.page2 + Parent: =>SilverStripe\CMS\Model\SiteTree.page2 Title: Page 2b page3a: - Parent: =>Page.page3 + Parent: =>SilverStripe\CMS\Model\SiteTree.page3 Title: Page 3a page3b: - Parent: =>Page.page3 + Parent: =>SilverStripe\CMS\Model\SiteTree.page3 Title: Page 3b page8: Title: EncodedUrlSegment diff --git a/tests/php/Controllers/CMSTreeTest.php b/tests/php/Controllers/CMSTreeTest.php index c17b75cd..d0023025 100644 --- a/tests/php/Controllers/CMSTreeTest.php +++ b/tests/php/Controllers/CMSTreeTest.php @@ -32,7 +32,7 @@ class CMSTreeTest extends FunctionalTest $data = [ 'SiblingIDs' => $siblingIDs, 'ID' => $page2->ID, - 'ParentID' => 0 + 'ParentID' => 0, ]; $response = $this->post('admin/pages/edit/savetreenode', $data); @@ -62,12 +62,12 @@ class CMSTreeTest extends FunctionalTest $siblingIDs = [ $page31->ID, $page2->ID, - $page32->ID + $page32->ID, ]; $data = [ 'SiblingIDs' => $siblingIDs, 'ID' => $page2->ID, - 'ParentID' => $page3->ID + 'ParentID' => $page3->ID, ]; $response = $this->post('admin/pages/edit/savetreenode', $data); $this->assertEquals(200, $response->getStatusCode()); @@ -95,7 +95,7 @@ class CMSTreeTest extends FunctionalTest $this->logInWithPermission('ADMIN'); // Check page - $result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page1->ID); + $result = $this->get('admin/pages/edit/updatetreenodes?ids=' . $page1->ID); $this->assertEquals(200, $result->getStatusCode()); $this->assertEquals('application/json', $result->getHeader('Content-Type')); $data = json_decode($result->getBody() ?? '', true); @@ -105,7 +105,7 @@ class CMSTreeTest extends FunctionalTest $this->assertEmpty($pageData['PrevID']); // check subpage - $result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page31->ID); + $result = $this->get('admin/pages/edit/updatetreenodes?ids=' . $page31->ID); $this->assertEquals(200, $result->getStatusCode()); $this->assertEquals('application/json', $result->getHeader('Content-Type')); $data = json_decode($result->getBody() ?? '', true); @@ -115,7 +115,7 @@ class CMSTreeTest extends FunctionalTest $this->assertEmpty($pageData['PrevID']); // Multiple pages - $result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page1->ID.','.$page2->ID); + $result = $this->get('admin/pages/edit/updatetreenodes?ids=' . $page1->ID . ',' . $page2->ID); $this->assertEquals(200, $result->getStatusCode()); $this->assertEquals('application/json', $result->getHeader('Content-Type')); $data = json_decode($result->getBody() ?? '', true); diff --git a/tests/php/Controllers/ContentControllerPermissionsTest.php b/tests/php/Controllers/ContentControllerPermissionsTest.php index 714ce932..a1f19faa 100644 --- a/tests/php/Controllers/ContentControllerPermissionsTest.php +++ b/tests/php/Controllers/ContentControllerPermissionsTest.php @@ -6,7 +6,7 @@ use SilverStripe\Versioned\Versioned; use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Core\Config\Config; use SilverStripe\Dev\FunctionalTest; -use Page; +use SilverStripe\CMS\Model\SiteTree; class ContentControllerPermissionsTest extends FunctionalTest { @@ -17,7 +17,7 @@ class ContentControllerPermissionsTest extends FunctionalTest public function testCanViewStage() { // Create a new page - $page = new Page(); + $page = new SiteTree(); $page->URLSegment = 'testpage'; $page->write(); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); @@ -38,7 +38,11 @@ class ContentControllerPermissionsTest extends FunctionalTest $response = $responseException->getResponse(); } // should redirect to login - $this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage'); + $this->assertEquals( + $response->getStatusCode(), + 302, + 'Redirects to login page when not logged in for draft stage' + ); $this->assertStringContainsString( Config::inst()->get('SilverStripe\\Security\\Security', 'login_url'), $response->getHeader('Location') @@ -47,6 +51,10 @@ class ContentControllerPermissionsTest extends FunctionalTest $this->logInWithPermission('CMS_ACCESS_CMSMain'); $response = $this->get('/testpage/?stage=Stage'); - $this->assertEquals($response->getStatusCode(), 200, 'Doesnt redirect to login, but shows page for authenticated user'); + $this->assertEquals( + $response->getStatusCode(), + 200, + 'Doesnt redirect to login, but shows page for authenticated user' + ); } } diff --git a/tests/php/Controllers/ContentControllerSearchExtensionTest.php b/tests/php/Controllers/ContentControllerSearchExtensionTest.php index 181ad36f..8eae5f00 100644 --- a/tests/php/Controllers/ContentControllerSearchExtensionTest.php +++ b/tests/php/Controllers/ContentControllerSearchExtensionTest.php @@ -4,23 +4,23 @@ namespace SilverStripe\CMS\Tests\Controllers; use SilverStripe\Assets\File; use SilverStripe\CMS\Controllers\ContentController; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Search\ContentControllerSearchExtension; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\Search\FulltextSearchable; use SilverStripe\Versioned\Versioned; -use Page; class ContentControllerSearchExtensionTest extends SapphireTest { protected static $required_extensions = [ ContentController::class => [ ContentControllerSearchExtension::class, - ] + ], ]; public function testCustomSearchFormClassesToTest() { - $page = new Page(); + $page = new SiteTree(); $page->URLSegment = 'whatever'; $page->Content = 'oh really?'; $page->write(); diff --git a/tests/php/Controllers/ContentControllerTest.php b/tests/php/Controllers/ContentControllerTest.php old mode 100755 new mode 100644 index e6acd9b5..476a23f6 --- a/tests/php/Controllers/ContentControllerTest.php +++ b/tests/php/Controllers/ContentControllerTest.php @@ -10,7 +10,6 @@ use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Core\Config\Config; use SilverStripe\Dev\FunctionalTest; use SilverStripe\Versioned\Versioned; -use Page; class ContentControllerTest extends FunctionalTest { @@ -31,8 +30,8 @@ class ContentControllerTest extends FunctionalTest Config::modify()->set(SiteTree::class, 'nested_urls', true); // Ensure all pages are published - /** @var Page $page */ - foreach (Page::get() as $page) { + /** @var SiteTree $page */ + foreach (SiteTree::get() as $page) { $page->publishSingle(); } } @@ -95,8 +94,7 @@ class ContentControllerTest extends FunctionalTest public function testDeepNestedURLs() { - - $page = new Page(); + $page = new SiteTree(); $page->URLSegment = 'base-page'; $page->write(); $page->publishSingle(); @@ -174,7 +172,7 @@ class ContentControllerTest extends FunctionalTest $response = $this->get($page->RelativeLink()); $this->assertEquals("ContentControllerTestPageWithoutController", trim($response->getBody() ?? '')); - // // This should fall over to user Page.ss + // This should fall over to user Page.ss $page = new ContentControllerTestPage(); $page->URLSegment = "test"; $page->write(); diff --git a/tests/php/Controllers/ContentControllerTestPage.php b/tests/php/Controllers/ContentControllerTestPage.php index 0c67a3b7..21c5efe7 100644 --- a/tests/php/Controllers/ContentControllerTestPage.php +++ b/tests/php/Controllers/ContentControllerTestPage.php @@ -2,10 +2,10 @@ namespace SilverStripe\CMS\Tests\Controllers; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\TestOnly; -use Page; -class ContentControllerTestPage extends Page implements TestOnly +class ContentControllerTestPage extends SiteTree implements TestOnly { private static $table_name = 'ContentControllerTestPage'; } diff --git a/tests/php/Controllers/ContentControllerTestPageController.php b/tests/php/Controllers/ContentControllerTestPageController.php index 4badf487..d1c4d2a0 100644 --- a/tests/php/Controllers/ContentControllerTestPageController.php +++ b/tests/php/Controllers/ContentControllerTestPageController.php @@ -9,7 +9,7 @@ class ContentControllerTestPageController extends PageController implements Test { private static $allowed_actions = [ 'test', - 'testwithouttemplate' + 'testwithouttemplate', ]; public function testwithouttemplate() diff --git a/tests/php/Controllers/ContentControllerTestPageWithoutController.php b/tests/php/Controllers/ContentControllerTestPageWithoutController.php index 8c2eb9ee..c459a360 100644 --- a/tests/php/Controllers/ContentControllerTestPageWithoutController.php +++ b/tests/php/Controllers/ContentControllerTestPageWithoutController.php @@ -2,10 +2,9 @@ namespace SilverStripe\CMS\Tests\Controllers; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\TestOnly; -use Page; -class ContentControllerTestPageWithoutController extends Page implements TestOnly +class ContentControllerTestPageWithoutController extends SiteTree implements TestOnly { - } diff --git a/tests/php/Controllers/ContentControllerTest_Page.php b/tests/php/Controllers/ContentControllerTest_Page.php index d8116fca..d52cb6ea 100644 --- a/tests/php/Controllers/ContentControllerTest_Page.php +++ b/tests/php/Controllers/ContentControllerTest_Page.php @@ -2,10 +2,10 @@ namespace SilverStripe\CMS\Tests\Controllers; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\TestOnly; -use Page; -class ContentControllerTest_Page extends Page implements TestOnly +class ContentControllerTest_Page extends SiteTree implements TestOnly { private static $table_name = 'ContentControllerTest_Page'; } diff --git a/tests/php/Controllers/ContentControllerTest_PageController.php b/tests/php/Controllers/ContentControllerTest_PageController.php index 45b0264f..d4ab02b5 100644 --- a/tests/php/Controllers/ContentControllerTest_PageController.php +++ b/tests/php/Controllers/ContentControllerTest_PageController.php @@ -2,14 +2,13 @@ namespace SilverStripe\CMS\Tests\Controllers; +use SilverStripe\CMS\Controllers\ContentController; use SilverStripe\Dev\TestOnly; -use PageController; -class ContentControllerTest_PageController extends PageController implements TestOnly +class ContentControllerTest_PageController extends ContentController implements TestOnly { - private static $allowed_actions = [ - 'second_index' + 'second_index', ]; public function index() diff --git a/tests/php/Controllers/ModelAsControllerTest.php b/tests/php/Controllers/ModelAsControllerTest.php index 14693086..96af0fe8 100644 --- a/tests/php/Controllers/ModelAsControllerTest.php +++ b/tests/php/Controllers/ModelAsControllerTest.php @@ -10,7 +10,6 @@ use SilverStripe\Core\Config\Config; use SilverStripe\Control\Director; use SilverStripe\Control\Controller; use SilverStripe\Dev\FunctionalTest; -use Page; use SilverStripe\View\Parsers\URLSegmentFilter; class ModelAsControllerTest extends FunctionalTest @@ -34,7 +33,7 @@ class ModelAsControllerTest extends FunctionalTest protected function generateNestedPagesFixture() { - $level1 = new Page(); + $level1 = new SiteTree(); $level1->Title = 'First Level'; $level1->URLSegment = 'level1'; $level1->write(); @@ -44,7 +43,7 @@ class ModelAsControllerTest extends FunctionalTest $level1->write(); $level1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $level2 = new Page(); + $level2 = new SiteTree(); $level2->Title = 'Second Level'; $level2->URLSegment = 'level2'; $level2->ParentID = $level1->ID; @@ -55,7 +54,7 @@ class ModelAsControllerTest extends FunctionalTest $level2->write(); $level2->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $level3 = new Page(); + $level3 = new SiteTree(); $level3->Title = "Level 3"; $level3->URLSegment = 'level3'; $level3->ParentID = $level2->ID; @@ -115,7 +114,7 @@ class ModelAsControllerTest extends FunctionalTest */ public function testHeavilyNestedRenamedRedirectedPages() { - $page = new Page(); + $page = new SiteTree(); $page->Title = 'First Level'; $page->URLSegment = 'oldurl'; $page->write(); @@ -125,28 +124,28 @@ class ModelAsControllerTest extends FunctionalTest $page->write(); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $page2 = new Page(); + $page2 = new SiteTree(); $page2->Title = 'Second Level Page'; $page2->URLSegment = 'level2'; $page2->ParentID = $page->ID; $page2->write(); $page2->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $page3 = new Page(); + $page3 = new SiteTree(); $page3->Title = 'Third Level Page'; $page3->URLSegment = 'level3'; $page3->ParentID = $page2->ID; $page3->write(); $page3->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $page4 = new Page(); + $page4 = new SiteTree(); $page4->Title = 'Fourth Level Page'; $page4->URLSegment = 'level4'; $page4->ParentID = $page3->ID; $page4->write(); $page4->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $page5 = new Page(); + $page5 = new SiteTree(); $page5->Title = 'Fifth Level Page'; $page5->URLSegment = 'level5'; $page5->ParentID = $page4->ID; @@ -188,8 +187,8 @@ class ModelAsControllerTest extends FunctionalTest { $this->generateNestedPagesFixture(); - $otherParent = new Page([ - 'URLSegment' => 'otherparent' + $otherParent = new SiteTree([ + 'URLSegment' => 'otherparent', ]); $otherParent->write(); $otherParent->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); @@ -232,9 +231,9 @@ class ModelAsControllerTest extends FunctionalTest { $this->generateNestedPagesFixture(); - $otherLevel1 = new Page([ + $otherLevel1 = new SiteTree([ 'Title' => "Other Level 1", - 'URLSegment' => 'level1' + 'URLSegment' => 'level1', ]); $otherLevel1->write(); $otherLevel1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); @@ -260,7 +259,7 @@ class ModelAsControllerTest extends FunctionalTest */ public function testFindOldPage() { - $page = new Page(); + $page = new SiteTree(); $page->Title = 'First Level'; $page->URLSegment = 'oldurl'; $page->write(); @@ -274,7 +273,7 @@ class ModelAsControllerTest extends FunctionalTest $matchedPage = SiteTree::get_by_link($url); $this->assertEquals('First Level', $matchedPage->Title); - $page2 = new Page(); + $page2 = new SiteTree(); $page2->Title = 'Second Level Page'; $page2->URLSegment = 'oldpage2'; $page2->ParentID = $page->ID; @@ -304,12 +303,12 @@ class ModelAsControllerTest extends FunctionalTest RootURLController::reset(); Config::modify()->set(SiteTree::class, 'nested_urls', true); - $draft = new Page(); + $draft = new SiteTree(); $draft->Title = 'Root Leve Draft Page'; $draft->URLSegment = 'root'; $draft->write(); - $published = new Page(); + $published = new SiteTree(); $published->Title = 'Published Page Under Draft Page'; $published->URLSegment = 'sub-root'; $published->write(); @@ -319,7 +318,8 @@ class ModelAsControllerTest extends FunctionalTest $this->assertEquals( $response->getStatusCode(), 404, - 'The page should not be found since its parent has not been published, in this case http:///root/sub-root or http:///sub-root' + 'The page should not be found since its parent has not been published, in this case ' . + 'http:///root/sub-root or http:///sub-root' ); } @@ -327,13 +327,13 @@ class ModelAsControllerTest extends FunctionalTest { Config::modify()->set(URLSegmentFilter::class, 'default_allow_multibyte', true); - $parent = new Page(); + $parent = new SiteTree(); $parent->Title = 'Multibyte test'; $parent->URLSegment = 'بلاگ'; $parent->write(); $parent->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $child = new Page(); + $child = new SiteTree(); $child->Title = 'Multibyte test'; $child->URLSegment = 'فضة'; $child->ParentID = $parent->ID; diff --git a/tests/php/Controllers/RootURLControllerTest.php b/tests/php/Controllers/RootURLControllerTest.php index 54905083..ef5f0ef0 100644 --- a/tests/php/Controllers/RootURLControllerTest.php +++ b/tests/php/Controllers/RootURLControllerTest.php @@ -13,7 +13,7 @@ class RootURLControllerTest extends SapphireTest public function testGetHomepageLink() { - $default = $this->objFromFixture('Page', 'home'); + $default = $this->objFromFixture(SiteTree::class, 'home'); Config::modify()->set(SiteTree::class, 'nested_urls', false); $this->assertEquals('home', RootURLController::get_homepage_link()); diff --git a/tests/php/Controllers/RootURLControllerTest.yml b/tests/php/Controllers/RootURLControllerTest.yml index 99f0e523..cc3f8cdf 100644 --- a/tests/php/Controllers/RootURLControllerTest.yml +++ b/tests/php/Controllers/RootURLControllerTest.yml @@ -1,9 +1,9 @@ -Page: +SilverStripe\CMS\Model\SiteTree: home: Title: Home nested: Title: Nested Home - Parent: =>Page.home + Parent: =>SilverStripe\CMS\Model\SiteTree.home page1: Title: First Page URLSegment: page1 diff --git a/tests/php/Controllers/SilverStripeNavigatorTest.php b/tests/php/Controllers/SilverStripeNavigatorTest.php index 6e59bde3..1e799f64 100644 --- a/tests/php/Controllers/SilverStripeNavigatorTest.php +++ b/tests/php/Controllers/SilverStripeNavigatorTest.php @@ -8,7 +8,6 @@ use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_LiveLink; use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_StageLink; use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_Unversioned; use SilverStripe\Dev\SapphireTest; -use SilverStripe\Security\Member; class SilverStripeNavigatorTest extends SapphireTest { diff --git a/tests/php/GraphQL/LinkablePluginTest.php b/tests/php/GraphQL/LinkablePluginTest.php index 2687a393..10dfb9f4 100644 --- a/tests/php/GraphQL/LinkablePluginTest.php +++ b/tests/php/GraphQL/LinkablePluginTest.php @@ -44,7 +44,7 @@ class LinkablePluginTest extends SapphireTest public function testResolver() { - $page = SiteTree::create([ + $page = new SiteTree([ 'Title' => 'Test page', 'URLSegment' => 'test-page', 'ParentID' => 0, @@ -52,7 +52,7 @@ class LinkablePluginTest extends SapphireTest $page->write(); $page->publishRecursive(); - $page = SiteTree::create([ + $page = new SiteTree([ 'Title' => 'Other test page', 'URLSegment' => 'other-test-page', 'ParentID' => 0, diff --git a/tests/php/Model/RedirectorPageTest.php b/tests/php/Model/RedirectorPageTest.php index b49998c8..ecfe793f 100644 --- a/tests/php/Model/RedirectorPageTest.php +++ b/tests/php/Model/RedirectorPageTest.php @@ -2,7 +2,7 @@ namespace SilverStripe\CMS\Tests\Model; -use Page; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\RedirectorPageController; use SilverStripe\Control\Director; @@ -36,31 +36,41 @@ class RedirectorPageTest extends FunctionalTest Director::config()->update('alternate_base_url', 'http://www.mysite.com/'); // Ensure all pages are published - /** @var Page $page */ - foreach (Page::get() as $page) { + /** @var SiteTree $page */ + foreach (SiteTree::get() as $page) { $page->publishSingle(); } } public function testGoodRedirectors() { - /* For good redirectors, the final destination URL will be returned */ - $this->assertEquals("http://www.google.com", $this->objFromFixture(RedirectorPage::class, 'goodexternal')->Link()); - $this->assertEquals("/redirection-dest/", $this->objFromFixture(RedirectorPage::class, 'goodinternal')->redirectionLink()); - $this->assertEquals("/redirection-dest/", $this->objFromFixture(RedirectorPage::class, 'goodinternal')->Link()); + // For good redirectors, the final destination URL will be returned + $this->assertEquals( + "http://www.google.com", + $this->objFromFixture(RedirectorPage::class, 'goodexternal')->Link() + ); + $this->assertEquals( + "/redirection-dest/", + $this->objFromFixture(RedirectorPage::class, 'goodinternal')->redirectionLink() + ); + $this->assertEquals( + "/redirection-dest/", + $this->objFromFixture(RedirectorPage::class, 'goodinternal')->Link() + ); } public function testEmptyRedirectors() { - /* If a redirector page is misconfigured, then its link method will just return the usual URLSegment-generated value */ + // If a redirector page is misconfigured, then its link method will just return the usual + // URLSegment-generated value $page1 = $this->objFromFixture(RedirectorPage::class, 'badexternal'); $this->assertEquals('/bad-external/', $page1->Link()); - /* An error message will be shown if you visit it */ + // An error message will be shown if you visit it $content = $this->get(Director::makeRelative($page1->Link()))->getBody(); $this->assertStringContainsString('message-setupWithoutRedirect', $content); - /* This also applies for internal links */ + // This also applies for internal links $page2 = $this->objFromFixture(RedirectorPage::class, 'badinternal'); $this->assertEquals('/bad-internal/', $page2->Link()); $content = $this->get(Director::makeRelative($page2->Link()))->getBody(); @@ -69,14 +79,16 @@ class RedirectorPageTest extends FunctionalTest public function testReflexiveAndTransitiveInternalRedirectors() { - /* Reflexive redirectors are those that point to themselves. They should behave the same as an empty redirector */ + // Reflexive redirectors are those that point to themselves. + // They should behave the same as an empty redirector $page = $this->objFromFixture(RedirectorPage::class, 'reflexive'); $this->assertEquals('/reflexive/', $page->Link()); $content = $this->get(Director::makeRelative($page->Link()))->getBody(); $this->assertStringContainsString('message-setupWithoutRedirect', $content); - /* Transitive redirectors are those that point to another redirector page. They should send people to the URLSegment - * of the destination page - the middle-stop, so to speak. That should redirect to the final destination */ + // Transitive redirectors are those that point to another redirector page. + // They should send people to the URLSegment of the destination page - the middle-stop, so to speak. + // That should redirect to the final destination $page = $this->objFromFixture(RedirectorPage::class, 'transitive'); $this->assertEquals('/good-internal/', $page->Link()); @@ -90,7 +102,11 @@ class RedirectorPageTest extends FunctionalTest $page = $this->objFromFixture(RedirectorPage::class, 'externalnoprefix'); $this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite has prefixed with http'); $page->write(); - $this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite will not double prefix if written again!'); + $this->assertEquals( + $page->ExternalURL, + 'http://google.com', + 'onBeforeWrite will not double prefix if written again!' + ); } public function testAllowsProtocolRelative() diff --git a/tests/php/Model/RedirectorPageTest.yml b/tests/php/Model/RedirectorPageTest.yml index a1a2d018..91f7b31b 100644 --- a/tests/php/Model/RedirectorPageTest.yml +++ b/tests/php/Model/RedirectorPageTest.yml @@ -1,4 +1,4 @@ -Page: +SilverStripe\CMS\Model\SiteTree: dest: Title: Redirection Dest URLSegment: redirection-dest @@ -17,7 +17,7 @@ SilverStripe\CMS\Model\RedirectorPage: Title: Good Internal URLSegment: good-internal RedirectionType: Internal - LinkTo: =>Page.dest + LinkTo: =>SilverStripe\CMS\Model\SiteTree.dest badexternal: Title: Bad External RedirectionType: External diff --git a/tests/php/Model/SiteTreeActionsTest.php b/tests/php/Model/SiteTreeActionsTest.php index bb6845ae..2786e271 100644 --- a/tests/php/Model/SiteTreeActionsTest.php +++ b/tests/php/Model/SiteTreeActionsTest.php @@ -2,7 +2,6 @@ namespace SilverStripe\CMS\Tests\Model; -use Page; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\FunctionalTest; use SilverStripe\ORM\DB; @@ -21,7 +20,6 @@ use SilverStripe\Versioned\Versioned; */ class SiteTreeActionsTest extends FunctionalTest { - protected static $fixture_file = 'SiteTreeActionsTest.yml'; public function testActionsReadonly() @@ -38,7 +36,7 @@ class SiteTreeActionsTest extends FunctionalTest Security::setCurrentUser($readonlyEditor); // Reload latest version - $page = Page::get()->byID($page->ID); + $page = SiteTree::get()->byID($page->ID); $actions = $page->getCMSActions(); $this->assertNull($actions->dataFieldByName('action_save')); @@ -84,14 +82,14 @@ class SiteTreeActionsTest extends FunctionalTest $author = $this->objFromFixture(Member::class, 'cmseditor'); Security::setCurrentUser($author); - /** @var Page $page */ - $page = new Page(); + /** @var SiteTree $page */ + $page = new SiteTree(); $page->CanEditType = 'LoggedInUsers'; $page->write(); $page->publishRecursive(); // Reload latest version - $page = Page::get()->byID($page->ID); + $page = SiteTree::get()->byID($page->ID); $actions = $page->getCMSActions(); @@ -108,7 +106,7 @@ class SiteTreeActionsTest extends FunctionalTest $author = $this->objFromFixture(Member::class, 'cmseditor'); Security::setCurrentUser($author); - $page = new Page(); + $page = new SiteTree(); $page->CanEditType = 'LoggedInUsers'; $page->write(); $this->assertTrue($page->canPublish()); @@ -135,7 +133,7 @@ class SiteTreeActionsTest extends FunctionalTest $author = $this->objFromFixture(Member::class, 'cmseditor'); Security::setCurrentUser($author); - $page = new Page(); + $page = new SiteTree(); $page->CanEditType = 'LoggedInUsers'; $page->write(); $this->assertTrue($page->canPublish()); @@ -145,7 +143,7 @@ class SiteTreeActionsTest extends FunctionalTest $page->flushCache(); // Reload latest version - $page = Page::get()->byID($page->ID); + $page = SiteTree::get()->byID($page->ID); $actions = $page->getCMSActions(); $this->assertNotNull($actions->dataFieldByName('action_save')); @@ -158,15 +156,17 @@ class SiteTreeActionsTest extends FunctionalTest public function testActionsViewingOldVersion() { - $p = new Page(); + $p = new SiteTree(); $p->Content = 'test page first version'; $p->write(); $p->Content = 'new content'; $p->write(); // Looking at the old version, the ability to rollback to that version is available - $version = DB::query('SELECT "Version" FROM "SiteTree_Versions" WHERE "Content" = \'test page first version\'')->value(); - $old = Versioned::get_version('Page', $p->ID, $version); + $version = DB::query( + 'SELECT "Version" FROM "SiteTree_Versions" WHERE "Content" = \'test page first version\'' + )->value(); + $old = Versioned::get_version(SiteTree::class, $p->ID, $version); $actions = $old->getCMSActions(); $this->assertNull($actions->dataFieldByName('action_save')); $this->assertNull($actions->dataFieldByName('action_publish')); diff --git a/tests/php/Model/SiteTreeActionsTest_Page.php b/tests/php/Model/SiteTreeActionsTest_Page.php index 4daac101..8b4728ec 100644 --- a/tests/php/Model/SiteTreeActionsTest_Page.php +++ b/tests/php/Model/SiteTreeActionsTest_Page.php @@ -4,9 +4,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; use SilverStripe\Security\Permission; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class SiteTreeActionsTest_Page extends Page implements TestOnly +class SiteTreeActionsTest_Page extends SiteTree implements TestOnly { public function canEdit($member = null) { diff --git a/tests/php/Model/SiteTreeBacklinksTest.php b/tests/php/Model/SiteTreeBacklinksTest.php index 927586db..d6b7e4b2 100644 --- a/tests/php/Model/SiteTreeBacklinksTest.php +++ b/tests/php/Model/SiteTreeBacklinksTest.php @@ -18,7 +18,7 @@ class SiteTreeBacklinksTest extends SapphireTest protected static $required_extensions = [ SiteTree::class => [ - SiteTreeBacklinksTest_DOD::class + SiteTreeBacklinksTest_DOD::class, ], ]; @@ -34,10 +34,10 @@ class SiteTreeBacklinksTest extends SapphireTest // testing here. $this->logInWithPermission('ADMIN'); - $page3 = $this->objFromFixture('Page', 'page3'); + $page3 = $this->objFromFixture(SiteTree::class, 'page3'); $page3->Content = str_replace( '$page1.ID', - $this->objFromFixture('Page', 'page1')->ID ?? '', + $this->objFromFixture(SiteTree::class, 'page1')->ID ?? '', $page3->Content ?? '' ); $page3->write(); @@ -46,18 +46,22 @@ class SiteTreeBacklinksTest extends SapphireTest public function testSavingPageWithLinkAddsBacklink() { // load page 1 - $page1 = $this->objFromFixture('Page', 'page1'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); // assert backlink to page 2 doesn't exist - $page2 = $this->objFromFixture('Page', 'page2'); - $this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 doesn\'t exist'); + $page2 = $this->objFromFixture(SiteTree::class, 'page2'); + $this->assertNotContains( + $page2->ID, + $page1->BackLinkTracking()->column('ID'), + 'Assert backlink to page 2 doesn\'t exist' + ); // add hyperlink to page 1 on page 2 - $page2->Content .= '

Testing page 1 link

'; + $page2->Content .= '

Testing page 1 link

'; $page2->write(); // load page 1 - $page1 = $this->objFromFixture('Page', 'page1'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); // assert backlink to page 2 exists $this->assertContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 exists'); @@ -66,10 +70,10 @@ class SiteTreeBacklinksTest extends SapphireTest public function testRemovingLinkFromPageRemovesBacklink() { // load page 1 - $page1 = $this->objFromFixture('Page', 'page1'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); // assert backlink to page 3 exits - $page3 = $this->objFromFixture('Page', 'page3'); + $page3 = $this->objFromFixture(SiteTree::class, 'page3'); $this->assertContains($page3->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 3 exists'); // remove hyperlink to page 1 @@ -77,116 +81,156 @@ class SiteTreeBacklinksTest extends SapphireTest $page3->write(); // load page 1 - $page1 = $this->objFromFixture('Page', 'page1'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); // assert backlink to page 3 exists - $this->assertNotContains($page3->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 3 doesn\'t exist'); + $this->assertNotContains( + $page3->ID, + $page1->BackLinkTracking()->column('ID'), + 'Assert backlink to page 3 doesn\'t exist' + ); } public function testChangingUrlOnDraftSiteRewritesLink() { // load page 1 - $page1 = $this->objFromFixture('Page', 'page1'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); // assert backlink to page 3 exists - $page3 = $this->objFromFixture('Page', 'page3'); + $page3 = $this->objFromFixture(SiteTree::class, 'page3'); $this->assertContains($page3->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 3 exists'); // assert hyperlink to page 1's current url exists on page 3 $links = HTTP::getLinksIn($page3->obj('Content')->forTemplate()); - $this->assertContains(Director::baseURL().'page1/', $links, 'Assert hyperlink to page 1\'s current url exists on page 3'); + $this->assertContains( + Director::baseURL() . 'page1/', + $links, + 'Assert hyperlink to page 1\'s current url exists on page 3' + ); // change url of page 1 $page1->URLSegment = 'new-url-segment'; $page1->write(); // load page 3 - $page3 = $this->objFromFixture('Page', 'page3'); + $page3 = $this->objFromFixture(SiteTree::class, 'page3'); // assert hyperlink to page 1's new url exists $links = HTTP::getLinksIn($page3->obj('Content')->forTemplate()); - $this->assertContains(Director::baseURL().'new-url-segment/', $links, 'Assert hyperlink to page 1\'s new url exists on page 3'); + $this->assertContains( + Director::baseURL() . 'new-url-segment/', + $links, + 'Assert hyperlink to page 1\'s new url exists on page 3' + ); } public function testChangingUrlOnLiveSiteRewritesLink() { // publish page 1 & 3 - $page1 = $this->objFromFixture('Page', 'page1'); - $page3 = $this->objFromFixture('Page', 'page3'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); + $page3 = $this->objFromFixture(SiteTree::class, 'page3'); $this->assertTrue($page1->publishRecursive()); $this->assertTrue($page3->publishRecursive()); // load pages from live - $page1live = Versioned::get_one_by_stage('Page', 'Live', '"SiteTree"."ID" = ' . $page1->ID); - $page3live = Versioned::get_one_by_stage('Page', 'Live', '"SiteTree"."ID" = ' . $page3->ID); + $page1live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page1->ID); + $page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID); // assert backlink to page 3 exists - $this->assertContains($page3live->ID, $page1live->BackLinkTracking()->column('ID'), 'Assert backlink to page 3 exists'); + $this->assertContains( + $page3live->ID, + $page1live->BackLinkTracking()->column('ID'), + 'Assert backlink to page 3 exists' + ); // assert hyperlink to page 1's current url exists on page 3 $links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); - $this->assertContains(Director::baseURL().'page1/', $links, 'Assert hyperlink to page 1\'s current url exists on page 3'); + $this->assertContains( + Director::baseURL() . 'page1/', + $links, + 'Assert hyperlink to page 1\'s current url exists on page 3' + ); // change url of page 1 $page1live->URLSegment = 'new-url-segment'; $page1live->writeToStage('Live'); // load page 3 from live - $page3live = Versioned::get_one_by_stage('Page', 'Live', '"SiteTree"."ID" = ' . $page3->ID); + $page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID); // assert hyperlink to page 1's new url exists Versioned::set_stage(Versioned::LIVE); $links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); - $this->assertContains(Director::baseURL().'new-url-segment/', $links, 'Assert hyperlink to page 1\'s new url exists on page 3'); + $this->assertContains( + Director::baseURL() . 'new-url-segment/', + $links, + 'Assert hyperlink to page 1\'s new url exists on page 3' + ); } public function testPublishingPageWithModifiedUrlRewritesLink() { // publish page 1 & 3 - $page1 = $this->objFromFixture('Page', 'page1'); - $page3 = $this->objFromFixture('Page', 'page3'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); + $page3 = $this->objFromFixture(SiteTree::class, 'page3'); $this->assertTrue($page1->publishRecursive()); $this->assertTrue($page3->publishRecursive()); // load page 3 from live - $page3live = Versioned::get_one_by_stage('Page', 'Live', '"SiteTree"."ID" = ' . $page3->ID); + $page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID); // assert hyperlink to page 1's current url exists $links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); - $this->assertContains(Director::baseURL().'page1/', $links, 'Assert hyperlink to page 1\'s current url exists on page 3'); + $this->assertContains( + Director::baseURL() . 'page1/', + $links, + 'Assert hyperlink to page 1\'s current url exists on page 3' + ); // rename url of page 1 on stage $page1->URLSegment = 'new-url-segment'; $page1->write(); // assert hyperlink to page 1's current publish url exists - $page3live = Versioned::get_one_by_stage('Page', 'Live', '"SiteTree"."ID" = ' . $page3->ID); + $page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID); Versioned::set_stage(Versioned::LIVE); $links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); - $this->assertContains(Director::baseURL().'page1/', $links, 'Assert hyperlink to page 1\'s current published url exists on page 3'); + $this->assertContains( + Director::baseURL() . 'page1/', + $links, + 'Assert hyperlink to page 1\'s current published url exists on page 3' + ); // publish page 1 $this->assertTrue($page1->publishRecursive()); // assert hyperlink to page 1's new published url exists - $page3live = Versioned::get_one_by_stage('Page', 'Live', '"SiteTree"."ID" = ' . $page3->ID); + $page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID); $links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); - $this->assertContains(Director::baseURL().'new-url-segment/', $links, 'Assert hyperlink to page 1\'s new published url exists on page 3'); + $this->assertContains( + Director::baseURL() . 'new-url-segment/', + $links, + 'Assert hyperlink to page 1\'s new published url exists on page 3' + ); } public function testPublishingPageWithModifiedLinksRewritesLinks() { // publish page 1 & 3 - $page1 = $this->objFromFixture('Page', 'page1'); - $page3 = $this->objFromFixture('Page', 'page3'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); + $page3 = $this->objFromFixture(SiteTree::class, 'page3'); $this->assertTrue($page1->publishRecursive()); $this->assertTrue($page3->publishRecursive()); // assert hyperlink to page 1's current url exists $links = HTTP::getLinksIn($page3->obj('Content')->forTemplate()); - $this->assertContains(Director::baseURL().'page1/', $links, 'Assert hyperlink to page 1\'s current published url exists on page 3'); + $this->assertContains( + Director::baseURL() . 'page1/', + $links, + 'Assert hyperlink to page 1\'s current published url exists on page 3' + ); // change page 1 url on draft $page1->URLSegment = 'new-url-segment'; @@ -195,42 +239,58 @@ class SiteTreeBacklinksTest extends SapphireTest $page1->write(); // assert page 3 on draft contains new page 1 url - $page3 = $this->objFromFixture('Page', 'page3'); + $page3 = $this->objFromFixture(SiteTree::class, 'page3'); $links = HTTP::getLinksIn($page3->obj('Content')->forTemplate()); - $this->assertContains(Director::baseURL().'new-url-segment/', $links, 'Assert hyperlink to page 1\'s current draft url exists on page 3'); + $this->assertContains( + Director::baseURL() . 'new-url-segment/', + $links, + 'Assert hyperlink to page 1\'s current draft url exists on page 3' + ); // publish page 3 $this->assertTrue($page3->publishRecursive()); // assert page 3 on published site contains old page 1 url - $page3live = Versioned::get_one_by_stage('Page', 'Live', '"SiteTree"."ID" = ' . $page3->ID); + $page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID); Versioned::set_stage(Versioned::LIVE); $links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); - $this->assertContains(Director::baseURL().'page1/', $links, 'Assert hyperlink to page 1\'s current published url exists on page 3'); + $this->assertContains( + Director::baseURL() . 'page1/', + $links, + 'Assert hyperlink to page 1\'s current published url exists on page 3' + ); // publish page 1 $this->assertTrue($page1->publishRecursive()); // assert page 3 on published site contains new page 1 url - $page3live = Versioned::get_one_by_stage('Page', 'Live', '"SiteTree"."ID" = ' . $page3->ID); + $page3live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page3->ID); $links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); - $this->assertContains(Director::baseURL().'new-url-segment/', $links, 'Assert hyperlink to page 1\'s current published url exists on page 3'); + $this->assertContains( + Director::baseURL() . 'new-url-segment/', + $links, + 'Assert hyperlink to page 1\'s current published url exists on page 3' + ); } public function testLinkTrackingOnExtraContentFields() { - /** @var Page $page1 */ - $page1 = $this->objFromFixture('Page', 'page1'); - /** @var Page $page2 */ - $page2 = $this->objFromFixture('Page', 'page2'); + /** @var SiteTree $page1 */ + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); + /** @var SiteTree $page2 */ + $page2 = $this->objFromFixture(SiteTree::class, 'page2'); $page1->publishRecursive(); $page2->publishRecursive(); // assert backlink to page 2 doesn't exist - $this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 doesn\'t exist'); + $this->assertNotContains( + $page2->ID, + $page1->BackLinkTracking()->column('ID'), + 'Assert backlink to page 2 doesn\'t exist' + ); // add hyperlink to page 1 on page 2 - $page2->ExtraContent .= '

Testing page 1 link

'; + $page2->ExtraContent .= '

Testing page 1 link

'; $page2->write(); $page2->publishRecursive(); @@ -238,23 +298,32 @@ class SiteTreeBacklinksTest extends SapphireTest $this->assertContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 exists'); // update page1 url - $page1 = $this->objFromFixture('Page', 'page1'); + $page1 = $this->objFromFixture(SiteTree::class, 'page1'); $page1->URLSegment = "page1-new-url"; $page1->write(); // confirm that draft link on page2 has been rewritten - $page2 = $this->objFromFixture('Page', 'page2'); - $this->assertEquals('

Testing page 1 link

', $page2->obj('ExtraContent')->forTemplate()); + $page2 = $this->objFromFixture(SiteTree::class, 'page2'); + $this->assertEquals( + '

Testing page 1 link

', + $page2->obj('ExtraContent')->forTemplate() + ); // confirm that published link hasn't - $page2Live = Versioned::get_one_by_stage("Page", "Live", "\"SiteTree\".\"ID\" = $page2->ID"); + $page2Live = Versioned::get_one_by_stage(SiteTree::class, "Live", "\"SiteTree\".\"ID\" = $page2->ID"); Versioned::set_stage(Versioned::LIVE); - $this->assertEquals('

Testing page 1 link

', $page2Live->obj('ExtraContent')->forTemplate()); + $this->assertEquals( + '

Testing page 1 link

', + $page2Live->obj('ExtraContent')->forTemplate() + ); // publish page1 and confirm that the link on the published page2 has now been updated $page1->publishRecursive(); - $page2Live = Versioned::get_one_by_stage("Page", "Live", "\"SiteTree\".\"ID\" = $page2->ID"); - $this->assertEquals('

Testing page 1 link

', $page2Live->obj('ExtraContent')->forTemplate()); + $page2Live = Versioned::get_one_by_stage(SiteTree::class, "Live", "\"SiteTree\".\"ID\" = $page2->ID"); + $this->assertEquals( + '

Testing page 1 link

', + $page2Live->obj('ExtraContent')->forTemplate() + ); // Edit draft again Versioned::set_stage(Versioned::DRAFT); @@ -262,12 +331,16 @@ class SiteTreeBacklinksTest extends SapphireTest $page2->write(); // assert backlink to page 2 no longer exists - $this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 has been removed'); + $this->assertNotContains( + $page2->ID, + $page1->BackLinkTracking()->column('ID'), + 'Assert backlink to page 2 has been removed' + ); } public function testLinkTrackingWithUntitledObjectsDisplaysAReadableIdentifier() { - $page = $this->objFromFixture('Page', 'page2'); + $page = $this->objFromFixture(SiteTree::class, 'page2'); $referencingObject = new SiteTreeBacklinksTestContentObject(); $referencingObject->Content = '

Testing page 1 link

' - LinkTracking: =>Page.page1 + LinkTracking: =>SilverStripe\CMS\Model\SiteTree.page1 diff --git a/tests/php/Model/SiteTreeBrokenLinksTest.php b/tests/php/Model/SiteTreeBrokenLinksTest.php index 0d69f96b..9caa0766 100644 --- a/tests/php/Model/SiteTreeBrokenLinksTest.php +++ b/tests/php/Model/SiteTreeBrokenLinksTest.php @@ -2,7 +2,6 @@ namespace SilverStripe\CMS\Tests\Model; -use Page; use Silverstripe\Assets\Dev\TestAssetStore; use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\SiteTree; @@ -42,15 +41,15 @@ class SiteTreeBrokenLinksTest extends SapphireTest public function testBrokenLinksBetweenPages() { - /** @var Page $obj */ - $obj = $this->objFromFixture('Page', 'content'); + /** @var SiteTree $obj */ + $obj = $this->objFromFixture(SiteTree::class, 'content'); $obj->Content = 'this is a broken link'; $obj->syncLinkTracking(); $this->assertTrue($obj->HasBrokenLink, 'Page has a broken link'); $obj->Content = 'this is not a broken link'; $obj->syncLinkTracking(); @@ -62,8 +61,8 @@ class SiteTreeBrokenLinksTest extends SapphireTest */ public function testBrokenLinksNonPage() { - /** @var Page $aboutPage */ - $aboutPage = $this->objFromFixture('Page', 'about'); + /** @var SiteTree $aboutPage */ + $aboutPage = $this->objFromFixture(SiteTree::class, 'about'); /** @var NotPageObject $obj */ $obj = $this->objFromFixture(NotPageObject::class, 'object1'); @@ -94,7 +93,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest // About-page backlinks contains this object $this->assertListEquals( [ - ['ID' => $obj->ID] + ['ID' => $obj->ID], ], $aboutPage->BackLinkTracking() ); @@ -102,9 +101,9 @@ class SiteTreeBrokenLinksTest extends SapphireTest public function testBrokenAnchorBetweenPages() { - /** @var Page $obj */ - $obj = $this->objFromFixture('Page', 'content'); - $target = $this->objFromFixture('Page', 'about'); + /** @var SiteTree $obj */ + $obj = $this->objFromFixture(SiteTree::class, 'content'); + $target = $this->objFromFixture(SiteTree::class, 'about'); $obj->Content = "ID}]#no-anchor-here\">this is a broken link"; $obj->syncLinkTracking(); @@ -117,7 +116,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest public function testBrokenVirtualPages() { - $obj = $this->objFromFixture('Page', 'content'); + $obj = $this->objFromFixture(SiteTree::class, 'content'); $vp = new VirtualPage(); $vp->CopyContentFromID = $obj->ID; @@ -131,7 +130,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest public function testBrokenInternalRedirectorPages() { - $obj = $this->objFromFixture('Page', 'content'); + $obj = $this->objFromFixture(SiteTree::class, 'content'); $rp = new RedirectorPage(); $rp->RedirectionType = 'Internal'; @@ -148,10 +147,10 @@ class SiteTreeBrokenLinksTest extends SapphireTest public function testDeletingMarksBackLinkedPagesAsBroken() { // Set up two published pages with a link from content -> about - $linkDest = $this->objFromFixture('Page', 'about'); + $linkDest = $this->objFromFixture(SiteTree::class, 'about'); - /** @var Page $linkSrc */ - $linkSrc = $this->objFromFixture('Page', 'content'); + /** @var SiteTree $linkSrc */ + $linkSrc = $this->objFromFixture(SiteTree::class, 'content'); $linkSrc->Content = "

ID]\">about us

"; $linkSrc->write(); @@ -163,7 +162,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest // Confirm draft has broken link $linkSrc->flushCache(); - $linkSrc = $this->objFromFixture('Page', 'content'); + $linkSrc = $this->objFromFixture(SiteTree::class, 'content'); $this->assertEquals(1, (int)$linkSrc->HasBrokenLink); } @@ -173,13 +172,13 @@ class SiteTreeBrokenLinksTest extends SapphireTest $this->logInWithPermission('ADMIN'); // Set up two draft pages with a link from content -> about - /** @var Page $linkDest */ - $linkDest = $this->objFromFixture('Page', 'about'); + /** @var SiteTree $linkDest */ + $linkDest = $this->objFromFixture(SiteTree::class, 'about'); // Ensure that it's not on the published site $linkDest->doUnpublish(); - /** @var Page $linkSrc */ - $linkSrc = $this->objFromFixture('Page', 'content'); + /** @var SiteTree $linkSrc */ + $linkSrc = $this->objFromFixture(SiteTree::class, 'content'); $linkSrc->Content = "

ID]\">about us

"; $linkSrc->write(); @@ -191,20 +190,20 @@ class SiteTreeBrokenLinksTest extends SapphireTest // Live doesn't have separate broken link tracking $this->assertEquals(0, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\" - WHERE \"ID\" = $linkSrc->ID")->value()); + WHERE \"ID\" = $linkSrc->ID")->value()); } public function testRestoreFixesBrokenLinks() { // Create page and virtual page - $p = new Page(); + $p = new SiteTree(); $p->Title = "source"; $p->write(); $pageID = $p->ID; $this->assertTrue($p->publishRecursive()); // Content links are one kind of link to pages - $p2 = new Page(); + $p2 = new SiteTree(); $p2->Title = "regular link"; $p2->Content = "ID]\">test"; $p2->write(); @@ -264,14 +263,14 @@ class SiteTreeBrokenLinksTest extends SapphireTest public function testRevertToLiveFixesBrokenLinks() { // Create page and virutal page - $page = new Page(); + $page = new SiteTree(); $page->Title = "source"; $page->write(); $pageID = $page->ID; $this->assertTrue($page->publishRecursive()); // Content links are one kind of link to pages - $page2 = new Page(); + $page2 = new SiteTree(); $page2->Title = "regular link"; $page2->Content = "test"; $page2->write(); @@ -302,7 +301,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest $this->assertEquals(1, $redirectorPage->HasBrokenLink); // Call doRevertToLive and confirm that broken links are restored - /** @var Page $pageLive */ + /** @var SiteTree $pageLive */ $pageLive = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $pageID); $pageLive->doRevertToLive(); @@ -316,15 +315,17 @@ class SiteTreeBrokenLinksTest extends SapphireTest public function testBrokenAnchorLinksInAPage() { - /** @var Page $obj */ - $obj = $this->objFromFixture('Page', 'content'); + /** @var SiteTree $obj */ + $obj = $this->objFromFixture(SiteTree::class, 'content'); $origContent = $obj->Content; - $obj->Content = $origContent . 'this links to a non-existent in-page anchor or skiplink'; + $obj->Content = $origContent . 'this links to a non-existent in-page anchor or ' . + 'skiplink'; $obj->syncLinkTracking(); $this->assertTrue($obj->HasBrokenLink, 'Page has a broken anchor/skiplink'); - $obj->Content = $origContent . 'this links to an existent in-page anchor/skiplink'; + $obj->Content = $origContent . 'this links to an existent in-page ' . + 'anchor/skiplink'; $obj->syncLinkTracking(); $this->assertFalse($obj->HasBrokenLink, 'Page doesn\'t have a broken anchor or skiplink'); } diff --git a/tests/php/Model/SiteTreeBrokenLinksTest.yml b/tests/php/Model/SiteTreeBrokenLinksTest.yml index 4e062f5b..71e7ad6a 100644 --- a/tests/php/Model/SiteTreeBrokenLinksTest.yml +++ b/tests/php/Model/SiteTreeBrokenLinksTest.yml @@ -1,4 +1,4 @@ -Page: +SilverStripe\CMS\Model\SiteTree: content: Title: ContentPage Content: 'This is some partially happy content. It has one missing a skiplink, but does have another skiplink here.' @@ -13,7 +13,7 @@ Page: workingInternalRedirector: RedirectionType: Internal Title: RedirectorPageToBrokenInteralPage - LinkTo: =>Page.content + LinkTo: =>SilverStripe\CMS\Model\SiteTree.content SilverStripe\CMS\Tests\Model\SiteTreeBrokenLinksTest\NotPageObject: object1: Content: 'Everything will be ok' diff --git a/tests/php/Model/SiteTreeHTMLEditorFieldTest.php b/tests/php/Model/SiteTreeHTMLEditorFieldTest.php index d2324b45..909fe4a4 100644 --- a/tests/php/Model/SiteTreeHTMLEditorFieldTest.php +++ b/tests/php/Model/SiteTreeHTMLEditorFieldTest.php @@ -2,7 +2,6 @@ namespace SilverStripe\CMS\Tests\Model; -use Page; use SilverStripe\Assets\Dev\TestAssetStore; use SilverStripe\Assets\File; use SilverStripe\Assets\Filesystem; @@ -31,8 +30,8 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest } // Ensure all pages are published - /** @var Page $page */ - foreach (Page::get() as $page) { + /** @var SiteTree $page */ + foreach (SiteTree::get() as $page) { $page->publishSingle(); } } @@ -55,7 +54,11 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest $editor->setValue("Example Link"); $editor->saveInto($sitetree); $sitetree->write(); - $this->assertEquals([$aboutID => $aboutID], $sitetree->LinkTracking()->getIdList(), 'Basic link tracking works.'); + $this->assertEquals( + [$aboutID => $aboutID], + $sitetree->LinkTracking()->getIdList(), + 'Basic link tracking works.' + ); $editor->setValue( "" diff --git a/tests/php/Model/SiteTreeLinkTrackingTest.php b/tests/php/Model/SiteTreeLinkTrackingTest.php index 4247eee1..54dab077 100644 --- a/tests/php/Model/SiteTreeLinkTrackingTest.php +++ b/tests/php/Model/SiteTreeLinkTrackingTest.php @@ -2,7 +2,6 @@ namespace SilverStripe\CMS\Tests\Model; -use Page; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTreeLinkTracking_Parser; use SilverStripe\Control\Director; @@ -32,7 +31,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest public function testParser() { - SiteTree::add_extension(Page::class, SiteTreeLinkTracking_Extension::class); + SiteTree::add_extension(SiteTree::class, SiteTreeLinkTracking_Extension::class); // Shortcodes $this->assertTrue($this->isBroken('link')); @@ -55,8 +54,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest $this->assertFalse($this->isBroken('anchor')); $this->assertTrue($this->isBroken('anchor')); - - $page = new Page(); + $page = new SiteTree(); $page->Content = 'nameid'; $page->write(); @@ -72,7 +70,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest protected function highlight($content) { - $page = new Page(); + $page = new SiteTree(); $page->Content = $content; $page->write(); return $page->Content; @@ -87,7 +85,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest $content = $this->highlight('link'); $this->assertEquals(substr_count($content ?? '', 'ss-broken'), 1, 'ss-broken class is added to the broken link.'); - $otherPage = new Page(); + $otherPage = new SiteTree(); $otherPage->Content = ''; $otherPage->write(); diff --git a/tests/php/Model/SiteTreePermissionsTest.php b/tests/php/Model/SiteTreePermissionsTest.php index 24f1cb2b..b4229473 100644 --- a/tests/php/Model/SiteTreePermissionsTest.php +++ b/tests/php/Model/SiteTreePermissionsTest.php @@ -2,7 +2,6 @@ namespace SilverStripe\CMS\Tests\Model; -use Page; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Dev\FunctionalTest; @@ -33,8 +32,8 @@ class SiteTreePermissionsTest extends FunctionalTest $this->autoFollowRedirection = false; // Ensure all pages are published - /** @var Page $page */ - foreach (Page::get() as $page) { + /** @var SiteTree $page */ + foreach (SiteTree::get() as $page) { if ($page->URLSegment !== 'draft-only') { $page->publishSingle(); } @@ -46,8 +45,8 @@ class SiteTreePermissionsTest extends FunctionalTest { $this->autoFollowRedirection = false; - /** @var Page $draftOnlyPage */ - $draftOnlyPage = $this->objFromFixture(Page::class, 'draftOnlyPage'); + /** @var SiteTree $draftOnlyPage */ + $draftOnlyPage = $this->objFromFixture(SiteTree::class, 'draftOnlyPage'); $this->logOut(); $response = $this->get($draftOnlyPage->URLSegment . '?stage=Live'); @@ -85,7 +84,7 @@ class SiteTreePermissionsTest extends FunctionalTest { // Set up fixture - a published page deleted from draft $this->logInWithPermission("ADMIN"); - $page = $this->objFromFixture(Page::class, 'restrictedEditOnlySubadminGroup'); + $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup'); $pageID = $page->ID; $this->assertTrue($page->publishRecursive()); $page->delete(); @@ -112,7 +111,7 @@ class SiteTreePermissionsTest extends FunctionalTest { // Set up fixture - an unpublished page $this->logInWithPermission("ADMIN"); - $page = $this->objFromFixture(Page::class, 'restrictedEditOnlySubadminGroup'); + $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup'); $pageID = $page->ID; $page->doUnpublish(); @@ -135,7 +134,7 @@ class SiteTreePermissionsTest extends FunctionalTest { // Find a page that exists and delete it from both stage and published $this->logInWithPermission("ADMIN"); - $page = $this->objFromFixture(Page::class, 'restrictedEditOnlySubadminGroup'); + $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup'); $pageID = $page->ID; $page->doUnpublish(); $page->delete(); @@ -153,8 +152,8 @@ class SiteTreePermissionsTest extends FunctionalTest public function testCanViewStage() { // Get page & make sure it exists on Live - /** @var Page $page */ - $page = $this->objFromFixture(Page::class, 'standardpage'); + /** @var SiteTree $page */ + $page = $this->objFromFixture(SiteTree::class, 'standardpage'); $page->publishSingle(); // Then make sure there's a new version on Stage @@ -173,7 +172,7 @@ class SiteTreePermissionsTest extends FunctionalTest public function testAccessTabOnlyDisplaysWithGrantAccessPermissions() { - $page = $this->objFromFixture(Page::class, 'standardpage'); + $page = $this->objFromFixture(SiteTree::class, 'standardpage'); $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); Security::setCurrentUser($subadminuser); @@ -204,7 +203,7 @@ class SiteTreePermissionsTest extends FunctionalTest public function testRestrictedViewLoggedInUsers() { - $page = $this->objFromFixture(Page::class, 'restrictedViewLoggedInUsers'); + $page = $this->objFromFixture(SiteTree::class, 'restrictedViewLoggedInUsers'); // unauthenticated users $this->assertFalse( @@ -223,21 +222,23 @@ class SiteTreePermissionsTest extends FunctionalTest $websiteuser = $this->objFromFixture(Member::class, 'websiteuser'); $this->assertTrue( $page->canView($websiteuser), - 'Authenticated members can view a page marked as "Viewable for any logged in users" even if they dont have access to the CMS' + 'Authenticated members can view a page marked as "Viewable for any logged in users" even if they dont ' . + 'have access to the CMS' ); $this->logInAs($websiteuser); $response = $this->get($page->RelativeLink()); $this->assertEquals( $response->getStatusCode(), 200, - 'Authenticated members can view a page marked as "Viewable for any logged in users" even if they dont have access to the CMS' + 'Authenticated members can view a page marked as "Viewable for any logged in users" even if they dont ' . + 'have access to the CMS' ); $this->logOut(); } public function testRestrictedViewOnlyTheseUsers() { - $page = $this->objFromFixture(Page::class, 'restrictedViewOnlyWebsiteUsers'); + $page = $this->objFromFixture(SiteTree::class, 'restrictedViewOnlyWebsiteUsers'); // unauthenticcated users $this->assertFalse( @@ -256,14 +257,16 @@ class SiteTreePermissionsTest extends FunctionalTest $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); $this->assertFalse( $page->canView($subadminuser), - 'Authenticated members cant view a page marked as "Viewable by these groups" if theyre not in the listed groups' + 'Authenticated members cant view a page marked as "Viewable by these groups" if theyre not in the listed ' . + 'groups' ); $this->LogInAs($subadminuser); $response = $this->get($page->RelativeLink()); $this->assertEquals( $response->getStatusCode(), 403, - 'Authenticated members cant view a page marked as "Viewable by these groups" if theyre not in the listed groups' + 'Authenticated members cant view a page marked as "Viewable by these groups" if theyre not in the listed ' . + 'groups' ); $this->logOut(); @@ -285,7 +288,7 @@ class SiteTreePermissionsTest extends FunctionalTest public function testRestrictedEditLoggedInUsers() { - $page = $this->objFromFixture(Page::class, 'restrictedEditLoggedInUsers'); + $page = $this->objFromFixture(SiteTree::class, 'restrictedEditLoggedInUsers'); // unauthenticcated users $this->assertFalse( @@ -298,20 +301,22 @@ class SiteTreePermissionsTest extends FunctionalTest Security::setCurrentUser($websiteuser); $this->assertFalse( $page->canEdit($websiteuser), - 'Authenticated members cant edit a page marked as "Editable by logged in users" if they dont have cms permissions' + 'Authenticated members cant edit a page marked as "Editable by logged in users" if they dont have cms ' . + 'permissions' ); // subadmin users $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); $this->assertTrue( $page->canEdit($subadminuser), - 'Authenticated members can edit a page marked as "Editable by logged in users" if they have cms permissions and belong to any of these groups' + 'Authenticated members can edit a page marked as "Editable by logged in users" if they have cms ' . + 'permissions and belong to any of these groups' ); } public function testRestrictedEditOnlySubadminGroup() { - $page = $this->objFromFixture(Page::class, 'restrictedEditOnlySubadminGroup'); + $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup'); // unauthenticated users $this->assertFalse( @@ -330,14 +335,15 @@ class SiteTreePermissionsTest extends FunctionalTest $websiteuser = $this->objFromFixture(Member::class, 'websiteuser'); $this->assertFalse( $page->canEdit($websiteuser), - 'Authenticated members cant edit a page marked as "Editable by these groups" if theyre not in the listed groups' + 'Authenticated members cant edit a page marked as "Editable by these groups" if theyre not in the listed ' . + 'groups' ); } public function testRestrictedViewInheritance() { - $parentPage = $this->objFromFixture(Page::class, 'parent_restrictedViewOnlySubadminGroup'); - $childPage = $this->objFromFixture(Page::class, 'child_restrictedViewOnlySubadminGroup'); + $parentPage = $this->objFromFixture(SiteTree::class, 'parent_restrictedViewOnlySubadminGroup'); + $childPage = $this->objFromFixture(SiteTree::class, 'child_restrictedViewOnlySubadminGroup'); // unauthenticated users $this->assertFalse( @@ -356,22 +362,24 @@ class SiteTreePermissionsTest extends FunctionalTest $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); $this->assertTrue( $childPage->canView($subadminuser), - 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed groups by inherited permission' + 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed ' . + 'groups by inherited permission' ); $this->logInAs($subadminuser); $response = $this->get($childPage->RelativeLink()); $this->assertEquals( $response->getStatusCode(), 200, - 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed groups by inherited permission' + 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed ' . + 'groups by inherited permission' ); $this->logOut(); } public function testRestrictedEditInheritance() { - $parentPage = $this->objFromFixture(Page::class, 'parent_restrictedEditOnlySubadminGroup'); - $childPage = $this->objFromFixture(Page::class, 'child_restrictedEditOnlySubadminGroup'); + $parentPage = $this->objFromFixture(SiteTree::class, 'parent_restrictedEditOnlySubadminGroup'); + $childPage = $this->objFromFixture(SiteTree::class, 'child_restrictedEditOnlySubadminGroup'); // unauthenticated users $this->assertFalse( @@ -383,14 +391,15 @@ class SiteTreePermissionsTest extends FunctionalTest $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); $this->assertTrue( $childPage->canEdit($subadminuser), - 'Authenticated members can edit a page marked as "Editable by these groups" if theyre in the listed groups by inherited permission' + 'Authenticated members can edit a page marked as "Editable by these groups" if theyre in the listed ' . + 'groups by inherited permission' ); } public function testDeleteRestrictedChild() { - $parentPage = $this->objFromFixture(Page::class, 'deleteTestParentPage'); - $childPage = $this->objFromFixture(Page::class, 'deleteTestChildPage'); + $parentPage = $this->objFromFixture(SiteTree::class, 'deleteTestParentPage'); + $childPage = $this->objFromFixture(SiteTree::class, 'deleteTestChildPage'); // unauthenticated users $this->assertFalse( @@ -405,7 +414,7 @@ class SiteTreePermissionsTest extends FunctionalTest public function testRestrictedEditLoggedInUsersDeletedFromStage() { - $page = $this->objFromFixture(Page::class, 'restrictedEditLoggedInUsers'); + $page = $this->objFromFixture(SiteTree::class, 'restrictedEditLoggedInUsers'); $pageID = $page->ID; $this->logInWithPermission("ADMIN"); @@ -421,39 +430,60 @@ class SiteTreePermissionsTest extends FunctionalTest $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); $this->assertTrue( $page->canEdit($subadminuser), - 'Authenticated members can edit a page that was deleted from stage and marked as "Editable by logged in users" if they have cms permissions and belong to any of these groups' + 'Authenticated members can edit a page that was deleted from stage and marked as "Editable by logged ' . + 'in users" if they have cms permissions and belong to any of these groups' ); } public function testInheritCanViewFromSiteConfig() { - $page = $this->objFromFixture(Page::class, 'inheritWithNoParent'); + $page = $this->objFromFixture(SiteTree::class, 'inheritWithNoParent'); $siteconfig = $this->objFromFixture(SiteConfig::class, 'default'); $editor = $this->objFromFixture(Member::class, 'editor'); $editorGroup = $this->objFromFixture(Group::class, 'editorgroup'); $siteconfig->CanViewType = 'Anyone'; $siteconfig->write(); - $this->assertTrue($page->canView(false), 'Anyone can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to LoggedInUsers'); + $this->assertTrue( + $page->canView(false), + 'Anyone can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to ' . + 'LoggedInUsers' + ); $siteconfig->CanViewType = 'LoggedInUsers'; $siteconfig->write(); - $this->assertFalse($page->canView(false), 'Anonymous can\'t view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to LoggedInUsers'); + $this->assertFalse( + $page->canView(false), + 'Anonymous can\'t view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to ' . + 'LoggedInUsers' + ); $siteconfig->CanViewType = 'LoggedInUsers'; $siteconfig->write(); - $this->assertTrue($page->canView($editor), 'Users can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to LoggedInUsers'); + $this->assertTrue( + $page->canView($editor), + 'Users can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to ' . + 'LoggedInUsers' + ); $siteconfig->CanViewType = 'OnlyTheseUsers'; $siteconfig->ViewerGroups()->add($editorGroup); $siteconfig->write(); - $this->assertTrue($page->canView($editor), 'Editors can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to OnlyTheseUsers'); - $this->assertFalse($page->canView(false), 'Anonymous can\'t view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to OnlyTheseUsers'); + $this->assertTrue( + $page->canView($editor), + 'Editors can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to ' . + 'OnlyTheseUsers' + ); + $this->assertFalse( + $page->canView(false), + 'Anonymous can\'t view a page when set to inherit from the SiteConfig, and SiteConfig has canView set ' . + 'to OnlyTheseUsers' + ); } public function testInheritCanEditFromSiteConfig() { - $page = $this->objFromFixture(Page::class, 'inheritWithNoParent'); + $page = $this->objFromFixture(SiteTree::class, 'inheritWithNoParent'); $siteconfig = $this->objFromFixture(SiteConfig::class, 'default'); $editor = $this->objFromFixture(Member::class, 'editor'); $user = $this->objFromFixture(Member::class, 'websiteuser'); @@ -462,17 +492,37 @@ class SiteTreePermissionsTest extends FunctionalTest $siteconfig->CanEditType = 'LoggedInUsers'; $siteconfig->write(); - $this->assertFalse($page->canEdit(false), 'Anonymous can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to LoggedInUsers'); + $this->assertFalse( + $page->canEdit(false), + 'Anonymous can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set ' . + 'to LoggedInUsers' + ); Security::setCurrentUser($editor); - $this->assertTrue($page->canEdit(), 'Users can edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to LoggedInUsers'); + $this->assertTrue( + $page->canEdit(), + 'Users can edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to ' . + 'LoggedInUsers' + ); $siteconfig->CanEditType = 'OnlyTheseUsers'; $siteconfig->EditorGroups()->add($editorGroup); $siteconfig->write(); - $this->assertTrue($page->canEdit($editor), 'Editors can edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to OnlyTheseUsers'); + $this->assertTrue( + $page->canEdit($editor), + 'Editors can edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to ' . + 'OnlyTheseUsers' + ); Security::setCurrentUser(null); - $this->assertFalse($page->canEdit(false), 'Anonymous can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to OnlyTheseUsers'); + $this->assertFalse( + $page->canEdit(false), + 'Anonymous can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set ' . + 'to OnlyTheseUsers' + ); Security::setCurrentUser($user); - $this->assertFalse($page->canEdit($user), 'Website user can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to OnlyTheseUsers'); + $this->assertFalse( + $page->canEdit($user), + 'Website user can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set ' . + 'to OnlyTheseUsers' + ); } } diff --git a/tests/php/Model/SiteTreePermissionsTest.yml b/tests/php/Model/SiteTreePermissionsTest.yml index 06faa371..a0772dca 100644 --- a/tests/php/Model/SiteTreePermissionsTest.yml +++ b/tests/php/Model/SiteTreePermissionsTest.yml @@ -35,7 +35,7 @@ SilverStripe\Security\Member: Email: websiteuser@test.com Password: test Groups: =>SilverStripe\Security\Group.websiteusers -Page: +SilverStripe\CMS\Model\SiteTree: standardpage: URLSegment: standardpage restrictedViewLoggedInUsers: @@ -66,7 +66,7 @@ Page: URLSegment: parent-restrictedViewOnlySubadminGroup child_restrictedViewOnlySubadminGroup: CanViewType: Inherit - Parent: =>Page.parent_restrictedViewOnlySubadminGroup + Parent: =>SilverStripe\CMS\Model\SiteTree.parent_restrictedViewOnlySubadminGroup URLSegment: child-restrictedViewOnlySubadminGroup parent_restrictedEditOnlySubadminGroup: CanEditType: OnlyTheseUsers @@ -74,7 +74,7 @@ Page: URLSegment: parent-restrictedEditOnlySubadminGroup child_restrictedEditOnlySubadminGroup: CanEditType: Inherit - Parent: =>Page.parent_restrictedEditOnlySubadminGroup + Parent: =>SilverStripe\CMS\Model\SiteTree.parent_restrictedEditOnlySubadminGroup URLSegment: child-restrictedEditOnlySubadminGroup deleteTestParentPage: CanEditType: Inherit diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index d919a674..6a3182a8 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -3,7 +3,6 @@ namespace SilverStripe\CMS\Tests\Model; use LogicException; -use Page; use Psr\SimpleCache\CacheInterface; use ReflectionMethod; use SilverStripe\CMS\Model\RedirectorPage; @@ -36,6 +35,9 @@ use SilverStripe\View\Parsers\ShortcodeParser; use SilverStripe\View\Parsers\URLSegmentFilter; use SilverStripe\View\Shortcodes\EmbedShortcodeProvider; use TractorCow\Fluent\Extension\FluentSiteTreeExtension; +use Page; +use PageController; + use const RESOURCES_DIR; class SiteTreeTest extends SapphireTest @@ -75,28 +77,28 @@ class SiteTreeTest extends SapphireTest public function testCreateDefaultpages() { - $remove = SiteTree::get(); + $remove = SiteTree::get(); if ($remove) { foreach ($remove as $page) { $page->delete(); } } - // Make sure the table is empty - $this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0); + // Make sure the table is empty + $this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0); - // Disable the creation - SiteTree::config()->create_default_pages = false; - singleton(SiteTree::class)->requireDefaultRecords(); + // Disable the creation + SiteTree::config()->create_default_pages = false; + singleton(SiteTree::class)->requireDefaultRecords(); - // The table should still be empty - $this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0); + // The table should still be empty + $this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0); - // Enable the creation - SiteTree::config()->create_default_pages = true; - singleton(SiteTree::class)->requireDefaultRecords(); + // Enable the creation + SiteTree::config()->create_default_pages = true; + singleton(SiteTree::class)->requireDefaultRecords(); - // The table should now have three rows (home, about-us, contact-us) - $this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 3); + // The table should now have three rows (home, about-us, contact-us) + $this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 3); } /** @@ -123,7 +125,7 @@ class SiteTreeTest extends SapphireTest ]; foreach ($expectedURLs as $fixture => $urlSegment) { - $obj = $this->objFromFixture('Page', $fixture); + $obj = $this->objFromFixture(SiteTree::class, $fixture); $this->assertEquals($urlSegment, $obj->URLSegment); } } @@ -134,9 +136,9 @@ class SiteTreeTest extends SapphireTest */ public function testDisallowedURLGeneration($title, $urlSegment) { - $page = Page::create(['Title' => $title]); + $page = new SiteTree(['Title' => $title]); $id = $page->write(); - $page = Page::get()->byID($id); + $page = SiteTree::get()->byID($id); $this->assertEquals($urlSegment, $page->URLSegment); } @@ -149,9 +151,9 @@ class SiteTreeTest extends SapphireTest { // Using the same dataprovider, strip out the -2 from the admin and dev segment $urlSegment = str_replace('-2', '', $urlSegment ?? ''); - $page = Page::create(['Title' => $title, 'ParentID' => 1]); + $page = new SiteTree(['Title' => $title, 'ParentID' => 1]); $id = $page->write(); - $page = Page::get()->byID($id); + $page = SiteTree::get()->byID($id); $this->assertEquals($urlSegment, $page->URLSegment); } @@ -166,7 +168,7 @@ class SiteTreeTest extends SapphireTest $this->markTestSkipped('This legacy test requires RESOURCES_DIR to be "resources"'); } - $page = SiteTree::create(['Title' => 'Resources']); + $page = new SiteTree(['Title' => 'Resources']); $id = $page->write(); $page = SiteTree::get()->byID($id); $this->assertSame('resources-2', $page->URLSegment); @@ -184,7 +186,7 @@ class SiteTreeTest extends SapphireTest $this->markTestSkipped('This test requires RESOURCES_DIR to be something other than "resources"'); } - $page = SiteTree::create(['Title' => '_Resources']); + $page = new SiteTree(['Title' => '_Resources']); $id = $page->write(); $page = SiteTree::get()->byID($id); $this->assertSame('resources', $page->URLSegment); @@ -195,10 +197,12 @@ class SiteTreeTest extends SapphireTest */ public function testPublishCopiesToLiveTable() { - $obj = $this->objFromFixture('Page', 'about'); + $obj = $this->objFromFixture(SiteTree::class, 'about'); $obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $createdID = DB::query("SELECT \"ID\" FROM \"SiteTree_Live\" WHERE \"URLSegment\" = '$obj->URLSegment'")->value(); + $createdID = DB::query( + "SELECT \"ID\" FROM \"SiteTree_Live\" WHERE \"URLSegment\" = '$obj->URLSegment'" + )->value(); $this->assertEquals($obj->ID, $createdID); } @@ -209,12 +213,15 @@ class SiteTreeTest extends SapphireTest { $this->logInWithPermission('ADMIN'); - $obj = $this->objFromFixture('Page', 'about'); + $obj = $this->objFromFixture(SiteTree::class, 'about'); $obj->Title = "asdfasdf"; $obj->write(); $this->assertTrue($obj->publishRecursive()); - $this->assertEquals('asdfasdf', DB::query("SELECT \"Title\" FROM \"SiteTree_Live\" WHERE \"ID\" = '$obj->ID'")->value()); + $this->assertEquals( + 'asdfasdf', + DB::query("SELECT \"Title\" FROM \"SiteTree_Live\" WHERE \"ID\" = '$obj->ID'")->value() + ); $obj->Title = null; $obj->write(); @@ -261,7 +268,7 @@ class SiteTreeTest extends SapphireTest Versioned::set_stage(Versioned::LIVE); $checkSiteTree = DataObject::get_one(SiteTree::class, [ - '"SiteTree"."URLSegment"' => 'get-one-test-page' + '"SiteTree"."URLSegment"' => 'get-one-test-page', ]); $this->assertEquals("V1", $checkSiteTree->Title); @@ -300,10 +307,13 @@ class SiteTreeTest extends SapphireTest { /* DataObject::write() should save to a has_one relationship if you set a field called (relname)ID */ $page = new SiteTree(); - $parentID = $this->idFromFixture('Page', 'home'); + $parentID = $this->idFromFixture(SiteTree::class, 'home'); $page->ParentID = $parentID; $page->write(); - $this->assertEquals($parentID, DB::query("SELECT \"ParentID\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value()); + $this->assertEquals( + $parentID, + DB::query("SELECT \"ParentID\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value() + ); /* You should then be able to save a null/0/'' value to the relation */ $page->ParentID = null; @@ -387,23 +397,23 @@ class SiteTreeTest extends SapphireTest */ public function testRestoreToStage() { - $page = $this->objFromFixture('Page', 'about'); + $page = $this->objFromFixture(SiteTree::class, 'about'); $pageID = $page->ID; $page->delete(); - $this->assertTrue(!DataObject::get_by_id("Page", $pageID)); + $this->assertTrue(!DataObject::get_by_id(SiteTree::class, $pageID)); $deletedPage = Versioned::get_latest_version(SiteTree::class, $pageID); $resultPage = $deletedPage->doRestoreToStage(); - $requeriedPage = DataObject::get_by_id("Page", $pageID); + $requeriedPage = DataObject::get_by_id(SiteTree::class, $pageID); $this->assertEquals($pageID, $resultPage->ID); $this->assertEquals($pageID, $requeriedPage->ID); $this->assertEquals('About Us', $requeriedPage->Title); - $this->assertInstanceOf('Page', $requeriedPage); + $this->assertInstanceOf(SiteTree::class, $requeriedPage); - $page2 = $this->objFromFixture('Page', 'products'); + $page2 = $this->objFromFixture(SiteTree::class, 'products'); $page2ID = $page2->ID; $page2->doUnpublish(); $page2->delete(); @@ -413,12 +423,14 @@ class SiteTreeTest extends SapphireTest Versioned::set_stage(Versioned::LIVE); $deletedPage = Versioned::get_latest_version(SiteTree::class, $page2ID); $deletedPage->doRestoreToStage(); - $this->assertFalse((bool)Versioned::get_one_by_stage(SiteTree::class, Versioned::LIVE, "\"SiteTree\".\"ID\" = " . $page2ID)); + $this->assertFalse( + (bool)Versioned::get_one_by_stage(SiteTree::class, Versioned::LIVE, "\"SiteTree\".\"ID\" = " . $page2ID) + ); Versioned::set_stage(Versioned::DRAFT); - $requeriedPage = DataObject::get_by_id("Page", $page2ID); + $requeriedPage = DataObject::get_by_id(SiteTree::class, $page2ID); $this->assertEquals('Products', $requeriedPage->Title); - $this->assertInstanceOf('Page', $requeriedPage); + $this->assertInstanceOf(SiteTree::class, $requeriedPage); } public function testNoCascadingDeleteWithoutID() @@ -442,10 +454,10 @@ class SiteTreeTest extends SapphireTest public function testGetByLink() { - $home = $this->objFromFixture('Page', 'home'); - $about = $this->objFromFixture('Page', 'about'); - $staff = $this->objFromFixture('Page', 'staff'); - $product = $this->objFromFixture('Page', 'product1'); + $home = $this->objFromFixture(SiteTree::class, 'home'); + $about = $this->objFromFixture(SiteTree::class, 'about'); + $staff = $this->objFromFixture(SiteTree::class, 'staff'); + $product = $this->objFromFixture(SiteTree::class, 'product1'); SiteTree::config()->nested_urls = false; @@ -472,10 +484,10 @@ class SiteTreeTest extends SapphireTest public function testGetByLinkAbsolute() { - $home = $this->objFromFixture('Page', 'home'); - $about = $this->objFromFixture('Page', 'about'); - $staff = $this->objFromFixture('Page', 'staff'); - $product = $this->objFromFixture('Page', 'product1'); + $home = $this->objFromFixture(SiteTree::class, 'home'); + $about = $this->objFromFixture(SiteTree::class, 'about'); + $staff = $this->objFromFixture(SiteTree::class, 'staff'); + $product = $this->objFromFixture(SiteTree::class, 'product1'); $base = 'https://example.test/'; $this->assertEquals($home->ID, SiteTree::get_by_link(Controller::join_links($base, '/'), false)->ID); @@ -487,29 +499,45 @@ class SiteTreeTest extends SapphireTest public function testRelativeLink() { - $about = $this->objFromFixture('Page', 'about'); - $staff = $this->objFromFixture('Page', 'staff'); + $about = $this->objFromFixture(SiteTree::class, 'about'); + $staff = $this->objFromFixture(SiteTree::class, 'staff'); Config::modify()->set(SiteTree::class, 'nested_urls', true); - $this->assertEquals('about-us/', $about->RelativeLink(), 'Matches URLSegment on top level without parameters'); - $this->assertEquals('about-us/my-staff/', $staff->RelativeLink(), 'Matches URLSegment plus parent on second level without parameters'); - $this->assertEquals('about-us/edit', $about->RelativeLink('edit'), 'Matches URLSegment plus parameter on top level'); - $this->assertEquals('about-us/tom&jerry', $about->RelativeLink('tom&jerry'), 'Doesnt url encode parameter'); + $this->assertEquals( + 'about-us/', + $about->RelativeLink(), + 'Matches URLSegment on top level without parameters' + ); + $this->assertEquals( + 'about-us/my-staff/', + $staff->RelativeLink(), + 'Matches URLSegment plus parent on second level without parameters' + ); + $this->assertEquals( + 'about-us/edit', + $about->RelativeLink('edit'), + 'Matches URLSegment plus parameter on top level' + ); + $this->assertEquals( + 'about-us/tom&jerry', + $about->RelativeLink('tom&jerry'), + 'Doesnt url encode parameter' + ); } public function testPageLevel() { - $about = $this->objFromFixture('Page', 'about'); - $staff = $this->objFromFixture('Page', 'staff'); + $about = $this->objFromFixture(SiteTree::class, 'about'); + $staff = $this->objFromFixture(SiteTree::class, 'staff'); $this->assertEquals(1, $about->getPageLevel()); $this->assertEquals(2, $staff->getPageLevel()); } public function testAbsoluteLiveLink() { - $parent = $this->objFromFixture('Page', 'about'); - $child = $this->objFromFixture('Page', 'staff'); + $parent = $this->objFromFixture(SiteTree::class, 'about'); + $child = $this->objFromFixture(SiteTree::class, 'staff'); Config::modify()->set(SiteTree::class, 'nested_urls', true); @@ -526,17 +554,17 @@ class SiteTreeTest extends SapphireTest public function testDuplicateChildrenRetainSort() { - $parent = new Page(); + $parent = new SiteTree(); $parent->Title = 'Parent'; $parent->write(); - $child1 = new Page(); + $child1 = new SiteTree(); $child1->ParentID = $parent->ID; $child1->Title = 'Child 1'; $child1->Sort = 2; $child1->write(); - $child2 = new Page(); + $child2 = new SiteTree(); $child2->ParentID = $parent->ID; $child2->Title = 'Child 2'; $child2->Sort = 1; @@ -560,34 +588,34 @@ class SiteTreeTest extends SapphireTest public function testDeleteFromStageOperatesRecursively() { Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', false); - $pageAbout = $this->objFromFixture('Page', 'about'); - $pageStaff = $this->objFromFixture('Page', 'staff'); - $pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); + $pageAbout = $this->objFromFixture(SiteTree::class, 'about'); + $pageStaff = $this->objFromFixture(SiteTree::class, 'staff'); + $pageStaffDuplicate = $this->objFromFixture(SiteTree::class, 'staffduplicate'); $pageAbout->delete(); - $this->assertNull(DataObject::get_by_id('Page', $pageAbout->ID)); - $this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page); - $this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page); + $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageAbout->ID)); + $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaff->ID) instanceof SiteTree); + $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaffDuplicate->ID) instanceof SiteTree); Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', true); } public function testDeleteFromStageOperatesRecursivelyStrict() { - $pageAbout = $this->objFromFixture('Page', 'about'); - $pageStaff = $this->objFromFixture('Page', 'staff'); - $pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); + $pageAbout = $this->objFromFixture(SiteTree::class, 'about'); + $pageStaff = $this->objFromFixture(SiteTree::class, 'staff'); + $pageStaffDuplicate = $this->objFromFixture(SiteTree::class, 'staffduplicate'); $pageAbout->delete(); - $this->assertNull(DataObject::get_by_id('Page', $pageAbout->ID)); - $this->assertNull(DataObject::get_by_id('Page', $pageStaff->ID)); - $this->assertNull(DataObject::get_by_id('Page', $pageStaffDuplicate->ID)); + $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageAbout->ID)); + $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageStaff->ID)); + $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageStaffDuplicate->ID)); } public function testDuplicate() { - $pageAbout = $this->objFromFixture('Page', 'about'); + $pageAbout = $this->objFromFixture(SiteTree::class, 'about'); $dupe = $pageAbout->duplicate(); $this->assertEquals($pageAbout->Title, $dupe->Title); $this->assertNotEquals($pageAbout->URLSegment, $dupe->URLSegment); @@ -599,22 +627,22 @@ class SiteTreeTest extends SapphireTest Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', false); $this->logInWithPermission('ADMIN'); - $pageAbout = $this->objFromFixture('Page', 'about'); + $pageAbout = $this->objFromFixture(SiteTree::class, 'about'); $pageAbout->publishRecursive(); - $pageStaff = $this->objFromFixture('Page', 'staff'); + $pageStaff = $this->objFromFixture(SiteTree::class, 'staff'); $pageStaff->publishRecursive(); - $pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); + $pageStaffDuplicate = $this->objFromFixture(SiteTree::class, 'staffduplicate'); $pageStaffDuplicate->publishRecursive(); - $parentPage = $this->objFromFixture('Page', 'about'); + $parentPage = $this->objFromFixture(SiteTree::class, 'about'); $parentPage->doUnpublish(); Versioned::set_stage(Versioned::LIVE); - $this->assertNull(DataObject::get_by_id('Page', $pageAbout->ID)); - $this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page); - $this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page); + $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageAbout->ID)); + $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaff->ID) instanceof SiteTree); + $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaffDuplicate->ID) instanceof SiteTree); Versioned::set_stage(Versioned::DRAFT); Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', true); } @@ -624,20 +652,20 @@ class SiteTreeTest extends SapphireTest Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', false); $this->logInWithPermission('ADMIN'); - $pageAbout = $this->objFromFixture('Page', 'about'); + $pageAbout = $this->objFromFixture(SiteTree::class, 'about'); $pageAbout->publishRecursive(); - $pageStaff = $this->objFromFixture('Page', 'staff'); + $pageStaff = $this->objFromFixture(SiteTree::class, 'staff'); $pageStaff->publishRecursive(); - $pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); + $pageStaffDuplicate = $this->objFromFixture(SiteTree::class, 'staffduplicate'); $pageStaffDuplicate->publishRecursive(); - $parentPage = $this->objFromFixture('Page', 'about'); + $parentPage = $this->objFromFixture(SiteTree::class, 'about'); $parentPage->doUnpublish(); Versioned::set_stage(Versioned::LIVE); - $this->assertNull(DataObject::get_by_id('Page', $pageAbout->ID)); - $this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page); - $this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page); + $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageAbout->ID)); + $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaff->ID) instanceof SiteTree); + $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaffDuplicate->ID) instanceof SiteTree); Versioned::set_stage(Versioned::DRAFT); Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', true); } @@ -646,20 +674,20 @@ class SiteTreeTest extends SapphireTest { $this->logInWithPermission('ADMIN'); - $pageAbout = $this->objFromFixture('Page', 'about'); + $pageAbout = $this->objFromFixture(SiteTree::class, 'about'); $pageAbout->publishRecursive(); - $pageStaff = $this->objFromFixture('Page', 'staff'); + $pageStaff = $this->objFromFixture(SiteTree::class, 'staff'); $pageStaff->publishRecursive(); - $pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); + $pageStaffDuplicate = $this->objFromFixture(SiteTree::class, 'staffduplicate'); $pageStaffDuplicate->publishRecursive(); - $parentPage = $this->objFromFixture('Page', 'about'); + $parentPage = $this->objFromFixture(SiteTree::class, 'about'); $parentPage->doUnpublish(); Versioned::set_stage(Versioned::LIVE); - $this->assertNull(DataObject::get_by_id('Page', $pageAbout->ID)); - $this->assertNull(DataObject::get_by_id('Page', $pageStaff->ID)); - $this->assertNull(DataObject::get_by_id('Page', $pageStaffDuplicate->ID)); + $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageAbout->ID)); + $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageStaff->ID)); + $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageStaffDuplicate->ID)); Versioned::set_stage(Versioned::DRAFT); } @@ -670,7 +698,7 @@ class SiteTreeTest extends SapphireTest public function testReadArchiveDate() { DBDatetime::set_mock_now('2009-07-02 14:05:07'); - $oldPage = SiteTree::create(); + $oldPage = new SiteTree(); $oldPage->Title = 'A really old page'; $oldPage->write(); DBDatetime::clear_mock_now(); @@ -678,7 +706,7 @@ class SiteTreeTest extends SapphireTest $date = '2009-07-02 14:05:07'; Versioned::reading_archived_date($date); $result = SiteTree::get()->where([ - '"SiteTree"."ParentID"' => 0 + '"SiteTree"."ParentID"' => 0, ]); $this->assertCount(1, $result, '"A really old page" should be returned'); } @@ -687,11 +715,11 @@ class SiteTreeTest extends SapphireTest { $editor = $this->objFromFixture(Member::class, "editor"); - $home = $this->objFromFixture("Page", "home"); - $staff = $this->objFromFixture("Page", "staff"); - $products = $this->objFromFixture("Page", "products"); - $product1 = $this->objFromFixture("Page", "product1"); - $product4 = $this->objFromFixture("Page", "product4"); + $home = $this->objFromFixture(SiteTree::class, "home"); + $staff = $this->objFromFixture(SiteTree::class, "staff"); + $products = $this->objFromFixture(SiteTree::class, "products"); + $product1 = $this->objFromFixture(SiteTree::class, "product1"); + $product4 = $this->objFromFixture(SiteTree::class, "product4"); // Test logged out users cannot edit $this->logOut(); @@ -712,7 +740,7 @@ class SiteTreeTest extends SapphireTest public function testCanEditWithAccessToAllSections() { - $page = new Page(); + $page = new SiteTree(); $page->write(); $allSectionMember = $this->objFromFixture(Member::class, 'allsections'); $securityAdminMember = $this->objFromFixture(Member::class, 'securityadmin'); @@ -737,7 +765,7 @@ class SiteTreeTest extends SapphireTest $this->assertTrue(singleton(SiteTree::class)->canCreate()); // Test creation underneath a parent which this user doesn't have access to - $parent = $this->objFromFixture('Page', 'about'); + $parent = $this->objFromFixture(SiteTree::class, 'about'); $this->assertFalse(singleton(SiteTree::class)->canCreate(null, ['Parent' => $parent])); // Test creation underneath a parent which doesn't allow a certain child @@ -753,13 +781,18 @@ class SiteTreeTest extends SapphireTest $this->assertTrue(singleton(SiteTree::class)->canCreate(null, ['Parent' => singleton(SiteTree::class)])); //Test we don't check for allowedChildren on parent context if it's not SiteTree instance - $this->assertTrue(singleton(SiteTree::class)->canCreate(null, ['Parent' => $this->objFromFixture(SiteTreeTest_DataObject::class, 'relations')])); + $this->assertTrue( + singleton(SiteTree::class)->canCreate( + null, + ['Parent' => $this->objFromFixture(SiteTreeTest_DataObject::class, 'relations')] + ) + ); } public function testEditPermissionsOnDraftVsLive() { // Create an inherit-permission page - $page = new Page(); + $page = new SiteTree(); $page->write(); $page->CanEditType = "Inherit"; $page->publishRecursive(); @@ -810,7 +843,7 @@ class SiteTreeTest extends SapphireTest $oldCleanerClass = Diff::$html_cleaner_class; Diff::$html_cleaner_class = SiteTreeTest_NullHtmlCleaner::class; - $page = new Page(); + $page = new SiteTree(); $page->write(); $this->assertEquals(1, $page->Version); @@ -838,14 +871,14 @@ class SiteTreeTest extends SapphireTest $this->logInAs($member); // Write the page - $about = $this->objFromFixture('Page', 'about'); + $about = $this->objFromFixture(SiteTree::class, 'about'); $about->Title = "Another title"; $about->write(); // Check the version created $savedVersion = DB::prepared_query( "SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\" - WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC", + WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC", [$about->ID] )->first(); $this->assertEquals($member->ID, $savedVersion['AuthorID']); @@ -855,7 +888,7 @@ class SiteTreeTest extends SapphireTest $about->publishRecursive(); $publishedVersion = DB::prepared_query( "SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\" - WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC", + WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC", [$about->ID] )->first(); @@ -866,7 +899,7 @@ class SiteTreeTest extends SapphireTest public function testLinkShortcodeHandler() { - $aboutPage = $this->objFromFixture('Page', 'about'); + $aboutPage = $this->objFromFixture(SiteTree::class, 'about'); $redirectPage = $this->objFromFixture(RedirectorPage::class, 'external'); $parser = new ShortcodeParser(); @@ -878,12 +911,24 @@ class SiteTreeTest extends SapphireTest $aboutShortcodeExpected = $aboutPage->Link(); $aboutEnclosedExpected = sprintf('Example Content', $aboutPage->Link()); - $this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test that simple linking works.'); - $this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed), 'Test enclosed content is linked.'); + $this->assertEquals( + $aboutShortcodeExpected, + $parser->parse($aboutShortcode), + 'Test that simple linking works.' + ); + $this->assertEquals( + $aboutEnclosedExpected, + $parser->parse($aboutEnclosed), + 'Test enclosed content is linked.' + ); $aboutPage->delete(); - $this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test that deleted pages still link.'); + $this->assertEquals( + $aboutShortcodeExpected, + $parser->parse($aboutShortcode), + 'Test that deleted pages still link.' + ); $this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed)); $aboutShortcode = '[sitetree_link,id="-1"]'; @@ -897,7 +942,10 @@ class SiteTreeTest extends SapphireTest $redirectExpected = 'http://www.google.com?a&b'; $this->assertEquals($redirectExpected, $parser->parse($redirectShortcode)); - $this->assertEquals(sprintf('Example Content', $redirectExpected), $parser->parse($redirectEnclosed)); + $this->assertEquals( + sprintf('Example Content', $redirectExpected), + $parser->parse($redirectEnclosed) + ); $this->assertEquals('', $parser->parse('[sitetree_link]'), 'Test that invalid ID attributes are not parsed.'); $this->assertEquals('', $parser->parse('[sitetree_link,id="text"]')); @@ -906,8 +954,8 @@ class SiteTreeTest extends SapphireTest public function testIsCurrent() { - $aboutPage = $this->objFromFixture('Page', 'about'); - $productPage = $this->objFromFixture('Page', 'products'); + $aboutPage = $this->objFromFixture(SiteTree::class, 'about'); + $productPage = $this->objFromFixture(SiteTree::class, 'products'); Director::set_current_page($aboutPage); $this->assertTrue($aboutPage->isCurrent(), 'Assert that basic isCurrent checks works.'); @@ -915,7 +963,7 @@ class SiteTreeTest extends SapphireTest $this->assertTrue( DataObject::get_one(SiteTree::class, [ - '"SiteTree"."Title"' => 'About Us' + '"SiteTree"."Title"' => 'About Us', ])->isCurrent(), 'Assert that isCurrent works on another instance with the same ID.' ); @@ -926,9 +974,9 @@ class SiteTreeTest extends SapphireTest public function testIsSection() { - $about = $this->objFromFixture('Page', 'about'); - $staff = $this->objFromFixture('Page', 'staff'); - $ceo = $this->objFromFixture('Page', 'ceo'); + $about = $this->objFromFixture(SiteTree::class, 'about'); + $staff = $this->objFromFixture(SiteTree::class, 'staff'); + $ceo = $this->objFromFixture(SiteTree::class, 'ceo'); Director::set_current_page($about); $this->assertTrue($about->isSection()); @@ -948,7 +996,7 @@ class SiteTreeTest extends SapphireTest public function testURLSegmentReserved() { - $siteTree = SiteTree::create(['URLSegment' => 'admin']); + $siteTree = new SiteTree(['URLSegment' => 'admin']); $segment = $siteTree->validURLSegment(); $this->assertFalse($segment); @@ -1036,7 +1084,7 @@ class SiteTreeTest extends SapphireTest $sitetree->URLSegment = 'home-noconflict'; $this->assertTrue($sitetree->validURLSegment()); - $sitetree->ParentID = $this->idFromFixture('Page', 'about'); + $sitetree->ParentID = $this->idFromFixture(SiteTree::class, 'about'); $sitetree->URLSegment = 'home'; $this->assertFalse($sitetree->validURLSegment(), 'Conflicts are still recognised with a ParentID value'); @@ -1046,7 +1094,7 @@ class SiteTreeTest extends SapphireTest $sitetree->URLSegment = 'home'; $this->assertFalse($sitetree->validURLSegment(), 'URLSegment conflicts are recognised'); - $sitetree->ParentID = $this->idFromFixture('Page', 'about'); + $sitetree->ParentID = $this->idFromFixture(SiteTree::class, 'about'); $this->assertTrue($sitetree->validURLSegment(), 'URLSegments can be the same across levels'); $sitetree->URLSegment = 'my-staff'; @@ -1116,13 +1164,18 @@ class SiteTreeTest extends SapphireTest $sitetree->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $sitetree = DataObject::get_by_id(SiteTree::class, $sitetree->ID, false); $this->assertEquals($sitetree->URLSegment, rawurlencode('brötchen')); - $sitetreeLive = Versioned::get_one_by_stage(SiteTree::class, Versioned::LIVE, '"SiteTree"."ID" = ' .$sitetree->ID, false); + $sitetreeLive = Versioned::get_one_by_stage( + SiteTree::class, + Versioned::LIVE, + '"SiteTree"."ID" = ' . $sitetree->ID, + false + ); $this->assertEquals($sitetreeLive->URLSegment, rawurlencode('brötchen')); } public function testVersionsAreCreated() { - $p = new Page(); + $p = new SiteTree(); $p->Content = "one"; $p->write(); $this->assertEquals(1, $p->Version); @@ -1210,23 +1263,23 @@ class SiteTreeTest extends SapphireTest // Expected [ SiteTreeTest_ClassB::class ], // Assertion message - 'Direct setting of allowed children' + 'Direct setting of allowed children', ], [ SiteTreeTest_ClassB::class, [ SiteTreeTest_ClassC::class, SiteTreeTest_ClassCext::class ], - 'Includes subclasses' + 'Includes subclasses', ], [ SiteTreeTest_ClassC::class, [], - 'Null setting' + 'Null setting', ], [ SiteTreeTest_ClassD::class, [SiteTreeTest_ClassC::class], - 'Excludes subclasses if class is prefixed by an asterisk' - ] + 'Excludes subclasses if class is prefixed by an asterisk', + ], ]; } @@ -1267,7 +1320,10 @@ class SiteTreeTest extends SapphireTest $classCext->ParentID = $classD->ID; $valid = $classCext->doValidate(); - $this->assertFalse($valid->isValid(), "Doesnt allow child where only parent class is allowed on parent node, and asterisk prefixing is used"); + $this->assertFalse( + $valid->isValid(), + "Doesnt allow child where only parent class is allowed on parent node, and asterisk prefixing is used" + ); } public function testClassDropdown() @@ -1286,8 +1342,8 @@ class SiteTreeTest extends SapphireTest $this->assertArrayHasKey(SiteTreeTest_ClassA::class, $method->invoke($sitetree)); $this->logInWithPermission('ADMIN'); - $rootPage = $this->objFromFixture(Page::class, 'home'); - $nonRootPage = $this->objFromFixture(Page::class, 'staff'); + $rootPage = $this->objFromFixture(SiteTree::class, 'home'); + $nonRootPage = $this->objFromFixture(SiteTree::class, 'staff'); $this->assertArrayNotHasKey(SiteTreeTest_NotRoot::class, $method->invoke($rootPage)); $this->assertArrayHasKey(SiteTreeTest_NotRoot::class, $method->invoke($nonRootPage)); @@ -1383,11 +1439,11 @@ class SiteTreeTest extends SapphireTest public function testGetBreadcrumbItems() { - $page = $this->objFromFixture("Page", "breadcrumbs"); + $page = $this->objFromFixture(SiteTree::class, "breadcrumbs"); $this->assertEquals(1, $page->getBreadcrumbItems()->count(), "Only display current page."); // Test breadcrumb order - $page = $this->objFromFixture("Page", "breadcrumbs5"); + $page = $this->objFromFixture(SiteTree::class, "breadcrumbs5"); $breadcrumbs = $page->getBreadcrumbItems(); $this->assertEquals($breadcrumbs->count(), 5, "Display all breadcrumbs"); $this->assertEquals($breadcrumbs->first()->Title, "Breadcrumbs", "Breadcrumbs should be the first item."); @@ -1407,16 +1463,16 @@ class SiteTreeTest extends SapphireTest public function testMetaTags() { $this->logInWithPermission('ADMIN'); - $page = $this->objFromFixture('Page', 'metapage'); + $page = $this->objFromFixture(SiteTree::class, 'metapage'); // Test with title $meta = $page->MetaTags(); $charset = Config::inst()->get(ContentNegotiator::class, 'encoding'); - $this->assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('assertStringContainsString('HTML & XML', $meta); // Test without title @@ -1431,7 +1487,7 @@ class SiteTreeTest extends SapphireTest { $this->logInWithPermission('ADMIN'); /** @var SiteTree $page */ - $page = $this->objFromFixture('Page', 'metapage'); + $page = $this->objFromFixture(SiteTree::class, 'metapage'); $charset = Config::inst()->get(ContentNegotiator::class, 'encoding'); @@ -1513,8 +1569,8 @@ class SiteTreeTest extends SapphireTest // both pages are viewable in stage Versioned::set_stage(Versioned::DRAFT); - $about = $this->objFromFixture('Page', 'about'); - $staff = $this->objFromFixture('Page', 'staff'); + $about = $this->objFromFixture(SiteTree::class, 'about'); + $staff = $this->objFromFixture(SiteTree::class, 'staff'); $this->assertFalse($about->isOrphaned()); $this->assertFalse($staff->isOrphaned()); $this->assertTrue($about->canView($member)); @@ -1525,23 +1581,23 @@ class SiteTreeTest extends SapphireTest $this->assertFalse($staff->isOrphaned()); $this->assertTrue($staff->canView($member)); Versioned::set_stage(Versioned::LIVE); - $staff = $this->objFromFixture('Page', 'staff'); // Live copy of page + $staff = $this->objFromFixture(SiteTree::class, 'staff'); // Live copy of page $this->assertTrue($staff->isOrphaned()); // because parent isn't published $this->assertFalse($staff->canView($member)); // Publishing the parent page should restore visibility Versioned::set_stage(Versioned::DRAFT); - $about = $this->objFromFixture('Page', 'about'); + $about = $this->objFromFixture(SiteTree::class, 'about'); $about->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); Versioned::set_stage(Versioned::LIVE); - $staff = $this->objFromFixture('Page', 'staff'); + $staff = $this->objFromFixture(SiteTree::class, 'staff'); $this->assertFalse($staff->isOrphaned()); $this->assertTrue($staff->canView($member)); // Removing staging page should not prevent live page being visible $about->deleteFromStage('Stage'); $staff->deleteFromStage('Stage'); - $staff = $this->objFromFixture('Page', 'staff'); + $staff = $this->objFromFixture(SiteTree::class, 'staff'); $this->assertFalse($staff->isOrphaned()); $this->assertTrue($staff->canView($member)); @@ -1556,8 +1612,8 @@ class SiteTreeTest extends SapphireTest { $this->logInWithPermission('ADMIN'); - /** @var Page $page */ - $page = $this->objFromFixture('Page', 'home'); + /** @var SiteTree $page */ + $page = $this->objFromFixture(SiteTree::class, 'home'); $this->assertTrue($page->canAddChildren()); $this->assertTrue($page->isOnDraft()); $this->assertFalse($page->isPublished()); @@ -1634,23 +1690,24 @@ class SiteTreeTest extends SapphireTest } /** - * Test that the controller name for a SiteTree instance can be gathered by appending "Controller" to the SiteTree + * Test that the controller name for a Page instance can be gathered by appending "Controller" to the Page * class name in a PSR-2 compliant manner. */ public function testGetControllerName() { - $class = new Page; - $this->assertSame('PageController', $class->getControllerName()); + $page = new Page(); + $this->assertSame(PageController::class, $page->getControllerName()); } + /** * Test that the controller name for a SiteTree instance can be gathered when set directly via config var */ public function testGetControllerNameFromConfig() { - Config::inst()->update(Page::class, 'controller_name', 'This\\Is\\A\\New\\Controller'); - $class = new Page; - $this->assertSame('This\\Is\\A\\New\\Controller', $class->getControllerName()); + Config::inst()->update(SiteTree::class, 'controller_name', 'This\\Is\\A\\New\\Controller'); + $page = new SiteTree(); + $this->assertSame('This\\Is\\A\\New\\Controller', $page->getControllerName()); } /** @@ -1671,13 +1728,13 @@ class SiteTreeTest extends SapphireTest */ public function testGetControllerNameWithUnderscoresIsSupported() { - $class = new SiteTreeTest_LegacyControllerName; + $class = new SiteTreeTest_LegacyControllerName(); $this->assertEquals(SiteTreeTest_LegacyControllerName_Controller::class, $class->getControllerName()); } public function testTreeTitleCache() { - $siteTree = SiteTree::create(); + $siteTree = new SiteTree(); $user = $this->objFromFixture(Member::class, 'allsections'); Security::setCurrentUser($user); $pageClass = array_values(SiteTree::page_type_classes())[0]; @@ -1764,7 +1821,7 @@ class SiteTreeTest extends SapphireTest } // Create new page on DRAFT - $page = SiteTree::create(); + $page = new SiteTree(); $page->Content = $content; $page->write(); @@ -1780,7 +1837,7 @@ class SiteTreeTest extends SapphireTest public function testGetCMSActions() { // Create new page on DRAFT - $page = SiteTree::create(); + $page = new SiteTree(); $page->Content = md5(rand(0, PHP_INT_MAX)); $page->write(); @@ -1910,7 +1967,7 @@ class SiteTreeTest extends SapphireTest public function testGetCMSActionsWithoutForms() { // Create new page on DRAFT - $page = SiteTree::create(); + $page = new SiteTree(); $page->Content = md5(rand(0, PHP_INT_MAX)); $page->write(); diff --git a/tests/php/Model/SiteTreeTest.yml b/tests/php/Model/SiteTreeTest.yml old mode 100755 new mode 100644 index 3b570f3b..da181d4e --- a/tests/php/Model/SiteTreeTest.yml +++ b/tests/php/Model/SiteTreeTest.yml @@ -44,7 +44,7 @@ SilverStripe\Security\Member: securityadmin: Groups: =>SilverStripe\Security\Group.securityadmins -Page: +SilverStripe\CMS\Model\SiteTree: home: Title: Home CanEditType: OnlyTheseUsers @@ -56,14 +56,14 @@ Page: staff: Title: Staff URLSegment: my-staff - Parent: =>Page.about + Parent: =>SilverStripe\CMS\Model\SiteTree.about ceo: Title: CEO - Parent: =>Page.staff + Parent: =>SilverStripe\CMS\Model\SiteTree.staff staffduplicate: Title: Staff URLSegment: my-staff - Parent: =>Page.about + Parent: =>SilverStripe\CMS\Model\SiteTree.about ShowInMenus: 0 products: Title: Products @@ -71,19 +71,19 @@ Page: EditorGroups: =>SilverStripe\Security\Group.editors product1: Title: 1.1 Test Product - Parent: =>Page.products + Parent: =>SilverStripe\CMS\Model\SiteTree.products CanEditType: Inherit product2: Title: Another Product - Parent: =>Page.products + Parent: =>SilverStripe\CMS\Model\SiteTree.products CanEditType: Inherit product3: Title: Another Product - Parent: =>Page.products + Parent: =>SilverStripe\CMS\Model\SiteTree.products CanEditType: Inherit product4: Title: Another Product - Parent: =>Page.products + Parent: =>SilverStripe\CMS\Model\SiteTree.products CanEditType: OnlyTheseUsers EditorGroups: =>SilverStripe\Security\Group.admins contact: @@ -102,16 +102,16 @@ Page: Title: 'Breadcrumbs' breadcrumbs2: Title: 'Breadcrumbs 2' - Parent: =>Page.breadcrumbs + Parent: =>SilverStripe\CMS\Model\SiteTree.breadcrumbs breadcrumbs3: Title: 'Breadcrumbs 3' - Parent: =>Page.breadcrumbs2 + Parent: =>SilverStripe\CMS\Model\SiteTree.breadcrumbs2 breadcrumbs4: Title: 'Breadcrumbs 4' - Parent: =>Page.breadcrumbs3 + Parent: =>SilverStripe\CMS\Model\SiteTree.breadcrumbs3 breadcrumbs5: Title: 'Breadcrumbs 5' - Parent: =>Page.breadcrumbs4 + Parent: =>SilverStripe\CMS\Model\SiteTree.breadcrumbs4 SilverStripe\CMS\Tests\Model\SiteTreeTest_Conflicted: parent: @@ -127,4 +127,4 @@ SilverStripe\CMS\Model\RedirectorPage: SilverStripe\CMS\Tests\Model\SiteTreeTest_DataObject: relations: Title: 'Linked DataObject' - Pages: =>Page.home,=>Page.about,=>Page.staff + Pages: =>SilverStripe\CMS\Model\SiteTree.home,=>SilverStripe\CMS\Model\SiteTree.about,=>SilverStripe\CMS\Model\SiteTree.staff diff --git a/tests/php/Model/SiteTreeTest_AdminDenied.php b/tests/php/Model/SiteTreeTest_AdminDenied.php index 7b50ccf1..91b66e1e 100644 --- a/tests/php/Model/SiteTreeTest_AdminDenied.php +++ b/tests/php/Model/SiteTreeTest_AdminDenied.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class SiteTreeTest_AdminDenied extends Page implements TestOnly +class SiteTreeTest_AdminDenied extends SiteTree implements TestOnly { private static $table_name = 'SiteTreeTest_AdminDenied'; diff --git a/tests/php/Model/SiteTreeTest_ClassA.php b/tests/php/Model/SiteTreeTest_ClassA.php index 009ea31d..7cf2020f 100644 --- a/tests/php/Model/SiteTreeTest_ClassA.php +++ b/tests/php/Model/SiteTreeTest_ClassA.php @@ -3,18 +3,18 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class SiteTreeTest_ClassA extends Page implements TestOnly +class SiteTreeTest_ClassA extends SiteTree implements TestOnly { private static $table_name = 'SiteTreeTest_ClassA'; private static $need_permission = [ 'ADMIN', - 'CMS_ACCESS_CMSMain' + 'CMS_ACCESS_CMSMain', ]; private static $allowed_children = [ - SiteTreeTest_ClassB::class + SiteTreeTest_ClassB::class, ]; } diff --git a/tests/php/Model/SiteTreeTest_ClassB.php b/tests/php/Model/SiteTreeTest_ClassB.php index a0e4bdbb..9f366c04 100644 --- a/tests/php/Model/SiteTreeTest_ClassB.php +++ b/tests/php/Model/SiteTreeTest_ClassB.php @@ -3,14 +3,14 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class SiteTreeTest_ClassB extends Page implements TestOnly +class SiteTreeTest_ClassB extends SiteTree implements TestOnly { private static $table_name = 'SiteTreeTest_ClassB'; // Also allowed subclasses private static $allowed_children = [ - SiteTreeTest_ClassC::class + SiteTreeTest_ClassC::class, ]; } diff --git a/tests/php/Model/SiteTreeTest_ClassC.php b/tests/php/Model/SiteTreeTest_ClassC.php index 25bfa69f..c826a63c 100644 --- a/tests/php/Model/SiteTreeTest_ClassC.php +++ b/tests/php/Model/SiteTreeTest_ClassC.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class SiteTreeTest_ClassC extends Page implements TestOnly +class SiteTreeTest_ClassC extends SiteTree implements TestOnly { private static $table_name = 'SiteTreeTest_ClassC'; diff --git a/tests/php/Model/SiteTreeTest_ClassCext.php b/tests/php/Model/SiteTreeTest_ClassCext.php index 154eb405..8ad10d84 100644 --- a/tests/php/Model/SiteTreeTest_ClassCext.php +++ b/tests/php/Model/SiteTreeTest_ClassCext.php @@ -10,6 +10,6 @@ class SiteTreeTest_ClassCext extends SiteTreeTest_ClassC implements TestOnly // Override SiteTreeTest_ClassC definitions private static $allowed_children = [ - SiteTreeTest_ClassB::class + SiteTreeTest_ClassB::class, ]; } diff --git a/tests/php/Model/SiteTreeTest_ClassD.php b/tests/php/Model/SiteTreeTest_ClassD.php index a2a96141..a8fd7a62 100644 --- a/tests/php/Model/SiteTreeTest_ClassD.php +++ b/tests/php/Model/SiteTreeTest_ClassD.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class SiteTreeTest_ClassD extends Page implements TestOnly +class SiteTreeTest_ClassD extends SiteTree implements TestOnly { private static $table_name = 'SiteTreeTest_ClassD'; diff --git a/tests/php/Model/SiteTreeTest_ClassE.php b/tests/php/Model/SiteTreeTest_ClassE.php index 7791bb07..5bf3afc7 100644 --- a/tests/php/Model/SiteTreeTest_ClassE.php +++ b/tests/php/Model/SiteTreeTest_ClassE.php @@ -4,9 +4,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; use SilverStripe\ORM\HiddenClass; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class SiteTreeTest_ClassE extends Page implements TestOnly, HiddenClass +class SiteTreeTest_ClassE extends SiteTree implements TestOnly, HiddenClass { private static $table_name = 'SiteTreeTest_ClassE'; } diff --git a/tests/php/Model/SiteTreeTest_Conflicted.php b/tests/php/Model/SiteTreeTest_Conflicted.php index 063a3da5..02ff9b9a 100644 --- a/tests/php/Model/SiteTreeTest_Conflicted.php +++ b/tests/php/Model/SiteTreeTest_Conflicted.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class SiteTreeTest_Conflicted extends Page implements TestOnly +class SiteTreeTest_Conflicted extends SiteTree implements TestOnly { private static $table_name = 'SiteTreeTest_Conflicted'; } diff --git a/tests/php/Model/SiteTreeTest_ConflictedController.php b/tests/php/Model/SiteTreeTest_ConflictedController.php index 2c489b68..19c81b08 100644 --- a/tests/php/Model/SiteTreeTest_ConflictedController.php +++ b/tests/php/Model/SiteTreeTest_ConflictedController.php @@ -3,12 +3,12 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use PageController; +use SilverStripe\CMS\Controllers\ContentController; -class SiteTreeTest_ConflictedController extends PageController implements TestOnly +class SiteTreeTest_ConflictedController extends ContentController implements TestOnly { private static $allowed_actions = [ - 'conflicted-action' + 'conflicted-action', ]; public function hasActionTemplate($template) diff --git a/tests/php/Model/SiteTreeTest_LegacyControllerName.php b/tests/php/Model/SiteTreeTest_LegacyControllerName.php index 53c10393..8861bf26 100644 --- a/tests/php/Model/SiteTreeTest_LegacyControllerName.php +++ b/tests/php/Model/SiteTreeTest_LegacyControllerName.php @@ -3,12 +3,12 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; /** * An empty SiteTree instance with a controller to test that legacy controller names can still be loaded */ -class SiteTreeTest_LegacyControllerName extends Page implements TestOnly +class SiteTreeTest_LegacyControllerName extends SiteTree implements TestOnly { private static $table_name = 'SiteTreeTest_LegacyControllerName'; } diff --git a/tests/php/Model/SiteTreeTest_LegacyControllerName_Controller.php b/tests/php/Model/SiteTreeTest_LegacyControllerName_Controller.php index e1e4507c..8bcb49da 100644 --- a/tests/php/Model/SiteTreeTest_LegacyControllerName_Controller.php +++ b/tests/php/Model/SiteTreeTest_LegacyControllerName_Controller.php @@ -3,9 +3,8 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use PageController; +use SilverStripe\CMS\Controllers\ContentController; -class SiteTreeTest_LegacyControllerName_Controller extends PageController implements TestOnly +class SiteTreeTest_LegacyControllerName_Controller extends ContentController implements TestOnly { - } diff --git a/tests/php/Model/SiteTreeTest_NotRoot.php b/tests/php/Model/SiteTreeTest_NotRoot.php index 72c1e17f..3c1fd1cd 100644 --- a/tests/php/Model/SiteTreeTest_NotRoot.php +++ b/tests/php/Model/SiteTreeTest_NotRoot.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class SiteTreeTest_NotRoot extends Page implements TestOnly +class SiteTreeTest_NotRoot extends SiteTree implements TestOnly { private static $table_name = 'SiteTreeTest_NotRoot'; diff --git a/tests/php/Model/SiteTreeTest_PageNode.php b/tests/php/Model/SiteTreeTest_PageNode.php index 71fb9870..30469a56 100644 --- a/tests/php/Model/SiteTreeTest_PageNode.php +++ b/tests/php/Model/SiteTreeTest_PageNode.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class SiteTreeTest_PageNode extends Page implements TestOnly +class SiteTreeTest_PageNode extends SiteTree implements TestOnly { private static $table_name = 'SiteTreeTest_PageNode'; } diff --git a/tests/php/Model/SiteTreeTest_PageNodeController.php b/tests/php/Model/SiteTreeTest_PageNodeController.php index e23ed6ca..8d80a684 100644 --- a/tests/php/Model/SiteTreeTest_PageNodeController.php +++ b/tests/php/Model/SiteTreeTest_PageNodeController.php @@ -3,8 +3,8 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use PageController; +use SilverStripe\CMS\Controllers\ContentController; -class SiteTreeTest_PageNodeController extends PageController implements TestOnly +class SiteTreeTest_PageNodeController extends ContentController implements TestOnly { } diff --git a/tests/php/Model/VirtualPageTest.php b/tests/php/Model/VirtualPageTest.php index b4ee7ba5..43340bfb 100644 --- a/tests/php/Model/VirtualPageTest.php +++ b/tests/php/Model/VirtualPageTest.php @@ -2,7 +2,6 @@ namespace SilverStripe\CMS\Tests\Model; -use Page; use SilverStripe\CMS\Controllers\ModelAsController; use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\SiteTree; @@ -43,8 +42,8 @@ class VirtualPageTest extends FunctionalTest protected static $required_extensions = [ SiteTree::class => [ - VirtualPageTest_PageExtension::class - ] + VirtualPageTest_PageExtension::class, + ], ]; protected function setUp(): void @@ -63,8 +62,8 @@ class VirtualPageTest extends FunctionalTest ); // Ensure all pages are published - /** @var Page $page */ - foreach (Page::get() as $page) { + /** @var SiteTree $page */ + foreach (SiteTree::get() as $page) { $page->publishSingle(); } } @@ -75,8 +74,8 @@ class VirtualPageTest extends FunctionalTest */ public function testEditingSourcePageUpdatesVirtualPages() { - /** @var Page $master */ - $master = $this->objFromFixture('Page', 'master'); + /** @var SiteTree $master */ + $master = $this->objFromFixture(SiteTree::class, 'master'); $master->Title = "New title"; $master->MenuTitle = "New menutitle"; $master->Content = "

New content

"; @@ -97,7 +96,7 @@ class VirtualPageTest extends FunctionalTest public function testMetaTags() { $this->logInWithPermission('ADMIN'); - $master = $this->objFromFixture('Page', 'master'); + $master = $this->objFromFixture(SiteTree::class, 'master'); $vp1 = $this->objFromFixture(VirtualPage::class, 'vp1'); // Test with title @@ -118,8 +117,8 @@ class VirtualPageTest extends FunctionalTest { $this->logInWithPermission('ADMIN'); - /** @var Page $master */ - $master = $this->objFromFixture('Page', 'master'); + /** @var SiteTree $master */ + $master = $this->objFromFixture(SiteTree::class, 'master'); $master->publishRecursive(); $master->Title = "New title"; @@ -160,13 +159,13 @@ class VirtualPageTest extends FunctionalTest $vp = new VirtualPage(); $vp->write(); - $vp->CopyContentFromID = $this->idFromFixture('Page', 'master'); + $vp->CopyContentFromID = $this->idFromFixture(SiteTree::class, 'master'); $vp->write(); $this->assertEquals("My Page", $vp->Title); $this->assertEquals("My Page Nav", $vp->MenuTitle); - $vp->CopyContentFromID = $this->idFromFixture('Page', 'master2'); + $vp->CopyContentFromID = $this->idFromFixture(SiteTree::class, 'master2'); $vp->write(); $this->assertEquals("My Other Page", $vp->Title); @@ -180,7 +179,7 @@ class VirtualPageTest extends FunctionalTest */ public function testPublishingAVirtualPageCopiedPublishedContentNotDraftContent() { - $p = new Page(); + $p = new SiteTree(); $p->Content = "published content"; $p->write(); $p->publishRecursive(); @@ -220,7 +219,7 @@ class VirtualPageTest extends FunctionalTest public function testCantPublishVirtualPagesBeforeTheirSource() { // An unpublished source page - $p = new Page(); + $p = new SiteTree(); $p->Content = "test content"; $p->write(); @@ -241,7 +240,7 @@ class VirtualPageTest extends FunctionalTest public function testCanEdit() { - $parentPage = $this->objFromFixture('Page', 'master3'); + $parentPage = $this->objFromFixture(SiteTree::class, 'master3'); $virtualPage = $this->objFromFixture(VirtualPage::class, 'vp3'); $bob = $this->objFromFixture(Member::class, 'bob'); $andrew = $this->objFromFixture(Member::class, 'andrew'); @@ -259,8 +258,8 @@ class VirtualPageTest extends FunctionalTest public function testCanView() { - /** @var Page $parentPage */ - $parentPage = $this->objFromFixture('Page', 'master3'); + /** @var SiteTree $parentPage */ + $parentPage = $this->objFromFixture(SiteTree::class, 'master3'); $parentPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); /** @var VirtualPage $virtualPage */ @@ -283,7 +282,7 @@ class VirtualPageTest extends FunctionalTest public function testVirtualPagesArentInappropriatelyPublished() { // Fixture - $p = new Page(); + $p = new SiteTree(); $p->Content = "test content"; $p->write(); $vp = new VirtualPage(); @@ -332,7 +331,7 @@ class VirtualPageTest extends FunctionalTest public function testUnpublishingSourcePageOfAVirtualPageAlsoUnpublishesVirtualPage() { // Create page and virutal page - $p = new Page(); + $p = new SiteTree(); $p->Title = "source"; $p->write(); $this->assertTrue($p->publishRecursive()); @@ -364,7 +363,7 @@ class VirtualPageTest extends FunctionalTest public function testDeletingFromLiveSourcePageOfAVirtualPageAlsoUnpublishesVirtualPage() { // Create page and virutal page - $p = new Page(); + $p = new SiteTree(); $p->Title = "source"; $p->write(); $this->assertTrue($p->publishRecursive()); @@ -384,7 +383,7 @@ class VirtualPageTest extends FunctionalTest ->byID($pID); $this->assertNull($vpDraft); // Delete the source page form live, confirm that the virtual page has also been unpublished - /** @var Page $pLive */ + /** @var SiteTree $pLive */ $pLive = Versioned::get_by_stage(SiteTree::class, Versioned::LIVE) ->byID($pID); $this->assertTrue($pLive->doUnpublish()); diff --git a/tests/php/Model/VirtualPageTest.yml b/tests/php/Model/VirtualPageTest.yml index 59571e47..37dc6f29 100644 --- a/tests/php/Model/VirtualPageTest.yml +++ b/tests/php/Model/VirtualPageTest.yml @@ -31,7 +31,7 @@ SilverStripe\Security\Member: alice: Email: alice@alice.com Groups: =>SilverStripe\Security\Group.alicegroup -Page: +SilverStripe\CMS\Model\SiteTree: master: Title: My Page MenuTitle: My Page Nav @@ -52,15 +52,15 @@ SilverStripe\CMS\Tests\Model\VirtualPageTest_ClassA: SilverStripe\CMS\Model\VirtualPage: vp1: Title: vp1 - CopyContentFrom: =>Page.master - Parent: =>Page.holder + CopyContentFrom: =>SilverStripe\CMS\Model\SiteTree.master + Parent: =>SilverStripe\CMS\Model\SiteTree.holder vp2: Title: vp2 - CopyContentFrom: =>Page.master - Parent: =>Page.holder + CopyContentFrom: =>SilverStripe\CMS\Model\SiteTree.master + Parent: =>SilverStripe\CMS\Model\SiteTree.holder vp3: - CopyContentFrom: =>Page.master3 - Parent: =>Page.holder + CopyContentFrom: =>SilverStripe\CMS\Model\SiteTree.master3 + Parent: =>SilverStripe\CMS\Model\SiteTree.holder CanEditType: OnlyTheseUsers CanViewType: OnlyTheseUsers EditorGroups: =>SilverStripe\Security\Group.andrewgroup diff --git a/tests/php/Model/VirtualPageTest_ClassA.php b/tests/php/Model/VirtualPageTest_ClassA.php index 55ae2320..b2cc31fc 100644 --- a/tests/php/Model/VirtualPageTest_ClassA.php +++ b/tests/php/Model/VirtualPageTest_ClassA.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class VirtualPageTest_ClassA extends Page implements TestOnly +class VirtualPageTest_ClassA extends SiteTree implements TestOnly { private static $table_name = 'VirtualPageTest_ClassA'; diff --git a/tests/php/Model/VirtualPageTest_ClassAController.php b/tests/php/Model/VirtualPageTest_ClassAController.php index 578d9db3..63e075a7 100644 --- a/tests/php/Model/VirtualPageTest_ClassAController.php +++ b/tests/php/Model/VirtualPageTest_ClassAController.php @@ -3,12 +3,12 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use PageController; +use SilverStripe\CMS\Controllers\ContentController; -class VirtualPageTest_ClassAController extends PageController implements TestOnly +class VirtualPageTest_ClassAController extends ContentController implements TestOnly { private static $allowed_actions = [ - 'testaction' + 'testaction', ]; public function testMethod() diff --git a/tests/php/Model/VirtualPageTest_ClassB.php b/tests/php/Model/VirtualPageTest_ClassB.php index 562a1290..52715e18 100644 --- a/tests/php/Model/VirtualPageTest_ClassB.php +++ b/tests/php/Model/VirtualPageTest_ClassB.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class VirtualPageTest_ClassB extends Page implements TestOnly +class VirtualPageTest_ClassB extends SiteTree implements TestOnly { private static $table_name = 'VirtualPageTest_ClassB'; diff --git a/tests/php/Model/VirtualPageTest_ClassC.php b/tests/php/Model/VirtualPageTest_ClassC.php index 61125eee..7bac2f3d 100644 --- a/tests/php/Model/VirtualPageTest_ClassC.php +++ b/tests/php/Model/VirtualPageTest_ClassC.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class VirtualPageTest_ClassC extends Page implements TestOnly +class VirtualPageTest_ClassC extends SiteTree implements TestOnly { private static $table_name = 'VirtualPageTest_ClassC'; diff --git a/tests/php/Model/VirtualPageTest_NotRoot.php b/tests/php/Model/VirtualPageTest_NotRoot.php index a3c5ce6b..5fbcc23f 100644 --- a/tests/php/Model/VirtualPageTest_NotRoot.php +++ b/tests/php/Model/VirtualPageTest_NotRoot.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class VirtualPageTest_NotRoot extends Page implements TestOnly +class VirtualPageTest_NotRoot extends SiteTree implements TestOnly { private static $table_name = 'VirtualPageTest_NotRoot'; diff --git a/tests/php/Model/VirtualPageTest_PageExtension.php b/tests/php/Model/VirtualPageTest_PageExtension.php index 8073c266..455cd9b9 100644 --- a/tests/php/Model/VirtualPageTest_PageExtension.php +++ b/tests/php/Model/VirtualPageTest_PageExtension.php @@ -9,7 +9,8 @@ class VirtualPageTest_PageExtension extends DataExtension implements TestOnly { private static $db = [ // These fields are just on an extension to simulate shared properties between Page and VirtualPage. - // Not possible through direct $db definitions due to VirtualPage inheriting from Page, and Page being defined elsewhere. + // Not possible through direct $db definitions due to VirtualPage inheriting from Page, + // and Page being defined elsewhere. 'MySharedVirtualField' => 'Text', 'MySharedNonVirtualField' => 'Text', ]; diff --git a/tests/php/Model/VirtualPageTest_PageWithAllowedChildren.php b/tests/php/Model/VirtualPageTest_PageWithAllowedChildren.php index d43441d3..4c9b8c73 100644 --- a/tests/php/Model/VirtualPageTest_PageWithAllowedChildren.php +++ b/tests/php/Model/VirtualPageTest_PageWithAllowedChildren.php @@ -4,9 +4,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\CMS\Model\VirtualPage; use SilverStripe\Dev\TestOnly; -use Page; +use SilverStripe\CMS\Model\SiteTree; -class VirtualPageTest_PageWithAllowedChildren extends Page implements TestOnly +class VirtualPageTest_PageWithAllowedChildren extends SiteTree implements TestOnly { private static $table_name = 'VirtualPageTest_PageWithAllowedChildren'; diff --git a/tests/php/Reports/CmsReportsTest.php b/tests/php/Reports/CmsReportsTest.php index ffb8fdaa..1f24c17d 100644 --- a/tests/php/Reports/CmsReportsTest.php +++ b/tests/php/Reports/CmsReportsTest.php @@ -2,24 +2,22 @@ namespace SilverStripe\CMS\Tests\Reports; +use SilverStripe\Assets\File; +use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\SiteTree; +use SilverStripe\CMS\Model\VirtualPage; +use SilverStripe\CMS\Reports\BrokenFilesReport; +use SilverStripe\CMS\Reports\BrokenLinksReport; +use SilverStripe\CMS\Reports\BrokenRedirectorPagesReport; +use SilverStripe\CMS\Reports\BrokenVirtualPagesReport; +use SilverStripe\CMS\Reports\RecentlyEditedReport; +use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DB; use SilverStripe\ORM\FieldType\DBDatetime; -use SilverStripe\CMS\Reports\RecentlyEditedReport; -use SilverStripe\CMS\Reports\BrokenLinksReport; -use SilverStripe\CMS\Reports\BrokenFilesReport; -use SilverStripe\CMS\Model\VirtualPage; -use SilverStripe\CMS\Reports\BrokenVirtualPagesReport; -use SilverStripe\CMS\Model\RedirectorPage; -use SilverStripe\CMS\Reports\BrokenRedirectorPagesReport; use SilverStripe\Reports\Report; -use SilverStripe\Assets\File; -use SilverStripe\Dev\SapphireTest; -use Page; class CmsReportsTest extends SapphireTest { - protected static $fixture_file = 'CmsReportsTest.yml'; private static $daysAgo = 14; @@ -29,14 +27,19 @@ class CmsReportsTest extends SapphireTest parent::setUp(); // set the dates by hand: impossible to set via yml - $afterThreshold = strtotime('-'.(self::$daysAgo-1).' days', strtotime('31-06-2009 00:00:00')); - $beforeThreshold = strtotime('-'.(self::$daysAgo+1).' days', strtotime('31-06-2009 00:00:00')); + $afterThreshold = strtotime('-' . (self::$daysAgo - 1) . ' days', strtotime('31-06-2009 00:00:00')); + $beforeThreshold = strtotime('-' . (self::$daysAgo + 1) . ' days', strtotime('31-06-2009 00:00:00')); $after = $this->objFromFixture(SiteTree::class, 'after'); $before = $this->objFromFixture(SiteTree::class, 'before'); - - DB::query("UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='".date('Y-m-d H:i:s', $afterThreshold)."' WHERE \"ID\"='".$after->ID."'"); - DB::query("UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='".date('Y-m-d H:i:s', $beforeThreshold)."' WHERE \"ID\"='".$before->ID."'"); + DB::query( + "UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='" . + date('Y-m-d H:i:s', $afterThreshold) . "' WHERE \"ID\"='" . $after->ID . "'" + ); + DB::query( + "UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='" . + date('Y-m-d H:i:s', $beforeThreshold) . "' WHERE \"ID\"='" . $before->ID . "'" + ); } /** @@ -52,13 +55,27 @@ class CmsReportsTest extends SapphireTest // ASSERT that the "draft" report is returning the correct results. $parameters = ['CheckSite' => 'Draft']; - $results = count($report->sourceRecords($parameters, null, null) ?? []) > 0; - $isDraftBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct DRAFT results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct DRAFT results, as pages were found."); + $results = count($report->sourceRecords($parameters, null, null)) > 0; + $isDraftBroken + ? $this->assertTrue( + $results, + "{$class} has NOT returned the correct DRAFT results, as NO pages were found." + ) : $this->assertFalse( + $results, + "{$class} has NOT returned the correct DRAFT results, as pages were found." + ); // ASSERT that the "published" report is returning the correct results. $parameters = ['CheckSite' => 'Published', 'OnLive' => 1]; $results = count($report->sourceRecords($parameters, null, null) ?? []) > 0; - $isPublishedBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct PUBLISHED results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct PUBLISHED results, as pages were found."); + $isPublishedBroken + ? $this->assertTrue( + $results, + "{$class} has NOT returned the correct PUBLISHED results, as NO pages were found." + ) : $this->assertFalse( + $results, + "{$class} has NOT returned the correct PUBLISHED results, as pages were found." + ); } public function testRecentlyEdited() @@ -81,18 +98,14 @@ class CmsReportsTest extends SapphireTest /** * Test the broken links side report. */ - public function testBrokenLinks() { - // Create a "draft" page with a broken link. - - $page = Page::create(); + $page = new SiteTree(); $page->Content = "This is a broken link."; $page->writeToStage('Stage'); // Retrieve the broken links side report. - $reports = Report::get_reports(); $brokenLinksReport = null; foreach ($reports as $report) { @@ -109,12 +122,11 @@ class CmsReportsTest extends SapphireTest } // ASSERT that the "draft" report has detected the page having a broken link. - // ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet. - + // ASSERT that the "published" report has NOT detected the page having a broken link, + // as the page has not been "published" yet. $this->isReportBroken($brokenLinksReport, true, false); // Make sure the page is now "published". - $page->writeToStage('Live'); // ASSERT that the "draft" report has detected the page having a broken link. @@ -123,17 +135,15 @@ class CmsReportsTest extends SapphireTest $this->isReportBroken($brokenLinksReport, true, true); // Correct the "draft" broken link. - $page->Content = str_replace('987654321', $page->ID ?? '', $page->Content ?? ''); $page->writeToStage('Stage'); // ASSERT that the "draft" report has NOT detected the page having a broken link. - // ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published". - + // ASSERT that the "published" report has detected the page having a broken link, + // as the previous content remains "published". $this->isReportBroken($brokenLinksReport, false, true); // Make sure the change has now been "published". - $page->writeToStage('Live'); // ASSERT that the "draft" report has NOT detected the page having a broken link. @@ -145,18 +155,14 @@ class CmsReportsTest extends SapphireTest /** * Test the broken files side report. */ - public function testBrokenFiles() { - // Create a "draft" page with a broken file. - - $page = Page::create(); + $page = new SiteTree(); $page->Content = "This is a broken file."; $page->writeToStage('Stage'); // Retrieve the broken files side report. - $reports = Report::get_reports(); $brokenFilesReport = null; foreach ($reports as $report) { @@ -173,21 +179,18 @@ class CmsReportsTest extends SapphireTest } // ASSERT that the "draft" report has detected the page having a broken file. - // ASSERT that the "published" report has NOT detected the page having a broken file, as the page has not been "published" yet. - + // ASSERT that the "published" report has NOT detected the page having a broken file, + // as the page has not been "published" yet. $this->isReportBroken($brokenFilesReport, true, false); // Make sure the page is now "published". - $page->writeToStage('Live'); // ASSERT that the "draft" report has detected the page having a broken file. // ASSERT that the "published" report has detected the page having a broken file. - $this->isReportBroken($brokenFilesReport, true, true); // Correct the "draft" broken file. - $file = File::create(); $file->Filename = 'name.pdf'; $file->write(); @@ -195,17 +198,15 @@ class CmsReportsTest extends SapphireTest $page->writeToStage('Stage'); // ASSERT that the "draft" report has NOT detected the page having a broken file. - // ASSERT that the "published" report has detected the page having a broken file, as the previous content remains "published". - + // ASSERT that the "published" report has detected the page having a broken file, + // as the previous content remains "published". $this->isReportBroken($brokenFilesReport, false, true); // Make sure the change has now been "published". - $page->writeToStage('Live'); // ASSERT that the "draft" report has NOT detected the page having a broken file. // ASSERT that the "published" report has NOT detected the page having a broken file. - $this->isReportBroken($brokenFilesReport, false, false); } @@ -215,15 +216,12 @@ class CmsReportsTest extends SapphireTest public function testBrokenVirtualPages() { - // Create a "draft" virtual page with a broken link. - $page = VirtualPage::create(); $page->CopyContentFromID = 987654321; $page->writeToStage('Stage'); // Retrieve the broken virtual pages side report. - $reports = Report::get_reports(); $brokenVirtualPagesReport = null; foreach ($reports as $report) { @@ -240,22 +238,19 @@ class CmsReportsTest extends SapphireTest } // ASSERT that the "draft" report has detected the page having a broken link. - // ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet. - + // ASSERT that the "published" report has NOT detected the page having a broken link, + // as the page has not been "published" yet. $this->isReportBroken($brokenVirtualPagesReport, true, false); // Make sure the page is now "published". - $page->writeToStage('Live'); // ASSERT that the "draft" report has detected the page having a broken link. // ASSERT that the "published" report has detected the page having a broken link. - $this->isReportBroken($brokenVirtualPagesReport, true, true); // Correct the "draft" broken link. - - $contentPage = Page::create(); + $contentPage = new SiteTree(); $contentPage->Content = 'This is some content.'; $contentPage->writeToStage('Stage'); $contentPage->writeToStage('Live'); @@ -263,36 +258,30 @@ class CmsReportsTest extends SapphireTest $page->writeToStage('Stage'); // ASSERT that the "draft" report has NOT detected the page having a broken link. - // ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published". - + // ASSERT that the "published" report has detected the page having a broken link, + // as the previous content remains "published". $this->isReportBroken($brokenVirtualPagesReport, false, true); // Make sure the change has now been "published". - $page->writeToStage('Live'); // ASSERT that the "draft" report has NOT detected the page having a broken link. // ASSERT that the "published" report has NOT detected the page having a broken link. - $this->isReportBroken($brokenVirtualPagesReport, false, false); } /** * Test the broken redirector pages side report. */ - public function testBrokenRedirectorPages() { - // Create a "draft" redirector page with a broken link. - $page = RedirectorPage::create(); $page->RedirectionType = 'Internal'; $page->LinkToID = 987654321; $page->writeToStage('Stage'); // Retrieve the broken redirector pages side report. - $reports = Report::get_reports(); $brokenRedirectorPagesReport = null; foreach ($reports as $report) { @@ -309,22 +298,19 @@ class CmsReportsTest extends SapphireTest } // ASSERT that the "draft" report has detected the page having a broken link. - // ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet. - + // ASSERT that the "published" report has NOT detected the page having a broken link, + // as the page has not been "published" yet. $this->isReportBroken($brokenRedirectorPagesReport, true, false); // Make sure the page is now "published". - $page->writeToStage('Live'); // ASSERT that the "draft" report has detected the page having a broken link. // ASSERT that the "published" report has detected the page having a broken link. - $this->isReportBroken($brokenRedirectorPagesReport, true, true); // Correct the "draft" broken link. - - $contentPage = Page::create(); + $contentPage = new SiteTree(); $contentPage->Content = 'This is some content.'; $contentPage->writeToStage('Stage'); $contentPage->writeToStage('Live'); @@ -332,17 +318,15 @@ class CmsReportsTest extends SapphireTest $page->writeToStage('Stage'); // ASSERT that the "draft" report has NOT detected the page having a broken link. - // ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published". - + // ASSERT that the "published" report has detected the page having a broken link, + // as the previous content remains "published". $this->isReportBroken($brokenRedirectorPagesReport, false, true); // Make sure the change has now been "published". - $page->writeToStage('Live'); // ASSERT that the "draft" report has NOT detected the page having a broken link. // ASSERT that the "published" report has NOT detected the page having a broken link. - $this->isReportBroken($brokenRedirectorPagesReport, false, false); } } diff --git a/tests/php/Search/CMSMainSearchFormTest.php b/tests/php/Search/CMSMainSearchFormTest.php index 9835552a..8be8a547 100644 --- a/tests/php/Search/CMSMainSearchFormTest.php +++ b/tests/php/Search/CMSMainSearchFormTest.php @@ -20,7 +20,7 @@ class CMSMainSearchFormTest extends FunctionalTest 'q' => [ 'Term' => 'Page 10', 'FilterClass' => CMSSiteTreeFilter_Search::class, - ] + ], ]) ); diff --git a/tests/php/Search/SearchFormTest.php b/tests/php/Search/SearchFormTest.php index 3f8653ab..390ba67b 100644 --- a/tests/php/Search/SearchFormTest.php +++ b/tests/php/Search/SearchFormTest.php @@ -2,7 +2,6 @@ namespace SilverStripe\CMS\Tests\Search; -use Page; use SilverStripe\Assets\File; use SilverStripe\CMS\Controllers\ContentController; use SilverStripe\CMS\Controllers\ModelAsController; @@ -29,7 +28,6 @@ use TractorCow\Fluent\Extension\FluentSiteTreeExtension; */ class ZZZSearchFormTest extends FunctionalTest { - protected static $fixture_file = 'SearchFormTest.yml'; protected static $illegal_extensions = [ diff --git a/tests/php/Tasks/RemoveOrphanedPagesTaskTest.php b/tests/php/Tasks/RemoveOrphanedPagesTaskTest.php index dc3450b6..52691154 100644 --- a/tests/php/Tasks/RemoveOrphanedPagesTaskTest.php +++ b/tests/php/Tasks/RemoveOrphanedPagesTaskTest.php @@ -3,8 +3,8 @@ namespace SilverStripe\CMS\Tests\Tasks; use SilverStripe\CMS\Tasks\RemoveOrphanedPagesTask; -use SilverStripe\Versioned\Versioned; use SilverStripe\Dev\FunctionalTest; +use SilverStripe\CMS\Model\SiteTree; /** *

Fixture tree

@@ -42,54 +42,54 @@ class RemoveOrphanedPagesTaskTest extends FunctionalTest { parent::setUp(); - $parent1_published = $this->objFromFixture('Page', 'parent1_published'); + $parent1_published = $this->objFromFixture(SiteTree::class, 'parent1_published'); $parent1_published->publishSingle(); - $child1_1_published = $this->objFromFixture('Page', 'child1_1_published'); + $child1_1_published = $this->objFromFixture(SiteTree::class, 'child1_1_published'); $child1_1_published->publishSingle(); - $child1_2_published = $this->objFromFixture('Page', 'child1_2_published'); + $child1_2_published = $this->objFromFixture(SiteTree::class, 'child1_2_published'); $child1_2_published->publishSingle(); - $child1_3_orphaned = $this->objFromFixture('Page', 'child1_3_orphaned'); + $child1_3_orphaned = $this->objFromFixture(SiteTree::class, 'child1_3_orphaned'); $child1_3_orphaned->ParentID = 9999; $child1_3_orphaned->write(); - $child1_4_orphaned_published = $this->objFromFixture('Page', 'child1_4_orphaned_published'); + $child1_4_orphaned_published = $this->objFromFixture(SiteTree::class, 'child1_4_orphaned_published'); $child1_4_orphaned_published->ParentID = 9999; $child1_4_orphaned_published->write(); $child1_4_orphaned_published->publishSingle(); - $grandchild1_1_2_published = $this->objFromFixture('Page', 'grandchild1_1_2_published'); + $grandchild1_1_2_published = $this->objFromFixture(SiteTree::class, 'grandchild1_1_2_published'); $grandchild1_1_2_published->publishSingle(); - $grandchild1_1_3_orphaned = $this->objFromFixture('Page', 'grandchild1_1_3_orphaned'); + $grandchild1_1_3_orphaned = $this->objFromFixture(SiteTree::class, 'grandchild1_1_3_orphaned'); $grandchild1_1_3_orphaned->ParentID = 9999; $grandchild1_1_3_orphaned->write(); $grandchild1_1_4_orphaned_published = $this->objFromFixture( - 'Page', + SiteTree::class, 'grandchild1_1_4_orphaned_published' ); $grandchild1_1_4_orphaned_published->ParentID = 9999; $grandchild1_1_4_orphaned_published->write(); $grandchild1_1_4_orphaned_published->publishSingle(); - $child2_1_published_orphaned = $this->objFromFixture('Page', 'child2_1_published_orphaned'); + $child2_1_published_orphaned = $this->objFromFixture(SiteTree::class, 'child2_1_published_orphaned'); $child2_1_published_orphaned->publishSingle(); } public function testGetOrphansByStage() { // all orphans - $child1_3_orphaned = $this->objFromFixture('Page', 'child1_3_orphaned'); - $child1_4_orphaned_published = $this->objFromFixture('Page', 'child1_4_orphaned_published'); - $grandchild1_1_3_orphaned = $this->objFromFixture('Page', 'grandchild1_1_3_orphaned'); + $child1_3_orphaned = $this->objFromFixture(SiteTree::class, 'child1_3_orphaned'); + $child1_4_orphaned_published = $this->objFromFixture(SiteTree::class, 'child1_4_orphaned_published'); + $grandchild1_1_3_orphaned = $this->objFromFixture(SiteTree::class, 'grandchild1_1_3_orphaned'); $grandchild1_1_4_orphaned_published = $this->objFromFixture( - 'Page', + SiteTree::class, 'grandchild1_1_4_orphaned_published' ); - $child2_1_published_orphaned = $this->objFromFixture('Page', 'child2_1_published_orphaned'); + $child2_1_published_orphaned = $this->objFromFixture(SiteTree::class, 'child2_1_published_orphaned'); $task = singleton(RemoveOrphanedPagesTask::class); $orphans = $task->getOrphanedPages(); @@ -100,7 +100,7 @@ class RemoveOrphanedPagesTaskTest extends FunctionalTest $child1_4_orphaned_published->ID, $grandchild1_1_3_orphaned->ID, $grandchild1_1_4_orphaned_published->ID, - $child2_1_published_orphaned->ID + $child2_1_published_orphaned->ID, ]; sort($compareIDs); diff --git a/tests/php/Tasks/RemoveOrphanedPagesTaskTest.yml b/tests/php/Tasks/RemoveOrphanedPagesTaskTest.yml index 79e81763..e8f3d68e 100644 --- a/tests/php/Tasks/RemoveOrphanedPagesTaskTest.yml +++ b/tests/php/Tasks/RemoveOrphanedPagesTaskTest.yml @@ -1,32 +1,32 @@ -Page: +SilverStripe\CMS\Model\SiteTree: parent1_published: Title: Parent1 child1_1_published: Title: Child1.1 - Parent: =>Page.parent1_published + Parent: =>SilverStripe\CMS\Model\SiteTree.parent1_published child1_2_published: Title: Child1.2 - Parent: =>Page.parent1_published + Parent: =>SilverStripe\CMS\Model\SiteTree.parent1_published child1_3_orphaned: Title: Child1.3 - Parent: =>Page.parent1_published + Parent: =>SilverStripe\CMS\Model\SiteTree.parent1_published child1_4_orphaned_published: Title: Child1.4 - Parent: =>Page.parent1_published + Parent: =>SilverStripe\CMS\Model\SiteTree.parent1_published grandchild1_1_1: Title: Grandchild1.1.1 - Parent: =>Page.child1_1_published + Parent: =>SilverStripe\CMS\Model\SiteTree.child1_1_published grandchild1_1_2_published: Title: Grandchild1.1.2 - Parent: =>Page.child1_1_published + Parent: =>SilverStripe\CMS\Model\SiteTree.child1_1_published grandchild1_1_3_orphaned: Title: Grandchild1.1.3 - Parent: =>Page.child1_1_published + Parent: =>SilverStripe\CMS\Model\SiteTree.child1_1_published grandchild1_1_4_orphaned_published: Title: Grandchild1.1.4 - Parent: =>Page.child1_1_published + Parent: =>SilverStripe\CMS\Model\SiteTree.child1_1_published parent2: Title: Parent2 child2_1_published_orphaned: Title: Child2.1 - Parent: =>Page.parent2 + Parent: =>SilverStripe\CMS\Model\SiteTree.parent2