2007-08-15 08:38:41 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
2008-06-15 15:33:53 +02:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage tests
|
2008-02-25 03:10:37 +01:00
|
|
|
*/
|
2007-08-15 08:38:41 +02:00
|
|
|
class SiteTreeTest extends SapphireTest {
|
|
|
|
static $fixture_file = 'sapphire/tests/SiteTreeTest.yml';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
function testURLGeneration() {
|
|
|
|
$expectedURLs = array(
|
|
|
|
'home' => 'home',
|
|
|
|
'staff' => 'my-staff',
|
|
|
|
'about' => 'about-us',
|
|
|
|
'staffduplicate' => 'my-staff-2',
|
|
|
|
'product1' => '1-1-test-product',
|
|
|
|
'product2' => 'another-product',
|
|
|
|
'product3' => 'another-product-2',
|
|
|
|
'product4' => 'another-product-3',
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($expectedURLs as $fixture => $urlSegment) {
|
2008-08-11 01:17:51 +02:00
|
|
|
$obj = $this->fixture->objFromFixture('Page', $fixture);
|
2007-08-15 08:38:41 +02:00
|
|
|
$this->assertEquals($urlSegment, $obj->URLSegment);
|
|
|
|
}
|
|
|
|
}
|
2007-08-16 08:36:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that publication copies data to SiteTree_Live
|
|
|
|
*/
|
|
|
|
function testPublishCopiesToLiveTable() {
|
2008-08-11 01:17:51 +02:00
|
|
|
$obj = $this->fixture->objFromFixture('Page','about');
|
2007-08-16 08:36:39 +02:00
|
|
|
$obj->publish('Stage', 'Live');
|
|
|
|
|
|
|
|
$createdID = DB::query("SELECT ID FROM SiteTree_Live WHERE URLSegment = '$obj->URLSegment'")->value();
|
|
|
|
$this->assertEquals($obj->ID, $createdID);
|
|
|
|
}
|
|
|
|
|
2008-07-14 13:09:44 +02:00
|
|
|
function testParentNodeCachedInMemory() {
|
|
|
|
$parent = new SiteTree();
|
|
|
|
$parent->Title = 'Section Title';
|
|
|
|
$child = new SiteTree();
|
|
|
|
$child->Title = 'Page Title';
|
|
|
|
$child->setParent($parent);
|
|
|
|
|
|
|
|
$this->assertType("SiteTree", $child->Parent);
|
|
|
|
$this->assertEquals("Section Title", $child->Parent->Title);
|
|
|
|
}
|
2007-08-16 08:36:39 +02:00
|
|
|
|
2008-07-14 13:09:44 +02:00
|
|
|
function testParentModelReturnType() {
|
2008-07-16 05:30:29 +02:00
|
|
|
$parent = new SiteTreeTest_PageNode();
|
|
|
|
$child = new SiteTreeTest_PageNode();
|
2008-07-14 13:09:44 +02:00
|
|
|
|
|
|
|
$child->setParent($parent);
|
2008-07-16 05:30:29 +02:00
|
|
|
$this->assertType('SiteTreeTest_PageNode', $child->Parent);
|
2008-07-14 13:09:44 +02:00
|
|
|
}
|
2007-08-16 08:36:39 +02:00
|
|
|
|
2008-08-11 05:42:59 +02:00
|
|
|
/**
|
|
|
|
* Confirm that DataObject::get_one() gets records from SiteTree_Live
|
|
|
|
*/
|
|
|
|
function testGetOneFromLive() {
|
|
|
|
$s = new SiteTree();
|
|
|
|
$s->Title = "V1";
|
|
|
|
$s->URLSegment = "get-one-test-page";
|
|
|
|
$s->write();
|
|
|
|
$s->publish("Stage", "Live");
|
|
|
|
$s->Title = "V2";
|
|
|
|
$s->write();
|
|
|
|
|
|
|
|
$oldStage = Versioned::current_stage();
|
|
|
|
Versioned::reading_stage('Live');
|
|
|
|
|
|
|
|
$checkSiteTree = DataObject::get_one("SiteTree", "URLSegment = 'get-one-test-page'");
|
|
|
|
$this->assertEquals("V1", $checkSiteTree->Title);
|
|
|
|
}
|
|
|
|
|
2008-08-12 01:51:45 +02:00
|
|
|
function testChidrenOfRootAreTopLevelPages() {
|
|
|
|
$pages = DataObject::get("SiteTree");
|
|
|
|
foreach($pages as $page) $page->publish('Stage', 'Live');
|
|
|
|
unset($pages);
|
|
|
|
|
|
|
|
/* If we create a new SiteTree object with ID = 0 */
|
|
|
|
$obj = new SiteTree();
|
|
|
|
/* Then its children should be the top-level pages */
|
|
|
|
$stageChildren = $obj->stageChildren()->toDropDownMap('ID','Title');
|
|
|
|
$liveChildren = $obj->liveChildren()->toDropDownMap('ID','Title');
|
|
|
|
$allChildren = $obj->AllChildrenIncludingDeleted()->toDropDownMap('ID','Title');
|
|
|
|
|
|
|
|
$this->assertContains('Home', $stageChildren);
|
|
|
|
$this->assertContains('Products', $stageChildren);
|
|
|
|
$this->assertNotContains('Staff', $stageChildren);
|
|
|
|
|
|
|
|
$this->assertContains('Home', $liveChildren);
|
|
|
|
$this->assertContains('Products', $liveChildren);
|
|
|
|
$this->assertNotContains('Staff', $liveChildren);
|
|
|
|
|
|
|
|
$this->assertContains('Home', $allChildren);
|
|
|
|
$this->assertContains('Products', $allChildren);
|
|
|
|
$this->assertNotContains('Staff', $allChildren);
|
|
|
|
}
|
2008-08-11 05:42:59 +02:00
|
|
|
|
2008-07-14 13:09:44 +02:00
|
|
|
}
|
|
|
|
|
2008-07-16 05:30:29 +02:00
|
|
|
class SiteTreeTest_PageNode extends SiteTree implements TestOnly { }
|
2008-07-14 13:09:44 +02:00
|
|
|
|
|
|
|
?>
|