2011-03-18 04:23:47 +01:00
|
|
|
<?php
|
2016-06-16 06:57:19 +02:00
|
|
|
|
|
|
|
use SilverStripe\ORM\DB;
|
|
|
|
use SilverStripe\ORM\Versioning\Versioned;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
use SilverStripe\ORM\ValidationException;
|
|
|
|
use SilverStripe\ORM\DataExtension;
|
2016-07-25 15:51:39 +02:00
|
|
|
use SilverStripe\ORM\HiddenClass;
|
2016-06-23 01:51:20 +02:00
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
use SilverStripe\Security\Permission;
|
|
|
|
use SilverStripe\Security\Group;
|
2016-07-22 01:32:32 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
|
|
|
use SilverStripe\CMS\Model\SiteTreeExtension;
|
|
|
|
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/**
|
2011-03-22 10:47:26 +01:00
|
|
|
* @package cms
|
2011-03-18 04:23:47 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class SiteTreeTest extends SapphireTest {
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2013-06-12 12:32:42 +02:00
|
|
|
protected static $fixture_file = 'SiteTreeTest.yml';
|
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
protected $illegalExtensions = array(
|
2014-01-15 23:36:25 +01:00
|
|
|
'SiteTree' => array('SiteTreeSubsites', 'Translatable')
|
2011-03-18 04:23:47 +01:00
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-10-06 16:47:59 +02:00
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'SiteTreeTest_ClassA',
|
|
|
|
'SiteTreeTest_ClassB',
|
|
|
|
'SiteTreeTest_ClassC',
|
|
|
|
'SiteTreeTest_ClassD',
|
2012-01-14 11:20:54 +01:00
|
|
|
'SiteTreeTest_ClassCext',
|
|
|
|
'SiteTreeTest_NotRoot',
|
2012-03-29 00:47:28 +02:00
|
|
|
'SiteTreeTest_StageStatusInherit',
|
2011-10-06 16:47:59 +02:00
|
|
|
);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure any current member is logged out
|
|
|
|
*/
|
|
|
|
public function logOut() {
|
|
|
|
if($member = Member::currentUser()) $member->logOut();
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testCreateDefaultpages() {
|
2013-06-21 00:45:33 +02:00
|
|
|
$remove = SiteTree::get();
|
2011-03-18 04:23:47 +01:00
|
|
|
if($remove) foreach($remove as $page) $page->delete();
|
|
|
|
// Make sure the table is empty
|
|
|
|
$this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Disable the creation
|
2013-03-18 11:47:15 +01:00
|
|
|
SiteTree::config()->create_default_pages = false;
|
2016-07-22 01:32:32 +02:00
|
|
|
singleton('SilverStripe\\CMS\\Model\\SiteTree')->requireDefaultRecords();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// The table should still be empty
|
|
|
|
$this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Enable the creation
|
2013-03-18 11:47:15 +01:00
|
|
|
SiteTree::config()->create_default_pages = true;
|
2016-07-22 01:32:32 +02:00
|
|
|
singleton('SilverStripe\\CMS\\Model\\SiteTree')->requireDefaultRecords();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// The table should now have three rows (home, about-us, contact-us)
|
|
|
|
$this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test generation of the URLSegment values.
|
|
|
|
* - Turns things into lowercase-hyphen-format
|
|
|
|
* - Generates from Title by default, unless URLSegment is explicitly set
|
|
|
|
* - Resolves duplicates by appending a number
|
|
|
|
* - renames classes with a class name conflict
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testURLGeneration() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$expectedURLs = array(
|
|
|
|
'home' => 'home',
|
|
|
|
'staff' => 'my-staff',
|
|
|
|
'about' => 'about-us',
|
|
|
|
'staffduplicate' => 'my-staff-2',
|
2013-04-02 11:39:25 +02:00
|
|
|
'product1' => '1-1-test-product',
|
2011-03-18 04:23:47 +01:00
|
|
|
'product2' => 'another-product',
|
|
|
|
'product3' => 'another-product-2',
|
|
|
|
'product4' => 'another-product-3',
|
|
|
|
'object' => 'object',
|
|
|
|
'controller' => 'controller-2',
|
|
|
|
'numericonly' => '1930',
|
|
|
|
);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
foreach($expectedURLs as $fixture => $urlSegment) {
|
|
|
|
$obj = $this->objFromFixture('Page', $fixture);
|
|
|
|
$this->assertEquals($urlSegment, $obj->URLSegment);
|
|
|
|
}
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/**
|
|
|
|
* Test that publication copies data to SiteTree_Live
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testPublishCopiesToLiveTable() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$obj = $this->objFromFixture('Page','about');
|
2016-04-01 05:17:37 +02:00
|
|
|
$obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$createdID = DB::query("SELECT \"ID\" FROM \"SiteTree_Live\" WHERE \"URLSegment\" = '$obj->URLSegment'")->value();
|
|
|
|
$this->assertEquals($obj->ID, $createdID);
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/**
|
|
|
|
* Test that field which are set and then cleared are also transferred to the published site.
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testPublishDeletedFields() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$obj = $this->objFromFixture('Page', 'about');
|
2012-09-21 11:31:00 +02:00
|
|
|
$obj->Title = "asdfasdf";
|
2011-03-18 04:23:47 +01:00
|
|
|
$obj->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$this->assertTrue($obj->publishRecursive());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-21 11:31:00 +02:00
|
|
|
$this->assertEquals('asdfasdf', DB::query("SELECT \"Title\" FROM \"SiteTree_Live\" WHERE \"ID\" = '$obj->ID'")->value());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-21 11:31:00 +02:00
|
|
|
$obj->Title = null;
|
2011-03-18 04:23:47 +01:00
|
|
|
$obj->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$this->assertTrue($obj->publishRecursive());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-21 11:31:00 +02:00
|
|
|
$this->assertNull(DB::query("SELECT \"Title\" FROM \"SiteTree_Live\" WHERE \"ID\" = '$obj->ID'")->value());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testParentNodeCachedInMemory() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$parent = new SiteTree();
|
2013-06-21 00:45:33 +02:00
|
|
|
$parent->Title = 'Section Title';
|
|
|
|
$child = new SiteTree();
|
|
|
|
$child->Title = 'Page Title';
|
2011-03-18 04:23:47 +01:00
|
|
|
$child->setParent($parent);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
$this->assertInstanceOf("SilverStripe\\CMS\\Model\\SiteTree", $child->Parent);
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertEquals("Section Title", $child->Parent->Title);
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testParentModelReturnType() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$parent = new SiteTreeTest_PageNode();
|
|
|
|
$child = new SiteTreeTest_PageNode();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$child->setParent($parent);
|
2012-05-09 13:06:55 +02:00
|
|
|
$this->assertInstanceOf('SiteTreeTest_PageNode', $child->Parent);
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/**
|
|
|
|
* Confirm that DataObject::get_one() gets records from SiteTree_Live
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testGetOneFromLive() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$s = new SiteTree();
|
|
|
|
$s->Title = "V1";
|
|
|
|
$s->URLSegment = "get-one-test-page";
|
|
|
|
$s->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$s->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2011-03-18 04:23:47 +01:00
|
|
|
$s->Title = "V2";
|
|
|
|
$s->write();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$oldMode = Versioned::get_reading_mode();
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::LIVE);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
$checkSiteTree = DataObject::get_one("SilverStripe\\CMS\\Model\\SiteTree", array(
|
2013-06-21 00:45:33 +02:00
|
|
|
'"SiteTree"."URLSegment"' => 'get-one-test-page'
|
|
|
|
));
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertEquals("V1", $checkSiteTree->Title);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
Versioned::set_reading_mode($oldMode);
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testChidrenOfRootAreTopLevelPages() {
|
2013-06-21 00:45:33 +02:00
|
|
|
$pages = SiteTree::get();
|
2016-04-01 05:17:37 +02:00
|
|
|
foreach($pages as $page) $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2011-03-18 04:23:47 +01:00
|
|
|
unset($pages);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/* If we create a new SiteTree object with ID = 0 */
|
|
|
|
$obj = new SiteTree();
|
|
|
|
/* Then its children should be the top-level pages */
|
2011-05-03 05:05:14 +02:00
|
|
|
$stageChildren = $obj->stageChildren()->map('ID','Title');
|
|
|
|
$liveChildren = $obj->liveChildren()->map('ID','Title');
|
|
|
|
$allChildren = $obj->AllChildrenIncludingDeleted()->map('ID','Title');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertContains('Home', $stageChildren);
|
|
|
|
$this->assertContains('Products', $stageChildren);
|
|
|
|
$this->assertNotContains('Staff', $stageChildren);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertContains('Home', $liveChildren);
|
|
|
|
$this->assertContains('Products', $liveChildren);
|
|
|
|
$this->assertNotContains('Staff', $liveChildren);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertContains('Home', $allChildren);
|
|
|
|
$this->assertContains('Products', $allChildren);
|
|
|
|
$this->assertNotContains('Staff', $allChildren);
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testCanSaveBlankToHasOneRelations() {
|
2011-03-18 04:23:47 +01:00
|
|
|
/* 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');
|
|
|
|
$page->ParentID = $parentID;
|
|
|
|
$page->write();
|
|
|
|
$this->assertEquals($parentID, DB::query("SELECT \"ParentID\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/* You should then be able to save a null/0/'' value to the relation */
|
|
|
|
$page->ParentID = null;
|
|
|
|
$page->write();
|
|
|
|
$this->assertEquals(0, DB::query("SELECT \"ParentID\" FROM \"SiteTree\" WHERE \"ID\" = $page->ID")->value());
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testStageStates() {
|
2011-03-18 04:23:47 +01:00
|
|
|
// newly created page
|
|
|
|
$createdPage = new SiteTree();
|
|
|
|
$createdPage->write();
|
2015-06-05 01:09:23 +02:00
|
|
|
$this->assertFalse($createdPage->getIsDeletedFromStage());
|
|
|
|
$this->assertTrue($createdPage->getIsAddedToStage());
|
|
|
|
$this->assertTrue($createdPage->getIsModifiedOnStage());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
|
|
|
// published page
|
2011-03-18 04:23:47 +01:00
|
|
|
$publishedPage = new SiteTree();
|
|
|
|
$publishedPage->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$publishedPage->copyVersionToStage('Stage','Live');
|
2015-06-05 01:09:23 +02:00
|
|
|
$this->assertFalse($publishedPage->getIsDeletedFromStage());
|
|
|
|
$this->assertFalse($publishedPage->getIsAddedToStage());
|
|
|
|
$this->assertFalse($publishedPage->getIsModifiedOnStage());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// published page, deleted from stage
|
|
|
|
$deletedFromDraftPage = new SiteTree();
|
|
|
|
$deletedFromDraftPage->write();
|
|
|
|
$deletedFromDraftPageID = $deletedFromDraftPage->ID;
|
2016-04-01 05:17:37 +02:00
|
|
|
$deletedFromDraftPage->copyVersionToStage('Stage','Live');
|
2011-03-18 04:23:47 +01:00
|
|
|
$deletedFromDraftPage->deleteFromStage('Stage');
|
2015-06-05 01:09:23 +02:00
|
|
|
$this->assertTrue($deletedFromDraftPage->getIsDeletedFromStage());
|
|
|
|
$this->assertFalse($deletedFromDraftPage->getIsAddedToStage());
|
|
|
|
$this->assertFalse($deletedFromDraftPage->getIsModifiedOnStage());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// published page, deleted from live
|
|
|
|
$deletedFromLivePage = new SiteTree();
|
|
|
|
$deletedFromLivePage->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$deletedFromLivePage->copyVersionToStage('Stage','Live');
|
2011-03-18 04:23:47 +01:00
|
|
|
$deletedFromLivePage->deleteFromStage('Stage');
|
|
|
|
$deletedFromLivePage->deleteFromStage('Live');
|
2015-06-05 01:09:23 +02:00
|
|
|
$this->assertTrue($deletedFromLivePage->getIsDeletedFromStage());
|
|
|
|
$this->assertFalse($deletedFromLivePage->getIsAddedToStage());
|
|
|
|
$this->assertFalse($deletedFromLivePage->getIsModifiedOnStage());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// published page, modified
|
|
|
|
$modifiedOnDraftPage = new SiteTree();
|
|
|
|
$modifiedOnDraftPage->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$modifiedOnDraftPage->copyVersionToStage('Stage','Live');
|
2011-03-18 04:23:47 +01:00
|
|
|
$modifiedOnDraftPage->Content = 'modified';
|
|
|
|
$modifiedOnDraftPage->write();
|
2015-06-05 01:09:23 +02:00
|
|
|
$this->assertFalse($modifiedOnDraftPage->getIsDeletedFromStage());
|
|
|
|
$this->assertFalse($modifiedOnDraftPage->getIsAddedToStage());
|
|
|
|
$this->assertTrue($modifiedOnDraftPage->getIsModifiedOnStage());
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/**
|
|
|
|
* Test that a page can be completely deleted and restored to the stage site
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testRestoreToStage() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$page = $this->objFromFixture('Page', 'about');
|
|
|
|
$pageID = $page->ID;
|
|
|
|
$page->delete();
|
|
|
|
$this->assertTrue(!DataObject::get_by_id("Page", $pageID));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
$deletedPage = Versioned::get_latest_version('SilverStripe\\CMS\\Model\\SiteTree', $pageID);
|
2011-03-18 04:23:47 +01:00
|
|
|
$resultPage = $deletedPage->doRestoreToStage();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$requeriedPage = DataObject::get_by_id("Page", $pageID);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertEquals($pageID, $resultPage->ID);
|
|
|
|
$this->assertEquals($pageID, $requeriedPage->ID);
|
|
|
|
$this->assertEquals('About Us', $requeriedPage->Title);
|
|
|
|
$this->assertEquals('Page', $requeriedPage->class);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$page2 = $this->objFromFixture('Page', 'products');
|
|
|
|
$page2ID = $page2->ID;
|
|
|
|
$page2->doUnpublish();
|
|
|
|
$page2->delete();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Check that if we restore while on the live site that the content still gets pushed to
|
|
|
|
// stage
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::LIVE);
|
2016-07-22 01:32:32 +02:00
|
|
|
$deletedPage = Versioned::get_latest_version('SilverStripe\\CMS\\Model\\SiteTree', $page2ID);
|
2011-03-18 04:23:47 +01:00
|
|
|
$deletedPage->doRestoreToStage();
|
2009-11-22 06:16:38 +01:00
|
|
|
$this->assertFalse((bool)Versioned::get_one_by_stage("Page", "Live", "\"SiteTree\".\"ID\" = " . $page2ID));
|
|
|
|
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::DRAFT);
|
2011-03-18 04:23:47 +01:00
|
|
|
$requeriedPage = DataObject::get_by_id("Page", $page2ID);
|
|
|
|
$this->assertEquals('Products', $requeriedPage->Title);
|
|
|
|
$this->assertEquals('Page', $requeriedPage->class);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
public function testGetByLink() {
|
|
|
|
$home = $this->objFromFixture('Page', 'home');
|
|
|
|
$about = $this->objFromFixture('Page', 'about');
|
|
|
|
$staff = $this->objFromFixture('Page', 'staff');
|
|
|
|
$product = $this->objFromFixture('Page', 'product1');
|
2016-07-22 01:32:32 +02:00
|
|
|
$notFound = $this->objFromFixture('SilverStripe\\CMS\\Model\\ErrorPage', '404');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
SiteTree::config()->nested_urls = false;
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertEquals($home->ID, SiteTree::get_by_link('/', false)->ID);
|
|
|
|
$this->assertEquals($home->ID, SiteTree::get_by_link('/home/', false)->ID);
|
|
|
|
$this->assertEquals($about->ID, SiteTree::get_by_link($about->Link(), false)->ID);
|
|
|
|
$this->assertEquals($staff->ID, SiteTree::get_by_link($staff->Link(), false)->ID);
|
|
|
|
$this->assertEquals($product->ID, SiteTree::get_by_link($product->Link(), false)->ID);
|
|
|
|
$this->assertEquals($notFound->ID, SiteTree::get_by_link($notFound->Link(), false)->ID);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'nested_urls', true);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertEquals($home->ID, SiteTree::get_by_link('/', false)->ID);
|
|
|
|
$this->assertEquals($home->ID, SiteTree::get_by_link('/home/', false)->ID);
|
|
|
|
$this->assertEquals($about->ID, SiteTree::get_by_link($about->Link(), false)->ID);
|
|
|
|
$this->assertEquals($staff->ID, SiteTree::get_by_link($staff->Link(), false)->ID);
|
|
|
|
$this->assertEquals($product->ID, SiteTree::get_by_link($product->Link(), false)->ID);
|
|
|
|
$this->assertEquals($notFound->ID, SiteTree::get_by_link($notFound->Link(), false)->ID);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertEquals (
|
|
|
|
$staff->ID, SiteTree::get_by_link('/my-staff/', false)->ID, 'Assert a unique URLSegment can be used for b/c.'
|
|
|
|
);
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testRelativeLink() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$about = $this->objFromFixture('Page', 'about');
|
|
|
|
$staff = $this->objFromFixture('Page', 'staff');
|
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'nested_urls', true);
|
2011-03-18 04:23:47 +01:00
|
|
|
|
|
|
|
$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');
|
|
|
|
}
|
2012-08-28 19:00:42 +02:00
|
|
|
|
2015-08-03 04:52:10 +02:00
|
|
|
public function testPageLevel() {
|
|
|
|
$about = $this->objFromFixture('Page', 'about');
|
|
|
|
$staff = $this->objFromFixture('Page', 'staff');
|
|
|
|
$this->assertEquals(1, $about->getPageLevel());
|
|
|
|
$this->assertEquals(2, $staff->getPageLevel());
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testAbsoluteLiveLink() {
|
2012-08-28 19:00:42 +02:00
|
|
|
$parent = $this->objFromFixture('Page', 'about');
|
|
|
|
$child = $this->objFromFixture('Page', 'staff');
|
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'nested_urls', true);
|
2012-08-28 19:00:42 +02:00
|
|
|
|
2016-04-01 05:17:37 +02:00
|
|
|
$child->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2012-08-28 19:00:42 +02:00
|
|
|
$parent->URLSegment = 'changed-on-live';
|
|
|
|
$parent->write();
|
2016-04-01 05:17:37 +02:00
|
|
|
$parent->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2012-08-28 19:00:42 +02:00
|
|
|
$parent->URLSegment = 'changed-on-draft';
|
|
|
|
$parent->write();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-08-28 19:00:42 +02:00
|
|
|
$this->assertStringEndsWith('changed-on-live/my-staff/', $child->getAbsoluteLiveLink(false));
|
|
|
|
$this->assertStringEndsWith('changed-on-live/my-staff/?stage=Live', $child->getAbsoluteLiveLink());
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testDeleteFromStageOperatesRecursively() {
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'enforce_strict_hierarchy', false);
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageAbout = $this->objFromFixture('Page', 'about');
|
|
|
|
$pageStaff = $this->objFromFixture('Page', 'staff');
|
|
|
|
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageAbout->delete();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertFalse(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);
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'enforce_strict_hierarchy', true);
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testDeleteFromStageOperatesRecursivelyStrict() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageAbout = $this->objFromFixture('Page', 'about');
|
|
|
|
$pageStaff = $this->objFromFixture('Page', 'staff');
|
|
|
|
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageAbout->delete();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertFalse(DataObject::get_by_id('Page', $pageAbout->ID));
|
|
|
|
$this->assertFalse(DataObject::get_by_id('Page', $pageStaff->ID));
|
|
|
|
$this->assertFalse(DataObject::get_by_id('Page', $pageStaffDuplicate->ID));
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-06-13 05:47:47 +02:00
|
|
|
public function testDuplicate() {
|
|
|
|
$pageAbout = $this->objFromFixture('Page', 'about');
|
|
|
|
$dupe = $pageAbout->duplicate();
|
|
|
|
$this->assertEquals($pageAbout->Title, $dupe->Title);
|
|
|
|
$this->assertNotEquals($pageAbout->URLSegment, $dupe->URLSegment);
|
|
|
|
$this->assertNotEquals($pageAbout->Sort, $dupe->Sort);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testDeleteFromLiveOperatesRecursively() {
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'enforce_strict_hierarchy', false);
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageAbout = $this->objFromFixture('Page', 'about');
|
2016-04-01 05:17:37 +02:00
|
|
|
$pageAbout->publishRecursive();
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageStaff = $this->objFromFixture('Page', 'staff');
|
2016-04-01 05:17:37 +02:00
|
|
|
$pageStaff->publishRecursive();
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate');
|
2016-04-01 05:17:37 +02:00
|
|
|
$pageStaffDuplicate->publishRecursive();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$parentPage = $this->objFromFixture('Page', 'about');
|
2009-11-22 06:16:38 +01:00
|
|
|
|
2016-01-26 06:38:42 +01:00
|
|
|
$parentPage->doUnpublish();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::LIVE);
|
2009-11-22 06:16:38 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertFalse(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);
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::DRAFT);
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'enforce_strict_hierarchy', true);
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testUnpublishDoesNotDeleteChildrenWithLooseHierachyOn() {
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'enforce_strict_hierarchy', false);
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageAbout = $this->objFromFixture('Page', 'about');
|
2016-04-01 05:17:37 +02:00
|
|
|
$pageAbout->publishRecursive();
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageStaff = $this->objFromFixture('Page', 'staff');
|
2016-04-01 05:17:37 +02:00
|
|
|
$pageStaff->publishRecursive();
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate');
|
2016-04-01 05:17:37 +02:00
|
|
|
$pageStaffDuplicate->publishRecursive();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$parentPage = $this->objFromFixture('Page', 'about');
|
|
|
|
$parentPage->doUnpublish();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::LIVE);
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertFalse(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);
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::DRAFT);
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'enforce_strict_hierarchy', true);
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2016-01-06 00:42:07 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testDeleteFromLiveOperatesRecursivelyStrict() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageAbout = $this->objFromFixture('Page', 'about');
|
2016-04-01 05:17:37 +02:00
|
|
|
$pageAbout->publishRecursive();
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageStaff = $this->objFromFixture('Page', 'staff');
|
2016-04-01 05:17:37 +02:00
|
|
|
$pageStaff->publishRecursive();
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate');
|
2016-04-01 05:17:37 +02:00
|
|
|
$pageStaffDuplicate->publishRecursive();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$parentPage = $this->objFromFixture('Page', 'about');
|
2016-01-26 06:38:42 +01:00
|
|
|
$parentPage->doUnpublish();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::LIVE);
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertFalse(DataObject::get_by_id('Page', $pageAbout->ID));
|
|
|
|
$this->assertFalse(DataObject::get_by_id('Page', $pageStaff->ID));
|
|
|
|
$this->assertFalse(DataObject::get_by_id('Page', $pageStaffDuplicate->ID));
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::DRAFT);
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/**
|
|
|
|
* Simple test to confirm that querying from a particular archive date doesn't throw
|
|
|
|
* an error
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testReadArchiveDate() {
|
2012-11-23 15:52:00 +01:00
|
|
|
$date = '2009-07-02 14:05:07';
|
|
|
|
Versioned::reading_archived_date($date);
|
2013-06-21 00:45:33 +02:00
|
|
|
SiteTree::get()->where(array(
|
|
|
|
'"SiteTree"."ParentID"' => 0
|
|
|
|
));
|
2011-03-18 04:23:47 +01:00
|
|
|
Versioned::reading_archived_date(null);
|
2012-11-23 15:52:00 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
Versioned::get_reading_mode(),
|
|
|
|
'Archive.'
|
|
|
|
);
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testEditPermissions() {
|
2016-06-23 01:51:20 +02:00
|
|
|
$editor = $this->objFromFixture("SilverStripe\\Security\\Member", "editor");
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$home = $this->objFromFixture("Page", "home");
|
2015-03-11 06:54:08 +01:00
|
|
|
$staff = $this->objFromFixture("Page", "staff");
|
2011-03-18 04:23:47 +01:00
|
|
|
$products = $this->objFromFixture("Page", "products");
|
|
|
|
$product1 = $this->objFromFixture("Page", "product1");
|
|
|
|
$product4 = $this->objFromFixture("Page", "product4");
|
|
|
|
|
2015-03-11 06:54:08 +01:00
|
|
|
// Test logged out users cannot edit
|
|
|
|
$this->logOut();
|
|
|
|
$this->assertFalse($staff->canEdit());
|
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Can't edit a page that is locked to admins
|
|
|
|
$this->assertFalse($home->canEdit($editor));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Can edit a page that is locked to editors
|
|
|
|
$this->assertTrue($products->canEdit($editor));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Can edit a child of that page that inherits
|
|
|
|
$this->assertTrue($product1->canEdit($editor));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Can't edit a child of that page that has its permissions overridden
|
|
|
|
$this->assertFalse($product4->canEdit($editor));
|
|
|
|
}
|
2013-12-13 10:03:01 +01:00
|
|
|
|
|
|
|
public function testCanEditWithAccessToAllSections() {
|
|
|
|
$page = new Page();
|
|
|
|
$page->write();
|
2016-06-23 01:51:20 +02:00
|
|
|
$allSectionMember = $this->objFromFixture('SilverStripe\\Security\\Member', 'allsections');
|
|
|
|
$securityAdminMember = $this->objFromFixture('SilverStripe\\Security\\Member', 'securityadmin');
|
2013-12-13 10:03:01 +01:00
|
|
|
|
|
|
|
$this->assertTrue($page->canEdit($allSectionMember));
|
|
|
|
$this->assertFalse($page->canEdit($securityAdminMember));
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
|
|
|
public function testCreatePermissions() {
|
|
|
|
// Test logged out users cannot create
|
|
|
|
$this->logOut();
|
2016-07-22 01:32:32 +02:00
|
|
|
$this->assertFalse(singleton('SilverStripe\\CMS\\Model\\SiteTree')->canCreate());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
|
|
|
// Login with another permission
|
|
|
|
$this->logInWithPermission('DUMMY');
|
2016-07-22 01:32:32 +02:00
|
|
|
$this->assertFalse(singleton('SilverStripe\\CMS\\Model\\SiteTree')->canCreate());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
|
|
|
// Login with basic CMS permission
|
|
|
|
$perms = SiteConfig::config()->required_permission;
|
|
|
|
$this->logInWithPermission(reset($perms));
|
2016-07-22 01:32:32 +02:00
|
|
|
$this->assertTrue(singleton('SilverStripe\\CMS\\Model\\SiteTree')->canCreate());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
|
|
|
// Test creation underneath a parent which this user doesn't have access to
|
|
|
|
$parent = $this->objFromFixture('Page', 'about');
|
2016-07-22 01:32:32 +02:00
|
|
|
$this->assertFalse(singleton('SilverStripe\\CMS\\Model\\SiteTree')->canCreate(null, array('Parent' => $parent)));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
|
|
|
// Test creation underneath a parent which doesn't allow a certain child
|
|
|
|
$parentB = new SiteTreeTest_ClassB();
|
|
|
|
$parentB->Title = 'Only Allows SiteTreeTest_ClassC';
|
|
|
|
$parentB->write();
|
|
|
|
$this->assertTrue(singleton('SiteTreeTest_ClassA')->canCreate(null));
|
|
|
|
$this->assertFalse(singleton('SiteTreeTest_ClassA')->canCreate(null, array('Parent' => $parentB)));
|
|
|
|
$this->assertTrue(singleton('SiteTreeTest_ClassC')->canCreate(null, array('Parent' => $parentB)));
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testEditPermissionsOnDraftVsLive() {
|
2011-03-18 04:23:47 +01:00
|
|
|
// Create an inherit-permission page
|
|
|
|
$page = new Page();
|
|
|
|
$page->write();
|
|
|
|
$page->CanEditType = "Inherit";
|
2016-04-01 05:17:37 +02:00
|
|
|
$page->publishRecursive();
|
2011-03-18 04:23:47 +01:00
|
|
|
$pageID = $page->ID;
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Lock down the site config
|
|
|
|
$sc = $page->SiteConfig;
|
|
|
|
$sc->CanEditType = 'OnlyTheseUsers';
|
2016-06-23 01:51:20 +02:00
|
|
|
$sc->EditorGroups()->add($this->idFromFixture('SilverStripe\\Security\\Group', 'admins'));
|
2011-03-18 04:23:47 +01:00
|
|
|
$sc->write();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Confirm that Member.editor can't edit the page
|
2016-06-23 01:51:20 +02:00
|
|
|
$this->objFromFixture('SilverStripe\\Security\\Member','editor')->logIn();
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertFalse($page->canEdit());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Change the page to be editable by Group.editors, but do not publish
|
2016-06-23 01:51:20 +02:00
|
|
|
$this->objFromFixture('SilverStripe\\Security\\Member','admin')->logIn();
|
2011-03-18 04:23:47 +01:00
|
|
|
$page->CanEditType = 'OnlyTheseUsers';
|
2016-06-23 01:51:20 +02:00
|
|
|
$page->EditorGroups()->add($this->idFromFixture('SilverStripe\\Security\\Group', 'editors'));
|
2011-03-18 04:23:47 +01:00
|
|
|
$page->write();
|
2011-10-07 10:36:56 +02:00
|
|
|
// Clear permission cache
|
|
|
|
SiteTree::on_db_reset();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Confirm that Member.editor can now edit the page
|
2016-06-23 01:51:20 +02:00
|
|
|
$this->objFromFixture('SilverStripe\\Security\\Member','editor')->logIn();
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertTrue($page->canEdit());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Publish the changes to the page
|
2016-06-23 01:51:20 +02:00
|
|
|
$this->objFromFixture('SilverStripe\\Security\\Member','admin')->logIn();
|
2016-04-01 05:17:37 +02:00
|
|
|
$page->publishRecursive();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Confirm that Member.editor can still edit the page
|
2016-06-23 01:51:20 +02:00
|
|
|
$this->objFromFixture('SilverStripe\\Security\\Member','editor')->logIn();
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertTrue($page->canEdit());
|
2015-06-13 16:23:22 +02:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testCompareVersions() {
|
2011-04-06 12:16:46 +02:00
|
|
|
// Necessary to avoid
|
|
|
|
$oldCleanerClass = Diff::$html_cleaner_class;
|
|
|
|
Diff::$html_cleaner_class = 'SiteTreeTest_NullHtmlCleaner';
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$page = new Page();
|
|
|
|
$page->write();
|
|
|
|
$this->assertEquals(1, $page->Version);
|
2011-04-06 12:16:46 +02:00
|
|
|
|
|
|
|
// Use inline element to avoid double wrapping applied to
|
|
|
|
// blocklevel elements depending on HTMLCleaner implementation:
|
|
|
|
// <ins><p> gets converted to <ins><p><inst>
|
|
|
|
$page->Content = "<span>This is a test</span>";
|
2011-03-18 04:23:47 +01:00
|
|
|
$page->write();
|
|
|
|
$this->assertEquals(2, $page->Version);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$diff = $page->compareVersions(1, 2);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$processedContent = trim($diff->Content);
|
|
|
|
$processedContent = preg_replace('/\s*</','<',$processedContent);
|
|
|
|
$processedContent = preg_replace('/>\s*/','>',$processedContent);
|
2011-04-06 12:16:46 +02:00
|
|
|
$this->assertEquals("<ins><span>This is a test</span></ins>", $processedContent);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-04-06 12:16:46 +02:00
|
|
|
Diff::$html_cleaner_class = $oldCleanerClass;
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testAuthorIDAndPublisherIDFilledOutOnPublish() {
|
2011-03-18 04:23:47 +01:00
|
|
|
// Ensure that we have a member ID who is doing all this work
|
|
|
|
$member = Member::currentUser();
|
|
|
|
if($member) {
|
|
|
|
$memberID = $member->ID;
|
|
|
|
} else {
|
2016-06-23 01:51:20 +02:00
|
|
|
$memberID = $this->idFromFixture("SilverStripe\\Security\\Member", "admin");
|
2011-03-18 04:23:47 +01:00
|
|
|
Session::set("loggedInAs", $memberID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the page
|
|
|
|
$about = $this->objFromFixture('Page','about');
|
|
|
|
$about->Title = "Another title";
|
|
|
|
$about->write();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Check the version created
|
2015-03-11 06:54:08 +01:00
|
|
|
$savedVersion = DB::query("SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_versions\"
|
2011-03-18 04:23:47 +01:00
|
|
|
WHERE \"RecordID\" = $about->ID ORDER BY \"Version\" DESC")->first();
|
|
|
|
$this->assertEquals($memberID, $savedVersion['AuthorID']);
|
|
|
|
$this->assertEquals(0, $savedVersion['PublisherID']);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Publish the page
|
2016-04-01 05:17:37 +02:00
|
|
|
$about->publishRecursive();
|
2015-03-11 06:54:08 +01:00
|
|
|
$publishedVersion = DB::query("SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_versions\"
|
2011-03-18 04:23:47 +01:00
|
|
|
WHERE \"RecordID\" = $about->ID ORDER BY \"Version\" DESC")->first();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// Check the version created
|
|
|
|
$this->assertEquals($memberID, $publishedVersion['AuthorID']);
|
|
|
|
$this->assertEquals($memberID, $publishedVersion['PublisherID']);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
public function testLinkShortcodeHandler() {
|
|
|
|
$aboutPage = $this->objFromFixture('Page', 'about');
|
2016-07-22 01:32:32 +02:00
|
|
|
$redirectPage = $this->objFromFixture('SilverStripe\\CMS\\Model\\RedirectorPage', 'external');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$parser = new ShortcodeParser();
|
2016-07-22 01:32:32 +02:00
|
|
|
$parser->register('sitetree_link', array('SilverStripe\\CMS\\Model\\SiteTree', 'link_shortcode_handler'));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-07-12 04:51:19 +02:00
|
|
|
$aboutShortcode = sprintf('[sitetree_link,id=%d]', $aboutPage->ID);
|
|
|
|
$aboutEnclosed = sprintf('[sitetree_link,id=%d]Example Content[/sitetree_link]', $aboutPage->ID);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$aboutShortcodeExpected = $aboutPage->Link();
|
|
|
|
$aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $aboutPage->Link());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test that simple linking works.');
|
|
|
|
$this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed), 'Test enclosed content is linked.');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$aboutPage->delete();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test that deleted pages still link.');
|
|
|
|
$this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-07-12 04:51:19 +02:00
|
|
|
$aboutShortcode = '[sitetree_link,id="-1"]';
|
|
|
|
$aboutEnclosed = '[sitetree_link,id="-1"]Example Content[/sitetree_link]';
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2015-12-28 21:17:31 +01:00
|
|
|
$this->assertEquals('', $parser->parse($aboutShortcode), 'Test empty result if no suitable matches.');
|
|
|
|
$this->assertEquals('', $parser->parse($aboutEnclosed));
|
2013-05-10 04:05:06 +02:00
|
|
|
|
|
|
|
$redirectShortcode = sprintf('[sitetree_link,id=%d]', $redirectPage->ID);
|
|
|
|
$redirectEnclosed = sprintf('[sitetree_link,id=%d]Example Content[/sitetree_link]', $redirectPage->ID);
|
|
|
|
$redirectExpected = 'http://www.google.com?a&b';
|
|
|
|
|
|
|
|
$this->assertEquals($redirectExpected, $parser->parse($redirectShortcode));
|
|
|
|
$this->assertEquals(sprintf('<a href="%s">Example Content</a>', $redirectExpected), $parser->parse($redirectEnclosed));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertEquals('', $parser->parse('[sitetree_link]'), 'Test that invalid ID attributes are not parsed.');
|
2012-07-12 04:51:19 +02:00
|
|
|
$this->assertEquals('', $parser->parse('[sitetree_link,id="text"]'));
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertEquals('', $parser->parse('[sitetree_link]Example Content[/sitetree_link]'));
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
public function testIsCurrent() {
|
|
|
|
$aboutPage = $this->objFromFixture('Page', 'about');
|
2016-07-22 01:32:32 +02:00
|
|
|
$errorPage = $this->objFromFixture('SilverStripe\\CMS\\Model\\ErrorPage', '404');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
Director::set_current_page($aboutPage);
|
|
|
|
$this->assertTrue($aboutPage->isCurrent(), 'Assert that basic isSection checks works.');
|
|
|
|
$this->assertFalse($errorPage->isCurrent());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
Director::set_current_page($errorPage);
|
|
|
|
$this->assertTrue($errorPage->isCurrent(), 'Assert isSection works on error pages.');
|
|
|
|
$this->assertFalse($aboutPage->isCurrent());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
Director::set_current_page($aboutPage);
|
|
|
|
$this->assertTrue (
|
2016-07-22 01:32:32 +02:00
|
|
|
DataObject::get_one('SilverStripe\\CMS\\Model\\SiteTree', array(
|
2013-06-21 00:45:33 +02:00
|
|
|
'"SiteTree"."Title"' => 'About Us'
|
|
|
|
))->isCurrent(),
|
2011-03-18 04:23:47 +01:00
|
|
|
'Assert that isCurrent works on another instance with the same ID.'
|
|
|
|
);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
Director::set_current_page($newPage = new SiteTree());
|
|
|
|
$this->assertTrue($newPage->isCurrent(), 'Assert that isCurrent works on unsaved pages.');
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
public function testIsSection() {
|
|
|
|
$about = $this->objFromFixture('Page', 'about');
|
|
|
|
$staff = $this->objFromFixture('Page', 'staff');
|
|
|
|
$ceo = $this->objFromFixture('Page', 'ceo');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
Director::set_current_page($about);
|
|
|
|
$this->assertTrue($about->isSection());
|
|
|
|
$this->assertFalse($staff->isSection());
|
|
|
|
$this->assertFalse($ceo->isSection());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
Director::set_current_page($staff);
|
|
|
|
$this->assertTrue($about->isSection());
|
|
|
|
$this->assertTrue($staff->isSection());
|
|
|
|
$this->assertFalse($ceo->isSection());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
Director::set_current_page($ceo);
|
|
|
|
$this->assertTrue($about->isSection());
|
|
|
|
$this->assertTrue($staff->isSection());
|
|
|
|
$this->assertTrue($ceo->isSection());
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2015-02-20 23:33:59 +01:00
|
|
|
public function testURLSegmentAutoUpdate() {
|
|
|
|
$sitetree = new SiteTree();
|
|
|
|
$sitetree->Title = _t(
|
|
|
|
'CMSMain.NEWPAGE',
|
|
|
|
array('pagetype' => $sitetree->i18n_singular_name())
|
|
|
|
);
|
|
|
|
$sitetree->write();
|
|
|
|
$this->assertEquals($sitetree->URLSegment, 'new-page',
|
|
|
|
'Sets based on default title on first save'
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2015-02-20 23:33:59 +01:00
|
|
|
$sitetree->Title = 'Changed';
|
|
|
|
$sitetree->write();
|
|
|
|
$this->assertEquals($sitetree->URLSegment, 'changed',
|
|
|
|
'Auto-updates when set to default title'
|
|
|
|
);
|
|
|
|
|
|
|
|
$sitetree->Title = 'Changed again';
|
|
|
|
$sitetree->write();
|
|
|
|
$this->assertEquals($sitetree->URLSegment, 'changed',
|
|
|
|
'Does not auto-update once title has been changed'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testURLSegmentAutoUpdateLocalized() {
|
|
|
|
$oldLocale = i18n::get_locale();
|
|
|
|
i18n::set_locale('de_DE');
|
|
|
|
|
|
|
|
$sitetree = new SiteTree();
|
|
|
|
$sitetree->Title = _t(
|
|
|
|
'CMSMain.NEWPAGE',
|
|
|
|
array('pagetype' => $sitetree->i18n_singular_name())
|
|
|
|
);
|
|
|
|
$sitetree->write();
|
|
|
|
$this->assertEquals($sitetree->URLSegment, 'neue-seite',
|
|
|
|
'Sets based on default title on first save'
|
|
|
|
);
|
|
|
|
|
|
|
|
$sitetree->Title = 'Changed';
|
|
|
|
$sitetree->write();
|
|
|
|
$this->assertEquals($sitetree->URLSegment, 'changed',
|
|
|
|
'Auto-updates when set to default title'
|
|
|
|
);
|
|
|
|
|
|
|
|
$sitetree->Title = 'Changed again';
|
|
|
|
$sitetree->write();
|
|
|
|
$this->assertEquals($sitetree->URLSegment, 'changed',
|
|
|
|
'Does not auto-update once title has been changed'
|
|
|
|
);
|
|
|
|
|
|
|
|
i18n::set_locale($oldLocale);
|
|
|
|
}
|
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/**
|
|
|
|
* @covers SiteTree::validURLSegment
|
|
|
|
*/
|
|
|
|
public function testValidURLSegmentURLSegmentConflicts() {
|
|
|
|
$sitetree = new SiteTree();
|
2013-03-18 11:47:15 +01:00
|
|
|
SiteTree::config()->nested_urls = false;
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$sitetree->URLSegment = 'home';
|
|
|
|
$this->assertFalse($sitetree->validURLSegment(), 'URLSegment conflicts are recognised');
|
|
|
|
$sitetree->URLSegment = 'home-noconflict';
|
|
|
|
$this->assertTrue($sitetree->validURLSegment());
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$sitetree->ParentID = $this->idFromFixture('Page', 'about');
|
|
|
|
$sitetree->URLSegment = 'home';
|
|
|
|
$this->assertFalse($sitetree->validURLSegment(), 'Conflicts are still recognised with a ParentID value');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'nested_urls', true);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$sitetree->ParentID = 0;
|
|
|
|
$sitetree->URLSegment = 'home';
|
|
|
|
$this->assertFalse($sitetree->validURLSegment(), 'URLSegment conflicts are recognised');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$sitetree->ParentID = $this->idFromFixture('Page', 'about');
|
|
|
|
$this->assertTrue($sitetree->validURLSegment(), 'URLSegments can be the same across levels');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$sitetree->URLSegment = 'my-staff';
|
|
|
|
$this->assertFalse($sitetree->validURLSegment(), 'Nested URLSegment conflicts are recognised');
|
|
|
|
$sitetree->URLSegment = 'my-staff-noconflict';
|
|
|
|
$this->assertTrue($sitetree->validURLSegment());
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/**
|
|
|
|
* @covers SiteTree::validURLSegment
|
|
|
|
*/
|
|
|
|
public function testValidURLSegmentClassNameConflicts() {
|
|
|
|
$sitetree = new SiteTree();
|
|
|
|
$sitetree->URLSegment = 'Controller';
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertFalse($sitetree->validURLSegment(), 'Class name conflicts are recognised');
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
/**
|
|
|
|
* @covers SiteTree::validURLSegment
|
|
|
|
*/
|
|
|
|
public function testValidURLSegmentControllerConflicts() {
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'nested_urls', true);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$sitetree = new SiteTree();
|
|
|
|
$sitetree->ParentID = $this->idFromFixture('SiteTreeTest_Conflicted', 'parent');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$sitetree->URLSegment = 'index';
|
|
|
|
$this->assertFalse($sitetree->validURLSegment(), 'index is not a valid URLSegment');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$sitetree->URLSegment = 'conflicted-action';
|
|
|
|
$this->assertFalse($sitetree->validURLSegment(), 'allowed_actions conflicts are recognised');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$sitetree->URLSegment = 'conflicted-template';
|
|
|
|
$this->assertFalse($sitetree->validURLSegment(), 'Action-specific template conflicts are recognised');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
$sitetree->URLSegment = 'valid';
|
|
|
|
$this->assertTrue($sitetree->validURLSegment(), 'Valid URLSegment values are allowed');
|
|
|
|
}
|
2012-05-08 22:11:17 +02:00
|
|
|
|
2013-06-12 12:32:42 +02:00
|
|
|
public function testURLSegmentPrioritizesExtensionVotes() {
|
|
|
|
$sitetree = new SiteTree();
|
|
|
|
$sitetree->URLSegment = 'unique-segment';
|
|
|
|
$this->assertTrue($sitetree->validURLSegment());
|
|
|
|
|
|
|
|
SiteTree::add_extension('SiteTreeTest_Extension');
|
|
|
|
$sitetree = new SiteTree();
|
|
|
|
$sitetree->URLSegment = 'unique-segment';
|
|
|
|
$this->assertFalse($sitetree->validURLSegment());
|
|
|
|
SiteTree::remove_extension('SiteTreeTest_Extension');
|
|
|
|
}
|
|
|
|
|
2012-05-08 22:11:17 +02:00
|
|
|
public function testURLSegmentMultiByte() {
|
2013-03-18 11:47:15 +01:00
|
|
|
$origAllow = Config::inst()->get('URLSegmentFilter', 'default_allow_multibyte');
|
|
|
|
Config::inst()->update('URLSegmentFilter', 'default_allow_multibyte', true);
|
2012-05-08 22:11:17 +02:00
|
|
|
$sitetree = new SiteTree();
|
|
|
|
$sitetree->write();
|
|
|
|
|
|
|
|
$sitetree->URLSegment = 'brötchen';
|
|
|
|
$sitetree->write();
|
2016-07-22 01:32:32 +02:00
|
|
|
$sitetree = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $sitetree->ID, false);
|
2012-05-08 22:11:17 +02:00
|
|
|
$this->assertEquals($sitetree->URLSegment, rawurlencode('brötchen'));
|
|
|
|
|
2016-04-01 05:17:37 +02:00
|
|
|
$sitetree->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2016-07-22 01:32:32 +02:00
|
|
|
$sitetree = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $sitetree->ID, false);
|
2012-05-08 22:11:17 +02:00
|
|
|
$this->assertEquals($sitetree->URLSegment, rawurlencode('brötchen'));
|
2016-07-22 01:32:32 +02:00
|
|
|
$sitetreeLive = Versioned::get_one_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', '"SiteTree"."ID" = ' .$sitetree->ID, false);
|
2012-05-08 22:11:17 +02:00
|
|
|
$this->assertEquals($sitetreeLive->URLSegment, rawurlencode('brötchen'));
|
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
Config::inst()->update('URLSegmentFilter', 'default_allow_multibyte', $origAllow);
|
2012-05-08 22:11:17 +02:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
public function testVersionsAreCreated() {
|
|
|
|
$p = new Page();
|
|
|
|
$p->Content = "one";
|
|
|
|
$p->write();
|
|
|
|
$this->assertEquals(1, $p->Version);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
// No changes don't bump version
|
|
|
|
$p->write();
|
|
|
|
$this->assertEquals(1, $p->Version);
|
|
|
|
|
|
|
|
$p->Content = "two";
|
|
|
|
$p->write();
|
|
|
|
$this->assertEquals(2, $p->Version);
|
|
|
|
|
|
|
|
// Only change meta-data don't bump version
|
|
|
|
$p->HasBrokenLink = true;
|
|
|
|
$p->write();
|
|
|
|
$p->HasBrokenLink = false;
|
|
|
|
$p->write();
|
|
|
|
$this->assertEquals(2, $p->Version);
|
|
|
|
|
|
|
|
$p->Content = "three";
|
|
|
|
$p->write();
|
|
|
|
$this->assertEquals(3, $p->Version);
|
|
|
|
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testPageTypeClasses() {
|
2011-03-18 04:23:47 +01:00
|
|
|
$classes = SiteTree::page_type_classes();
|
2016-07-22 01:32:32 +02:00
|
|
|
$this->assertNotContains('SilverStripe\\CMS\\Model\\SiteTree', $classes, 'Page types do not include base class');
|
2011-03-18 04:23:47 +01:00
|
|
|
$this->assertContains('Page', $classes, 'Page types do contain subclasses');
|
2015-11-04 11:17:04 +01:00
|
|
|
|
|
|
|
// Testing what happens in an incorrect config value is set - hide_ancestor should be a string
|
|
|
|
Config::inst()->update('SiteTreeTest_ClassA', 'hide_ancestor', true);
|
|
|
|
$newClasses = SiteTree::page_type_classes();
|
|
|
|
$this->assertEquals(
|
|
|
|
$classes,
|
|
|
|
$newClasses,
|
|
|
|
'Setting hide_ancestor to a boolean (incorrect) value caused a page class to be hidden'
|
|
|
|
);
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-07-22 10:45:14 +02:00
|
|
|
/**
|
|
|
|
* Tests that core subclasses of SiteTree are included in allowedChildren() by default, but not instances of
|
|
|
|
* HiddenClass
|
|
|
|
*/
|
|
|
|
public function testAllowedChildrenContainsCoreSubclassesButNotHiddenClass()
|
|
|
|
{
|
2011-10-06 16:47:59 +02:00
|
|
|
$page = new SiteTree();
|
2016-07-22 10:45:14 +02:00
|
|
|
$allowedChildren = $page->allowedChildren();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-07-22 10:45:14 +02:00
|
|
|
$this->assertContains(
|
2016-07-22 01:32:32 +02:00
|
|
|
'SilverStripe\\CMS\\Model\\VirtualPage',
|
2016-07-22 10:45:14 +02:00
|
|
|
$allowedChildren,
|
2016-07-22 01:32:32 +02:00
|
|
|
'Includes core subclasses by default'
|
|
|
|
);
|
2016-07-22 10:45:14 +02:00
|
|
|
|
|
|
|
$this->assertNotContains(
|
|
|
|
'SiteTreeTest_ClassE',
|
|
|
|
$allowedChildren,
|
|
|
|
'HiddenClass instances should not be returned'
|
|
|
|
);
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2016-07-22 10:45:14 +02:00
|
|
|
/**
|
|
|
|
* Tests that various types of SiteTree classes will or will not be returned from the allowedChildren method
|
|
|
|
* @dataProvider allowedChildrenProvider
|
|
|
|
* @param string $className
|
|
|
|
* @param array $expected
|
|
|
|
* @param string $assertionMessage
|
|
|
|
*/
|
|
|
|
public function testAllowedChildren($className, $expected, $assertionMessage)
|
|
|
|
{
|
|
|
|
$class = new $className;
|
|
|
|
$this->assertEquals($expected, $class->allowedChildren(), $assertionMessage);
|
2011-10-06 16:47:59 +02:00
|
|
|
}
|
|
|
|
|
2016-07-22 10:45:14 +02:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function allowedChildrenProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
// Class name
|
|
|
|
'SiteTreeTest_ClassA',
|
|
|
|
// Expected
|
2016-07-22 01:32:32 +02:00
|
|
|
array('SiteTreeTest_ClassB'),
|
2016-07-22 10:45:14 +02:00
|
|
|
// Assertion message
|
2016-07-22 01:32:32 +02:00
|
|
|
'Direct setting of allowed children'
|
2016-07-22 10:45:14 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'SiteTreeTest_ClassB',
|
2016-07-22 01:32:32 +02:00
|
|
|
array('SiteTreeTest_ClassC', 'SiteTreeTest_ClassCext'),
|
|
|
|
'Includes subclasses'
|
2016-07-22 10:45:14 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'SiteTreeTest_ClassC',
|
|
|
|
array(),
|
|
|
|
'Null setting'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'SiteTreeTest_ClassD',
|
2016-07-22 01:32:32 +02:00
|
|
|
array('SiteTreeTest_ClassC'),
|
|
|
|
'Excludes subclasses if class is prefixed by an asterisk'
|
2016-07-22 10:45:14 +02:00
|
|
|
)
|
2016-07-22 01:32:32 +02:00
|
|
|
);
|
|
|
|
}
|
2016-07-22 10:45:14 +02:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testAllowedChildrenValidation() {
|
2011-10-06 16:47:59 +02:00
|
|
|
$page = new SiteTree();
|
|
|
|
$page->write();
|
|
|
|
$classA = new SiteTreeTest_ClassA();
|
|
|
|
$classA->write();
|
|
|
|
$classB = new SiteTreeTest_ClassB();
|
|
|
|
$classB->write();
|
|
|
|
$classC = new SiteTreeTest_ClassC();
|
|
|
|
$classC->write();
|
|
|
|
$classD = new SiteTreeTest_ClassD();
|
|
|
|
$classD->write();
|
|
|
|
$classCext = new SiteTreeTest_ClassCext();
|
|
|
|
$classCext->write();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-10-06 16:47:59 +02:00
|
|
|
$classB->ParentID = $page->ID;
|
2015-06-19 00:47:19 +02:00
|
|
|
$valid = $classB->doValidate();
|
2011-10-06 16:47:59 +02:00
|
|
|
$this->assertTrue($valid->valid(), "Does allow children on unrestricted parent");
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-10-06 16:47:59 +02:00
|
|
|
$classB->ParentID = $classA->ID;
|
2015-06-19 00:47:19 +02:00
|
|
|
$valid = $classB->doValidate();
|
2011-10-06 16:47:59 +02:00
|
|
|
$this->assertTrue($valid->valid(), "Does allow child specifically allowed by parent");
|
|
|
|
|
|
|
|
$classC->ParentID = $classA->ID;
|
2015-06-19 00:47:19 +02:00
|
|
|
$valid = $classC->doValidate();
|
2011-10-06 16:47:59 +02:00
|
|
|
$this->assertFalse($valid->valid(), "Doesnt allow child on parents specifically restricting children");
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-10-06 16:47:59 +02:00
|
|
|
$classB->ParentID = $classC->ID;
|
2015-06-19 00:47:19 +02:00
|
|
|
$valid = $classB->doValidate();
|
2011-10-06 16:47:59 +02:00
|
|
|
$this->assertFalse($valid->valid(), "Doesnt allow child on parents disallowing all children");
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2015-01-25 22:07:41 +01:00
|
|
|
$classB->ParentID = $classCext->ID;
|
2015-06-19 00:47:19 +02:00
|
|
|
$valid = $classB->doValidate();
|
2015-01-25 22:07:41 +01:00
|
|
|
$this->assertTrue($valid->valid(), "Extensions of allowed classes are incorrectly reported as invalid");
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-10-06 16:47:59 +02:00
|
|
|
$classCext->ParentID = $classD->ID;
|
2015-06-19 00:47:19 +02:00
|
|
|
$valid = $classCext->doValidate();
|
2011-10-06 16:47:59 +02:00
|
|
|
$this->assertFalse($valid->valid(), "Doesnt allow child where only parent class is allowed on parent node, and asterisk prefixing is used");
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testClassDropdown() {
|
2011-10-07 09:29:03 +02:00
|
|
|
$sitetree = new SiteTree();
|
|
|
|
$method = new ReflectionMethod($sitetree, 'getClassDropdown');
|
|
|
|
$method->setAccessible(true);
|
|
|
|
|
|
|
|
Session::set("loggedInAs", null);
|
|
|
|
$this->assertArrayNotHasKey('SiteTreeTest_ClassA', $method->invoke($sitetree));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-10-07 09:29:03 +02:00
|
|
|
$this->loginWithPermission('ADMIN');
|
|
|
|
$this->assertArrayHasKey('SiteTreeTest_ClassA', $method->invoke($sitetree));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-10-07 09:29:03 +02:00
|
|
|
$this->loginWithPermission('CMS_ACCESS_CMSMain');
|
|
|
|
$this->assertArrayHasKey('SiteTreeTest_ClassA', $method->invoke($sitetree));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2011-10-07 09:29:03 +02:00
|
|
|
Session::set("loggedInAs", null);
|
|
|
|
}
|
2012-01-14 11:20:54 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testCanBeRoot() {
|
2012-01-14 11:20:54 +01:00
|
|
|
$page = new SiteTree();
|
|
|
|
$page->ParentID = 0;
|
|
|
|
$page->write();
|
|
|
|
|
|
|
|
$notRootPage = new SiteTreeTest_NotRoot();
|
|
|
|
$notRootPage->ParentID = 0;
|
|
|
|
$isDetected = false;
|
|
|
|
try {
|
2015-03-11 06:54:08 +01:00
|
|
|
$notRootPage->write();
|
2012-01-14 11:20:54 +01:00
|
|
|
} catch(ValidationException $e) {
|
|
|
|
$this->assertContains('is not allowed on the root level', $e->getMessage());
|
|
|
|
$isDetected = true;
|
2015-03-11 06:54:08 +01:00
|
|
|
}
|
2012-01-14 11:20:54 +01:00
|
|
|
|
|
|
|
if(!$isDetected) $this->fail('Fails validation with $can_be_root=false');
|
2015-03-11 06:54:08 +01:00
|
|
|
}
|
2012-03-29 00:47:28 +02:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testModifyStatusFlagByInheritance(){
|
2012-03-29 00:47:28 +02:00
|
|
|
$node = new SiteTreeTest_StageStatusInherit();
|
|
|
|
$treeTitle = $node->getTreeTitle();
|
|
|
|
$this->assertContains('InheritedTitle', $treeTitle);
|
|
|
|
$this->assertContains('inherited-class', $treeTitle);
|
2012-01-14 11:20:54 +01:00
|
|
|
}
|
2012-06-20 18:26:55 +02:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testMenuTitleIsUnsetWhenEqualsTitle() {
|
2012-06-20 18:26:55 +02:00
|
|
|
$page = new SiteTree();
|
|
|
|
$page->Title = 'orig';
|
|
|
|
$page->MenuTitle = 'orig';
|
|
|
|
$page->write();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2012-06-20 18:26:55 +02:00
|
|
|
// change menu title
|
|
|
|
$page->MenuTitle = 'changed';
|
|
|
|
$page->write();
|
|
|
|
$page = SiteTree::get()->byID($page->ID);
|
|
|
|
$this->assertEquals('changed', $page->getField('MenuTitle'));
|
|
|
|
|
|
|
|
// change menu title back
|
|
|
|
$page->MenuTitle = 'orig';
|
|
|
|
$page->write();
|
|
|
|
$page = SiteTree::get()->byID($page->ID);
|
|
|
|
$this->assertEquals(null, $page->getField('MenuTitle'));
|
|
|
|
}
|
2013-06-17 22:29:02 +02:00
|
|
|
|
|
|
|
public function testMetaTagGeneratorDisabling() {
|
2016-07-22 01:32:32 +02:00
|
|
|
$generator = Config::inst()->get('SilverStripe\\CMS\\Model\\SiteTree', 'meta_generator');
|
2013-06-17 22:29:02 +02:00
|
|
|
|
|
|
|
$page = new SiteTreeTest_PageNode();
|
|
|
|
|
|
|
|
$meta = $page->MetaTags();
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
|
|
|
preg_match('/.*meta name="generator" content="SilverStripe - http:\/\/silverstripe.org".*/', $meta),
|
|
|
|
'test default functionality - uses value from Config');
|
|
|
|
|
|
|
|
// test proper escaping of quotes in attribute value
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'meta_generator', 'Generator with "quotes" in it');
|
2013-06-17 22:29:02 +02:00
|
|
|
$meta = $page->MetaTags();
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
|
|
|
preg_match('/.*meta name="generator" content="Generator with "quotes" in it".*/', $meta),
|
|
|
|
'test proper escaping of values from Config');
|
|
|
|
|
|
|
|
// test empty generator - no tag should appear at all
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'meta_generator', '');
|
2013-06-17 22:29:02 +02:00
|
|
|
$meta = $page->MetaTags();
|
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
|
|
|
preg_match('/.*meta name=.generator..*/', $meta),
|
|
|
|
'test blank value means no tag generated');
|
|
|
|
|
|
|
|
// reset original value
|
2016-07-22 01:32:32 +02:00
|
|
|
Config::inst()->update('SilverStripe\\CMS\\Model\\SiteTree', 'meta_generator', $generator);
|
2013-06-17 22:29:02 +02:00
|
|
|
}
|
2014-05-08 04:09:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
public function testGetBreadcrumbItems() {
|
|
|
|
$page = $this->objFromFixture("Page", "breadcrumbs");
|
|
|
|
$this->assertEquals($page->getBreadcrumbItems()->count(), 1, "Only display current page.");
|
|
|
|
|
|
|
|
// Test breadcrumb order
|
|
|
|
$page = $this->objFromFixture("Page", "breadcrumbs5");
|
|
|
|
$breadcrumbs = $page->getBreadcrumbItems();
|
|
|
|
$this->assertEquals($breadcrumbs->count(), 5, "Display all breadcrumbs");
|
|
|
|
$this->assertEquals($breadcrumbs->first()->Title, "Breadcrumbs", "Breadcrumbs should be the first item.");
|
|
|
|
$this->assertEquals($breadcrumbs->last()->Title, "Breadcrumbs 5", "Breadcrumbs 5 should be last item.");
|
|
|
|
|
|
|
|
// Test breadcrumb max depth
|
|
|
|
$breadcrumbs = $page->getBreadcrumbItems(2);
|
|
|
|
$this->assertEquals($breadcrumbs->count(), 2, "Max depth should limit the breadcrumbs to 2 items.");
|
|
|
|
$this->assertEquals($breadcrumbs->first()->Title, "Breadcrumbs 4", "First item should be Breadrcumbs 4.");
|
|
|
|
$this->assertEquals($breadcrumbs->last()->Title, "Breadcrumbs 5", "Breadcrumbs 5 should be last.");
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-04-28 22:54:17 +02:00
|
|
|
/**
|
|
|
|
* Tests SiteTree::MetaTags
|
|
|
|
* Note that this test makes no assumption on the closing of tags (other than <title></title>)
|
|
|
|
*/
|
|
|
|
public function testMetaTags() {
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$page = $this->objFromFixture('Page', 'metapage');
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2014-04-28 22:54:17 +02:00
|
|
|
// Test with title
|
|
|
|
$meta = $page->MetaTags();
|
|
|
|
$charset = Config::inst()->get('ContentNegotiator', 'encoding');
|
2015-02-11 00:13:55 +01:00
|
|
|
$this->assertContains('<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'"', $meta);
|
2014-04-28 22:54:17 +02:00
|
|
|
$this->assertContains('<meta name="description" content="The <br /> and <br> tags"', $meta);
|
|
|
|
$this->assertContains('<link rel="canonical" href="http://www.mysite.com/html-and-xml"', $meta);
|
|
|
|
$this->assertContains('<meta name="x-page-id" content="'.$page->ID.'"', $meta);
|
2015-02-11 00:13:55 +01:00
|
|
|
$this->assertContains('<meta name="x-cms-edit-link" content="'.$page->CMSEditLink().'"', $meta);
|
2014-04-28 22:54:17 +02:00
|
|
|
$this->assertContains('<title>HTML & XML</title>', $meta);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2014-04-28 22:54:17 +02:00
|
|
|
// Test without title
|
|
|
|
$meta = $page->MetaTags(false);
|
|
|
|
$this->assertNotContains('<title>', $meta);
|
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2014-04-07 02:21:57 +02:00
|
|
|
/**
|
|
|
|
* Test that orphaned pages are handled correctly
|
|
|
|
*/
|
|
|
|
public function testOrphanedPages() {
|
|
|
|
$origStage = Versioned::get_reading_mode();
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2014-04-07 02:21:57 +02:00
|
|
|
// Setup user who can view draft content, but lacks cms permission.
|
|
|
|
// To users such as this, orphaned pages should be inaccessible. canView for these pages is only
|
|
|
|
// necessary for admin / cms users, who require this permission to edit / rearrange these pages.
|
|
|
|
$permission = new Permission();
|
|
|
|
$permission->Code = 'VIEW_DRAFT_CONTENT';
|
|
|
|
$group = new Group(array('Title' => 'Staging Users'));
|
|
|
|
$group->write();
|
|
|
|
$group->Permissions()->add($permission);
|
|
|
|
$member = new Member();
|
|
|
|
$member->Email = 'someguy@example.com';
|
|
|
|
$member->write();
|
|
|
|
$member->Groups()->add($group);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2014-04-07 02:21:57 +02:00
|
|
|
// both pages are viewable in stage
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::DRAFT);
|
2014-04-07 02:21:57 +02:00
|
|
|
$about = $this->objFromFixture('Page', 'about');
|
|
|
|
$staff = $this->objFromFixture('Page', 'staff');
|
|
|
|
$this->assertFalse($about->isOrphaned());
|
|
|
|
$this->assertFalse($staff->isOrphaned());
|
|
|
|
$this->assertTrue($about->canView($member));
|
|
|
|
$this->assertTrue($staff->canView($member));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2014-04-07 02:21:57 +02:00
|
|
|
// Publishing only the child page to live should orphan the live record, but not the staging one
|
2016-04-01 05:17:37 +02:00
|
|
|
$staff->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2014-04-07 02:21:57 +02:00
|
|
|
$this->assertFalse($staff->isOrphaned());
|
|
|
|
$this->assertTrue($staff->canView($member));
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::LIVE);
|
2014-04-07 02:21:57 +02:00
|
|
|
$staff = $this->objFromFixture('Page', 'staff'); // Live copy of page
|
|
|
|
$this->assertTrue($staff->isOrphaned()); // because parent isn't published
|
|
|
|
$this->assertFalse($staff->canView($member));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2014-04-07 02:21:57 +02:00
|
|
|
// Publishing the parent page should restore visibility
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::DRAFT);
|
2014-04-07 02:21:57 +02:00
|
|
|
$about = $this->objFromFixture('Page', 'about');
|
2016-04-01 05:17:37 +02:00
|
|
|
$about->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2016-03-17 01:02:50 +01:00
|
|
|
Versioned::set_stage(Versioned::LIVE);
|
2014-04-07 02:21:57 +02:00
|
|
|
$staff = $this->objFromFixture('Page', 'staff');
|
|
|
|
$this->assertFalse($staff->isOrphaned());
|
|
|
|
$this->assertTrue($staff->canView($member));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2014-04-07 02:21:57 +02:00
|
|
|
// Removing staging page should not prevent live page being visible
|
|
|
|
$about->deleteFromStage('Stage');
|
|
|
|
$staff->deleteFromStage('Stage');
|
|
|
|
$staff = $this->objFromFixture('Page', 'staff');
|
|
|
|
$this->assertFalse($staff->isOrphaned());
|
|
|
|
$this->assertTrue($staff->canView($member));
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2014-04-07 02:21:57 +02:00
|
|
|
// Cleanup
|
|
|
|
Versioned::set_reading_mode($origStage);
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2014-04-07 02:21:57 +02:00
|
|
|
}
|
2015-03-11 06:54:08 +01:00
|
|
|
|
2015-08-24 05:16:09 +02:00
|
|
|
/**
|
|
|
|
* Test archived page behaviour
|
|
|
|
*/
|
|
|
|
public function testArchivedPages() {
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
|
|
|
|
$page = $this->objFromFixture('Page', 'home');
|
|
|
|
$this->assertTrue($page->canAddChildren());
|
|
|
|
$this->assertFalse($page->getIsDeletedFromStage());
|
|
|
|
$this->assertFalse($page->isPublished());
|
|
|
|
|
|
|
|
// Publish
|
2016-04-01 05:17:37 +02:00
|
|
|
$page->publishRecursive();
|
2015-08-24 05:16:09 +02:00
|
|
|
$this->assertTrue($page->canAddChildren());
|
|
|
|
$this->assertFalse($page->getIsDeletedFromStage());
|
|
|
|
$this->assertTrue($page->isPublished());
|
|
|
|
|
|
|
|
// Archive
|
|
|
|
$page->doArchive();
|
|
|
|
$this->assertFalse($page->canAddChildren());
|
|
|
|
$this->assertTrue($page->getIsDeletedFromStage());
|
|
|
|
$this->assertFalse($page->isPublished());
|
|
|
|
}
|
|
|
|
|
2016-05-23 06:12:48 +02:00
|
|
|
public function testCanNot() {
|
|
|
|
// Test that
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$page = new SiteTreeTest_AdminDenied();
|
|
|
|
$this->assertFalse($page->canCreate());
|
|
|
|
$this->assertFalse($page->canEdit());
|
|
|
|
$this->assertFalse($page->canDelete());
|
|
|
|
$this->assertFalse($page->canAddChildren());
|
|
|
|
$this->assertFalse($page->canView());
|
|
|
|
}
|
|
|
|
|
2016-06-30 07:33:46 +02:00
|
|
|
public function testCanPublish() {
|
|
|
|
$page = new SiteTreeTest_ClassD();
|
|
|
|
Session::clear("loggedInAs");
|
|
|
|
|
|
|
|
// Test that false overrides any can_publish = true
|
|
|
|
SiteTreeTest_ExtensionA::$can_publish = true;
|
|
|
|
SiteTreeTest_ExtensionB::$can_publish = false;
|
|
|
|
$this->assertFalse($page->canPublish());
|
|
|
|
SiteTreeTest_ExtensionA::$can_publish = false;
|
|
|
|
SiteTreeTest_ExtensionB::$can_publish = true;
|
|
|
|
$this->assertFalse($page->canPublish());
|
|
|
|
|
|
|
|
// Test null extensions fall back to canEdit()
|
|
|
|
SiteTreeTest_ExtensionA::$can_publish = null;
|
|
|
|
SiteTreeTest_ExtensionB::$can_publish = null;
|
|
|
|
$page->canEditValue = true;
|
|
|
|
$this->assertTrue($page->canPublish());
|
|
|
|
$page->canEditValue = false;
|
|
|
|
$this->assertFalse($page->canPublish());
|
|
|
|
}
|
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**#@+
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
|
|
|
|
class SiteTreeTest_PageNode extends Page implements TestOnly { }
|
|
|
|
class SiteTreeTest_PageNode_Controller extends Page_Controller implements TestOnly {
|
|
|
|
}
|
|
|
|
|
|
|
|
class SiteTreeTest_Conflicted extends Page implements TestOnly { }
|
|
|
|
class SiteTreeTest_Conflicted_Controller extends Page_Controller implements TestOnly {
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $allowed_actions = array (
|
2011-03-18 04:23:47 +01:00
|
|
|
'conflicted-action'
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
public function hasActionTemplate($template) {
|
|
|
|
if($template == 'conflicted-template') {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return parent::hasActionTemplate($template);
|
|
|
|
}
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-03-18 04:23:47 +01:00
|
|
|
}
|
|
|
|
|
2011-04-06 12:16:46 +02:00
|
|
|
class SiteTreeTest_NullHtmlCleaner extends HTMLCleaner {
|
2012-09-19 12:07:46 +02:00
|
|
|
public function cleanHTML($html) {
|
2011-04-06 12:16:46 +02:00
|
|
|
return $html;
|
|
|
|
}
|
2011-10-06 16:47:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class SiteTreeTest_ClassA extends Page implements TestOnly {
|
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $need_permission = array('ADMIN', 'CMS_ACCESS_CMSMain');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $allowed_children = array('SiteTreeTest_ClassB');
|
2011-10-06 16:47:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class SiteTreeTest_ClassB extends Page implements TestOnly {
|
|
|
|
// Also allowed subclasses
|
2016-01-06 00:42:07 +01:00
|
|
|
private static $allowed_children = array('SiteTreeTest_ClassC');
|
2011-10-06 16:47:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class SiteTreeTest_ClassC extends Page implements TestOnly {
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $allowed_children = array();
|
2011-10-06 16:47:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class SiteTreeTest_ClassD extends Page implements TestOnly {
|
|
|
|
// Only allows this class, no children classes
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $allowed_children = array('*SiteTreeTest_ClassC');
|
2016-06-30 07:33:46 +02:00
|
|
|
|
|
|
|
private static $extensions = [
|
|
|
|
'SiteTreeTest_ExtensionA',
|
|
|
|
'SiteTreeTest_ExtensionB',
|
|
|
|
];
|
|
|
|
|
|
|
|
public $canEditValue = null;
|
|
|
|
|
|
|
|
public function canEdit($member = null)
|
|
|
|
{
|
|
|
|
return isset($this->canEditValue)
|
|
|
|
? $this->canEditValue
|
|
|
|
: parent::canEdit($member);
|
|
|
|
}
|
2011-10-06 16:47:59 +02:00
|
|
|
}
|
|
|
|
|
2016-07-22 10:45:14 +02:00
|
|
|
class SiteTreeTest_ClassE extends Page implements TestOnly, HiddenClass {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-06 16:47:59 +02:00
|
|
|
class SiteTreeTest_ClassCext extends SiteTreeTest_ClassC implements TestOnly {
|
|
|
|
// Override SiteTreeTest_ClassC definitions
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $allowed_children = array('SiteTreeTest_ClassB');
|
2012-01-14 11:20:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class SiteTreeTest_NotRoot extends Page implements TestOnly {
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $can_be_root = false;
|
2012-03-29 00:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class SiteTreeTest_StageStatusInherit extends SiteTree implements TestOnly {
|
2012-09-19 12:07:46 +02:00
|
|
|
public function getStatusFlags($cached = true){
|
2012-06-12 15:55:05 +02:00
|
|
|
$flags = parent::getStatusFlags($cached);
|
2012-03-29 00:47:28 +02:00
|
|
|
$flags['inherited-class'] = "InheritedTitle";
|
|
|
|
return $flags;
|
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|
2013-06-12 12:32:42 +02:00
|
|
|
|
|
|
|
class SiteTreeTest_Extension extends DataExtension implements TestOnly {
|
|
|
|
|
|
|
|
public function augmentValidURLSegment() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-25 11:18:08 +02:00
|
|
|
}
|
2016-05-23 06:12:48 +02:00
|
|
|
|
|
|
|
class SiteTreeTest_AdminDenied extends Page implements TestOnly {
|
|
|
|
private static $extensions = array(
|
|
|
|
'SiteTreeTest_AdminDeniedExtension'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-30 07:33:46 +02:00
|
|
|
class SiteTreeTest_ExtensionA extends SiteTreeExtension implements TestOnly {
|
|
|
|
|
|
|
|
public static $can_publish = true;
|
|
|
|
|
|
|
|
public function canPublish($member)
|
|
|
|
{
|
|
|
|
return static::$can_publish;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SiteTreeTest_ExtensionB extends SiteTreeExtension implements TestOnly {
|
|
|
|
|
|
|
|
public static $can_publish = true;
|
|
|
|
|
|
|
|
public function canPublish($member)
|
|
|
|
{
|
|
|
|
return static::$can_publish;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-23 06:12:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An extension that can even deny actions to admins
|
|
|
|
*/
|
|
|
|
class SiteTreeTest_AdminDeniedExtension extends DataExtension implements TestOnly {
|
|
|
|
public function canCreate($member) { return false; }
|
|
|
|
public function canEdit($member) { return false; }
|
|
|
|
public function canDelete($member) { return false; }
|
|
|
|
public function canAddChildren() { return false; }
|
|
|
|
public function canView() { return false; }
|
|
|
|
}
|