Merge pull request #2766 from creative-commoners/pulls/5/rescue-master-sitetree-not-page

Rescue Master Branch PR: MNT Use SiteTree instead of Page in tests
This commit is contained in:
Steve Boyd 2022-08-25 11:47:14 +12:00 committed by GitHub
commit c130b55ecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
67 changed files with 849 additions and 663 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ use SilverStripe\Versioned\Versioned;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class ContentControllerPermissionsTest extends FunctionalTest
{
@ -17,7 +17,7 @@ class ContentControllerPermissionsTest extends FunctionalTest
public function testCanViewStage()
{
// Create a new page
$page = new Page();
$page = new SiteTree();
$page->URLSegment = 'testpage';
$page->write();
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
@ -38,7 +38,11 @@ class ContentControllerPermissionsTest extends FunctionalTest
$response = $responseException->getResponse();
}
// should redirect to login
$this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage');
$this->assertEquals(
$response->getStatusCode(),
302,
'Redirects to login page when not logged in for draft stage'
);
$this->assertStringContainsString(
Config::inst()->get('SilverStripe\\Security\\Security', 'login_url'),
$response->getHeader('Location')
@ -47,6 +51,10 @@ class ContentControllerPermissionsTest extends FunctionalTest
$this->logInWithPermission('CMS_ACCESS_CMSMain');
$response = $this->get('/testpage/?stage=Stage');
$this->assertEquals($response->getStatusCode(), 200, 'Doesnt redirect to login, but shows page for authenticated user');
$this->assertEquals(
$response->getStatusCode(),
200,
'Doesnt redirect to login, but shows page for authenticated user'
);
}
}

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
namespace SilverStripe\CMS\Tests\Model;
use Page;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\RedirectorPageController;
use SilverStripe\Control\Director;
@ -36,31 +36,41 @@ class RedirectorPageTest extends FunctionalTest
Director::config()->update('alternate_base_url', 'http://www.mysite.com/');
// Ensure all pages are published
/** @var Page $page */
foreach (Page::get() as $page) {
/** @var SiteTree $page */
foreach (SiteTree::get() as $page) {
$page->publishSingle();
}
}
public function testGoodRedirectors()
{
/* For good redirectors, the final destination URL will be returned */
$this->assertEquals("http://www.google.com", $this->objFromFixture(RedirectorPage::class, 'goodexternal')->Link());
$this->assertEquals("/redirection-dest/", $this->objFromFixture(RedirectorPage::class, 'goodinternal')->redirectionLink());
$this->assertEquals("/redirection-dest/", $this->objFromFixture(RedirectorPage::class, 'goodinternal')->Link());
// For good redirectors, the final destination URL will be returned
$this->assertEquals(
"http://www.google.com",
$this->objFromFixture(RedirectorPage::class, 'goodexternal')->Link()
);
$this->assertEquals(
"/redirection-dest/",
$this->objFromFixture(RedirectorPage::class, 'goodinternal')->redirectionLink()
);
$this->assertEquals(
"/redirection-dest/",
$this->objFromFixture(RedirectorPage::class, 'goodinternal')->Link()
);
}
public function testEmptyRedirectors()
{
/* If a redirector page is misconfigured, then its link method will just return the usual URLSegment-generated value */
// If a redirector page is misconfigured, then its link method will just return the usual
// URLSegment-generated value
$page1 = $this->objFromFixture(RedirectorPage::class, 'badexternal');
$this->assertEquals('/bad-external/', $page1->Link());
/* An error message will be shown if you visit it */
// An error message will be shown if you visit it
$content = $this->get(Director::makeRelative($page1->Link()))->getBody();
$this->assertStringContainsString('message-setupWithoutRedirect', $content);
/* This also applies for internal links */
// This also applies for internal links
$page2 = $this->objFromFixture(RedirectorPage::class, 'badinternal');
$this->assertEquals('/bad-internal/', $page2->Link());
$content = $this->get(Director::makeRelative($page2->Link()))->getBody();
@ -69,14 +79,16 @@ class RedirectorPageTest extends FunctionalTest
public function testReflexiveAndTransitiveInternalRedirectors()
{
/* Reflexive redirectors are those that point to themselves. They should behave the same as an empty redirector */
// Reflexive redirectors are those that point to themselves.
// They should behave the same as an empty redirector
$page = $this->objFromFixture(RedirectorPage::class, 'reflexive');
$this->assertEquals('/reflexive/', $page->Link());
$content = $this->get(Director::makeRelative($page->Link()))->getBody();
$this->assertStringContainsString('message-setupWithoutRedirect', $content);
/* Transitive redirectors are those that point to another redirector page. They should send people to the URLSegment
* of the destination page - the middle-stop, so to speak. That should redirect to the final destination */
// Transitive redirectors are those that point to another redirector page.
// They should send people to the URLSegment of the destination page - the middle-stop, so to speak.
// That should redirect to the final destination
$page = $this->objFromFixture(RedirectorPage::class, 'transitive');
$this->assertEquals('/good-internal/', $page->Link());
@ -90,7 +102,11 @@ class RedirectorPageTest extends FunctionalTest
$page = $this->objFromFixture(RedirectorPage::class, 'externalnoprefix');
$this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite has prefixed with http');
$page->write();
$this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite will not double prefix if written again!');
$this->assertEquals(
$page->ExternalURL,
'http://google.com',
'onBeforeWrite will not double prefix if written again!'
);
}
public function testAllowsProtocolRelative()

View File

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

View File

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

View File

@ -4,9 +4,9 @@ namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Security\Permission;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class SiteTreeActionsTest_Page extends Page implements TestOnly
class SiteTreeActionsTest_Page extends SiteTree implements TestOnly
{
public function canEdit($member = null)
{

View File

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

View File

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

View File

@ -2,7 +2,6 @@
namespace SilverStripe\CMS\Tests\Model;
use Page;
use SilverStripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Filesystem;
@ -31,8 +30,8 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest
}
// Ensure all pages are published
/** @var Page $page */
foreach (Page::get() as $page) {
/** @var SiteTree $page */
foreach (SiteTree::get() as $page) {
$page->publishSingle();
}
}
@ -55,7 +54,11 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest
$editor->setValue("<a href=\"[sitetree_link,id=$aboutID]\">Example Link</a>");
$editor->saveInto($sitetree);
$sitetree->write();
$this->assertEquals([$aboutID => $aboutID], $sitetree->LinkTracking()->getIdList(), 'Basic link tracking works.');
$this->assertEquals(
[$aboutID => $aboutID],
$sitetree->LinkTracking()->getIdList(),
'Basic link tracking works.'
);
$editor->setValue(
"<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;
use Page;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\SiteTreeLinkTracking_Parser;
use SilverStripe\Control\Director;
@ -32,7 +31,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest
public function testParser()
{
SiteTree::add_extension(Page::class, SiteTreeLinkTracking_Extension::class);
SiteTree::add_extension(SiteTree::class, SiteTreeLinkTracking_Extension::class);
// Shortcodes
$this->assertTrue($this->isBroken('<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->assertTrue($this->isBroken('<a href="##anchor">anchor</a>'));
$page = new Page();
$page = new SiteTree();
$page->Content = '<a name="yes-name-anchor">name</a><a id="yes-id-anchor">id</a>';
$page->write();
@ -72,7 +70,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest
protected function highlight($content)
{
$page = new Page();
$page = new SiteTree();
$page->Content = $content;
$page->write();
return $page->Content;
@ -87,7 +85,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest
$content = $this->highlight('<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.');
$otherPage = new Page();
$otherPage = new SiteTree();
$otherPage->Content = '';
$otherPage->write();

View File

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

View File

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

View File

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

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

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

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class SiteTreeTest_AdminDenied extends Page implements TestOnly
class SiteTreeTest_AdminDenied extends SiteTree implements TestOnly
{
private static $table_name = 'SiteTreeTest_AdminDenied';

View File

@ -3,18 +3,18 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class SiteTreeTest_ClassA extends Page implements TestOnly
class SiteTreeTest_ClassA extends SiteTree implements TestOnly
{
private static $table_name = 'SiteTreeTest_ClassA';
private static $need_permission = [
'ADMIN',
'CMS_ACCESS_CMSMain'
'CMS_ACCESS_CMSMain',
];
private static $allowed_children = [
SiteTreeTest_ClassB::class
SiteTreeTest_ClassB::class,
];
}

View File

@ -3,14 +3,14 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class SiteTreeTest_ClassB extends Page implements TestOnly
class SiteTreeTest_ClassB extends SiteTree implements TestOnly
{
private static $table_name = 'SiteTreeTest_ClassB';
// Also allowed subclasses
private static $allowed_children = [
SiteTreeTest_ClassC::class
SiteTreeTest_ClassC::class,
];
}

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class SiteTreeTest_ClassC extends Page implements TestOnly
class SiteTreeTest_ClassC extends SiteTree implements TestOnly
{
private static $table_name = 'SiteTreeTest_ClassC';

View File

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

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class SiteTreeTest_ClassD extends Page implements TestOnly
class SiteTreeTest_ClassD extends SiteTree implements TestOnly
{
private static $table_name = 'SiteTreeTest_ClassD';

View File

@ -4,9 +4,9 @@ namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\HiddenClass;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class SiteTreeTest_ClassE extends Page implements TestOnly, HiddenClass
class SiteTreeTest_ClassE extends SiteTree implements TestOnly, HiddenClass
{
private static $table_name = 'SiteTreeTest_ClassE';
}

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class SiteTreeTest_Conflicted extends Page implements TestOnly
class SiteTreeTest_Conflicted extends SiteTree implements TestOnly
{
private static $table_name = 'SiteTreeTest_Conflicted';
}

View File

@ -3,12 +3,12 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use PageController;
use SilverStripe\CMS\Controllers\ContentController;
class SiteTreeTest_ConflictedController extends PageController implements TestOnly
class SiteTreeTest_ConflictedController extends ContentController implements TestOnly
{
private static $allowed_actions = [
'conflicted-action'
'conflicted-action',
];
public function hasActionTemplate($template)

View File

@ -3,12 +3,12 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
/**
* An empty SiteTree instance with a controller to test that legacy controller names can still be loaded
*/
class SiteTreeTest_LegacyControllerName extends Page implements TestOnly
class SiteTreeTest_LegacyControllerName extends SiteTree implements TestOnly
{
private static $table_name = 'SiteTreeTest_LegacyControllerName';
}

View File

@ -3,9 +3,8 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use PageController;
use SilverStripe\CMS\Controllers\ContentController;
class SiteTreeTest_LegacyControllerName_Controller extends PageController implements TestOnly
class SiteTreeTest_LegacyControllerName_Controller extends ContentController implements TestOnly
{
}

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class SiteTreeTest_NotRoot extends Page implements TestOnly
class SiteTreeTest_NotRoot extends SiteTree implements TestOnly
{
private static $table_name = 'SiteTreeTest_NotRoot';

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class SiteTreeTest_PageNode extends Page implements TestOnly
class SiteTreeTest_PageNode extends SiteTree implements TestOnly
{
private static $table_name = 'SiteTreeTest_PageNode';
}

View File

@ -3,8 +3,8 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use PageController;
use SilverStripe\CMS\Controllers\ContentController;
class SiteTreeTest_PageNodeController extends PageController implements TestOnly
class SiteTreeTest_PageNodeController extends ContentController implements TestOnly
{
}

View File

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

View File

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

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class VirtualPageTest_ClassA extends Page implements TestOnly
class VirtualPageTest_ClassA extends SiteTree implements TestOnly
{
private static $table_name = 'VirtualPageTest_ClassA';

View File

@ -3,12 +3,12 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use PageController;
use SilverStripe\CMS\Controllers\ContentController;
class VirtualPageTest_ClassAController extends PageController implements TestOnly
class VirtualPageTest_ClassAController extends ContentController implements TestOnly
{
private static $allowed_actions = [
'testaction'
'testaction',
];
public function testMethod()

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class VirtualPageTest_ClassB extends Page implements TestOnly
class VirtualPageTest_ClassB extends SiteTree implements TestOnly
{
private static $table_name = 'VirtualPageTest_ClassB';

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class VirtualPageTest_ClassC extends Page implements TestOnly
class VirtualPageTest_ClassC extends SiteTree implements TestOnly
{
private static $table_name = 'VirtualPageTest_ClassC';

View File

@ -3,9 +3,9 @@
namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class VirtualPageTest_NotRoot extends Page implements TestOnly
class VirtualPageTest_NotRoot extends SiteTree implements TestOnly
{
private static $table_name = 'VirtualPageTest_NotRoot';

View File

@ -9,7 +9,8 @@ class VirtualPageTest_PageExtension extends DataExtension implements TestOnly
{
private static $db = [
// These fields are just on an extension to simulate shared properties between Page and VirtualPage.
// Not possible through direct $db definitions due to VirtualPage inheriting from Page, and Page being defined elsewhere.
// Not possible through direct $db definitions due to VirtualPage inheriting from Page,
// and Page being defined elsewhere.
'MySharedVirtualField' => 'Text',
'MySharedNonVirtualField' => 'Text',
];

View File

@ -4,9 +4,9 @@ namespace SilverStripe\CMS\Tests\Model;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\Dev\TestOnly;
use Page;
use SilverStripe\CMS\Model\SiteTree;
class VirtualPageTest_PageWithAllowedChildren extends Page implements TestOnly
class VirtualPageTest_PageWithAllowedChildren extends SiteTree implements TestOnly
{
private static $table_name = 'VirtualPageTest_PageWithAllowedChildren';

View File

@ -2,24 +2,22 @@
namespace SilverStripe\CMS\Tests\Reports;
use SilverStripe\Assets\File;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\CMS\Reports\BrokenFilesReport;
use SilverStripe\CMS\Reports\BrokenLinksReport;
use SilverStripe\CMS\Reports\BrokenRedirectorPagesReport;
use SilverStripe\CMS\Reports\BrokenVirtualPagesReport;
use SilverStripe\CMS\Reports\RecentlyEditedReport;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\CMS\Reports\RecentlyEditedReport;
use SilverStripe\CMS\Reports\BrokenLinksReport;
use SilverStripe\CMS\Reports\BrokenFilesReport;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\CMS\Reports\BrokenVirtualPagesReport;
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Reports\BrokenRedirectorPagesReport;
use SilverStripe\Reports\Report;
use SilverStripe\Assets\File;
use SilverStripe\Dev\SapphireTest;
use Page;
class CmsReportsTest extends SapphireTest
{
protected static $fixture_file = 'CmsReportsTest.yml';
private static $daysAgo = 14;
@ -29,14 +27,19 @@ class CmsReportsTest extends SapphireTest
parent::setUp();
// set the dates by hand: impossible to set via yml
$afterThreshold = strtotime('-'.(self::$daysAgo-1).' days', strtotime('31-06-2009 00:00:00'));
$beforeThreshold = strtotime('-'.(self::$daysAgo+1).' days', strtotime('31-06-2009 00:00:00'));
$afterThreshold = strtotime('-' . (self::$daysAgo - 1) . ' days', strtotime('31-06-2009 00:00:00'));
$beforeThreshold = strtotime('-' . (self::$daysAgo + 1) . ' days', strtotime('31-06-2009 00:00:00'));
$after = $this->objFromFixture(SiteTree::class, 'after');
$before = $this->objFromFixture(SiteTree::class, 'before');
DB::query("UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='".date('Y-m-d H:i:s', $afterThreshold)."' WHERE \"ID\"='".$after->ID."'");
DB::query("UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='".date('Y-m-d H:i:s', $beforeThreshold)."' WHERE \"ID\"='".$before->ID."'");
DB::query(
"UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='" .
date('Y-m-d H:i:s', $afterThreshold) . "' WHERE \"ID\"='" . $after->ID . "'"
);
DB::query(
"UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='" .
date('Y-m-d H:i:s', $beforeThreshold) . "' WHERE \"ID\"='" . $before->ID . "'"
);
}
/**
@ -52,13 +55,27 @@ class CmsReportsTest extends SapphireTest
// ASSERT that the "draft" report is returning the correct results.
$parameters = ['CheckSite' => 'Draft'];
$results = count($report->sourceRecords($parameters, null, null) ?? []) > 0;
$isDraftBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct DRAFT results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct DRAFT results, as pages were found.");
$results = count($report->sourceRecords($parameters, null, null)) > 0;
$isDraftBroken
? $this->assertTrue(
$results,
"{$class} has NOT returned the correct DRAFT results, as NO pages were found."
) : $this->assertFalse(
$results,
"{$class} has NOT returned the correct DRAFT results, as pages were found."
);
// ASSERT that the "published" report is returning the correct results.
$parameters = ['CheckSite' => 'Published', 'OnLive' => 1];
$results = count($report->sourceRecords($parameters, null, null) ?? []) > 0;
$isPublishedBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct PUBLISHED results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct PUBLISHED results, as pages were found.");
$isPublishedBroken
? $this->assertTrue(
$results,
"{$class} has NOT returned the correct PUBLISHED results, as NO pages were found."
) : $this->assertFalse(
$results,
"{$class} has NOT returned the correct PUBLISHED results, as pages were found."
);
}
public function testRecentlyEdited()
@ -81,18 +98,14 @@ class CmsReportsTest extends SapphireTest
/**
* Test the broken links side report.
*/
public function testBrokenLinks()
{
// Create a "draft" page with a broken link.
$page = Page::create();
$page = new SiteTree();
$page->Content = "<a href='[sitetree_link,id=987654321]'>This</a> is a broken link.";
$page->writeToStage('Stage');
// Retrieve the broken links side report.
$reports = Report::get_reports();
$brokenLinksReport = null;
foreach ($reports as $report) {
@ -109,12 +122,11 @@ class CmsReportsTest extends SapphireTest
}
// ASSERT that the "draft" report has detected the page having a broken link.
// ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet.
// ASSERT that the "published" report has NOT detected the page having a broken link,
// as the page has not been "published" yet.
$this->isReportBroken($brokenLinksReport, true, false);
// Make sure the page is now "published".
$page->writeToStage('Live');
// ASSERT that the "draft" report has detected the page having a broken link.
@ -123,17 +135,15 @@ class CmsReportsTest extends SapphireTest
$this->isReportBroken($brokenLinksReport, true, true);
// Correct the "draft" broken link.
$page->Content = str_replace('987654321', $page->ID ?? '', $page->Content ?? '');
$page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken link.
// ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published".
// ASSERT that the "published" report has detected the page having a broken link,
// as the previous content remains "published".
$this->isReportBroken($brokenLinksReport, false, true);
// Make sure the change has now been "published".
$page->writeToStage('Live');
// ASSERT that the "draft" report has NOT detected the page having a broken link.
@ -145,18 +155,14 @@ class CmsReportsTest extends SapphireTest
/**
* Test the broken files side report.
*/
public function testBrokenFiles()
{
// Create a "draft" page with a broken file.
$page = Page::create();
$page = new SiteTree();
$page->Content = "<a href='[file_link,id=987654321]'>This</a> is a broken file.";
$page->writeToStage('Stage');
// Retrieve the broken files side report.
$reports = Report::get_reports();
$brokenFilesReport = null;
foreach ($reports as $report) {
@ -173,21 +179,18 @@ class CmsReportsTest extends SapphireTest
}
// ASSERT that the "draft" report has detected the page having a broken file.
// ASSERT that the "published" report has NOT detected the page having a broken file, as the page has not been "published" yet.
// ASSERT that the "published" report has NOT detected the page having a broken file,
// as the page has not been "published" yet.
$this->isReportBroken($brokenFilesReport, true, false);
// Make sure the page is now "published".
$page->writeToStage('Live');
// ASSERT that the "draft" report has detected the page having a broken file.
// ASSERT that the "published" report has detected the page having a broken file.
$this->isReportBroken($brokenFilesReport, true, true);
// Correct the "draft" broken file.
$file = File::create();
$file->Filename = 'name.pdf';
$file->write();
@ -195,17 +198,15 @@ class CmsReportsTest extends SapphireTest
$page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken file.
// ASSERT that the "published" report has detected the page having a broken file, as the previous content remains "published".
// ASSERT that the "published" report has detected the page having a broken file,
// as the previous content remains "published".
$this->isReportBroken($brokenFilesReport, false, true);
// Make sure the change has now been "published".
$page->writeToStage('Live');
// ASSERT that the "draft" report has NOT detected the page having a broken file.
// ASSERT that the "published" report has NOT detected the page having a broken file.
$this->isReportBroken($brokenFilesReport, false, false);
}
@ -215,15 +216,12 @@ class CmsReportsTest extends SapphireTest
public function testBrokenVirtualPages()
{
// Create a "draft" virtual page with a broken link.
$page = VirtualPage::create();
$page->CopyContentFromID = 987654321;
$page->writeToStage('Stage');
// Retrieve the broken virtual pages side report.
$reports = Report::get_reports();
$brokenVirtualPagesReport = null;
foreach ($reports as $report) {
@ -240,22 +238,19 @@ class CmsReportsTest extends SapphireTest
}
// ASSERT that the "draft" report has detected the page having a broken link.
// ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet.
// ASSERT that the "published" report has NOT detected the page having a broken link,
// as the page has not been "published" yet.
$this->isReportBroken($brokenVirtualPagesReport, true, false);
// Make sure the page is now "published".
$page->writeToStage('Live');
// ASSERT that the "draft" report has detected the page having a broken link.
// ASSERT that the "published" report has detected the page having a broken link.
$this->isReportBroken($brokenVirtualPagesReport, true, true);
// Correct the "draft" broken link.
$contentPage = Page::create();
$contentPage = new SiteTree();
$contentPage->Content = 'This is some content.';
$contentPage->writeToStage('Stage');
$contentPage->writeToStage('Live');
@ -263,36 +258,30 @@ class CmsReportsTest extends SapphireTest
$page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken link.
// ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published".
// ASSERT that the "published" report has detected the page having a broken link,
// as the previous content remains "published".
$this->isReportBroken($brokenVirtualPagesReport, false, true);
// Make sure the change has now been "published".
$page->writeToStage('Live');
// ASSERT that the "draft" report has NOT detected the page having a broken link.
// ASSERT that the "published" report has NOT detected the page having a broken link.
$this->isReportBroken($brokenVirtualPagesReport, false, false);
}
/**
* Test the broken redirector pages side report.
*/
public function testBrokenRedirectorPages()
{
// Create a "draft" redirector page with a broken link.
$page = RedirectorPage::create();
$page->RedirectionType = 'Internal';
$page->LinkToID = 987654321;
$page->writeToStage('Stage');
// Retrieve the broken redirector pages side report.
$reports = Report::get_reports();
$brokenRedirectorPagesReport = null;
foreach ($reports as $report) {
@ -309,22 +298,19 @@ class CmsReportsTest extends SapphireTest
}
// ASSERT that the "draft" report has detected the page having a broken link.
// ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet.
// ASSERT that the "published" report has NOT detected the page having a broken link,
// as the page has not been "published" yet.
$this->isReportBroken($brokenRedirectorPagesReport, true, false);
// Make sure the page is now "published".
$page->writeToStage('Live');
// ASSERT that the "draft" report has detected the page having a broken link.
// ASSERT that the "published" report has detected the page having a broken link.
$this->isReportBroken($brokenRedirectorPagesReport, true, true);
// Correct the "draft" broken link.
$contentPage = Page::create();
$contentPage = new SiteTree();
$contentPage->Content = 'This is some content.';
$contentPage->writeToStage('Stage');
$contentPage->writeToStage('Live');
@ -332,17 +318,15 @@ class CmsReportsTest extends SapphireTest
$page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken link.
// ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published".
// ASSERT that the "published" report has detected the page having a broken link,
// as the previous content remains "published".
$this->isReportBroken($brokenRedirectorPagesReport, false, true);
// Make sure the change has now been "published".
$page->writeToStage('Live');
// ASSERT that the "draft" report has NOT detected the page having a broken link.
// ASSERT that the "published" report has NOT detected the page having a broken link.
$this->isReportBroken($brokenRedirectorPagesReport, false, false);
}
}

View File

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

View File

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

View File

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

View File

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