MNT Use SiteTree instead of Page in tests

This commit is contained in:
Mike Cochrane 2018-05-04 01:04:18 +00:00 committed by Guy Sartorelli
parent 859ff00184
commit 2219899c10
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A
67 changed files with 849 additions and 663 deletions

View File

@ -16,7 +16,6 @@ use SilverStripe\Versioned\Versioned;
*/ */
class CMSBatchActionsTest extends SapphireTest class CMSBatchActionsTest extends SapphireTest
{ {
protected static $fixture_file = 'CMSBatchActionsTest.yml'; protected static $fixture_file = 'CMSBatchActionsTest.yml';
protected function setUp(): void protected function setUp(): void
@ -145,7 +144,7 @@ class CMSBatchActionsTest extends SapphireTest
$result = json_decode($action->run($list) ?? '', true); $result = json_decode($action->run($list) ?? '', true);
$this->assertEquals( $this->assertEquals(
[ [
$archivedxID => $archivedxID $archivedxID => $archivedxID,
], ],
$result['success'] $result['success']
); );
@ -168,7 +167,7 @@ class CMSBatchActionsTest extends SapphireTest
// Order of archived is opposite to order items are passed in, as // Order of archived is opposite to order items are passed in, as
// these are sorted by level first // these are sorted by level first
$archivedID => $archivedID, $archivedID => $archivedID,
$archivedyID => $archivedyID $archivedyID => $archivedyID,
], ],
$result['success'] $result['success']
); );

View File

@ -2,7 +2,6 @@
namespace SilverStripe\CMS\Tests\Controllers; namespace SilverStripe\CMS\Tests\Controllers;
use Page;
use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\CacheInterface;
use SilverStripe\Admin\CMSBatchActionHandler; use SilverStripe\Admin\CMSBatchActionHandler;
use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\CMS\Controllers\CMSMain;
@ -123,8 +122,8 @@ class CMSMainTest extends FunctionalTest
*/ */
public function testPublish() public function testPublish()
{ {
$page1 = $this->objFromFixture(Page::class, "page1"); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
$page2 = $this->objFromFixture(Page::class, "page2"); $page2 = $this->objFromFixture(SiteTree::class, 'page2');
$this->logInAs('admin'); $this->logInAs('admin');
$response = $this->get('admin/pages/publishall?confirm=1'); $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 // Some modules (e.g., cmsworkflow) will remove this action
$actions = CMSBatchActionHandler::config()->batch_actions; $actions = CMSBatchActionHandler::config()->batch_actions;
if (isset($actions['publish'])) { 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); $responseData = json_decode($response->getBody() ?? '', true);
$this->assertArrayHasKey($page1->ID, $responseData['modified']); $this->assertArrayHasKey($page1->ID, $responseData['modified']);
$this->assertArrayHasKey($page2->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 // Get the latest version of the redirector page
$pageID = $this->idFromFixture(RedirectorPage::class, 'page5'); $pageID = $this->idFromFixture(RedirectorPage::class, 'page5');
$latestID = DB::prepared_query('select max("Version") from "RedirectorPage_Versions" where "RecordID" = ?', [$pageID])->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(); $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); $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'); $this->logInWithPermission('ADMIN');
Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', true); Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', true);
$parentPage = $this->objFromFixture(Page::class, 'page3'); $parentPage = $this->objFromFixture(SiteTree::class, 'page3');
$childPage = $this->objFromFixture(Page::class, 'page1'); $childPage = $this->objFromFixture(SiteTree::class, 'page1');
$parentPage->doUnpublish(); $parentPage->doUnpublish();
$childPage->doUnpublish(); $childPage->doUnpublish();
@ -204,7 +205,7 @@ class CMSMainTest extends FunctionalTest
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
// Set up a page that is delete from live // Set up a page that is delete from live
$page = $this->objFromFixture(Page::class, 'page1'); $page = $this->objFromFixture(SiteTree::class, 'page1');
$pageID = $page->ID; $pageID = $page->ID;
$page->publishRecursive(); $page->publishRecursive();
$page->delete(); $page->delete();
@ -212,7 +213,7 @@ class CMSMainTest extends FunctionalTest
$response = $this->get('admin/pages/edit/show/' . $pageID); $response = $this->get('admin/pages/edit/show/' . $pageID);
$livePage = Versioned::get_one_by_stage(SiteTree::class, Versioned::LIVE, [ $livePage = Versioned::get_one_by_stage(SiteTree::class, Versioned::LIVE, [
'"SiteTree"."ID"' => $pageID '"SiteTree"."ID"' => $pageID,
]); ]);
$this->assertInstanceOf(SiteTree::class, $livePage); $this->assertInstanceOf(SiteTree::class, $livePage);
$this->assertTrue($livePage->canDelete()); $this->assertTrue($livePage->canDelete());
@ -229,7 +230,7 @@ class CMSMainTest extends FunctionalTest
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
// Set up a page that is delete from live // Set up a page that is delete from live
$page1 = $this->objFromFixture(Page::class, 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
$page1ID = $page1->ID; $page1ID = $page1->ID;
$page1->publishRecursive(); $page1->publishRecursive();
$page1->delete(); $page1->delete();
@ -242,18 +243,18 @@ class CMSMainTest extends FunctionalTest
$this->assertNull($cmsMain->getRecord('asdf')); $this->assertNull($cmsMain->getRecord('asdf'));
// Pages that are on draft and aren't on draft should both work // Pages that are on draft and aren't on draft should both work
$this->assertInstanceOf('Page', $cmsMain->getRecord($page1ID)); $this->assertInstanceOf(SiteTree::class, $cmsMain->getRecord($page1ID));
$this->assertInstanceOf('Page', $cmsMain->getRecord($this->idFromFixture('Page', 'page2'))); $this->assertInstanceOf(SiteTree::class, $cmsMain->getRecord($this->idFromFixture(SiteTree::class, 'page2')));
// This functionality isn't actually used any more. // This functionality isn't actually used any more.
$newPage = $cmsMain->getRecord('new-Page-5'); $newPage = $cmsMain->getRecord('new-Page-5');
$this->assertInstanceOf('Page', $newPage); $this->assertInstanceOf(SiteTree::class, $newPage);
$this->assertEquals('5', $newPage->ParentID); $this->assertEquals('5', $newPage->ParentID);
} }
public function testDeletedPagesSiteTreeFilter() public function testDeletedPagesSiteTreeFilter()
{ {
$id = $this->idFromFixture('Page', 'page3'); $id = $this->idFromFixture(SiteTree::class, 'page3');
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$result = $this->get('admin/pages/getsubtree?filter=CMSSiteTreeFilter_DeletedPages&ajax=1&ID=' . $id); $result = $this->get('admin/pages/getsubtree?filter=CMSSiteTreeFilter_DeletedPages&ajax=1&ID=' . $id);
$this->assertEquals(200, $result->getStatusCode()); $this->assertEquals(200, $result->getStatusCode());
@ -274,7 +275,7 @@ class CMSMainTest extends FunctionalTest
'admin/pages/add/AddForm', 'admin/pages/add/AddForm',
[ [
'ParentID' => '0', 'ParentID' => '0',
'PageType' => 'Page', 'PageType' => RedirectorPage::class,
'Locale' => 'en_US', 'Locale' => 'en_US',
'action_doAdd' => 1, 'action_doAdd' => 1,
'ajax' => 1, 'ajax' => 1,
@ -294,7 +295,7 @@ class CMSMainTest extends FunctionalTest
'admin/pages/add/AddForm', 'admin/pages/add/AddForm',
[ [
'ParentID' => '0', 'ParentID' => '0',
'PageType' => 'Page', 'PageType' => RedirectorPage::class,
'Locale' => 'en_US', 'Locale' => 'en_US',
'action_doAdd' => 1, 'action_doAdd' => 1,
'ajax' => 1, 'ajax' => 1,
@ -328,7 +329,7 @@ class CMSMainTest extends FunctionalTest
'PageType' => CMSMainTest_ClassA::class, 'PageType' => CMSMainTest_ClassA::class,
'Locale' => 'en_US', 'Locale' => 'en_US',
'action_doAdd' => 1, 'action_doAdd' => 1,
'ajax' => 1 'ajax' => 1,
], ],
[ [
'X-Pjax' => 'CurrentForm,Breadcrumbs', 'X-Pjax' => 'CurrentForm,Breadcrumbs',
@ -348,7 +349,7 @@ class CMSMainTest extends FunctionalTest
'PageType' => CMSMainTest_ClassB::class, 'PageType' => CMSMainTest_ClassB::class,
'Locale' => 'en_US', 'Locale' => 'en_US',
'action_doAdd' => 1, 'action_doAdd' => 1,
'ajax' => 1 'ajax' => 1,
], ],
[ [
'X-Pjax' => 'CurrentForm,Breadcrumbs', 'X-Pjax' => 'CurrentForm,Breadcrumbs',
@ -371,10 +372,10 @@ class CMSMainTest extends FunctionalTest
'admin/pages/add/AddForm', 'admin/pages/add/AddForm',
[ [
'ParentID' => $newPageId, 'ParentID' => $newPageId,
'PageType' => 'Page', 'PageType' => RedirectorPage::class,
'Locale' => 'en_US', 'Locale' => 'en_US',
'action_doAdd' => 1, 'action_doAdd' => 1,
'ajax' => 1 'ajax' => 1,
], ],
[ [
'X-Pjax' => 'CurrentForm,Breadcrumbs', 'X-Pjax' => 'CurrentForm,Breadcrumbs',
@ -389,8 +390,8 @@ class CMSMainTest extends FunctionalTest
public function testBreadcrumbs() public function testBreadcrumbs()
{ {
$page3 = $this->objFromFixture(Page::class, 'page3'); $page3 = $this->objFromFixture(SiteTree::class, 'page3');
$page31 = $this->objFromFixture(Page::class, 'page31'); $page31 = $this->objFromFixture(SiteTree::class, 'page31');
$this->logInAs('admin'); $this->logInAs('admin');
$response = $this->get('admin/pages/edit/show/' . $page31->ID); $response = $this->get('admin/pages/edit/show/' . $page31->ID);
@ -416,7 +417,7 @@ class CMSMainTest extends FunctionalTest
$this->assertEquals($page->Title, 'New Page'); $this->assertEquals($page->Title, 'New Page');
$this->assertNotEquals($page->Sort, 0); $this->assertNotEquals($page->Sort, 0);
$this->assertInstanceOf('Page', $page); $this->assertInstanceOf(SiteTree::class, $page);
// Test failure // Test failure
try { try {
@ -445,10 +446,10 @@ class CMSMainTest extends FunctionalTest
); );
// Change state of tree // Change state of tree
$page1 = $this->objFromFixture(Page::class, 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
$page3 = $this->objFromFixture(Page::class, 'page3'); $page3 = $this->objFromFixture(SiteTree::class, 'page3');
$page11 = $this->objFromFixture(Page::class, 'page11'); $page11 = $this->objFromFixture(SiteTree::class, 'page11');
$page12 = $this->objFromFixture(Page::class, 'page12'); $page12 = $this->objFromFixture(SiteTree::class, 'page12');
// Deleted // Deleted
$page1->doUnpublish(); $page1->doUnpublish();
$page1->delete(); $page1->delete();
@ -468,7 +469,7 @@ class CMSMainTest extends FunctionalTest
// Test deleted page filter // Test deleted page filter
$params = [ $params = [
'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_StatusDeletedPages' 'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_StatusDeletedPages',
]; ];
$pages = $controller->getList($params); $pages = $controller->getList($params);
$this->assertEquals(1, $pages->count()); $this->assertEquals(1, $pages->count());
@ -479,7 +480,7 @@ class CMSMainTest extends FunctionalTest
// Test live, but not on draft filter // Test live, but not on draft filter
$params = [ $params = [
'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_StatusRemovedFromDraftPages' 'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_StatusRemovedFromDraftPages',
]; ];
$pages = $controller->getList($params); $pages = $controller->getList($params);
$this->assertEquals(1, $pages->count()); $this->assertEquals(1, $pages->count());
@ -490,7 +491,7 @@ class CMSMainTest extends FunctionalTest
// Test live pages filter // Test live pages filter
$params = [ $params = [
'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_PublishedPages' 'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_PublishedPages',
]; ];
$pages = $controller->getList($params); $pages = $controller->getList($params);
$this->assertEquals(2, $pages->count()); $this->assertEquals(2, $pages->count());
@ -525,7 +526,7 @@ class CMSMainTest extends FunctionalTest
$this->loginWithPermission('ADMIN'); $this->loginWithPermission('ADMIN');
// Get a associated with a fixture page. // Get a associated with a fixture page.
$page = $this->objFromFixture(Page::class, 'page1'); $page = $this->objFromFixture(SiteTree::class, 'page1');
$controller = CMSMain::create(); $controller = CMSMain::create();
$controller->setRequest(Controller::curr()->getRequest()); $controller->setRequest(Controller::curr()->getRequest());
$form = $controller->getEditForm($page->ID); $form = $controller->getEditForm($page->ID);
@ -553,7 +554,7 @@ class CMSMainTest extends FunctionalTest
$form->loadDataFrom(['ClassName' => CMSMainTest_ClassB::class]); $form->loadDataFrom(['ClassName' => CMSMainTest_ClassB::class]);
$result = $cms->save([ $result = $cms->save([
'ID' => $page->ID, 'ID' => $page->ID,
'ClassName' => CMSMainTest_ClassB::class 'ClassName' => CMSMainTest_ClassB::class,
], $form); ], $form);
$this->assertEquals(200, $result->getStatusCode()); $this->assertEquals(200, $result->getStatusCode());

View File

@ -1,4 +1,4 @@
Page: SilverStripe\CMS\Model\SiteTree:
page1: page1:
Title: Page 1 Title: Page 1
Sort: 1 Sort: 1
@ -10,11 +10,11 @@ Page:
Sort: 3 Sort: 3
page31: page31:
Title: Page 3.1 Title: Page 3.1
Parent: =>Page.page3 Parent: =>SilverStripe\CMS\Model\SiteTree.page3
Sort: 1 Sort: 1
page32: page32:
Title: Page 3.2 Title: Page 3.2
Parent: =>Page.page3 Parent: =>SilverStripe\CMS\Model\SiteTree.page3
Sort: 2 Sort: 2
page4: page4:
Title: Page 4 Title: Page 4

View File

@ -2,11 +2,11 @@
namespace SilverStripe\CMS\Tests\Controllers; namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\ValidationException; 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'; private static $table_name = 'CMSMainTest_ClassA';

View File

@ -2,11 +2,11 @@
namespace SilverStripe\CMS\Tests\Controllers; namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\ValidationException; 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'; private static $table_name = 'CMSMainTest_ClassB';

View File

@ -2,11 +2,10 @@
namespace SilverStripe\CMS\Tests\Controllers; namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\HiddenClass; use SilverStripe\ORM\HiddenClass;
use Page;
class CMSMainTest_HiddenClass extends Page implements TestOnly, HiddenClass class CMSMainTest_HiddenClass extends SiteTree implements TestOnly, HiddenClass
{ {
} }

View File

@ -2,10 +2,10 @@
namespace SilverStripe\CMS\Tests\Controllers; namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'CMSMainTest_NotRoot';

24
tests/php/Controllers/CMSPageHistoryControllerTest.php Executable file → Normal file
View File

@ -2,16 +2,15 @@
namespace SilverStripe\CMS\Tests\Controllers; namespace SilverStripe\CMS\Tests\Controllers;
use Page;
use SilverStripe\CMS\Controllers\CMSPageHistoryController; use SilverStripe\CMS\Controllers\CMSPageHistoryController;
use SilverStripe\CMS\Tests\Controllers\CMSPageHistoryControllerTest\HistoryController; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Forms\FieldGroup; use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\HTMLReadonlyField; use SilverStripe\Forms\HTMLReadonlyField;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\TextField; use SilverStripe\Forms\TextField;
class CMSPageHistoryControllerTest extends FunctionalTest class CMSPageHistoryControllerTest extends FunctionalTest
@ -40,7 +39,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
$this->loginWithPermission('ADMIN'); $this->loginWithPermission('ADMIN');
// creates a series of published, unpublished versions of a page // creates a series of published, unpublished versions of a page
$this->page = new Page(); $this->page = new SiteTree();
$this->page->URLSegment = "test"; $this->page->URLSegment = "test";
$this->page->Content = "new content"; $this->page->Content = "new content";
$this->page->write(); $this->page->write();
@ -90,7 +89,12 @@ class CMSPageHistoryControllerTest extends FunctionalTest
); );
// check that compare mode updates the message // 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( $this->assertStringContainsString(
sprintf("Comparing versions %s", $this->versionPublishCheck), sprintf("Comparing versions %s", $this->versionPublishCheck),
$form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent() $form->Fields()->fieldByName('Root.Main.CurrentlyViewingMessage')->getContent()
@ -108,7 +112,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
*/ */
public function testVersionsForm() 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'); $form = $this->cssParser()->getBySelector('#Form_VersionsForm');
@ -127,7 +131,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
public function testVersionsFormTableContainsInformation() 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'); $form = $this->cssParser()->getBySelector('#Form_VersionsForm');
$rows = $form[0]->xpath("fieldset/table/tbody/tr"); $rows = $form[0]->xpath("fieldset/table/tbody/tr");
@ -135,7 +139,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
['version' => $this->versionPublishCheck2, 'status' => 'published'], ['version' => $this->versionPublishCheck2, 'status' => 'published'],
['version' => $this->versionUnpublishedCheck2, 'status' => 'internal'], ['version' => $this->versionUnpublishedCheck2, 'status' => 'internal'],
['version' => $this->versionPublishCheck, 'status' => 'published'], ['version' => $this->versionPublishCheck, 'status' => 'published'],
['version' => $this->versionUnpublishedCheck, 'status' => 'internal'] ['version' => $this->versionUnpublishedCheck, 'status' => 'internal'],
]; ];
// goes the reverse order that we created in setUp() // goes the reverse order that we created in setUp()
@ -153,7 +157,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
public function testVersionsFormSelectsUnpublishedCheckbox() 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'); $checkbox = $this->cssParser()->getBySelector('#Form_VersionsForm_ShowUnpublished');
$this->assertThat($checkbox[0], $this->logicalNot($this->isNull())); $this->assertThat($checkbox[0], $this->logicalNot($this->isNull()));
@ -162,7 +166,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
$this->assertThat($checked, $this->logicalNot($this->stringContains('checked'))); $this->assertThat($checked, $this->logicalNot($this->stringContains('checked')));
// viewing an unpublished // 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'); $checkbox = $this->cssParser()->getBySelector('#Form_VersionsForm_ShowUnpublished');
$this->assertThat($checkbox[0], $this->logicalNot($this->isNull())); $this->assertThat($checkbox[0], $this->logicalNot($this->isNull()));

View File

@ -1,4 +1,4 @@
Page: SilverStripe\CMS\Model\SiteTree:
page1: page1:
Title: Page 1 Title: Page 1
Sort: 1 Sort: 1

View File

@ -2,7 +2,6 @@
namespace SilverStripe\CMS\Tests\Controllers; namespace SilverStripe\CMS\Tests\Controllers;
use Page;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
use SilverStripe\CMS\Controllers\CMSSiteTreeFilter_Search; use SilverStripe\CMS\Controllers\CMSSiteTreeFilter_Search;
@ -15,13 +14,12 @@ use SilverStripe\Dev\SapphireTest;
class CMSSiteTreeFilterTest extends SapphireTest class CMSSiteTreeFilterTest extends SapphireTest
{ {
protected static $fixture_file = 'CMSSiteTreeFilterTest.yml'; protected static $fixture_file = 'CMSSiteTreeFilterTest.yml';
public function testSearchFilterEmpty() public function testSearchFilterEmpty()
{ {
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
$page2 = $this->objFromFixture('Page', 'page2'); $page2 = $this->objFromFixture(SiteTree::class, 'page2');
$f = new CMSSiteTreeFilter_Search(); $f = new CMSSiteTreeFilter_Search();
$results = $f->pagesIncluded(); $results = $f->pagesIncluded();
@ -32,8 +30,8 @@ class CMSSiteTreeFilterTest extends SapphireTest
public function testSearchFilterByTitle() public function testSearchFilterByTitle()
{ {
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
$page2 = $this->objFromFixture('Page', 'page2'); $page2 = $this->objFromFixture(SiteTree::class, 'page2');
$f = new CMSSiteTreeFilter_Search(['Title' => 'Page 1']); $f = new CMSSiteTreeFilter_Search(['Title' => 'Page 1']);
$results = $f->pagesIncluded(); $results = $f->pagesIncluded();
@ -49,7 +47,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
public function testUrlSegmentFilter() public function testUrlSegmentFilter()
{ {
$page = $this->objFromFixture(Page::class, 'page8'); $page = $this->objFromFixture(SiteTree::class, 'page8');
$filter = CMSSiteTreeFilter_Search::create(['Term' => 'lake-wanaka+adventure']); $filter = CMSSiteTreeFilter_Search::create(['Term' => 'lake-wanaka+adventure']);
$this->assertTrue($filter->isPageIncluded($page)); $this->assertTrue($filter->isPageIncluded($page));
@ -60,8 +58,8 @@ class CMSSiteTreeFilterTest extends SapphireTest
public function testIncludesParentsForNestedMatches() public function testIncludesParentsForNestedMatches()
{ {
$parent = $this->objFromFixture('Page', 'page3'); $parent = $this->objFromFixture(SiteTree::class, 'page3');
$child = $this->objFromFixture('Page', 'page3b'); $child = $this->objFromFixture(SiteTree::class, 'page3b');
$f = new CMSSiteTreeFilter_Search(['Title' => 'Page 3b']); $f = new CMSSiteTreeFilter_Search(['Title' => 'Page 3b']);
$results = $f->pagesIncluded(); $results = $f->pagesIncluded();
@ -78,11 +76,11 @@ class CMSSiteTreeFilterTest extends SapphireTest
public function testChangedPagesFilter() public function testChangedPagesFilter()
{ {
/** @var Page $unchangedPage */ /** @var Page $unchangedPage */
$unchangedPage = $this->objFromFixture('Page', 'page1'); $unchangedPage = $this->objFromFixture(SiteTree::class, 'page1');
$unchangedPage->publishRecursive(); $unchangedPage->publishRecursive();
/** @var Page $changedPage */ /** @var Page $changedPage */
$changedPage = $this->objFromFixture('Page', 'page2'); $changedPage = $this->objFromFixture(SiteTree::class, 'page2');
$changedPage->Title = 'Original'; $changedPage->Title = 'Original';
$changedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $changedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$changedPage->Title = 'Changed'; $changedPage->Title = 'Changed';
@ -121,7 +119,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
public function testDeletedPagesFilter() public function testDeletedPagesFilter()
{ {
$deletedPage = $this->objFromFixture('Page', 'page2'); $deletedPage = $this->objFromFixture(SiteTree::class, 'page2');
$deletedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $deletedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$deletedPageID = $deletedPage->ID; $deletedPageID = $deletedPage->ID;
$deletedPage->delete(); $deletedPage->delete();
@ -141,7 +139,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
public function testStatusDraftPagesFilter() public function testStatusDraftPagesFilter()
{ {
$draftPage = $this->objFromFixture('Page', 'page4'); $draftPage = $this->objFromFixture(SiteTree::class, 'page4');
$draftPage = Versioned::get_one_by_stage( $draftPage = Versioned::get_one_by_stage(
SiteTree::class, SiteTree::class,
'Stage', 'Stage',
@ -164,20 +162,23 @@ class CMSSiteTreeFilterTest extends SapphireTest
public function testDateFromToLastSameDate() public function testDateFromToLastSameDate()
{ {
$draftPage = $this->objFromFixture('Page', 'page4'); $draftPage = $this->objFromFixture(SiteTree::class, 'page4');
// Grab the date // Grab the date
$date = substr($draftPage->LastEdited ?? '', 0, 10); $date = substr($draftPage->LastEdited ?? '', 0, 10);
// Filter with that date // Filter with that date
$filter = new CMSSiteTreeFilter_Search([ $filter = new CMSSiteTreeFilter_Search([
'LastEditedFrom' => $date, '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() public function testStatusRemovedFromDraftFilter()
{ {
$removedDraftPage = $this->objFromFixture('Page', 'page6'); $removedDraftPage = $this->objFromFixture(SiteTree::class, 'page6');
$removedDraftPage->publishRecursive(); $removedDraftPage->publishRecursive();
$removedDraftPage->deleteFromStage('Stage'); $removedDraftPage->deleteFromStage('Stage');
$removedDraftPage = Versioned::get_one_by_stage( $removedDraftPage = Versioned::get_one_by_stage(
@ -202,7 +203,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
public function testStatusDeletedFilter() public function testStatusDeletedFilter()
{ {
$deletedPage = $this->objFromFixture('Page', 'page7'); $deletedPage = $this->objFromFixture(SiteTree::class, 'page7');
$deletedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $deletedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$deletedPageID = $deletedPage->ID; $deletedPageID = $deletedPage->ID;

View File

@ -1,4 +1,4 @@
Page: SilverStripe\CMS\Model\SiteTree:
page1: page1:
Title: Page 1 Title: Page 1
page2: page2:
@ -15,19 +15,19 @@ Page:
page7: page7:
Title: Page 7 Title: Page 7
page7a: page7a:
Parent: =>Page.page7 Parent: =>SilverStripe\CMS\Model\SiteTree.page7
Title: Page 7a Title: Page 7a
page2a: page2a:
Parent: =>Page.page2 Parent: =>SilverStripe\CMS\Model\SiteTree.page2
Title: Page 2a Title: Page 2a
page2b: page2b:
Parent: =>Page.page2 Parent: =>SilverStripe\CMS\Model\SiteTree.page2
Title: Page 2b Title: Page 2b
page3a: page3a:
Parent: =>Page.page3 Parent: =>SilverStripe\CMS\Model\SiteTree.page3
Title: Page 3a Title: Page 3a
page3b: page3b:
Parent: =>Page.page3 Parent: =>SilverStripe\CMS\Model\SiteTree.page3
Title: Page 3b Title: Page 3b
page8: page8:
Title: EncodedUrlSegment Title: EncodedUrlSegment

View File

@ -32,7 +32,7 @@ class CMSTreeTest extends FunctionalTest
$data = [ $data = [
'SiblingIDs' => $siblingIDs, 'SiblingIDs' => $siblingIDs,
'ID' => $page2->ID, 'ID' => $page2->ID,
'ParentID' => 0 'ParentID' => 0,
]; ];
$response = $this->post('admin/pages/edit/savetreenode', $data); $response = $this->post('admin/pages/edit/savetreenode', $data);
@ -62,12 +62,12 @@ class CMSTreeTest extends FunctionalTest
$siblingIDs = [ $siblingIDs = [
$page31->ID, $page31->ID,
$page2->ID, $page2->ID,
$page32->ID $page32->ID,
]; ];
$data = [ $data = [
'SiblingIDs' => $siblingIDs, 'SiblingIDs' => $siblingIDs,
'ID' => $page2->ID, 'ID' => $page2->ID,
'ParentID' => $page3->ID 'ParentID' => $page3->ID,
]; ];
$response = $this->post('admin/pages/edit/savetreenode', $data); $response = $this->post('admin/pages/edit/savetreenode', $data);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
@ -95,7 +95,7 @@ class CMSTreeTest extends FunctionalTest
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
// Check page // 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(200, $result->getStatusCode());
$this->assertEquals('application/json', $result->getHeader('Content-Type')); $this->assertEquals('application/json', $result->getHeader('Content-Type'));
$data = json_decode($result->getBody() ?? '', true); $data = json_decode($result->getBody() ?? '', true);
@ -105,7 +105,7 @@ class CMSTreeTest extends FunctionalTest
$this->assertEmpty($pageData['PrevID']); $this->assertEmpty($pageData['PrevID']);
// check subpage // 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(200, $result->getStatusCode());
$this->assertEquals('application/json', $result->getHeader('Content-Type')); $this->assertEquals('application/json', $result->getHeader('Content-Type'));
$data = json_decode($result->getBody() ?? '', true); $data = json_decode($result->getBody() ?? '', true);
@ -115,7 +115,7 @@ class CMSTreeTest extends FunctionalTest
$this->assertEmpty($pageData['PrevID']); $this->assertEmpty($pageData['PrevID']);
// Multiple pages // 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(200, $result->getStatusCode());
$this->assertEquals('application/json', $result->getHeader('Content-Type')); $this->assertEquals('application/json', $result->getHeader('Content-Type'));
$data = json_decode($result->getBody() ?? '', true); $data = json_decode($result->getBody() ?? '', true);

View File

@ -6,7 +6,7 @@ use SilverStripe\Versioned\Versioned;
use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use Page; use SilverStripe\CMS\Model\SiteTree;
class ContentControllerPermissionsTest extends FunctionalTest class ContentControllerPermissionsTest extends FunctionalTest
{ {
@ -17,7 +17,7 @@ class ContentControllerPermissionsTest extends FunctionalTest
public function testCanViewStage() public function testCanViewStage()
{ {
// Create a new page // Create a new page
$page = new Page(); $page = new SiteTree();
$page->URLSegment = 'testpage'; $page->URLSegment = 'testpage';
$page->write(); $page->write();
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
@ -38,7 +38,11 @@ class ContentControllerPermissionsTest extends FunctionalTest
$response = $responseException->getResponse(); $response = $responseException->getResponse();
} }
// should redirect to login // 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( $this->assertStringContainsString(
Config::inst()->get('SilverStripe\\Security\\Security', 'login_url'), Config::inst()->get('SilverStripe\\Security\\Security', 'login_url'),
$response->getHeader('Location') $response->getHeader('Location')
@ -47,6 +51,10 @@ class ContentControllerPermissionsTest extends FunctionalTest
$this->logInWithPermission('CMS_ACCESS_CMSMain'); $this->logInWithPermission('CMS_ACCESS_CMSMain');
$response = $this->get('/testpage/?stage=Stage'); $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'
);
} }
} }

View File

@ -4,23 +4,23 @@ namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\Assets\File; use SilverStripe\Assets\File;
use SilverStripe\CMS\Controllers\ContentController; use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Search\ContentControllerSearchExtension; use SilverStripe\CMS\Search\ContentControllerSearchExtension;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\Search\FulltextSearchable; use SilverStripe\ORM\Search\FulltextSearchable;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
use Page;
class ContentControllerSearchExtensionTest extends SapphireTest class ContentControllerSearchExtensionTest extends SapphireTest
{ {
protected static $required_extensions = [ protected static $required_extensions = [
ContentController::class => [ ContentController::class => [
ContentControllerSearchExtension::class, ContentControllerSearchExtension::class,
] ],
]; ];
public function testCustomSearchFormClassesToTest() public function testCustomSearchFormClassesToTest()
{ {
$page = new Page(); $page = new SiteTree();
$page->URLSegment = 'whatever'; $page->URLSegment = 'whatever';
$page->Content = 'oh really?'; $page->Content = 'oh really?';
$page->write(); $page->write();

10
tests/php/Controllers/ContentControllerTest.php Executable file → Normal file
View File

@ -10,7 +10,6 @@ use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
use Page;
class ContentControllerTest extends FunctionalTest class ContentControllerTest extends FunctionalTest
{ {
@ -31,8 +30,8 @@ class ContentControllerTest extends FunctionalTest
Config::modify()->set(SiteTree::class, 'nested_urls', true); Config::modify()->set(SiteTree::class, 'nested_urls', true);
// Ensure all pages are published // Ensure all pages are published
/** @var Page $page */ /** @var SiteTree $page */
foreach (Page::get() as $page) { foreach (SiteTree::get() as $page) {
$page->publishSingle(); $page->publishSingle();
} }
} }
@ -95,8 +94,7 @@ class ContentControllerTest extends FunctionalTest
public function testDeepNestedURLs() public function testDeepNestedURLs()
{ {
$page = new SiteTree();
$page = new Page();
$page->URLSegment = 'base-page'; $page->URLSegment = 'base-page';
$page->write(); $page->write();
$page->publishSingle(); $page->publishSingle();
@ -174,7 +172,7 @@ class ContentControllerTest extends FunctionalTest
$response = $this->get($page->RelativeLink()); $response = $this->get($page->RelativeLink());
$this->assertEquals("ContentControllerTestPageWithoutController", trim($response->getBody() ?? '')); $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 = new ContentControllerTestPage();
$page->URLSegment = "test"; $page->URLSegment = "test";
$page->write(); $page->write();

View File

@ -2,10 +2,10 @@
namespace SilverStripe\CMS\Tests\Controllers; namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
use Page;
class ContentControllerTestPage extends Page implements TestOnly class ContentControllerTestPage extends SiteTree implements TestOnly
{ {
private static $table_name = 'ContentControllerTestPage'; private static $table_name = 'ContentControllerTestPage';
} }

View File

@ -9,7 +9,7 @@ class ContentControllerTestPageController extends PageController implements Test
{ {
private static $allowed_actions = [ private static $allowed_actions = [
'test', 'test',
'testwithouttemplate' 'testwithouttemplate',
]; ];
public function testwithouttemplate() public function testwithouttemplate()

View File

@ -2,10 +2,9 @@
namespace SilverStripe\CMS\Tests\Controllers; namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
use Page;
class ContentControllerTestPageWithoutController extends Page implements TestOnly class ContentControllerTestPageWithoutController extends SiteTree implements TestOnly
{ {
} }

View File

@ -2,10 +2,10 @@
namespace SilverStripe\CMS\Tests\Controllers; namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'ContentControllerTest_Page';
} }

View File

@ -2,14 +2,13 @@
namespace SilverStripe\CMS\Tests\Controllers; namespace SilverStripe\CMS\Tests\Controllers;
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
use PageController;
class ContentControllerTest_PageController extends PageController implements TestOnly class ContentControllerTest_PageController extends ContentController implements TestOnly
{ {
private static $allowed_actions = [ private static $allowed_actions = [
'second_index' 'second_index',
]; ];
public function index() public function index()

View File

@ -10,7 +10,6 @@ use SilverStripe\Core\Config\Config;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use Page;
use SilverStripe\View\Parsers\URLSegmentFilter; use SilverStripe\View\Parsers\URLSegmentFilter;
class ModelAsControllerTest extends FunctionalTest class ModelAsControllerTest extends FunctionalTest
@ -34,7 +33,7 @@ class ModelAsControllerTest extends FunctionalTest
protected function generateNestedPagesFixture() protected function generateNestedPagesFixture()
{ {
$level1 = new Page(); $level1 = new SiteTree();
$level1->Title = 'First Level'; $level1->Title = 'First Level';
$level1->URLSegment = 'level1'; $level1->URLSegment = 'level1';
$level1->write(); $level1->write();
@ -44,7 +43,7 @@ class ModelAsControllerTest extends FunctionalTest
$level1->write(); $level1->write();
$level1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $level1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$level2 = new Page(); $level2 = new SiteTree();
$level2->Title = 'Second Level'; $level2->Title = 'Second Level';
$level2->URLSegment = 'level2'; $level2->URLSegment = 'level2';
$level2->ParentID = $level1->ID; $level2->ParentID = $level1->ID;
@ -55,7 +54,7 @@ class ModelAsControllerTest extends FunctionalTest
$level2->write(); $level2->write();
$level2->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $level2->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$level3 = new Page(); $level3 = new SiteTree();
$level3->Title = "Level 3"; $level3->Title = "Level 3";
$level3->URLSegment = 'level3'; $level3->URLSegment = 'level3';
$level3->ParentID = $level2->ID; $level3->ParentID = $level2->ID;
@ -115,7 +114,7 @@ class ModelAsControllerTest extends FunctionalTest
*/ */
public function testHeavilyNestedRenamedRedirectedPages() public function testHeavilyNestedRenamedRedirectedPages()
{ {
$page = new Page(); $page = new SiteTree();
$page->Title = 'First Level'; $page->Title = 'First Level';
$page->URLSegment = 'oldurl'; $page->URLSegment = 'oldurl';
$page->write(); $page->write();
@ -125,28 +124,28 @@ class ModelAsControllerTest extends FunctionalTest
$page->write(); $page->write();
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$page2 = new Page(); $page2 = new SiteTree();
$page2->Title = 'Second Level Page'; $page2->Title = 'Second Level Page';
$page2->URLSegment = 'level2'; $page2->URLSegment = 'level2';
$page2->ParentID = $page->ID; $page2->ParentID = $page->ID;
$page2->write(); $page2->write();
$page2->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $page2->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$page3 = new Page(); $page3 = new SiteTree();
$page3->Title = 'Third Level Page'; $page3->Title = 'Third Level Page';
$page3->URLSegment = 'level3'; $page3->URLSegment = 'level3';
$page3->ParentID = $page2->ID; $page3->ParentID = $page2->ID;
$page3->write(); $page3->write();
$page3->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $page3->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$page4 = new Page(); $page4 = new SiteTree();
$page4->Title = 'Fourth Level Page'; $page4->Title = 'Fourth Level Page';
$page4->URLSegment = 'level4'; $page4->URLSegment = 'level4';
$page4->ParentID = $page3->ID; $page4->ParentID = $page3->ID;
$page4->write(); $page4->write();
$page4->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $page4->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$page5 = new Page(); $page5 = new SiteTree();
$page5->Title = 'Fifth Level Page'; $page5->Title = 'Fifth Level Page';
$page5->URLSegment = 'level5'; $page5->URLSegment = 'level5';
$page5->ParentID = $page4->ID; $page5->ParentID = $page4->ID;
@ -188,8 +187,8 @@ class ModelAsControllerTest extends FunctionalTest
{ {
$this->generateNestedPagesFixture(); $this->generateNestedPagesFixture();
$otherParent = new Page([ $otherParent = new SiteTree([
'URLSegment' => 'otherparent' 'URLSegment' => 'otherparent',
]); ]);
$otherParent->write(); $otherParent->write();
$otherParent->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $otherParent->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
@ -232,9 +231,9 @@ class ModelAsControllerTest extends FunctionalTest
{ {
$this->generateNestedPagesFixture(); $this->generateNestedPagesFixture();
$otherLevel1 = new Page([ $otherLevel1 = new SiteTree([
'Title' => "Other Level 1", 'Title' => "Other Level 1",
'URLSegment' => 'level1' 'URLSegment' => 'level1',
]); ]);
$otherLevel1->write(); $otherLevel1->write();
$otherLevel1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $otherLevel1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
@ -260,7 +259,7 @@ class ModelAsControllerTest extends FunctionalTest
*/ */
public function testFindOldPage() public function testFindOldPage()
{ {
$page = new Page(); $page = new SiteTree();
$page->Title = 'First Level'; $page->Title = 'First Level';
$page->URLSegment = 'oldurl'; $page->URLSegment = 'oldurl';
$page->write(); $page->write();
@ -274,7 +273,7 @@ class ModelAsControllerTest extends FunctionalTest
$matchedPage = SiteTree::get_by_link($url); $matchedPage = SiteTree::get_by_link($url);
$this->assertEquals('First Level', $matchedPage->Title); $this->assertEquals('First Level', $matchedPage->Title);
$page2 = new Page(); $page2 = new SiteTree();
$page2->Title = 'Second Level Page'; $page2->Title = 'Second Level Page';
$page2->URLSegment = 'oldpage2'; $page2->URLSegment = 'oldpage2';
$page2->ParentID = $page->ID; $page2->ParentID = $page->ID;
@ -304,12 +303,12 @@ class ModelAsControllerTest extends FunctionalTest
RootURLController::reset(); RootURLController::reset();
Config::modify()->set(SiteTree::class, 'nested_urls', true); Config::modify()->set(SiteTree::class, 'nested_urls', true);
$draft = new Page(); $draft = new SiteTree();
$draft->Title = 'Root Leve Draft Page'; $draft->Title = 'Root Leve Draft Page';
$draft->URLSegment = 'root'; $draft->URLSegment = 'root';
$draft->write(); $draft->write();
$published = new Page(); $published = new SiteTree();
$published->Title = 'Published Page Under Draft Page'; $published->Title = 'Published Page Under Draft Page';
$published->URLSegment = 'sub-root'; $published->URLSegment = 'sub-root';
$published->write(); $published->write();
@ -319,7 +318,8 @@ class ModelAsControllerTest extends FunctionalTest
$this->assertEquals( $this->assertEquals(
$response->getStatusCode(), $response->getStatusCode(),
404, 404,
'The page should not be found since its parent has not been published, in this case http://<yousitename>/root/sub-root or http://<yousitename>/sub-root' 'The page should not be found since its parent has not been published, in this case ' .
'http://<yousitename>/root/sub-root or http://<yousitename>/sub-root'
); );
} }
@ -327,13 +327,13 @@ class ModelAsControllerTest extends FunctionalTest
{ {
Config::modify()->set(URLSegmentFilter::class, 'default_allow_multibyte', true); Config::modify()->set(URLSegmentFilter::class, 'default_allow_multibyte', true);
$parent = new Page(); $parent = new SiteTree();
$parent->Title = 'Multibyte test'; $parent->Title = 'Multibyte test';
$parent->URLSegment = 'بلاگ'; $parent->URLSegment = 'بلاگ';
$parent->write(); $parent->write();
$parent->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $parent->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$child = new Page(); $child = new SiteTree();
$child->Title = 'Multibyte test'; $child->Title = 'Multibyte test';
$child->URLSegment = 'فضة'; $child->URLSegment = 'فضة';
$child->ParentID = $parent->ID; $child->ParentID = $parent->ID;

View File

@ -13,7 +13,7 @@ class RootURLControllerTest extends SapphireTest
public function testGetHomepageLink() public function testGetHomepageLink()
{ {
$default = $this->objFromFixture('Page', 'home'); $default = $this->objFromFixture(SiteTree::class, 'home');
Config::modify()->set(SiteTree::class, 'nested_urls', false); Config::modify()->set(SiteTree::class, 'nested_urls', false);
$this->assertEquals('home', RootURLController::get_homepage_link()); $this->assertEquals('home', RootURLController::get_homepage_link());

View File

@ -1,9 +1,9 @@
Page: SilverStripe\CMS\Model\SiteTree:
home: home:
Title: Home Title: Home
nested: nested:
Title: Nested Home Title: Nested Home
Parent: =>Page.home Parent: =>SilverStripe\CMS\Model\SiteTree.home
page1: page1:
Title: First Page Title: First Page
URLSegment: page1 URLSegment: page1

View File

@ -8,7 +8,6 @@ use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_LiveLink;
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_StageLink; use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_StageLink;
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_Unversioned; use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_Unversioned;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Member;
class SilverStripeNavigatorTest extends SapphireTest class SilverStripeNavigatorTest extends SapphireTest
{ {

View File

@ -44,7 +44,7 @@ class LinkablePluginTest extends SapphireTest
public function testResolver() public function testResolver()
{ {
$page = SiteTree::create([ $page = new SiteTree([
'Title' => 'Test page', 'Title' => 'Test page',
'URLSegment' => 'test-page', 'URLSegment' => 'test-page',
'ParentID' => 0, 'ParentID' => 0,
@ -52,7 +52,7 @@ class LinkablePluginTest extends SapphireTest
$page->write(); $page->write();
$page->publishRecursive(); $page->publishRecursive();
$page = SiteTree::create([ $page = new SiteTree([
'Title' => 'Other test page', 'Title' => 'Other test page',
'URLSegment' => 'other-test-page', 'URLSegment' => 'other-test-page',
'ParentID' => 0, 'ParentID' => 0,

View File

@ -2,7 +2,7 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use Page; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\RedirectorPageController; use SilverStripe\CMS\Model\RedirectorPageController;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
@ -36,31 +36,41 @@ class RedirectorPageTest extends FunctionalTest
Director::config()->update('alternate_base_url', 'http://www.mysite.com/'); Director::config()->update('alternate_base_url', 'http://www.mysite.com/');
// Ensure all pages are published // Ensure all pages are published
/** @var Page $page */ /** @var SiteTree $page */
foreach (Page::get() as $page) { foreach (SiteTree::get() as $page) {
$page->publishSingle(); $page->publishSingle();
} }
} }
public function testGoodRedirectors() public function testGoodRedirectors()
{ {
/* For good redirectors, the final destination URL will be returned */ // For good redirectors, the final destination URL will be returned
$this->assertEquals("http://www.google.com", $this->objFromFixture(RedirectorPage::class, 'goodexternal')->Link()); $this->assertEquals(
$this->assertEquals("/redirection-dest/", $this->objFromFixture(RedirectorPage::class, 'goodinternal')->redirectionLink()); "http://www.google.com",
$this->assertEquals("/redirection-dest/", $this->objFromFixture(RedirectorPage::class, 'goodinternal')->Link()); $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() 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'); $page1 = $this->objFromFixture(RedirectorPage::class, 'badexternal');
$this->assertEquals('/bad-external/', $page1->Link()); $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(); $content = $this->get(Director::makeRelative($page1->Link()))->getBody();
$this->assertStringContainsString('message-setupWithoutRedirect', $content); $this->assertStringContainsString('message-setupWithoutRedirect', $content);
/* This also applies for internal links */ // This also applies for internal links
$page2 = $this->objFromFixture(RedirectorPage::class, 'badinternal'); $page2 = $this->objFromFixture(RedirectorPage::class, 'badinternal');
$this->assertEquals('/bad-internal/', $page2->Link()); $this->assertEquals('/bad-internal/', $page2->Link());
$content = $this->get(Director::makeRelative($page2->Link()))->getBody(); $content = $this->get(Director::makeRelative($page2->Link()))->getBody();
@ -69,14 +79,16 @@ class RedirectorPageTest extends FunctionalTest
public function testReflexiveAndTransitiveInternalRedirectors() 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'); $page = $this->objFromFixture(RedirectorPage::class, 'reflexive');
$this->assertEquals('/reflexive/', $page->Link()); $this->assertEquals('/reflexive/', $page->Link());
$content = $this->get(Director::makeRelative($page->Link()))->getBody(); $content = $this->get(Director::makeRelative($page->Link()))->getBody();
$this->assertStringContainsString('message-setupWithoutRedirect', $content); $this->assertStringContainsString('message-setupWithoutRedirect', $content);
/* Transitive redirectors are those that point to another redirector page. They should send people to the URLSegment // Transitive redirectors are those that point to another redirector page.
* of the destination page - the middle-stop, so to speak. That should redirect to the final destination */ // 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'); $page = $this->objFromFixture(RedirectorPage::class, 'transitive');
$this->assertEquals('/good-internal/', $page->Link()); $this->assertEquals('/good-internal/', $page->Link());
@ -90,7 +102,11 @@ class RedirectorPageTest extends FunctionalTest
$page = $this->objFromFixture(RedirectorPage::class, 'externalnoprefix'); $page = $this->objFromFixture(RedirectorPage::class, 'externalnoprefix');
$this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite has prefixed with http'); $this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite has prefixed with http');
$page->write(); $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() public function testAllowsProtocolRelative()

View File

@ -1,4 +1,4 @@
Page: SilverStripe\CMS\Model\SiteTree:
dest: dest:
Title: Redirection Dest Title: Redirection Dest
URLSegment: redirection-dest URLSegment: redirection-dest
@ -17,7 +17,7 @@ SilverStripe\CMS\Model\RedirectorPage:
Title: Good Internal Title: Good Internal
URLSegment: good-internal URLSegment: good-internal
RedirectionType: Internal RedirectionType: Internal
LinkTo: =>Page.dest LinkTo: =>SilverStripe\CMS\Model\SiteTree.dest
badexternal: badexternal:
Title: Bad External Title: Bad External
RedirectionType: External RedirectionType: External

View File

@ -2,7 +2,6 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use Page;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
@ -21,7 +20,6 @@ use SilverStripe\Versioned\Versioned;
*/ */
class SiteTreeActionsTest extends FunctionalTest class SiteTreeActionsTest extends FunctionalTest
{ {
protected static $fixture_file = 'SiteTreeActionsTest.yml'; protected static $fixture_file = 'SiteTreeActionsTest.yml';
public function testActionsReadonly() public function testActionsReadonly()
@ -38,7 +36,7 @@ class SiteTreeActionsTest extends FunctionalTest
Security::setCurrentUser($readonlyEditor); Security::setCurrentUser($readonlyEditor);
// Reload latest version // Reload latest version
$page = Page::get()->byID($page->ID); $page = SiteTree::get()->byID($page->ID);
$actions = $page->getCMSActions(); $actions = $page->getCMSActions();
$this->assertNull($actions->dataFieldByName('action_save')); $this->assertNull($actions->dataFieldByName('action_save'));
@ -84,14 +82,14 @@ class SiteTreeActionsTest extends FunctionalTest
$author = $this->objFromFixture(Member::class, 'cmseditor'); $author = $this->objFromFixture(Member::class, 'cmseditor');
Security::setCurrentUser($author); Security::setCurrentUser($author);
/** @var Page $page */ /** @var SiteTree $page */
$page = new Page(); $page = new SiteTree();
$page->CanEditType = 'LoggedInUsers'; $page->CanEditType = 'LoggedInUsers';
$page->write(); $page->write();
$page->publishRecursive(); $page->publishRecursive();
// Reload latest version // Reload latest version
$page = Page::get()->byID($page->ID); $page = SiteTree::get()->byID($page->ID);
$actions = $page->getCMSActions(); $actions = $page->getCMSActions();
@ -108,7 +106,7 @@ class SiteTreeActionsTest extends FunctionalTest
$author = $this->objFromFixture(Member::class, 'cmseditor'); $author = $this->objFromFixture(Member::class, 'cmseditor');
Security::setCurrentUser($author); Security::setCurrentUser($author);
$page = new Page(); $page = new SiteTree();
$page->CanEditType = 'LoggedInUsers'; $page->CanEditType = 'LoggedInUsers';
$page->write(); $page->write();
$this->assertTrue($page->canPublish()); $this->assertTrue($page->canPublish());
@ -135,7 +133,7 @@ class SiteTreeActionsTest extends FunctionalTest
$author = $this->objFromFixture(Member::class, 'cmseditor'); $author = $this->objFromFixture(Member::class, 'cmseditor');
Security::setCurrentUser($author); Security::setCurrentUser($author);
$page = new Page(); $page = new SiteTree();
$page->CanEditType = 'LoggedInUsers'; $page->CanEditType = 'LoggedInUsers';
$page->write(); $page->write();
$this->assertTrue($page->canPublish()); $this->assertTrue($page->canPublish());
@ -145,7 +143,7 @@ class SiteTreeActionsTest extends FunctionalTest
$page->flushCache(); $page->flushCache();
// Reload latest version // Reload latest version
$page = Page::get()->byID($page->ID); $page = SiteTree::get()->byID($page->ID);
$actions = $page->getCMSActions(); $actions = $page->getCMSActions();
$this->assertNotNull($actions->dataFieldByName('action_save')); $this->assertNotNull($actions->dataFieldByName('action_save'));
@ -158,15 +156,17 @@ class SiteTreeActionsTest extends FunctionalTest
public function testActionsViewingOldVersion() public function testActionsViewingOldVersion()
{ {
$p = new Page(); $p = new SiteTree();
$p->Content = 'test page first version'; $p->Content = 'test page first version';
$p->write(); $p->write();
$p->Content = 'new content'; $p->Content = 'new content';
$p->write(); $p->write();
// Looking at the old version, the ability to rollback to that version is available // 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(); $version = DB::query(
$old = Versioned::get_version('Page', $p->ID, $version); 'SELECT "Version" FROM "SiteTree_Versions" WHERE "Content" = \'test page first version\''
)->value();
$old = Versioned::get_version(SiteTree::class, $p->ID, $version);
$actions = $old->getCMSActions(); $actions = $old->getCMSActions();
$this->assertNull($actions->dataFieldByName('action_save')); $this->assertNull($actions->dataFieldByName('action_save'));
$this->assertNull($actions->dataFieldByName('action_publish')); $this->assertNull($actions->dataFieldByName('action_publish'));

View File

@ -4,9 +4,9 @@ namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
use SilverStripe\Security\Permission; 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) public function canEdit($member = null)
{ {

View File

@ -18,7 +18,7 @@ class SiteTreeBacklinksTest extends SapphireTest
protected static $required_extensions = [ protected static $required_extensions = [
SiteTree::class => [ SiteTree::class => [
SiteTreeBacklinksTest_DOD::class SiteTreeBacklinksTest_DOD::class,
], ],
]; ];
@ -34,10 +34,10 @@ class SiteTreeBacklinksTest extends SapphireTest
// testing here. // testing here.
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$page3 = $this->objFromFixture('Page', 'page3'); $page3 = $this->objFromFixture(SiteTree::class, 'page3');
$page3->Content = str_replace( $page3->Content = str_replace(
'$page1.ID', '$page1.ID',
$this->objFromFixture('Page', 'page1')->ID ?? '', $this->objFromFixture(SiteTree::class, 'page1')->ID ?? '',
$page3->Content ?? '' $page3->Content ?? ''
); );
$page3->write(); $page3->write();
@ -46,18 +46,22 @@ class SiteTreeBacklinksTest extends SapphireTest
public function testSavingPageWithLinkAddsBacklink() public function testSavingPageWithLinkAddsBacklink()
{ {
// load page 1 // load page 1
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
// assert backlink to page 2 doesn't exist // assert backlink to page 2 doesn't exist
$page2 = $this->objFromFixture('Page', 'page2'); $page2 = $this->objFromFixture(SiteTree::class, 'page2');
$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 // add hyperlink to page 1 on page 2
$page2->Content .= '<p><a href="[sitetree_link,id='.$page1->ID.']">Testing page 1 link</a></p>'; $page2->Content .= '<p><a href="[sitetree_link,id=' . $page1->ID . ']">Testing page 1 link</a></p>';
$page2->write(); $page2->write();
// load page 1 // load page 1
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
// assert backlink to page 2 exists // assert backlink to page 2 exists
$this->assertContains($page2->ID, $page1->BackLinkTracking()->column('ID'), '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() public function testRemovingLinkFromPageRemovesBacklink()
{ {
// load page 1 // load page 1
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
// assert backlink to page 3 exits // 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'); $this->assertContains($page3->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 3 exists');
// remove hyperlink to page 1 // remove hyperlink to page 1
@ -77,116 +81,156 @@ class SiteTreeBacklinksTest extends SapphireTest
$page3->write(); $page3->write();
// load page 1 // load page 1
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
// assert backlink to page 3 exists // 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() public function testChangingUrlOnDraftSiteRewritesLink()
{ {
// load page 1 // load page 1
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
// assert backlink to page 3 exists // 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'); $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 // assert hyperlink to page 1's current url exists on page 3
$links = HTTP::getLinksIn($page3->obj('Content')->forTemplate()); $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 // change url of page 1
$page1->URLSegment = 'new-url-segment'; $page1->URLSegment = 'new-url-segment';
$page1->write(); $page1->write();
// load page 3 // load page 3
$page3 = $this->objFromFixture('Page', 'page3'); $page3 = $this->objFromFixture(SiteTree::class, 'page3');
// assert hyperlink to page 1's new url exists // assert hyperlink to page 1's new url exists
$links = HTTP::getLinksIn($page3->obj('Content')->forTemplate()); $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() public function testChangingUrlOnLiveSiteRewritesLink()
{ {
// publish page 1 & 3 // publish page 1 & 3
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
$page3 = $this->objFromFixture('Page', 'page3'); $page3 = $this->objFromFixture(SiteTree::class, 'page3');
$this->assertTrue($page1->publishRecursive()); $this->assertTrue($page1->publishRecursive());
$this->assertTrue($page3->publishRecursive()); $this->assertTrue($page3->publishRecursive());
// load pages from live // load pages from live
$page1live = Versioned::get_one_by_stage('Page', 'Live', '"SiteTree"."ID" = ' . $page1->ID); $page1live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $page1->ID);
$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 backlink to page 3 exists // 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 // assert hyperlink to page 1's current url exists on page 3
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); $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 // change url of page 1
$page1live->URLSegment = 'new-url-segment'; $page1live->URLSegment = 'new-url-segment';
$page1live->writeToStage('Live'); $page1live->writeToStage('Live');
// load page 3 from 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 // assert hyperlink to page 1's new url exists
Versioned::set_stage(Versioned::LIVE); Versioned::set_stage(Versioned::LIVE);
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); $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() public function testPublishingPageWithModifiedUrlRewritesLink()
{ {
// publish page 1 & 3 // publish page 1 & 3
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
$page3 = $this->objFromFixture('Page', 'page3'); $page3 = $this->objFromFixture(SiteTree::class, 'page3');
$this->assertTrue($page1->publishRecursive()); $this->assertTrue($page1->publishRecursive());
$this->assertTrue($page3->publishRecursive()); $this->assertTrue($page3->publishRecursive());
// load page 3 from 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 current url exists // assert hyperlink to page 1's current url exists
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); $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 // rename url of page 1 on stage
$page1->URLSegment = 'new-url-segment'; $page1->URLSegment = 'new-url-segment';
$page1->write(); $page1->write();
// assert hyperlink to page 1's current publish url exists // 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); Versioned::set_stage(Versioned::LIVE);
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); $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 // publish page 1
$this->assertTrue($page1->publishRecursive()); $this->assertTrue($page1->publishRecursive());
// assert hyperlink to page 1's new published url exists // 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()); $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() public function testPublishingPageWithModifiedLinksRewritesLinks()
{ {
// publish page 1 & 3 // publish page 1 & 3
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
$page3 = $this->objFromFixture('Page', 'page3'); $page3 = $this->objFromFixture(SiteTree::class, 'page3');
$this->assertTrue($page1->publishRecursive()); $this->assertTrue($page1->publishRecursive());
$this->assertTrue($page3->publishRecursive()); $this->assertTrue($page3->publishRecursive());
// assert hyperlink to page 1's current url exists // assert hyperlink to page 1's current url exists
$links = HTTP::getLinksIn($page3->obj('Content')->forTemplate()); $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 // change page 1 url on draft
$page1->URLSegment = 'new-url-segment'; $page1->URLSegment = 'new-url-segment';
@ -195,42 +239,58 @@ class SiteTreeBacklinksTest extends SapphireTest
$page1->write(); $page1->write();
// assert page 3 on draft contains new page 1 url // 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()); $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 // publish page 3
$this->assertTrue($page3->publishRecursive()); $this->assertTrue($page3->publishRecursive());
// assert page 3 on published site contains old page 1 url // 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); Versioned::set_stage(Versioned::LIVE);
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate()); $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 // publish page 1
$this->assertTrue($page1->publishRecursive()); $this->assertTrue($page1->publishRecursive());
// assert page 3 on published site contains new page 1 url // 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()); $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() public function testLinkTrackingOnExtraContentFields()
{ {
/** @var Page $page1 */ /** @var SiteTree $page1 */
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
/** @var Page $page2 */ /** @var SiteTree $page2 */
$page2 = $this->objFromFixture('Page', 'page2'); $page2 = $this->objFromFixture(SiteTree::class, 'page2');
$page1->publishRecursive(); $page1->publishRecursive();
$page2->publishRecursive(); $page2->publishRecursive();
// assert backlink to page 2 doesn't exist // 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 // add hyperlink to page 1 on page 2
$page2->ExtraContent .= '<p><a href="[sitetree_link,id='.$page1->ID.']">Testing page 1 link</a></p>'; $page2->ExtraContent .= '<p><a href="[sitetree_link,id=' . $page1->ID . ']">Testing page 1 link</a></p>';
$page2->write(); $page2->write();
$page2->publishRecursive(); $page2->publishRecursive();
@ -238,23 +298,32 @@ class SiteTreeBacklinksTest extends SapphireTest
$this->assertContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 exists'); $this->assertContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 exists');
// update page1 url // update page1 url
$page1 = $this->objFromFixture('Page', 'page1'); $page1 = $this->objFromFixture(SiteTree::class, 'page1');
$page1->URLSegment = "page1-new-url"; $page1->URLSegment = "page1-new-url";
$page1->write(); $page1->write();
// confirm that draft link on page2 has been rewritten // confirm that draft link on page2 has been rewritten
$page2 = $this->objFromFixture('Page', 'page2'); $page2 = $this->objFromFixture(SiteTree::class, 'page2');
$this->assertEquals('<p><a href="'.Director::baseURL().'page1-new-url/">Testing page 1 link</a></p>', $page2->obj('ExtraContent')->forTemplate()); $this->assertEquals(
'<p><a href="' . Director::baseURL() . 'page1-new-url/">Testing page 1 link</a></p>',
$page2->obj('ExtraContent')->forTemplate()
);
// confirm that published link hasn't // 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); Versioned::set_stage(Versioned::LIVE);
$this->assertEquals('<p><a href="'.Director::baseURL().'page1/">Testing page 1 link</a></p>', $page2Live->obj('ExtraContent')->forTemplate()); $this->assertEquals(
'<p><a href="' . Director::baseURL() . 'page1/">Testing page 1 link</a></p>',
$page2Live->obj('ExtraContent')->forTemplate()
);
// publish page1 and confirm that the link on the published page2 has now been updated // publish page1 and confirm that the link on the published page2 has now been updated
$page1->publishRecursive(); $page1->publishRecursive();
$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");
$this->assertEquals('<p><a href="'.Director::baseURL().'page1-new-url/">Testing page 1 link</a></p>', $page2Live->obj('ExtraContent')->forTemplate()); $this->assertEquals(
'<p><a href="' . Director::baseURL() . 'page1-new-url/">Testing page 1 link</a></p>',
$page2Live->obj('ExtraContent')->forTemplate()
);
// Edit draft again // Edit draft again
Versioned::set_stage(Versioned::DRAFT); Versioned::set_stage(Versioned::DRAFT);
@ -262,12 +331,16 @@ class SiteTreeBacklinksTest extends SapphireTest
$page2->write(); $page2->write();
// assert backlink to page 2 no longer exists // 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() public function testLinkTrackingWithUntitledObjectsDisplaysAReadableIdentifier()
{ {
$page = $this->objFromFixture('Page', 'page2'); $page = $this->objFromFixture(SiteTree::class, 'page2');
$referencingObject = new SiteTreeBacklinksTestContentObject(); $referencingObject = new SiteTreeBacklinksTestContentObject();
$referencingObject->Content = '<p><a href="[sitetree_link,id=' $referencingObject->Content = '<p><a href="[sitetree_link,id='

View File

@ -1,4 +1,4 @@
Page: SilverStripe\CMS\Model\SiteTree:
page1: page1:
Title: page1 Title: page1
URLSegment: page1 URLSegment: page1
@ -11,6 +11,6 @@ Page:
Title: page3 Title: page3
URLSegment: page3 URLSegment: page3
Content: '<p><a href="[sitetree_link,id=$page1.ID]">Testing page 1 link</a></p>' Content: '<p><a href="[sitetree_link,id=$page1.ID]">Testing page 1 link</a></p>'
LinkTracking: =>Page.page1 LinkTracking: =>SilverStripe\CMS\Model\SiteTree.page1

View File

@ -2,7 +2,6 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use Page;
use Silverstripe\Assets\Dev\TestAssetStore; use Silverstripe\Assets\Dev\TestAssetStore;
use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
@ -42,15 +41,15 @@ class SiteTreeBrokenLinksTest extends SapphireTest
public function testBrokenLinksBetweenPages() public function testBrokenLinksBetweenPages()
{ {
/** @var Page $obj */ /** @var SiteTree $obj */
$obj = $this->objFromFixture('Page', 'content'); $obj = $this->objFromFixture(SiteTree::class, 'content');
$obj->Content = '<a href="[sitetree_link,id=3423423]">this is a broken link</a>'; $obj->Content = '<a href="[sitetree_link,id=3423423]">this is a broken link</a>';
$obj->syncLinkTracking(); $obj->syncLinkTracking();
$this->assertTrue($obj->HasBrokenLink, 'Page has a broken link'); $this->assertTrue($obj->HasBrokenLink, 'Page has a broken link');
$obj->Content = '<a href="[sitetree_link,id=' . $this->idFromFixture( $obj->Content = '<a href="[sitetree_link,id=' . $this->idFromFixture(
'Page', SiteTree::class,
'about' 'about'
) . ']">this is not a broken link</a>'; ) . ']">this is not a broken link</a>';
$obj->syncLinkTracking(); $obj->syncLinkTracking();
@ -62,8 +61,8 @@ class SiteTreeBrokenLinksTest extends SapphireTest
*/ */
public function testBrokenLinksNonPage() public function testBrokenLinksNonPage()
{ {
/** @var Page $aboutPage */ /** @var SiteTree $aboutPage */
$aboutPage = $this->objFromFixture('Page', 'about'); $aboutPage = $this->objFromFixture(SiteTree::class, 'about');
/** @var NotPageObject $obj */ /** @var NotPageObject $obj */
$obj = $this->objFromFixture(NotPageObject::class, 'object1'); $obj = $this->objFromFixture(NotPageObject::class, 'object1');
@ -94,7 +93,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest
// About-page backlinks contains this object // About-page backlinks contains this object
$this->assertListEquals( $this->assertListEquals(
[ [
['ID' => $obj->ID] ['ID' => $obj->ID],
], ],
$aboutPage->BackLinkTracking() $aboutPage->BackLinkTracking()
); );
@ -102,9 +101,9 @@ class SiteTreeBrokenLinksTest extends SapphireTest
public function testBrokenAnchorBetweenPages() public function testBrokenAnchorBetweenPages()
{ {
/** @var Page $obj */ /** @var SiteTree $obj */
$obj = $this->objFromFixture('Page', 'content'); $obj = $this->objFromFixture(SiteTree::class, 'content');
$target = $this->objFromFixture('Page', 'about'); $target = $this->objFromFixture(SiteTree::class, 'about');
$obj->Content = "<a href=\"[sitetree_link,id={$target->ID}]#no-anchor-here\">this is a broken link</a>"; $obj->Content = "<a href=\"[sitetree_link,id={$target->ID}]#no-anchor-here\">this is a broken link</a>";
$obj->syncLinkTracking(); $obj->syncLinkTracking();
@ -117,7 +116,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest
public function testBrokenVirtualPages() public function testBrokenVirtualPages()
{ {
$obj = $this->objFromFixture('Page', 'content'); $obj = $this->objFromFixture(SiteTree::class, 'content');
$vp = new VirtualPage(); $vp = new VirtualPage();
$vp->CopyContentFromID = $obj->ID; $vp->CopyContentFromID = $obj->ID;
@ -131,7 +130,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest
public function testBrokenInternalRedirectorPages() public function testBrokenInternalRedirectorPages()
{ {
$obj = $this->objFromFixture('Page', 'content'); $obj = $this->objFromFixture(SiteTree::class, 'content');
$rp = new RedirectorPage(); $rp = new RedirectorPage();
$rp->RedirectionType = 'Internal'; $rp->RedirectionType = 'Internal';
@ -148,10 +147,10 @@ class SiteTreeBrokenLinksTest extends SapphireTest
public function testDeletingMarksBackLinkedPagesAsBroken() public function testDeletingMarksBackLinkedPagesAsBroken()
{ {
// Set up two published pages with a link from content -> about // 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 */ /** @var SiteTree $linkSrc */
$linkSrc = $this->objFromFixture('Page', 'content'); $linkSrc = $this->objFromFixture(SiteTree::class, 'content');
$linkSrc->Content = "<p><a href=\"[sitetree_link,id=$linkDest->ID]\">about us</a></p>"; $linkSrc->Content = "<p><a href=\"[sitetree_link,id=$linkDest->ID]\">about us</a></p>";
$linkSrc->write(); $linkSrc->write();
@ -163,7 +162,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest
// Confirm draft has broken link // Confirm draft has broken link
$linkSrc->flushCache(); $linkSrc->flushCache();
$linkSrc = $this->objFromFixture('Page', 'content'); $linkSrc = $this->objFromFixture(SiteTree::class, 'content');
$this->assertEquals(1, (int)$linkSrc->HasBrokenLink); $this->assertEquals(1, (int)$linkSrc->HasBrokenLink);
} }
@ -173,13 +172,13 @@ class SiteTreeBrokenLinksTest extends SapphireTest
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
// Set up two draft pages with a link from content -> about // Set up two draft pages with a link from content -> about
/** @var Page $linkDest */ /** @var SiteTree $linkDest */
$linkDest = $this->objFromFixture('Page', 'about'); $linkDest = $this->objFromFixture(SiteTree::class, 'about');
// Ensure that it's not on the published site // Ensure that it's not on the published site
$linkDest->doUnpublish(); $linkDest->doUnpublish();
/** @var Page $linkSrc */ /** @var SiteTree $linkSrc */
$linkSrc = $this->objFromFixture('Page', 'content'); $linkSrc = $this->objFromFixture(SiteTree::class, 'content');
$linkSrc->Content = "<p><a href=\"[sitetree_link,id=$linkDest->ID]\">about us</a></p>"; $linkSrc->Content = "<p><a href=\"[sitetree_link,id=$linkDest->ID]\">about us</a></p>";
$linkSrc->write(); $linkSrc->write();
@ -191,20 +190,20 @@ class SiteTreeBrokenLinksTest extends SapphireTest
// Live doesn't have separate broken link tracking // Live doesn't have separate broken link tracking
$this->assertEquals(0, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\" $this->assertEquals(0, DB::query("SELECT \"HasBrokenLink\" FROM \"SiteTree_Live\"
WHERE \"ID\" = $linkSrc->ID")->value()); WHERE \"ID\" = $linkSrc->ID")->value());
} }
public function testRestoreFixesBrokenLinks() public function testRestoreFixesBrokenLinks()
{ {
// Create page and virtual page // Create page and virtual page
$p = new Page(); $p = new SiteTree();
$p->Title = "source"; $p->Title = "source";
$p->write(); $p->write();
$pageID = $p->ID; $pageID = $p->ID;
$this->assertTrue($p->publishRecursive()); $this->assertTrue($p->publishRecursive());
// Content links are one kind of link to pages // Content links are one kind of link to pages
$p2 = new Page(); $p2 = new SiteTree();
$p2->Title = "regular link"; $p2->Title = "regular link";
$p2->Content = "<a href=\"[sitetree_link,id=$p->ID]\">test</a>"; $p2->Content = "<a href=\"[sitetree_link,id=$p->ID]\">test</a>";
$p2->write(); $p2->write();
@ -264,14 +263,14 @@ class SiteTreeBrokenLinksTest extends SapphireTest
public function testRevertToLiveFixesBrokenLinks() public function testRevertToLiveFixesBrokenLinks()
{ {
// Create page and virutal page // Create page and virutal page
$page = new Page(); $page = new SiteTree();
$page->Title = "source"; $page->Title = "source";
$page->write(); $page->write();
$pageID = $page->ID; $pageID = $page->ID;
$this->assertTrue($page->publishRecursive()); $this->assertTrue($page->publishRecursive());
// Content links are one kind of link to pages // Content links are one kind of link to pages
$page2 = new Page(); $page2 = new SiteTree();
$page2->Title = "regular link"; $page2->Title = "regular link";
$page2->Content = "<a href=\"[sitetree_link,id={$pageID}]\">test</a>"; $page2->Content = "<a href=\"[sitetree_link,id={$pageID}]\">test</a>";
$page2->write(); $page2->write();
@ -302,7 +301,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest
$this->assertEquals(1, $redirectorPage->HasBrokenLink); $this->assertEquals(1, $redirectorPage->HasBrokenLink);
// Call doRevertToLive and confirm that broken links are restored // 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 = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $pageID);
$pageLive->doRevertToLive(); $pageLive->doRevertToLive();
@ -316,15 +315,17 @@ class SiteTreeBrokenLinksTest extends SapphireTest
public function testBrokenAnchorLinksInAPage() public function testBrokenAnchorLinksInAPage()
{ {
/** @var Page $obj */ /** @var SiteTree $obj */
$obj = $this->objFromFixture('Page', 'content'); $obj = $this->objFromFixture(SiteTree::class, 'content');
$origContent = $obj->Content; $origContent = $obj->Content;
$obj->Content = $origContent . '<a href="#no-anchor-here">this links to a non-existent in-page anchor or skiplink</a>'; $obj->Content = $origContent . '<a href="#no-anchor-here">this links to a non-existent in-page anchor or ' .
'skiplink</a>';
$obj->syncLinkTracking(); $obj->syncLinkTracking();
$this->assertTrue($obj->HasBrokenLink, 'Page has a broken anchor/skiplink'); $this->assertTrue($obj->HasBrokenLink, 'Page has a broken anchor/skiplink');
$obj->Content = $origContent . '<a href="#yes-anchor-here">this links to an existent in-page anchor/skiplink</a>'; $obj->Content = $origContent . '<a href="#yes-anchor-here">this links to an existent in-page ' .
'anchor/skiplink</a>';
$obj->syncLinkTracking(); $obj->syncLinkTracking();
$this->assertFalse($obj->HasBrokenLink, 'Page doesn\'t have a broken anchor or skiplink'); $this->assertFalse($obj->HasBrokenLink, 'Page doesn\'t have a broken anchor or skiplink');
} }

View File

@ -1,4 +1,4 @@
Page: SilverStripe\CMS\Model\SiteTree:
content: content:
Title: ContentPage Title: ContentPage
Content: 'This is some partially happy content. It has one missing a skiplink, but does have another <a name="yes-anchor-here">skiplink here</a>.' Content: 'This is some partially happy content. It has one missing a skiplink, but does have another <a name="yes-anchor-here">skiplink here</a>.'
@ -13,7 +13,7 @@ Page:
workingInternalRedirector: workingInternalRedirector:
RedirectionType: Internal RedirectionType: Internal
Title: RedirectorPageToBrokenInteralPage Title: RedirectorPageToBrokenInteralPage
LinkTo: =>Page.content LinkTo: =>SilverStripe\CMS\Model\SiteTree.content
SilverStripe\CMS\Tests\Model\SiteTreeBrokenLinksTest\NotPageObject: SilverStripe\CMS\Tests\Model\SiteTreeBrokenLinksTest\NotPageObject:
object1: object1:
Content: 'Everything will be ok' Content: 'Everything will be ok'

View File

@ -2,7 +2,6 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use Page;
use SilverStripe\Assets\Dev\TestAssetStore; use SilverStripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\File; use SilverStripe\Assets\File;
use SilverStripe\Assets\Filesystem; use SilverStripe\Assets\Filesystem;
@ -31,8 +30,8 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest
} }
// Ensure all pages are published // Ensure all pages are published
/** @var Page $page */ /** @var SiteTree $page */
foreach (Page::get() as $page) { foreach (SiteTree::get() as $page) {
$page->publishSingle(); $page->publishSingle();
} }
} }
@ -55,7 +54,11 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest
$editor->setValue("<a href=\"[sitetree_link,id=$aboutID]\">Example Link</a>"); $editor->setValue("<a href=\"[sitetree_link,id=$aboutID]\">Example Link</a>");
$editor->saveInto($sitetree); $editor->saveInto($sitetree);
$sitetree->write(); $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( $editor->setValue(
"<a href=\"[sitetree_link,id=$aboutID]\"></a><a href=\"[sitetree_link,id=$contactID]\"></a>" "<a href=\"[sitetree_link,id=$aboutID]\"></a><a href=\"[sitetree_link,id=$contactID]\"></a>"

View File

@ -2,7 +2,6 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use Page;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\SiteTreeLinkTracking_Parser; use SilverStripe\CMS\Model\SiteTreeLinkTracking_Parser;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
@ -32,7 +31,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest
public function testParser() public function testParser()
{ {
SiteTree::add_extension(Page::class, SiteTreeLinkTracking_Extension::class); SiteTree::add_extension(SiteTree::class, SiteTreeLinkTracking_Extension::class);
// Shortcodes // Shortcodes
$this->assertTrue($this->isBroken('<a href="[sitetree_link,id=123]">link</a>')); $this->assertTrue($this->isBroken('<a href="[sitetree_link,id=123]">link</a>'));
@ -55,8 +54,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest
$this->assertFalse($this->isBroken('<a id="anchor">anchor</a>')); $this->assertFalse($this->isBroken('<a id="anchor">anchor</a>'));
$this->assertTrue($this->isBroken('<a href="##anchor">anchor</a>')); $this->assertTrue($this->isBroken('<a href="##anchor">anchor</a>'));
$page = new SiteTree();
$page = new Page();
$page->Content = '<a name="yes-name-anchor">name</a><a id="yes-id-anchor">id</a>'; $page->Content = '<a name="yes-name-anchor">name</a><a id="yes-id-anchor">id</a>';
$page->write(); $page->write();
@ -72,7 +70,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest
protected function highlight($content) protected function highlight($content)
{ {
$page = new Page(); $page = new SiteTree();
$page->Content = $content; $page->Content = $content;
$page->write(); $page->write();
return $page->Content; return $page->Content;
@ -87,7 +85,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest
$content = $this->highlight('<a href="[sitetree_link,id=123]">link</a>'); $content = $this->highlight('<a href="[sitetree_link,id=123]">link</a>');
$this->assertEquals(substr_count($content ?? '', 'ss-broken'), 1, 'ss-broken class is added to the broken 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->Content = '';
$otherPage->write(); $otherPage->write();

View File

@ -2,7 +2,6 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use Page;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
@ -33,8 +32,8 @@ class SiteTreePermissionsTest extends FunctionalTest
$this->autoFollowRedirection = false; $this->autoFollowRedirection = false;
// Ensure all pages are published // Ensure all pages are published
/** @var Page $page */ /** @var SiteTree $page */
foreach (Page::get() as $page) { foreach (SiteTree::get() as $page) {
if ($page->URLSegment !== 'draft-only') { if ($page->URLSegment !== 'draft-only') {
$page->publishSingle(); $page->publishSingle();
} }
@ -46,8 +45,8 @@ class SiteTreePermissionsTest extends FunctionalTest
{ {
$this->autoFollowRedirection = false; $this->autoFollowRedirection = false;
/** @var Page $draftOnlyPage */ /** @var SiteTree $draftOnlyPage */
$draftOnlyPage = $this->objFromFixture(Page::class, 'draftOnlyPage'); $draftOnlyPage = $this->objFromFixture(SiteTree::class, 'draftOnlyPage');
$this->logOut(); $this->logOut();
$response = $this->get($draftOnlyPage->URLSegment . '?stage=Live'); $response = $this->get($draftOnlyPage->URLSegment . '?stage=Live');
@ -85,7 +84,7 @@ class SiteTreePermissionsTest extends FunctionalTest
{ {
// Set up fixture - a published page deleted from draft // Set up fixture - a published page deleted from draft
$this->logInWithPermission("ADMIN"); $this->logInWithPermission("ADMIN");
$page = $this->objFromFixture(Page::class, 'restrictedEditOnlySubadminGroup'); $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup');
$pageID = $page->ID; $pageID = $page->ID;
$this->assertTrue($page->publishRecursive()); $this->assertTrue($page->publishRecursive());
$page->delete(); $page->delete();
@ -112,7 +111,7 @@ class SiteTreePermissionsTest extends FunctionalTest
{ {
// Set up fixture - an unpublished page // Set up fixture - an unpublished page
$this->logInWithPermission("ADMIN"); $this->logInWithPermission("ADMIN");
$page = $this->objFromFixture(Page::class, 'restrictedEditOnlySubadminGroup'); $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup');
$pageID = $page->ID; $pageID = $page->ID;
$page->doUnpublish(); $page->doUnpublish();
@ -135,7 +134,7 @@ class SiteTreePermissionsTest extends FunctionalTest
{ {
// Find a page that exists and delete it from both stage and published // Find a page that exists and delete it from both stage and published
$this->logInWithPermission("ADMIN"); $this->logInWithPermission("ADMIN");
$page = $this->objFromFixture(Page::class, 'restrictedEditOnlySubadminGroup'); $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup');
$pageID = $page->ID; $pageID = $page->ID;
$page->doUnpublish(); $page->doUnpublish();
$page->delete(); $page->delete();
@ -153,8 +152,8 @@ class SiteTreePermissionsTest extends FunctionalTest
public function testCanViewStage() public function testCanViewStage()
{ {
// Get page & make sure it exists on Live // Get page & make sure it exists on Live
/** @var Page $page */ /** @var SiteTree $page */
$page = $this->objFromFixture(Page::class, 'standardpage'); $page = $this->objFromFixture(SiteTree::class, 'standardpage');
$page->publishSingle(); $page->publishSingle();
// Then make sure there's a new version on Stage // Then make sure there's a new version on Stage
@ -173,7 +172,7 @@ class SiteTreePermissionsTest extends FunctionalTest
public function testAccessTabOnlyDisplaysWithGrantAccessPermissions() public function testAccessTabOnlyDisplaysWithGrantAccessPermissions()
{ {
$page = $this->objFromFixture(Page::class, 'standardpage'); $page = $this->objFromFixture(SiteTree::class, 'standardpage');
$subadminuser = $this->objFromFixture(Member::class, 'subadmin'); $subadminuser = $this->objFromFixture(Member::class, 'subadmin');
Security::setCurrentUser($subadminuser); Security::setCurrentUser($subadminuser);
@ -204,7 +203,7 @@ class SiteTreePermissionsTest extends FunctionalTest
public function testRestrictedViewLoggedInUsers() public function testRestrictedViewLoggedInUsers()
{ {
$page = $this->objFromFixture(Page::class, 'restrictedViewLoggedInUsers'); $page = $this->objFromFixture(SiteTree::class, 'restrictedViewLoggedInUsers');
// unauthenticated users // unauthenticated users
$this->assertFalse( $this->assertFalse(
@ -223,21 +222,23 @@ class SiteTreePermissionsTest extends FunctionalTest
$websiteuser = $this->objFromFixture(Member::class, 'websiteuser'); $websiteuser = $this->objFromFixture(Member::class, 'websiteuser');
$this->assertTrue( $this->assertTrue(
$page->canView($websiteuser), $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); $this->logInAs($websiteuser);
$response = $this->get($page->RelativeLink()); $response = $this->get($page->RelativeLink());
$this->assertEquals( $this->assertEquals(
$response->getStatusCode(), $response->getStatusCode(),
200, 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(); $this->logOut();
} }
public function testRestrictedViewOnlyTheseUsers() public function testRestrictedViewOnlyTheseUsers()
{ {
$page = $this->objFromFixture(Page::class, 'restrictedViewOnlyWebsiteUsers'); $page = $this->objFromFixture(SiteTree::class, 'restrictedViewOnlyWebsiteUsers');
// unauthenticcated users // unauthenticcated users
$this->assertFalse( $this->assertFalse(
@ -256,14 +257,16 @@ class SiteTreePermissionsTest extends FunctionalTest
$subadminuser = $this->objFromFixture(Member::class, 'subadmin'); $subadminuser = $this->objFromFixture(Member::class, 'subadmin');
$this->assertFalse( $this->assertFalse(
$page->canView($subadminuser), $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); $this->LogInAs($subadminuser);
$response = $this->get($page->RelativeLink()); $response = $this->get($page->RelativeLink());
$this->assertEquals( $this->assertEquals(
$response->getStatusCode(), $response->getStatusCode(),
403, 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(); $this->logOut();
@ -285,7 +288,7 @@ class SiteTreePermissionsTest extends FunctionalTest
public function testRestrictedEditLoggedInUsers() public function testRestrictedEditLoggedInUsers()
{ {
$page = $this->objFromFixture(Page::class, 'restrictedEditLoggedInUsers'); $page = $this->objFromFixture(SiteTree::class, 'restrictedEditLoggedInUsers');
// unauthenticcated users // unauthenticcated users
$this->assertFalse( $this->assertFalse(
@ -298,20 +301,22 @@ class SiteTreePermissionsTest extends FunctionalTest
Security::setCurrentUser($websiteuser); Security::setCurrentUser($websiteuser);
$this->assertFalse( $this->assertFalse(
$page->canEdit($websiteuser), $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 // subadmin users
$subadminuser = $this->objFromFixture(Member::class, 'subadmin'); $subadminuser = $this->objFromFixture(Member::class, 'subadmin');
$this->assertTrue( $this->assertTrue(
$page->canEdit($subadminuser), $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() public function testRestrictedEditOnlySubadminGroup()
{ {
$page = $this->objFromFixture(Page::class, 'restrictedEditOnlySubadminGroup'); $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup');
// unauthenticated users // unauthenticated users
$this->assertFalse( $this->assertFalse(
@ -330,14 +335,15 @@ class SiteTreePermissionsTest extends FunctionalTest
$websiteuser = $this->objFromFixture(Member::class, 'websiteuser'); $websiteuser = $this->objFromFixture(Member::class, 'websiteuser');
$this->assertFalse( $this->assertFalse(
$page->canEdit($websiteuser), $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() public function testRestrictedViewInheritance()
{ {
$parentPage = $this->objFromFixture(Page::class, 'parent_restrictedViewOnlySubadminGroup'); $parentPage = $this->objFromFixture(SiteTree::class, 'parent_restrictedViewOnlySubadminGroup');
$childPage = $this->objFromFixture(Page::class, 'child_restrictedViewOnlySubadminGroup'); $childPage = $this->objFromFixture(SiteTree::class, 'child_restrictedViewOnlySubadminGroup');
// unauthenticated users // unauthenticated users
$this->assertFalse( $this->assertFalse(
@ -356,22 +362,24 @@ class SiteTreePermissionsTest extends FunctionalTest
$subadminuser = $this->objFromFixture(Member::class, 'subadmin'); $subadminuser = $this->objFromFixture(Member::class, 'subadmin');
$this->assertTrue( $this->assertTrue(
$childPage->canView($subadminuser), $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); $this->logInAs($subadminuser);
$response = $this->get($childPage->RelativeLink()); $response = $this->get($childPage->RelativeLink());
$this->assertEquals( $this->assertEquals(
$response->getStatusCode(), $response->getStatusCode(),
200, 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(); $this->logOut();
} }
public function testRestrictedEditInheritance() public function testRestrictedEditInheritance()
{ {
$parentPage = $this->objFromFixture(Page::class, 'parent_restrictedEditOnlySubadminGroup'); $parentPage = $this->objFromFixture(SiteTree::class, 'parent_restrictedEditOnlySubadminGroup');
$childPage = $this->objFromFixture(Page::class, 'child_restrictedEditOnlySubadminGroup'); $childPage = $this->objFromFixture(SiteTree::class, 'child_restrictedEditOnlySubadminGroup');
// unauthenticated users // unauthenticated users
$this->assertFalse( $this->assertFalse(
@ -383,14 +391,15 @@ class SiteTreePermissionsTest extends FunctionalTest
$subadminuser = $this->objFromFixture(Member::class, 'subadmin'); $subadminuser = $this->objFromFixture(Member::class, 'subadmin');
$this->assertTrue( $this->assertTrue(
$childPage->canEdit($subadminuser), $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() public function testDeleteRestrictedChild()
{ {
$parentPage = $this->objFromFixture(Page::class, 'deleteTestParentPage'); $parentPage = $this->objFromFixture(SiteTree::class, 'deleteTestParentPage');
$childPage = $this->objFromFixture(Page::class, 'deleteTestChildPage'); $childPage = $this->objFromFixture(SiteTree::class, 'deleteTestChildPage');
// unauthenticated users // unauthenticated users
$this->assertFalse( $this->assertFalse(
@ -405,7 +414,7 @@ class SiteTreePermissionsTest extends FunctionalTest
public function testRestrictedEditLoggedInUsersDeletedFromStage() public function testRestrictedEditLoggedInUsersDeletedFromStage()
{ {
$page = $this->objFromFixture(Page::class, 'restrictedEditLoggedInUsers'); $page = $this->objFromFixture(SiteTree::class, 'restrictedEditLoggedInUsers');
$pageID = $page->ID; $pageID = $page->ID;
$this->logInWithPermission("ADMIN"); $this->logInWithPermission("ADMIN");
@ -421,39 +430,60 @@ class SiteTreePermissionsTest extends FunctionalTest
$subadminuser = $this->objFromFixture(Member::class, 'subadmin'); $subadminuser = $this->objFromFixture(Member::class, 'subadmin');
$this->assertTrue( $this->assertTrue(
$page->canEdit($subadminuser), $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() public function testInheritCanViewFromSiteConfig()
{ {
$page = $this->objFromFixture(Page::class, 'inheritWithNoParent'); $page = $this->objFromFixture(SiteTree::class, 'inheritWithNoParent');
$siteconfig = $this->objFromFixture(SiteConfig::class, 'default'); $siteconfig = $this->objFromFixture(SiteConfig::class, 'default');
$editor = $this->objFromFixture(Member::class, 'editor'); $editor = $this->objFromFixture(Member::class, 'editor');
$editorGroup = $this->objFromFixture(Group::class, 'editorgroup'); $editorGroup = $this->objFromFixture(Group::class, 'editorgroup');
$siteconfig->CanViewType = 'Anyone'; $siteconfig->CanViewType = 'Anyone';
$siteconfig->write(); $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->CanViewType = 'LoggedInUsers';
$siteconfig->write(); $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->CanViewType = 'LoggedInUsers';
$siteconfig->write(); $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->CanViewType = 'OnlyTheseUsers';
$siteconfig->ViewerGroups()->add($editorGroup); $siteconfig->ViewerGroups()->add($editorGroup);
$siteconfig->write(); $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->assertTrue(
$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'); $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() public function testInheritCanEditFromSiteConfig()
{ {
$page = $this->objFromFixture(Page::class, 'inheritWithNoParent'); $page = $this->objFromFixture(SiteTree::class, 'inheritWithNoParent');
$siteconfig = $this->objFromFixture(SiteConfig::class, 'default'); $siteconfig = $this->objFromFixture(SiteConfig::class, 'default');
$editor = $this->objFromFixture(Member::class, 'editor'); $editor = $this->objFromFixture(Member::class, 'editor');
$user = $this->objFromFixture(Member::class, 'websiteuser'); $user = $this->objFromFixture(Member::class, 'websiteuser');
@ -462,17 +492,37 @@ class SiteTreePermissionsTest extends FunctionalTest
$siteconfig->CanEditType = 'LoggedInUsers'; $siteconfig->CanEditType = 'LoggedInUsers';
$siteconfig->write(); $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); 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->CanEditType = 'OnlyTheseUsers';
$siteconfig->EditorGroups()->add($editorGroup); $siteconfig->EditorGroups()->add($editorGroup);
$siteconfig->write(); $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); 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); 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'
);
} }
} }

View File

@ -35,7 +35,7 @@ SilverStripe\Security\Member:
Email: websiteuser@test.com Email: websiteuser@test.com
Password: test Password: test
Groups: =>SilverStripe\Security\Group.websiteusers Groups: =>SilverStripe\Security\Group.websiteusers
Page: SilverStripe\CMS\Model\SiteTree:
standardpage: standardpage:
URLSegment: standardpage URLSegment: standardpage
restrictedViewLoggedInUsers: restrictedViewLoggedInUsers:
@ -66,7 +66,7 @@ Page:
URLSegment: parent-restrictedViewOnlySubadminGroup URLSegment: parent-restrictedViewOnlySubadminGroup
child_restrictedViewOnlySubadminGroup: child_restrictedViewOnlySubadminGroup:
CanViewType: Inherit CanViewType: Inherit
Parent: =>Page.parent_restrictedViewOnlySubadminGroup Parent: =>SilverStripe\CMS\Model\SiteTree.parent_restrictedViewOnlySubadminGroup
URLSegment: child-restrictedViewOnlySubadminGroup URLSegment: child-restrictedViewOnlySubadminGroup
parent_restrictedEditOnlySubadminGroup: parent_restrictedEditOnlySubadminGroup:
CanEditType: OnlyTheseUsers CanEditType: OnlyTheseUsers
@ -74,7 +74,7 @@ Page:
URLSegment: parent-restrictedEditOnlySubadminGroup URLSegment: parent-restrictedEditOnlySubadminGroup
child_restrictedEditOnlySubadminGroup: child_restrictedEditOnlySubadminGroup:
CanEditType: Inherit CanEditType: Inherit
Parent: =>Page.parent_restrictedEditOnlySubadminGroup Parent: =>SilverStripe\CMS\Model\SiteTree.parent_restrictedEditOnlySubadminGroup
URLSegment: child-restrictedEditOnlySubadminGroup URLSegment: child-restrictedEditOnlySubadminGroup
deleteTestParentPage: deleteTestParentPage:
CanEditType: Inherit CanEditType: Inherit

View File

@ -3,7 +3,6 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use LogicException; use LogicException;
use Page;
use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\CacheInterface;
use ReflectionMethod; use ReflectionMethod;
use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\RedirectorPage;
@ -36,6 +35,9 @@ use SilverStripe\View\Parsers\ShortcodeParser;
use SilverStripe\View\Parsers\URLSegmentFilter; use SilverStripe\View\Parsers\URLSegmentFilter;
use SilverStripe\View\Shortcodes\EmbedShortcodeProvider; use SilverStripe\View\Shortcodes\EmbedShortcodeProvider;
use TractorCow\Fluent\Extension\FluentSiteTreeExtension; use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
use Page;
use PageController;
use const RESOURCES_DIR; use const RESOURCES_DIR;
class SiteTreeTest extends SapphireTest class SiteTreeTest extends SapphireTest
@ -75,28 +77,28 @@ class SiteTreeTest extends SapphireTest
public function testCreateDefaultpages() public function testCreateDefaultpages()
{ {
$remove = SiteTree::get(); $remove = SiteTree::get();
if ($remove) { if ($remove) {
foreach ($remove as $page) { foreach ($remove as $page) {
$page->delete(); $page->delete();
} }
} }
// Make sure the table is empty // Make sure the table is empty
$this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0); $this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0);
// Disable the creation // Disable the creation
SiteTree::config()->create_default_pages = false; SiteTree::config()->create_default_pages = false;
singleton(SiteTree::class)->requireDefaultRecords(); singleton(SiteTree::class)->requireDefaultRecords();
// The table should still be empty // The table should still be empty
$this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0); $this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0);
// Enable the creation // Enable the creation
SiteTree::config()->create_default_pages = true; SiteTree::config()->create_default_pages = true;
singleton(SiteTree::class)->requireDefaultRecords(); singleton(SiteTree::class)->requireDefaultRecords();
// The table should now have three rows (home, about-us, contact-us) // The table should now have three rows (home, about-us, contact-us)
$this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 3); $this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 3);
} }
/** /**
@ -123,7 +125,7 @@ class SiteTreeTest extends SapphireTest
]; ];
foreach ($expectedURLs as $fixture => $urlSegment) { foreach ($expectedURLs as $fixture => $urlSegment) {
$obj = $this->objFromFixture('Page', $fixture); $obj = $this->objFromFixture(SiteTree::class, $fixture);
$this->assertEquals($urlSegment, $obj->URLSegment); $this->assertEquals($urlSegment, $obj->URLSegment);
} }
} }
@ -134,9 +136,9 @@ class SiteTreeTest extends SapphireTest
*/ */
public function testDisallowedURLGeneration($title, $urlSegment) public function testDisallowedURLGeneration($title, $urlSegment)
{ {
$page = Page::create(['Title' => $title]); $page = new SiteTree(['Title' => $title]);
$id = $page->write(); $id = $page->write();
$page = Page::get()->byID($id); $page = SiteTree::get()->byID($id);
$this->assertEquals($urlSegment, $page->URLSegment); $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 // Using the same dataprovider, strip out the -2 from the admin and dev segment
$urlSegment = str_replace('-2', '', $urlSegment ?? ''); $urlSegment = str_replace('-2', '', $urlSegment ?? '');
$page = Page::create(['Title' => $title, 'ParentID' => 1]); $page = new SiteTree(['Title' => $title, 'ParentID' => 1]);
$id = $page->write(); $id = $page->write();
$page = Page::get()->byID($id); $page = SiteTree::get()->byID($id);
$this->assertEquals($urlSegment, $page->URLSegment); $this->assertEquals($urlSegment, $page->URLSegment);
} }
@ -166,7 +168,7 @@ class SiteTreeTest extends SapphireTest
$this->markTestSkipped('This legacy test requires RESOURCES_DIR to be "resources"'); $this->markTestSkipped('This legacy test requires RESOURCES_DIR to be "resources"');
} }
$page = SiteTree::create(['Title' => 'Resources']); $page = new SiteTree(['Title' => 'Resources']);
$id = $page->write(); $id = $page->write();
$page = SiteTree::get()->byID($id); $page = SiteTree::get()->byID($id);
$this->assertSame('resources-2', $page->URLSegment); $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"'); $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(); $id = $page->write();
$page = SiteTree::get()->byID($id); $page = SiteTree::get()->byID($id);
$this->assertSame('resources', $page->URLSegment); $this->assertSame('resources', $page->URLSegment);
@ -195,10 +197,12 @@ class SiteTreeTest extends SapphireTest
*/ */
public function testPublishCopiesToLiveTable() public function testPublishCopiesToLiveTable()
{ {
$obj = $this->objFromFixture('Page', 'about'); $obj = $this->objFromFixture(SiteTree::class, 'about');
$obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $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); $this->assertEquals($obj->ID, $createdID);
} }
@ -209,12 +213,15 @@ class SiteTreeTest extends SapphireTest
{ {
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$obj = $this->objFromFixture('Page', 'about'); $obj = $this->objFromFixture(SiteTree::class, 'about');
$obj->Title = "asdfasdf"; $obj->Title = "asdfasdf";
$obj->write(); $obj->write();
$this->assertTrue($obj->publishRecursive()); $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->Title = null;
$obj->write(); $obj->write();
@ -261,7 +268,7 @@ class SiteTreeTest extends SapphireTest
Versioned::set_stage(Versioned::LIVE); Versioned::set_stage(Versioned::LIVE);
$checkSiteTree = DataObject::get_one(SiteTree::class, [ $checkSiteTree = DataObject::get_one(SiteTree::class, [
'"SiteTree"."URLSegment"' => 'get-one-test-page' '"SiteTree"."URLSegment"' => 'get-one-test-page',
]); ]);
$this->assertEquals("V1", $checkSiteTree->Title); $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 */ /* DataObject::write() should save to a has_one relationship if you set a field called (relname)ID */
$page = new SiteTree(); $page = new SiteTree();
$parentID = $this->idFromFixture('Page', 'home'); $parentID = $this->idFromFixture(SiteTree::class, 'home');
$page->ParentID = $parentID; $page->ParentID = $parentID;
$page->write(); $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 */ /* You should then be able to save a null/0/'' value to the relation */
$page->ParentID = null; $page->ParentID = null;
@ -387,23 +397,23 @@ class SiteTreeTest extends SapphireTest
*/ */
public function testRestoreToStage() public function testRestoreToStage()
{ {
$page = $this->objFromFixture('Page', 'about'); $page = $this->objFromFixture(SiteTree::class, 'about');
$pageID = $page->ID; $pageID = $page->ID;
$page->delete(); $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); $deletedPage = Versioned::get_latest_version(SiteTree::class, $pageID);
$resultPage = $deletedPage->doRestoreToStage(); $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, $resultPage->ID);
$this->assertEquals($pageID, $requeriedPage->ID); $this->assertEquals($pageID, $requeriedPage->ID);
$this->assertEquals('About Us', $requeriedPage->Title); $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; $page2ID = $page2->ID;
$page2->doUnpublish(); $page2->doUnpublish();
$page2->delete(); $page2->delete();
@ -413,12 +423,14 @@ class SiteTreeTest extends SapphireTest
Versioned::set_stage(Versioned::LIVE); Versioned::set_stage(Versioned::LIVE);
$deletedPage = Versioned::get_latest_version(SiteTree::class, $page2ID); $deletedPage = Versioned::get_latest_version(SiteTree::class, $page2ID);
$deletedPage->doRestoreToStage(); $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); 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->assertEquals('Products', $requeriedPage->Title);
$this->assertInstanceOf('Page', $requeriedPage); $this->assertInstanceOf(SiteTree::class, $requeriedPage);
} }
public function testNoCascadingDeleteWithoutID() public function testNoCascadingDeleteWithoutID()
@ -442,10 +454,10 @@ class SiteTreeTest extends SapphireTest
public function testGetByLink() public function testGetByLink()
{ {
$home = $this->objFromFixture('Page', 'home'); $home = $this->objFromFixture(SiteTree::class, 'home');
$about = $this->objFromFixture('Page', 'about'); $about = $this->objFromFixture(SiteTree::class, 'about');
$staff = $this->objFromFixture('Page', 'staff'); $staff = $this->objFromFixture(SiteTree::class, 'staff');
$product = $this->objFromFixture('Page', 'product1'); $product = $this->objFromFixture(SiteTree::class, 'product1');
SiteTree::config()->nested_urls = false; SiteTree::config()->nested_urls = false;
@ -472,10 +484,10 @@ class SiteTreeTest extends SapphireTest
public function testGetByLinkAbsolute() public function testGetByLinkAbsolute()
{ {
$home = $this->objFromFixture('Page', 'home'); $home = $this->objFromFixture(SiteTree::class, 'home');
$about = $this->objFromFixture('Page', 'about'); $about = $this->objFromFixture(SiteTree::class, 'about');
$staff = $this->objFromFixture('Page', 'staff'); $staff = $this->objFromFixture(SiteTree::class, 'staff');
$product = $this->objFromFixture('Page', 'product1'); $product = $this->objFromFixture(SiteTree::class, 'product1');
$base = 'https://example.test/'; $base = 'https://example.test/';
$this->assertEquals($home->ID, SiteTree::get_by_link(Controller::join_links($base, '/'), false)->ID); $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() public function testRelativeLink()
{ {
$about = $this->objFromFixture('Page', 'about'); $about = $this->objFromFixture(SiteTree::class, 'about');
$staff = $this->objFromFixture('Page', 'staff'); $staff = $this->objFromFixture(SiteTree::class, 'staff');
Config::modify()->set(SiteTree::class, 'nested_urls', true); Config::modify()->set(SiteTree::class, 'nested_urls', true);
$this->assertEquals('about-us/', $about->RelativeLink(), 'Matches URLSegment on top level without parameters'); $this->assertEquals(
$this->assertEquals('about-us/my-staff/', $staff->RelativeLink(), 'Matches URLSegment plus parent on second level without parameters'); 'about-us/',
$this->assertEquals('about-us/edit', $about->RelativeLink('edit'), 'Matches URLSegment plus parameter on top level'); $about->RelativeLink(),
$this->assertEquals('about-us/tom&jerry', $about->RelativeLink('tom&jerry'), 'Doesnt url encode parameter'); '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() public function testPageLevel()
{ {
$about = $this->objFromFixture('Page', 'about'); $about = $this->objFromFixture(SiteTree::class, 'about');
$staff = $this->objFromFixture('Page', 'staff'); $staff = $this->objFromFixture(SiteTree::class, 'staff');
$this->assertEquals(1, $about->getPageLevel()); $this->assertEquals(1, $about->getPageLevel());
$this->assertEquals(2, $staff->getPageLevel()); $this->assertEquals(2, $staff->getPageLevel());
} }
public function testAbsoluteLiveLink() public function testAbsoluteLiveLink()
{ {
$parent = $this->objFromFixture('Page', 'about'); $parent = $this->objFromFixture(SiteTree::class, 'about');
$child = $this->objFromFixture('Page', 'staff'); $child = $this->objFromFixture(SiteTree::class, 'staff');
Config::modify()->set(SiteTree::class, 'nested_urls', true); Config::modify()->set(SiteTree::class, 'nested_urls', true);
@ -526,17 +554,17 @@ class SiteTreeTest extends SapphireTest
public function testDuplicateChildrenRetainSort() public function testDuplicateChildrenRetainSort()
{ {
$parent = new Page(); $parent = new SiteTree();
$parent->Title = 'Parent'; $parent->Title = 'Parent';
$parent->write(); $parent->write();
$child1 = new Page(); $child1 = new SiteTree();
$child1->ParentID = $parent->ID; $child1->ParentID = $parent->ID;
$child1->Title = 'Child 1'; $child1->Title = 'Child 1';
$child1->Sort = 2; $child1->Sort = 2;
$child1->write(); $child1->write();
$child2 = new Page(); $child2 = new SiteTree();
$child2->ParentID = $parent->ID; $child2->ParentID = $parent->ID;
$child2->Title = 'Child 2'; $child2->Title = 'Child 2';
$child2->Sort = 1; $child2->Sort = 1;
@ -560,34 +588,34 @@ class SiteTreeTest extends SapphireTest
public function testDeleteFromStageOperatesRecursively() public function testDeleteFromStageOperatesRecursively()
{ {
Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', false); Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', false);
$pageAbout = $this->objFromFixture('Page', 'about'); $pageAbout = $this->objFromFixture(SiteTree::class, 'about');
$pageStaff = $this->objFromFixture('Page', 'staff'); $pageStaff = $this->objFromFixture(SiteTree::class, 'staff');
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); $pageStaffDuplicate = $this->objFromFixture(SiteTree::class, 'staffduplicate');
$pageAbout->delete(); $pageAbout->delete();
$this->assertNull(DataObject::get_by_id('Page', $pageAbout->ID)); $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageAbout->ID));
$this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page); $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaff->ID) instanceof SiteTree);
$this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page); $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaffDuplicate->ID) instanceof SiteTree);
Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', true); Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', true);
} }
public function testDeleteFromStageOperatesRecursivelyStrict() public function testDeleteFromStageOperatesRecursivelyStrict()
{ {
$pageAbout = $this->objFromFixture('Page', 'about'); $pageAbout = $this->objFromFixture(SiteTree::class, 'about');
$pageStaff = $this->objFromFixture('Page', 'staff'); $pageStaff = $this->objFromFixture(SiteTree::class, 'staff');
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); $pageStaffDuplicate = $this->objFromFixture(SiteTree::class, 'staffduplicate');
$pageAbout->delete(); $pageAbout->delete();
$this->assertNull(DataObject::get_by_id('Page', $pageAbout->ID)); $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageAbout->ID));
$this->assertNull(DataObject::get_by_id('Page', $pageStaff->ID)); $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageStaff->ID));
$this->assertNull(DataObject::get_by_id('Page', $pageStaffDuplicate->ID)); $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageStaffDuplicate->ID));
} }
public function testDuplicate() public function testDuplicate()
{ {
$pageAbout = $this->objFromFixture('Page', 'about'); $pageAbout = $this->objFromFixture(SiteTree::class, 'about');
$dupe = $pageAbout->duplicate(); $dupe = $pageAbout->duplicate();
$this->assertEquals($pageAbout->Title, $dupe->Title); $this->assertEquals($pageAbout->Title, $dupe->Title);
$this->assertNotEquals($pageAbout->URLSegment, $dupe->URLSegment); $this->assertNotEquals($pageAbout->URLSegment, $dupe->URLSegment);
@ -599,22 +627,22 @@ class SiteTreeTest extends SapphireTest
Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', false); Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', false);
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$pageAbout = $this->objFromFixture('Page', 'about'); $pageAbout = $this->objFromFixture(SiteTree::class, 'about');
$pageAbout->publishRecursive(); $pageAbout->publishRecursive();
$pageStaff = $this->objFromFixture('Page', 'staff'); $pageStaff = $this->objFromFixture(SiteTree::class, 'staff');
$pageStaff->publishRecursive(); $pageStaff->publishRecursive();
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); $pageStaffDuplicate = $this->objFromFixture(SiteTree::class, 'staffduplicate');
$pageStaffDuplicate->publishRecursive(); $pageStaffDuplicate->publishRecursive();
$parentPage = $this->objFromFixture('Page', 'about'); $parentPage = $this->objFromFixture(SiteTree::class, 'about');
$parentPage->doUnpublish(); $parentPage->doUnpublish();
Versioned::set_stage(Versioned::LIVE); Versioned::set_stage(Versioned::LIVE);
$this->assertNull(DataObject::get_by_id('Page', $pageAbout->ID)); $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageAbout->ID));
$this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page); $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaff->ID) instanceof SiteTree);
$this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page); $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaffDuplicate->ID) instanceof SiteTree);
Versioned::set_stage(Versioned::DRAFT); Versioned::set_stage(Versioned::DRAFT);
Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', true); 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); Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', false);
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$pageAbout = $this->objFromFixture('Page', 'about'); $pageAbout = $this->objFromFixture(SiteTree::class, 'about');
$pageAbout->publishRecursive(); $pageAbout->publishRecursive();
$pageStaff = $this->objFromFixture('Page', 'staff'); $pageStaff = $this->objFromFixture(SiteTree::class, 'staff');
$pageStaff->publishRecursive(); $pageStaff->publishRecursive();
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); $pageStaffDuplicate = $this->objFromFixture(SiteTree::class, 'staffduplicate');
$pageStaffDuplicate->publishRecursive(); $pageStaffDuplicate->publishRecursive();
$parentPage = $this->objFromFixture('Page', 'about'); $parentPage = $this->objFromFixture(SiteTree::class, 'about');
$parentPage->doUnpublish(); $parentPage->doUnpublish();
Versioned::set_stage(Versioned::LIVE); Versioned::set_stage(Versioned::LIVE);
$this->assertNull(DataObject::get_by_id('Page', $pageAbout->ID)); $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageAbout->ID));
$this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page); $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaff->ID) instanceof SiteTree);
$this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page); $this->assertTrue(DataObject::get_by_id(SiteTree::class, $pageStaffDuplicate->ID) instanceof SiteTree);
Versioned::set_stage(Versioned::DRAFT); Versioned::set_stage(Versioned::DRAFT);
Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', true); Config::modify()->set(SiteTree::class, 'enforce_strict_hierarchy', true);
} }
@ -646,20 +674,20 @@ class SiteTreeTest extends SapphireTest
{ {
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$pageAbout = $this->objFromFixture('Page', 'about'); $pageAbout = $this->objFromFixture(SiteTree::class, 'about');
$pageAbout->publishRecursive(); $pageAbout->publishRecursive();
$pageStaff = $this->objFromFixture('Page', 'staff'); $pageStaff = $this->objFromFixture(SiteTree::class, 'staff');
$pageStaff->publishRecursive(); $pageStaff->publishRecursive();
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); $pageStaffDuplicate = $this->objFromFixture(SiteTree::class, 'staffduplicate');
$pageStaffDuplicate->publishRecursive(); $pageStaffDuplicate->publishRecursive();
$parentPage = $this->objFromFixture('Page', 'about'); $parentPage = $this->objFromFixture(SiteTree::class, 'about');
$parentPage->doUnpublish(); $parentPage->doUnpublish();
Versioned::set_stage(Versioned::LIVE); Versioned::set_stage(Versioned::LIVE);
$this->assertNull(DataObject::get_by_id('Page', $pageAbout->ID)); $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageAbout->ID));
$this->assertNull(DataObject::get_by_id('Page', $pageStaff->ID)); $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageStaff->ID));
$this->assertNull(DataObject::get_by_id('Page', $pageStaffDuplicate->ID)); $this->assertNull(DataObject::get_by_id(SiteTree::class, $pageStaffDuplicate->ID));
Versioned::set_stage(Versioned::DRAFT); Versioned::set_stage(Versioned::DRAFT);
} }
@ -670,7 +698,7 @@ class SiteTreeTest extends SapphireTest
public function testReadArchiveDate() public function testReadArchiveDate()
{ {
DBDatetime::set_mock_now('2009-07-02 14:05:07'); DBDatetime::set_mock_now('2009-07-02 14:05:07');
$oldPage = SiteTree::create(); $oldPage = new SiteTree();
$oldPage->Title = 'A really old page'; $oldPage->Title = 'A really old page';
$oldPage->write(); $oldPage->write();
DBDatetime::clear_mock_now(); DBDatetime::clear_mock_now();
@ -678,7 +706,7 @@ class SiteTreeTest extends SapphireTest
$date = '2009-07-02 14:05:07'; $date = '2009-07-02 14:05:07';
Versioned::reading_archived_date($date); Versioned::reading_archived_date($date);
$result = SiteTree::get()->where([ $result = SiteTree::get()->where([
'"SiteTree"."ParentID"' => 0 '"SiteTree"."ParentID"' => 0,
]); ]);
$this->assertCount(1, $result, '"A really old page" should be returned'); $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"); $editor = $this->objFromFixture(Member::class, "editor");
$home = $this->objFromFixture("Page", "home"); $home = $this->objFromFixture(SiteTree::class, "home");
$staff = $this->objFromFixture("Page", "staff"); $staff = $this->objFromFixture(SiteTree::class, "staff");
$products = $this->objFromFixture("Page", "products"); $products = $this->objFromFixture(SiteTree::class, "products");
$product1 = $this->objFromFixture("Page", "product1"); $product1 = $this->objFromFixture(SiteTree::class, "product1");
$product4 = $this->objFromFixture("Page", "product4"); $product4 = $this->objFromFixture(SiteTree::class, "product4");
// Test logged out users cannot edit // Test logged out users cannot edit
$this->logOut(); $this->logOut();
@ -712,7 +740,7 @@ class SiteTreeTest extends SapphireTest
public function testCanEditWithAccessToAllSections() public function testCanEditWithAccessToAllSections()
{ {
$page = new Page(); $page = new SiteTree();
$page->write(); $page->write();
$allSectionMember = $this->objFromFixture(Member::class, 'allsections'); $allSectionMember = $this->objFromFixture(Member::class, 'allsections');
$securityAdminMember = $this->objFromFixture(Member::class, 'securityadmin'); $securityAdminMember = $this->objFromFixture(Member::class, 'securityadmin');
@ -737,7 +765,7 @@ class SiteTreeTest extends SapphireTest
$this->assertTrue(singleton(SiteTree::class)->canCreate()); $this->assertTrue(singleton(SiteTree::class)->canCreate());
// Test creation underneath a parent which this user doesn't have access to // 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])); $this->assertFalse(singleton(SiteTree::class)->canCreate(null, ['Parent' => $parent]));
// Test creation underneath a parent which doesn't allow a certain child // 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)])); $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 //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() public function testEditPermissionsOnDraftVsLive()
{ {
// Create an inherit-permission page // Create an inherit-permission page
$page = new Page(); $page = new SiteTree();
$page->write(); $page->write();
$page->CanEditType = "Inherit"; $page->CanEditType = "Inherit";
$page->publishRecursive(); $page->publishRecursive();
@ -810,7 +843,7 @@ class SiteTreeTest extends SapphireTest
$oldCleanerClass = Diff::$html_cleaner_class; $oldCleanerClass = Diff::$html_cleaner_class;
Diff::$html_cleaner_class = SiteTreeTest_NullHtmlCleaner::class; Diff::$html_cleaner_class = SiteTreeTest_NullHtmlCleaner::class;
$page = new Page(); $page = new SiteTree();
$page->write(); $page->write();
$this->assertEquals(1, $page->Version); $this->assertEquals(1, $page->Version);
@ -838,14 +871,14 @@ class SiteTreeTest extends SapphireTest
$this->logInAs($member); $this->logInAs($member);
// Write the page // Write the page
$about = $this->objFromFixture('Page', 'about'); $about = $this->objFromFixture(SiteTree::class, 'about');
$about->Title = "Another title"; $about->Title = "Another title";
$about->write(); $about->write();
// Check the version created // Check the version created
$savedVersion = DB::prepared_query( $savedVersion = DB::prepared_query(
"SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\" "SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\"
WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC", WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC",
[$about->ID] [$about->ID]
)->first(); )->first();
$this->assertEquals($member->ID, $savedVersion['AuthorID']); $this->assertEquals($member->ID, $savedVersion['AuthorID']);
@ -855,7 +888,7 @@ class SiteTreeTest extends SapphireTest
$about->publishRecursive(); $about->publishRecursive();
$publishedVersion = DB::prepared_query( $publishedVersion = DB::prepared_query(
"SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\" "SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\"
WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC", WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC",
[$about->ID] [$about->ID]
)->first(); )->first();
@ -866,7 +899,7 @@ class SiteTreeTest extends SapphireTest
public function testLinkShortcodeHandler() public function testLinkShortcodeHandler()
{ {
$aboutPage = $this->objFromFixture('Page', 'about'); $aboutPage = $this->objFromFixture(SiteTree::class, 'about');
$redirectPage = $this->objFromFixture(RedirectorPage::class, 'external'); $redirectPage = $this->objFromFixture(RedirectorPage::class, 'external');
$parser = new ShortcodeParser(); $parser = new ShortcodeParser();
@ -878,12 +911,24 @@ class SiteTreeTest extends SapphireTest
$aboutShortcodeExpected = $aboutPage->Link(); $aboutShortcodeExpected = $aboutPage->Link();
$aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $aboutPage->Link()); $aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $aboutPage->Link());
$this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test that simple linking works.'); $this->assertEquals(
$this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed), 'Test enclosed content is linked.'); $aboutShortcodeExpected,
$parser->parse($aboutShortcode),
'Test that simple linking works.'
);
$this->assertEquals(
$aboutEnclosedExpected,
$parser->parse($aboutEnclosed),
'Test enclosed content is linked.'
);
$aboutPage->delete(); $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)); $this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed));
$aboutShortcode = '[sitetree_link,id="-1"]'; $aboutShortcode = '[sitetree_link,id="-1"]';
@ -897,7 +942,10 @@ class SiteTreeTest extends SapphireTest
$redirectExpected = 'http://www.google.com?a&amp;b'; $redirectExpected = 'http://www.google.com?a&amp;b';
$this->assertEquals($redirectExpected, $parser->parse($redirectShortcode)); $this->assertEquals($redirectExpected, $parser->parse($redirectShortcode));
$this->assertEquals(sprintf('<a href="%s">Example Content</a>', $redirectExpected), $parser->parse($redirectEnclosed)); $this->assertEquals(
sprintf('<a href="%s">Example Content</a>', $redirectExpected),
$parser->parse($redirectEnclosed)
);
$this->assertEquals('', $parser->parse('[sitetree_link]'), 'Test that invalid ID attributes are not parsed.'); $this->assertEquals('', $parser->parse('[sitetree_link]'), 'Test that invalid ID attributes are not parsed.');
$this->assertEquals('', $parser->parse('[sitetree_link,id="text"]')); $this->assertEquals('', $parser->parse('[sitetree_link,id="text"]'));
@ -906,8 +954,8 @@ class SiteTreeTest extends SapphireTest
public function testIsCurrent() public function testIsCurrent()
{ {
$aboutPage = $this->objFromFixture('Page', 'about'); $aboutPage = $this->objFromFixture(SiteTree::class, 'about');
$productPage = $this->objFromFixture('Page', 'products'); $productPage = $this->objFromFixture(SiteTree::class, 'products');
Director::set_current_page($aboutPage); Director::set_current_page($aboutPage);
$this->assertTrue($aboutPage->isCurrent(), 'Assert that basic isCurrent checks works.'); $this->assertTrue($aboutPage->isCurrent(), 'Assert that basic isCurrent checks works.');
@ -915,7 +963,7 @@ class SiteTreeTest extends SapphireTest
$this->assertTrue( $this->assertTrue(
DataObject::get_one(SiteTree::class, [ DataObject::get_one(SiteTree::class, [
'"SiteTree"."Title"' => 'About Us' '"SiteTree"."Title"' => 'About Us',
])->isCurrent(), ])->isCurrent(),
'Assert that isCurrent works on another instance with the same ID.' 'Assert that isCurrent works on another instance with the same ID.'
); );
@ -926,9 +974,9 @@ class SiteTreeTest extends SapphireTest
public function testIsSection() public function testIsSection()
{ {
$about = $this->objFromFixture('Page', 'about'); $about = $this->objFromFixture(SiteTree::class, 'about');
$staff = $this->objFromFixture('Page', 'staff'); $staff = $this->objFromFixture(SiteTree::class, 'staff');
$ceo = $this->objFromFixture('Page', 'ceo'); $ceo = $this->objFromFixture(SiteTree::class, 'ceo');
Director::set_current_page($about); Director::set_current_page($about);
$this->assertTrue($about->isSection()); $this->assertTrue($about->isSection());
@ -948,7 +996,7 @@ class SiteTreeTest extends SapphireTest
public function testURLSegmentReserved() public function testURLSegmentReserved()
{ {
$siteTree = SiteTree::create(['URLSegment' => 'admin']); $siteTree = new SiteTree(['URLSegment' => 'admin']);
$segment = $siteTree->validURLSegment(); $segment = $siteTree->validURLSegment();
$this->assertFalse($segment); $this->assertFalse($segment);
@ -1036,7 +1084,7 @@ class SiteTreeTest extends SapphireTest
$sitetree->URLSegment = 'home-noconflict'; $sitetree->URLSegment = 'home-noconflict';
$this->assertTrue($sitetree->validURLSegment()); $this->assertTrue($sitetree->validURLSegment());
$sitetree->ParentID = $this->idFromFixture('Page', 'about'); $sitetree->ParentID = $this->idFromFixture(SiteTree::class, 'about');
$sitetree->URLSegment = 'home'; $sitetree->URLSegment = 'home';
$this->assertFalse($sitetree->validURLSegment(), 'Conflicts are still recognised with a ParentID value'); $this->assertFalse($sitetree->validURLSegment(), 'Conflicts are still recognised with a ParentID value');
@ -1046,7 +1094,7 @@ class SiteTreeTest extends SapphireTest
$sitetree->URLSegment = 'home'; $sitetree->URLSegment = 'home';
$this->assertFalse($sitetree->validURLSegment(), 'URLSegment conflicts are recognised'); $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'); $this->assertTrue($sitetree->validURLSegment(), 'URLSegments can be the same across levels');
$sitetree->URLSegment = 'my-staff'; $sitetree->URLSegment = 'my-staff';
@ -1116,13 +1164,18 @@ class SiteTreeTest extends SapphireTest
$sitetree->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $sitetree->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$sitetree = DataObject::get_by_id(SiteTree::class, $sitetree->ID, false); $sitetree = DataObject::get_by_id(SiteTree::class, $sitetree->ID, false);
$this->assertEquals($sitetree->URLSegment, rawurlencode('brötchen')); $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')); $this->assertEquals($sitetreeLive->URLSegment, rawurlencode('brötchen'));
} }
public function testVersionsAreCreated() public function testVersionsAreCreated()
{ {
$p = new Page(); $p = new SiteTree();
$p->Content = "one"; $p->Content = "one";
$p->write(); $p->write();
$this->assertEquals(1, $p->Version); $this->assertEquals(1, $p->Version);
@ -1210,23 +1263,23 @@ class SiteTreeTest extends SapphireTest
// Expected // Expected
[ SiteTreeTest_ClassB::class ], [ SiteTreeTest_ClassB::class ],
// Assertion message // Assertion message
'Direct setting of allowed children' 'Direct setting of allowed children',
], ],
[ [
SiteTreeTest_ClassB::class, SiteTreeTest_ClassB::class,
[ SiteTreeTest_ClassC::class, SiteTreeTest_ClassCext::class ], [ SiteTreeTest_ClassC::class, SiteTreeTest_ClassCext::class ],
'Includes subclasses' 'Includes subclasses',
], ],
[ [
SiteTreeTest_ClassC::class, SiteTreeTest_ClassC::class,
[], [],
'Null setting' 'Null setting',
], ],
[ [
SiteTreeTest_ClassD::class, SiteTreeTest_ClassD::class,
[SiteTreeTest_ClassC::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; $classCext->ParentID = $classD->ID;
$valid = $classCext->doValidate(); $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() public function testClassDropdown()
@ -1286,8 +1342,8 @@ class SiteTreeTest extends SapphireTest
$this->assertArrayHasKey(SiteTreeTest_ClassA::class, $method->invoke($sitetree)); $this->assertArrayHasKey(SiteTreeTest_ClassA::class, $method->invoke($sitetree));
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$rootPage = $this->objFromFixture(Page::class, 'home'); $rootPage = $this->objFromFixture(SiteTree::class, 'home');
$nonRootPage = $this->objFromFixture(Page::class, 'staff'); $nonRootPage = $this->objFromFixture(SiteTree::class, 'staff');
$this->assertArrayNotHasKey(SiteTreeTest_NotRoot::class, $method->invoke($rootPage)); $this->assertArrayNotHasKey(SiteTreeTest_NotRoot::class, $method->invoke($rootPage));
$this->assertArrayHasKey(SiteTreeTest_NotRoot::class, $method->invoke($nonRootPage)); $this->assertArrayHasKey(SiteTreeTest_NotRoot::class, $method->invoke($nonRootPage));
@ -1383,11 +1439,11 @@ class SiteTreeTest extends SapphireTest
public function testGetBreadcrumbItems() public function testGetBreadcrumbItems()
{ {
$page = $this->objFromFixture("Page", "breadcrumbs"); $page = $this->objFromFixture(SiteTree::class, "breadcrumbs");
$this->assertEquals(1, $page->getBreadcrumbItems()->count(), "Only display current page."); $this->assertEquals(1, $page->getBreadcrumbItems()->count(), "Only display current page.");
// Test breadcrumb order // Test breadcrumb order
$page = $this->objFromFixture("Page", "breadcrumbs5"); $page = $this->objFromFixture(SiteTree::class, "breadcrumbs5");
$breadcrumbs = $page->getBreadcrumbItems(); $breadcrumbs = $page->getBreadcrumbItems();
$this->assertEquals($breadcrumbs->count(), 5, "Display all breadcrumbs"); $this->assertEquals($breadcrumbs->count(), 5, "Display all breadcrumbs");
$this->assertEquals($breadcrumbs->first()->Title, "Breadcrumbs", "Breadcrumbs should be the first item."); $this->assertEquals($breadcrumbs->first()->Title, "Breadcrumbs", "Breadcrumbs should be the first item.");
@ -1407,16 +1463,16 @@ class SiteTreeTest extends SapphireTest
public function testMetaTags() public function testMetaTags()
{ {
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$page = $this->objFromFixture('Page', 'metapage'); $page = $this->objFromFixture(SiteTree::class, 'metapage');
// Test with title // Test with title
$meta = $page->MetaTags(); $meta = $page->MetaTags();
$charset = Config::inst()->get(ContentNegotiator::class, 'encoding'); $charset = Config::inst()->get(ContentNegotiator::class, 'encoding');
$this->assertStringContainsString('<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'"', $meta); $this->assertStringContainsString('<meta http-equiv="Content-Type" content="text/html; charset=' . $charset . '"', $meta);
$this->assertStringContainsString('<meta name="description" content="The &lt;br /&gt; and &lt;br&gt; tags"', $meta); $this->assertStringContainsString('<meta name="description" content="The &lt;br /&gt; and &lt;br&gt; tags"', $meta);
$this->assertStringContainsString('<link rel="canonical" href="http://www.mysite.com/html-and-xml"', $meta); $this->assertStringContainsString('<link rel="canonical" href="http://www.mysite.com/html-and-xml"', $meta);
$this->assertStringContainsString('<meta name="x-page-id" content="'.$page->ID.'"', $meta); $this->assertStringContainsString('<meta name="x-page-id" content="' . $page->ID.'"', $meta);
$this->assertStringContainsString('<meta name="x-cms-edit-link" content="'.$page->CMSEditLink().'"', $meta); $this->assertStringContainsString('<meta name="x-cms-edit-link" content="' . $page->CMSEditLink().'"', $meta);
$this->assertStringContainsString('<title>HTML &amp; XML</title>', $meta); $this->assertStringContainsString('<title>HTML &amp; XML</title>', $meta);
// Test without title // Test without title
@ -1431,7 +1487,7 @@ class SiteTreeTest extends SapphireTest
{ {
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
/** @var SiteTree $page */ /** @var SiteTree $page */
$page = $this->objFromFixture('Page', 'metapage'); $page = $this->objFromFixture(SiteTree::class, 'metapage');
$charset = Config::inst()->get(ContentNegotiator::class, 'encoding'); $charset = Config::inst()->get(ContentNegotiator::class, 'encoding');
@ -1513,8 +1569,8 @@ class SiteTreeTest extends SapphireTest
// both pages are viewable in stage // both pages are viewable in stage
Versioned::set_stage(Versioned::DRAFT); Versioned::set_stage(Versioned::DRAFT);
$about = $this->objFromFixture('Page', 'about'); $about = $this->objFromFixture(SiteTree::class, 'about');
$staff = $this->objFromFixture('Page', 'staff'); $staff = $this->objFromFixture(SiteTree::class, 'staff');
$this->assertFalse($about->isOrphaned()); $this->assertFalse($about->isOrphaned());
$this->assertFalse($staff->isOrphaned()); $this->assertFalse($staff->isOrphaned());
$this->assertTrue($about->canView($member)); $this->assertTrue($about->canView($member));
@ -1525,23 +1581,23 @@ class SiteTreeTest extends SapphireTest
$this->assertFalse($staff->isOrphaned()); $this->assertFalse($staff->isOrphaned());
$this->assertTrue($staff->canView($member)); $this->assertTrue($staff->canView($member));
Versioned::set_stage(Versioned::LIVE); 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->assertTrue($staff->isOrphaned()); // because parent isn't published
$this->assertFalse($staff->canView($member)); $this->assertFalse($staff->canView($member));
// Publishing the parent page should restore visibility // Publishing the parent page should restore visibility
Versioned::set_stage(Versioned::DRAFT); Versioned::set_stage(Versioned::DRAFT);
$about = $this->objFromFixture('Page', 'about'); $about = $this->objFromFixture(SiteTree::class, 'about');
$about->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $about->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
Versioned::set_stage(Versioned::LIVE); Versioned::set_stage(Versioned::LIVE);
$staff = $this->objFromFixture('Page', 'staff'); $staff = $this->objFromFixture(SiteTree::class, 'staff');
$this->assertFalse($staff->isOrphaned()); $this->assertFalse($staff->isOrphaned());
$this->assertTrue($staff->canView($member)); $this->assertTrue($staff->canView($member));
// Removing staging page should not prevent live page being visible // Removing staging page should not prevent live page being visible
$about->deleteFromStage('Stage'); $about->deleteFromStage('Stage');
$staff->deleteFromStage('Stage'); $staff->deleteFromStage('Stage');
$staff = $this->objFromFixture('Page', 'staff'); $staff = $this->objFromFixture(SiteTree::class, 'staff');
$this->assertFalse($staff->isOrphaned()); $this->assertFalse($staff->isOrphaned());
$this->assertTrue($staff->canView($member)); $this->assertTrue($staff->canView($member));
@ -1556,8 +1612,8 @@ class SiteTreeTest extends SapphireTest
{ {
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
/** @var Page $page */ /** @var SiteTree $page */
$page = $this->objFromFixture('Page', 'home'); $page = $this->objFromFixture(SiteTree::class, 'home');
$this->assertTrue($page->canAddChildren()); $this->assertTrue($page->canAddChildren());
$this->assertTrue($page->isOnDraft()); $this->assertTrue($page->isOnDraft());
$this->assertFalse($page->isPublished()); $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. * class name in a PSR-2 compliant manner.
*/ */
public function testGetControllerName() public function testGetControllerName()
{ {
$class = new Page; $page = new Page();
$this->assertSame('PageController', $class->getControllerName()); $this->assertSame(PageController::class, $page->getControllerName());
} }
/** /**
* Test that the controller name for a SiteTree instance can be gathered when set directly via config var * Test that the controller name for a SiteTree instance can be gathered when set directly via config var
*/ */
public function testGetControllerNameFromConfig() public function testGetControllerNameFromConfig()
{ {
Config::inst()->update(Page::class, 'controller_name', 'This\\Is\\A\\New\\Controller'); Config::inst()->update(SiteTree::class, 'controller_name', 'This\\Is\\A\\New\\Controller');
$class = new Page; $page = new SiteTree();
$this->assertSame('This\\Is\\A\\New\\Controller', $class->getControllerName()); $this->assertSame('This\\Is\\A\\New\\Controller', $page->getControllerName());
} }
/** /**
@ -1671,13 +1728,13 @@ class SiteTreeTest extends SapphireTest
*/ */
public function testGetControllerNameWithUnderscoresIsSupported() public function testGetControllerNameWithUnderscoresIsSupported()
{ {
$class = new SiteTreeTest_LegacyControllerName; $class = new SiteTreeTest_LegacyControllerName();
$this->assertEquals(SiteTreeTest_LegacyControllerName_Controller::class, $class->getControllerName()); $this->assertEquals(SiteTreeTest_LegacyControllerName_Controller::class, $class->getControllerName());
} }
public function testTreeTitleCache() public function testTreeTitleCache()
{ {
$siteTree = SiteTree::create(); $siteTree = new SiteTree();
$user = $this->objFromFixture(Member::class, 'allsections'); $user = $this->objFromFixture(Member::class, 'allsections');
Security::setCurrentUser($user); Security::setCurrentUser($user);
$pageClass = array_values(SiteTree::page_type_classes())[0]; $pageClass = array_values(SiteTree::page_type_classes())[0];
@ -1764,7 +1821,7 @@ class SiteTreeTest extends SapphireTest
} }
// Create new page on DRAFT // Create new page on DRAFT
$page = SiteTree::create(); $page = new SiteTree();
$page->Content = $content; $page->Content = $content;
$page->write(); $page->write();
@ -1780,7 +1837,7 @@ class SiteTreeTest extends SapphireTest
public function testGetCMSActions() public function testGetCMSActions()
{ {
// Create new page on DRAFT // Create new page on DRAFT
$page = SiteTree::create(); $page = new SiteTree();
$page->Content = md5(rand(0, PHP_INT_MAX)); $page->Content = md5(rand(0, PHP_INT_MAX));
$page->write(); $page->write();
@ -1910,7 +1967,7 @@ class SiteTreeTest extends SapphireTest
public function testGetCMSActionsWithoutForms() public function testGetCMSActionsWithoutForms()
{ {
// Create new page on DRAFT // Create new page on DRAFT
$page = SiteTree::create(); $page = new SiteTree();
$page->Content = md5(rand(0, PHP_INT_MAX)); $page->Content = md5(rand(0, PHP_INT_MAX));
$page->write(); $page->write();

26
tests/php/Model/SiteTreeTest.yml Executable file → Normal file
View File

@ -44,7 +44,7 @@ SilverStripe\Security\Member:
securityadmin: securityadmin:
Groups: =>SilverStripe\Security\Group.securityadmins Groups: =>SilverStripe\Security\Group.securityadmins
Page: SilverStripe\CMS\Model\SiteTree:
home: home:
Title: Home Title: Home
CanEditType: OnlyTheseUsers CanEditType: OnlyTheseUsers
@ -56,14 +56,14 @@ Page:
staff: staff:
Title: Staff Title: Staff
URLSegment: my-staff URLSegment: my-staff
Parent: =>Page.about Parent: =>SilverStripe\CMS\Model\SiteTree.about
ceo: ceo:
Title: CEO Title: CEO
Parent: =>Page.staff Parent: =>SilverStripe\CMS\Model\SiteTree.staff
staffduplicate: staffduplicate:
Title: Staff Title: Staff
URLSegment: my-staff URLSegment: my-staff
Parent: =>Page.about Parent: =>SilverStripe\CMS\Model\SiteTree.about
ShowInMenus: 0 ShowInMenus: 0
products: products:
Title: Products Title: Products
@ -71,19 +71,19 @@ Page:
EditorGroups: =>SilverStripe\Security\Group.editors EditorGroups: =>SilverStripe\Security\Group.editors
product1: product1:
Title: 1.1 Test Product Title: 1.1 Test Product
Parent: =>Page.products Parent: =>SilverStripe\CMS\Model\SiteTree.products
CanEditType: Inherit CanEditType: Inherit
product2: product2:
Title: Another Product Title: Another Product
Parent: =>Page.products Parent: =>SilverStripe\CMS\Model\SiteTree.products
CanEditType: Inherit CanEditType: Inherit
product3: product3:
Title: Another Product Title: Another Product
Parent: =>Page.products Parent: =>SilverStripe\CMS\Model\SiteTree.products
CanEditType: Inherit CanEditType: Inherit
product4: product4:
Title: Another Product Title: Another Product
Parent: =>Page.products Parent: =>SilverStripe\CMS\Model\SiteTree.products
CanEditType: OnlyTheseUsers CanEditType: OnlyTheseUsers
EditorGroups: =>SilverStripe\Security\Group.admins EditorGroups: =>SilverStripe\Security\Group.admins
contact: contact:
@ -102,16 +102,16 @@ Page:
Title: 'Breadcrumbs' Title: 'Breadcrumbs'
breadcrumbs2: breadcrumbs2:
Title: 'Breadcrumbs 2' Title: 'Breadcrumbs 2'
Parent: =>Page.breadcrumbs Parent: =>SilverStripe\CMS\Model\SiteTree.breadcrumbs
breadcrumbs3: breadcrumbs3:
Title: 'Breadcrumbs 3' Title: 'Breadcrumbs 3'
Parent: =>Page.breadcrumbs2 Parent: =>SilverStripe\CMS\Model\SiteTree.breadcrumbs2
breadcrumbs4: breadcrumbs4:
Title: 'Breadcrumbs 4' Title: 'Breadcrumbs 4'
Parent: =>Page.breadcrumbs3 Parent: =>SilverStripe\CMS\Model\SiteTree.breadcrumbs3
breadcrumbs5: breadcrumbs5:
Title: 'Breadcrumbs 5' Title: 'Breadcrumbs 5'
Parent: =>Page.breadcrumbs4 Parent: =>SilverStripe\CMS\Model\SiteTree.breadcrumbs4
SilverStripe\CMS\Tests\Model\SiteTreeTest_Conflicted: SilverStripe\CMS\Tests\Model\SiteTreeTest_Conflicted:
parent: parent:
@ -127,4 +127,4 @@ SilverStripe\CMS\Model\RedirectorPage:
SilverStripe\CMS\Tests\Model\SiteTreeTest_DataObject: SilverStripe\CMS\Tests\Model\SiteTreeTest_DataObject:
relations: relations:
Title: 'Linked DataObject' 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

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'SiteTreeTest_AdminDenied';

View File

@ -3,18 +3,18 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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 $table_name = 'SiteTreeTest_ClassA';
private static $need_permission = [ private static $need_permission = [
'ADMIN', 'ADMIN',
'CMS_ACCESS_CMSMain' 'CMS_ACCESS_CMSMain',
]; ];
private static $allowed_children = [ private static $allowed_children = [
SiteTreeTest_ClassB::class SiteTreeTest_ClassB::class,
]; ];
} }

View File

@ -3,14 +3,14 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'SiteTreeTest_ClassB';
// Also allowed subclasses // Also allowed subclasses
private static $allowed_children = [ private static $allowed_children = [
SiteTreeTest_ClassC::class SiteTreeTest_ClassC::class,
]; ];
} }

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'SiteTreeTest_ClassC';

View File

@ -10,6 +10,6 @@ class SiteTreeTest_ClassCext extends SiteTreeTest_ClassC implements TestOnly
// Override SiteTreeTest_ClassC definitions // Override SiteTreeTest_ClassC definitions
private static $allowed_children = [ private static $allowed_children = [
SiteTreeTest_ClassB::class SiteTreeTest_ClassB::class,
]; ];
} }

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'SiteTreeTest_ClassD';

View File

@ -4,9 +4,9 @@ namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\HiddenClass; 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'; private static $table_name = 'SiteTreeTest_ClassE';
} }

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'SiteTreeTest_Conflicted';
} }

View File

@ -3,12 +3,12 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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 = [ private static $allowed_actions = [
'conflicted-action' 'conflicted-action',
]; ];
public function hasActionTemplate($template) public function hasActionTemplate($template)

View File

@ -3,12 +3,12 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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 * 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'; private static $table_name = 'SiteTreeTest_LegacyControllerName';
} }

View File

@ -3,9 +3,8 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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
{ {
} }

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'SiteTreeTest_NotRoot';

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'SiteTreeTest_PageNode';
} }

View File

@ -3,8 +3,8 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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
{ {
} }

View File

@ -2,7 +2,6 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use Page;
use SilverStripe\CMS\Controllers\ModelAsController; use SilverStripe\CMS\Controllers\ModelAsController;
use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
@ -43,8 +42,8 @@ class VirtualPageTest extends FunctionalTest
protected static $required_extensions = [ protected static $required_extensions = [
SiteTree::class => [ SiteTree::class => [
VirtualPageTest_PageExtension::class VirtualPageTest_PageExtension::class,
] ],
]; ];
protected function setUp(): void protected function setUp(): void
@ -63,8 +62,8 @@ class VirtualPageTest extends FunctionalTest
); );
// Ensure all pages are published // Ensure all pages are published
/** @var Page $page */ /** @var SiteTree $page */
foreach (Page::get() as $page) { foreach (SiteTree::get() as $page) {
$page->publishSingle(); $page->publishSingle();
} }
} }
@ -75,8 +74,8 @@ class VirtualPageTest extends FunctionalTest
*/ */
public function testEditingSourcePageUpdatesVirtualPages() public function testEditingSourcePageUpdatesVirtualPages()
{ {
/** @var Page $master */ /** @var SiteTree $master */
$master = $this->objFromFixture('Page', 'master'); $master = $this->objFromFixture(SiteTree::class, 'master');
$master->Title = "New title"; $master->Title = "New title";
$master->MenuTitle = "New menutitle"; $master->MenuTitle = "New menutitle";
$master->Content = "<p>New content</p>"; $master->Content = "<p>New content</p>";
@ -97,7 +96,7 @@ class VirtualPageTest extends FunctionalTest
public function testMetaTags() public function testMetaTags()
{ {
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$master = $this->objFromFixture('Page', 'master'); $master = $this->objFromFixture(SiteTree::class, 'master');
$vp1 = $this->objFromFixture(VirtualPage::class, 'vp1'); $vp1 = $this->objFromFixture(VirtualPage::class, 'vp1');
// Test with title // Test with title
@ -118,8 +117,8 @@ class VirtualPageTest extends FunctionalTest
{ {
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
/** @var Page $master */ /** @var SiteTree $master */
$master = $this->objFromFixture('Page', 'master'); $master = $this->objFromFixture(SiteTree::class, 'master');
$master->publishRecursive(); $master->publishRecursive();
$master->Title = "New title"; $master->Title = "New title";
@ -160,13 +159,13 @@ class VirtualPageTest extends FunctionalTest
$vp = new VirtualPage(); $vp = new VirtualPage();
$vp->write(); $vp->write();
$vp->CopyContentFromID = $this->idFromFixture('Page', 'master'); $vp->CopyContentFromID = $this->idFromFixture(SiteTree::class, 'master');
$vp->write(); $vp->write();
$this->assertEquals("My Page", $vp->Title); $this->assertEquals("My Page", $vp->Title);
$this->assertEquals("My Page Nav", $vp->MenuTitle); $this->assertEquals("My Page Nav", $vp->MenuTitle);
$vp->CopyContentFromID = $this->idFromFixture('Page', 'master2'); $vp->CopyContentFromID = $this->idFromFixture(SiteTree::class, 'master2');
$vp->write(); $vp->write();
$this->assertEquals("My Other Page", $vp->Title); $this->assertEquals("My Other Page", $vp->Title);
@ -180,7 +179,7 @@ class VirtualPageTest extends FunctionalTest
*/ */
public function testPublishingAVirtualPageCopiedPublishedContentNotDraftContent() public function testPublishingAVirtualPageCopiedPublishedContentNotDraftContent()
{ {
$p = new Page(); $p = new SiteTree();
$p->Content = "published content"; $p->Content = "published content";
$p->write(); $p->write();
$p->publishRecursive(); $p->publishRecursive();
@ -220,7 +219,7 @@ class VirtualPageTest extends FunctionalTest
public function testCantPublishVirtualPagesBeforeTheirSource() public function testCantPublishVirtualPagesBeforeTheirSource()
{ {
// An unpublished source page // An unpublished source page
$p = new Page(); $p = new SiteTree();
$p->Content = "test content"; $p->Content = "test content";
$p->write(); $p->write();
@ -241,7 +240,7 @@ class VirtualPageTest extends FunctionalTest
public function testCanEdit() public function testCanEdit()
{ {
$parentPage = $this->objFromFixture('Page', 'master3'); $parentPage = $this->objFromFixture(SiteTree::class, 'master3');
$virtualPage = $this->objFromFixture(VirtualPage::class, 'vp3'); $virtualPage = $this->objFromFixture(VirtualPage::class, 'vp3');
$bob = $this->objFromFixture(Member::class, 'bob'); $bob = $this->objFromFixture(Member::class, 'bob');
$andrew = $this->objFromFixture(Member::class, 'andrew'); $andrew = $this->objFromFixture(Member::class, 'andrew');
@ -259,8 +258,8 @@ class VirtualPageTest extends FunctionalTest
public function testCanView() public function testCanView()
{ {
/** @var Page $parentPage */ /** @var SiteTree $parentPage */
$parentPage = $this->objFromFixture('Page', 'master3'); $parentPage = $this->objFromFixture(SiteTree::class, 'master3');
$parentPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $parentPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
/** @var VirtualPage $virtualPage */ /** @var VirtualPage $virtualPage */
@ -283,7 +282,7 @@ class VirtualPageTest extends FunctionalTest
public function testVirtualPagesArentInappropriatelyPublished() public function testVirtualPagesArentInappropriatelyPublished()
{ {
// Fixture // Fixture
$p = new Page(); $p = new SiteTree();
$p->Content = "test content"; $p->Content = "test content";
$p->write(); $p->write();
$vp = new VirtualPage(); $vp = new VirtualPage();
@ -332,7 +331,7 @@ class VirtualPageTest extends FunctionalTest
public function testUnpublishingSourcePageOfAVirtualPageAlsoUnpublishesVirtualPage() public function testUnpublishingSourcePageOfAVirtualPageAlsoUnpublishesVirtualPage()
{ {
// Create page and virutal page // Create page and virutal page
$p = new Page(); $p = new SiteTree();
$p->Title = "source"; $p->Title = "source";
$p->write(); $p->write();
$this->assertTrue($p->publishRecursive()); $this->assertTrue($p->publishRecursive());
@ -364,7 +363,7 @@ class VirtualPageTest extends FunctionalTest
public function testDeletingFromLiveSourcePageOfAVirtualPageAlsoUnpublishesVirtualPage() public function testDeletingFromLiveSourcePageOfAVirtualPageAlsoUnpublishesVirtualPage()
{ {
// Create page and virutal page // Create page and virutal page
$p = new Page(); $p = new SiteTree();
$p->Title = "source"; $p->Title = "source";
$p->write(); $p->write();
$this->assertTrue($p->publishRecursive()); $this->assertTrue($p->publishRecursive());
@ -384,7 +383,7 @@ class VirtualPageTest extends FunctionalTest
->byID($pID); ->byID($pID);
$this->assertNull($vpDraft); $this->assertNull($vpDraft);
// Delete the source page form live, confirm that the virtual page has also been unpublished // 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) $pLive = Versioned::get_by_stage(SiteTree::class, Versioned::LIVE)
->byID($pID); ->byID($pID);
$this->assertTrue($pLive->doUnpublish()); $this->assertTrue($pLive->doUnpublish());

View File

@ -31,7 +31,7 @@ SilverStripe\Security\Member:
alice: alice:
Email: alice@alice.com Email: alice@alice.com
Groups: =>SilverStripe\Security\Group.alicegroup Groups: =>SilverStripe\Security\Group.alicegroup
Page: SilverStripe\CMS\Model\SiteTree:
master: master:
Title: My Page Title: My Page
MenuTitle: My Page Nav MenuTitle: My Page Nav
@ -52,15 +52,15 @@ SilverStripe\CMS\Tests\Model\VirtualPageTest_ClassA:
SilverStripe\CMS\Model\VirtualPage: SilverStripe\CMS\Model\VirtualPage:
vp1: vp1:
Title: vp1 Title: vp1
CopyContentFrom: =>Page.master CopyContentFrom: =>SilverStripe\CMS\Model\SiteTree.master
Parent: =>Page.holder Parent: =>SilverStripe\CMS\Model\SiteTree.holder
vp2: vp2:
Title: vp2 Title: vp2
CopyContentFrom: =>Page.master CopyContentFrom: =>SilverStripe\CMS\Model\SiteTree.master
Parent: =>Page.holder Parent: =>SilverStripe\CMS\Model\SiteTree.holder
vp3: vp3:
CopyContentFrom: =>Page.master3 CopyContentFrom: =>SilverStripe\CMS\Model\SiteTree.master3
Parent: =>Page.holder Parent: =>SilverStripe\CMS\Model\SiteTree.holder
CanEditType: OnlyTheseUsers CanEditType: OnlyTheseUsers
CanViewType: OnlyTheseUsers CanViewType: OnlyTheseUsers
EditorGroups: =>SilverStripe\Security\Group.andrewgroup EditorGroups: =>SilverStripe\Security\Group.andrewgroup

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'VirtualPageTest_ClassA';

View File

@ -3,12 +3,12 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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 = [ private static $allowed_actions = [
'testaction' 'testaction',
]; ];
public function testMethod() public function testMethod()

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'VirtualPageTest_ClassB';

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'VirtualPageTest_ClassC';

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model; namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'VirtualPageTest_NotRoot';

View File

@ -9,7 +9,8 @@ class VirtualPageTest_PageExtension extends DataExtension implements TestOnly
{ {
private static $db = [ private static $db = [
// These fields are just on an extension to simulate shared properties between Page and VirtualPage. // 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', 'MySharedVirtualField' => 'Text',
'MySharedNonVirtualField' => 'Text', 'MySharedNonVirtualField' => 'Text',
]; ];

View File

@ -4,9 +4,9 @@ namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\CMS\Model\VirtualPage; use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\Dev\TestOnly; 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'; private static $table_name = 'VirtualPageTest_PageWithAllowedChildren';

View File

@ -2,24 +2,22 @@
namespace SilverStripe\CMS\Tests\Reports; namespace SilverStripe\CMS\Tests\Reports;
use SilverStripe\Assets\File;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree; 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\DB;
use SilverStripe\ORM\FieldType\DBDatetime; 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\Reports\Report;
use SilverStripe\Assets\File;
use SilverStripe\Dev\SapphireTest;
use Page;
class CmsReportsTest extends SapphireTest class CmsReportsTest extends SapphireTest
{ {
protected static $fixture_file = 'CmsReportsTest.yml'; protected static $fixture_file = 'CmsReportsTest.yml';
private static $daysAgo = 14; private static $daysAgo = 14;
@ -29,14 +27,19 @@ class CmsReportsTest extends SapphireTest
parent::setUp(); parent::setUp();
// set the dates by hand: impossible to set via yml // set the dates by hand: impossible to set via yml
$afterThreshold = 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')); $beforeThreshold = strtotime('-' . (self::$daysAgo + 1) . ' days', strtotime('31-06-2009 00:00:00'));
$after = $this->objFromFixture(SiteTree::class, 'after'); $after = $this->objFromFixture(SiteTree::class, 'after');
$before = $this->objFromFixture(SiteTree::class, 'before'); $before = $this->objFromFixture(SiteTree::class, 'before');
DB::query(
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."'"); "UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='" .
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."'"); 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. // ASSERT that the "draft" report is returning the correct results.
$parameters = ['CheckSite' => 'Draft']; $parameters = ['CheckSite' => 'Draft'];
$results = count($report->sourceRecords($parameters, null, null) ?? []) > 0; $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."); $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. // ASSERT that the "published" report is returning the correct results.
$parameters = ['CheckSite' => 'Published', 'OnLive' => 1]; $parameters = ['CheckSite' => 'Published', 'OnLive' => 1];
$results = count($report->sourceRecords($parameters, null, null) ?? []) > 0; $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() public function testRecentlyEdited()
@ -81,18 +98,14 @@ class CmsReportsTest extends SapphireTest
/** /**
* Test the broken links side report. * Test the broken links side report.
*/ */
public function testBrokenLinks() public function testBrokenLinks()
{ {
// Create a "draft" page with a broken link. // Create a "draft" page with a broken link.
$page = new SiteTree();
$page = Page::create();
$page->Content = "<a href='[sitetree_link,id=987654321]'>This</a> is a broken link."; $page->Content = "<a href='[sitetree_link,id=987654321]'>This</a> is a broken link.";
$page->writeToStage('Stage'); $page->writeToStage('Stage');
// Retrieve the broken links side report. // Retrieve the broken links side report.
$reports = Report::get_reports(); $reports = Report::get_reports();
$brokenLinksReport = null; $brokenLinksReport = null;
foreach ($reports as $report) { 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 "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); $this->isReportBroken($brokenLinksReport, true, false);
// Make sure the page is now "published". // Make sure the page is now "published".
$page->writeToStage('Live'); $page->writeToStage('Live');
// ASSERT that the "draft" report has detected the page having a broken link. // 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); $this->isReportBroken($brokenLinksReport, true, true);
// Correct the "draft" broken link. // Correct the "draft" broken link.
$page->Content = str_replace('987654321', $page->ID ?? '', $page->Content ?? ''); $page->Content = str_replace('987654321', $page->ID ?? '', $page->Content ?? '');
$page->writeToStage('Stage'); $page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken link. // 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); $this->isReportBroken($brokenLinksReport, false, true);
// Make sure the change has now been "published". // Make sure the change has now been "published".
$page->writeToStage('Live'); $page->writeToStage('Live');
// ASSERT that the "draft" report has NOT detected the page having a broken link. // 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. * Test the broken files side report.
*/ */
public function testBrokenFiles() public function testBrokenFiles()
{ {
// Create a "draft" page with a broken file. // Create a "draft" page with a broken file.
$page = new SiteTree();
$page = Page::create();
$page->Content = "<a href='[file_link,id=987654321]'>This</a> is a broken file."; $page->Content = "<a href='[file_link,id=987654321]'>This</a> is a broken file.";
$page->writeToStage('Stage'); $page->writeToStage('Stage');
// Retrieve the broken files side report. // Retrieve the broken files side report.
$reports = Report::get_reports(); $reports = Report::get_reports();
$brokenFilesReport = null; $brokenFilesReport = null;
foreach ($reports as $report) { 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 "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); $this->isReportBroken($brokenFilesReport, true, false);
// Make sure the page is now "published". // Make sure the page is now "published".
$page->writeToStage('Live'); $page->writeToStage('Live');
// ASSERT that the "draft" report has detected the page having a broken file. // 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. // ASSERT that the "published" report has detected the page having a broken file.
$this->isReportBroken($brokenFilesReport, true, true); $this->isReportBroken($brokenFilesReport, true, true);
// Correct the "draft" broken file. // Correct the "draft" broken file.
$file = File::create(); $file = File::create();
$file->Filename = 'name.pdf'; $file->Filename = 'name.pdf';
$file->write(); $file->write();
@ -195,17 +198,15 @@ class CmsReportsTest extends SapphireTest
$page->writeToStage('Stage'); $page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken file. // 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); $this->isReportBroken($brokenFilesReport, false, true);
// Make sure the change has now been "published". // Make sure the change has now been "published".
$page->writeToStage('Live'); $page->writeToStage('Live');
// ASSERT that the "draft" report has NOT detected the page having a broken file. // 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. // ASSERT that the "published" report has NOT detected the page having a broken file.
$this->isReportBroken($brokenFilesReport, false, false); $this->isReportBroken($brokenFilesReport, false, false);
} }
@ -215,15 +216,12 @@ class CmsReportsTest extends SapphireTest
public function testBrokenVirtualPages() public function testBrokenVirtualPages()
{ {
// Create a "draft" virtual page with a broken link. // Create a "draft" virtual page with a broken link.
$page = VirtualPage::create(); $page = VirtualPage::create();
$page->CopyContentFromID = 987654321; $page->CopyContentFromID = 987654321;
$page->writeToStage('Stage'); $page->writeToStage('Stage');
// Retrieve the broken virtual pages side report. // Retrieve the broken virtual pages side report.
$reports = Report::get_reports(); $reports = Report::get_reports();
$brokenVirtualPagesReport = null; $brokenVirtualPagesReport = null;
foreach ($reports as $report) { 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 "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); $this->isReportBroken($brokenVirtualPagesReport, true, false);
// Make sure the page is now "published". // Make sure the page is now "published".
$page->writeToStage('Live'); $page->writeToStage('Live');
// ASSERT that the "draft" report has detected the page having a broken link. // 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. // ASSERT that the "published" report has detected the page having a broken link.
$this->isReportBroken($brokenVirtualPagesReport, true, true); $this->isReportBroken($brokenVirtualPagesReport, true, true);
// Correct the "draft" broken link. // Correct the "draft" broken link.
$contentPage = new SiteTree();
$contentPage = Page::create();
$contentPage->Content = 'This is some content.'; $contentPage->Content = 'This is some content.';
$contentPage->writeToStage('Stage'); $contentPage->writeToStage('Stage');
$contentPage->writeToStage('Live'); $contentPage->writeToStage('Live');
@ -263,36 +258,30 @@ class CmsReportsTest extends SapphireTest
$page->writeToStage('Stage'); $page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken link. // 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); $this->isReportBroken($brokenVirtualPagesReport, false, true);
// Make sure the change has now been "published". // Make sure the change has now been "published".
$page->writeToStage('Live'); $page->writeToStage('Live');
// ASSERT that the "draft" report has NOT detected the page having a broken link. // 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. // ASSERT that the "published" report has NOT detected the page having a broken link.
$this->isReportBroken($brokenVirtualPagesReport, false, false); $this->isReportBroken($brokenVirtualPagesReport, false, false);
} }
/** /**
* Test the broken redirector pages side report. * Test the broken redirector pages side report.
*/ */
public function testBrokenRedirectorPages() public function testBrokenRedirectorPages()
{ {
// Create a "draft" redirector page with a broken link. // Create a "draft" redirector page with a broken link.
$page = RedirectorPage::create(); $page = RedirectorPage::create();
$page->RedirectionType = 'Internal'; $page->RedirectionType = 'Internal';
$page->LinkToID = 987654321; $page->LinkToID = 987654321;
$page->writeToStage('Stage'); $page->writeToStage('Stage');
// Retrieve the broken redirector pages side report. // Retrieve the broken redirector pages side report.
$reports = Report::get_reports(); $reports = Report::get_reports();
$brokenRedirectorPagesReport = null; $brokenRedirectorPagesReport = null;
foreach ($reports as $report) { 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 "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); $this->isReportBroken($brokenRedirectorPagesReport, true, false);
// Make sure the page is now "published". // Make sure the page is now "published".
$page->writeToStage('Live'); $page->writeToStage('Live');
// ASSERT that the "draft" report has detected the page having a broken link. // 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. // ASSERT that the "published" report has detected the page having a broken link.
$this->isReportBroken($brokenRedirectorPagesReport, true, true); $this->isReportBroken($brokenRedirectorPagesReport, true, true);
// Correct the "draft" broken link. // Correct the "draft" broken link.
$contentPage = new SiteTree();
$contentPage = Page::create();
$contentPage->Content = 'This is some content.'; $contentPage->Content = 'This is some content.';
$contentPage->writeToStage('Stage'); $contentPage->writeToStage('Stage');
$contentPage->writeToStage('Live'); $contentPage->writeToStage('Live');
@ -332,17 +318,15 @@ class CmsReportsTest extends SapphireTest
$page->writeToStage('Stage'); $page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken link. // 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); $this->isReportBroken($brokenRedirectorPagesReport, false, true);
// Make sure the change has now been "published". // Make sure the change has now been "published".
$page->writeToStage('Live'); $page->writeToStage('Live');
// ASSERT that the "draft" report has NOT detected the page having a broken link. // 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. // ASSERT that the "published" report has NOT detected the page having a broken link.
$this->isReportBroken($brokenRedirectorPagesReport, false, false); $this->isReportBroken($brokenRedirectorPagesReport, false, false);
} }
} }

View File

@ -20,7 +20,7 @@ class CMSMainSearchFormTest extends FunctionalTest
'q' => [ 'q' => [
'Term' => 'Page 10', 'Term' => 'Page 10',
'FilterClass' => CMSSiteTreeFilter_Search::class, 'FilterClass' => CMSSiteTreeFilter_Search::class,
] ],
]) ])
); );

View File

@ -2,7 +2,6 @@
namespace SilverStripe\CMS\Tests\Search; namespace SilverStripe\CMS\Tests\Search;
use Page;
use SilverStripe\Assets\File; use SilverStripe\Assets\File;
use SilverStripe\CMS\Controllers\ContentController; use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\CMS\Controllers\ModelAsController; use SilverStripe\CMS\Controllers\ModelAsController;
@ -29,7 +28,6 @@ use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
*/ */
class ZZZSearchFormTest extends FunctionalTest class ZZZSearchFormTest extends FunctionalTest
{ {
protected static $fixture_file = 'SearchFormTest.yml'; protected static $fixture_file = 'SearchFormTest.yml';
protected static $illegal_extensions = [ protected static $illegal_extensions = [

View File

@ -3,8 +3,8 @@
namespace SilverStripe\CMS\Tests\Tasks; namespace SilverStripe\CMS\Tests\Tasks;
use SilverStripe\CMS\Tasks\RemoveOrphanedPagesTask; use SilverStripe\CMS\Tasks\RemoveOrphanedPagesTask;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\CMS\Model\SiteTree;
/** /**
* <h2>Fixture tree</h2> * <h2>Fixture tree</h2>
@ -42,54 +42,54 @@ class RemoveOrphanedPagesTaskTest extends FunctionalTest
{ {
parent::setUp(); parent::setUp();
$parent1_published = $this->objFromFixture('Page', 'parent1_published'); $parent1_published = $this->objFromFixture(SiteTree::class, 'parent1_published');
$parent1_published->publishSingle(); $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_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_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->ParentID = 9999;
$child1_3_orphaned->write(); $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->ParentID = 9999;
$child1_4_orphaned_published->write(); $child1_4_orphaned_published->write();
$child1_4_orphaned_published->publishSingle(); $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_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->ParentID = 9999;
$grandchild1_1_3_orphaned->write(); $grandchild1_1_3_orphaned->write();
$grandchild1_1_4_orphaned_published = $this->objFromFixture( $grandchild1_1_4_orphaned_published = $this->objFromFixture(
'Page', SiteTree::class,
'grandchild1_1_4_orphaned_published' 'grandchild1_1_4_orphaned_published'
); );
$grandchild1_1_4_orphaned_published->ParentID = 9999; $grandchild1_1_4_orphaned_published->ParentID = 9999;
$grandchild1_1_4_orphaned_published->write(); $grandchild1_1_4_orphaned_published->write();
$grandchild1_1_4_orphaned_published->publishSingle(); $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(); $child2_1_published_orphaned->publishSingle();
} }
public function testGetOrphansByStage() public function testGetOrphansByStage()
{ {
// all orphans // all orphans
$child1_3_orphaned = $this->objFromFixture('Page', 'child1_3_orphaned'); $child1_3_orphaned = $this->objFromFixture(SiteTree::class, 'child1_3_orphaned');
$child1_4_orphaned_published = $this->objFromFixture('Page', 'child1_4_orphaned_published'); $child1_4_orphaned_published = $this->objFromFixture(SiteTree::class, 'child1_4_orphaned_published');
$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_4_orphaned_published = $this->objFromFixture( $grandchild1_1_4_orphaned_published = $this->objFromFixture(
'Page', SiteTree::class,
'grandchild1_1_4_orphaned_published' '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); $task = singleton(RemoveOrphanedPagesTask::class);
$orphans = $task->getOrphanedPages(); $orphans = $task->getOrphanedPages();
@ -100,7 +100,7 @@ class RemoveOrphanedPagesTaskTest extends FunctionalTest
$child1_4_orphaned_published->ID, $child1_4_orphaned_published->ID,
$grandchild1_1_3_orphaned->ID, $grandchild1_1_3_orphaned->ID,
$grandchild1_1_4_orphaned_published->ID, $grandchild1_1_4_orphaned_published->ID,
$child2_1_published_orphaned->ID $child2_1_published_orphaned->ID,
]; ];
sort($compareIDs); sort($compareIDs);

View File

@ -1,32 +1,32 @@
Page: SilverStripe\CMS\Model\SiteTree:
parent1_published: parent1_published:
Title: Parent1 Title: Parent1
child1_1_published: child1_1_published:
Title: Child1.1 Title: Child1.1
Parent: =>Page.parent1_published Parent: =>SilverStripe\CMS\Model\SiteTree.parent1_published
child1_2_published: child1_2_published:
Title: Child1.2 Title: Child1.2
Parent: =>Page.parent1_published Parent: =>SilverStripe\CMS\Model\SiteTree.parent1_published
child1_3_orphaned: child1_3_orphaned:
Title: Child1.3 Title: Child1.3
Parent: =>Page.parent1_published Parent: =>SilverStripe\CMS\Model\SiteTree.parent1_published
child1_4_orphaned_published: child1_4_orphaned_published:
Title: Child1.4 Title: Child1.4
Parent: =>Page.parent1_published Parent: =>SilverStripe\CMS\Model\SiteTree.parent1_published
grandchild1_1_1: grandchild1_1_1:
Title: Grandchild1.1.1 Title: Grandchild1.1.1
Parent: =>Page.child1_1_published Parent: =>SilverStripe\CMS\Model\SiteTree.child1_1_published
grandchild1_1_2_published: grandchild1_1_2_published:
Title: Grandchild1.1.2 Title: Grandchild1.1.2
Parent: =>Page.child1_1_published Parent: =>SilverStripe\CMS\Model\SiteTree.child1_1_published
grandchild1_1_3_orphaned: grandchild1_1_3_orphaned:
Title: Grandchild1.1.3 Title: Grandchild1.1.3
Parent: =>Page.child1_1_published Parent: =>SilverStripe\CMS\Model\SiteTree.child1_1_published
grandchild1_1_4_orphaned_published: grandchild1_1_4_orphaned_published:
Title: Grandchild1.1.4 Title: Grandchild1.1.4
Parent: =>Page.child1_1_published Parent: =>SilverStripe\CMS\Model\SiteTree.child1_1_published
parent2: parent2:
Title: Parent2 Title: Parent2
child2_1_published_orphaned: child2_1_published_orphaned:
Title: Child2.1 Title: Child2.1
Parent: =>Page.parent2 Parent: =>SilverStripe\CMS\Model\SiteTree.parent2