silverstripe-framework/tests/SiteTreeTest.php
Ingo Schommer 46417f5d8a (merged from branches/roa. use "svn log -c <changeset> -g <module-svn-path>" for detailed commit message)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60354 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-08-11 03:42:59 +00:00

91 lines
2.4 KiB
PHP

<?php
/**
* @package sapphire
* @subpackage tests
*/
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) {
$obj = $this->fixture->objFromFixture('Page', $fixture);
$this->assertEquals($urlSegment, $obj->URLSegment);
}
}
/**
* Test that publication copies data to SiteTree_Live
*/
function testPublishCopiesToLiveTable() {
$obj = $this->fixture->objFromFixture('Page','about');
$obj->publish('Stage', 'Live');
$createdID = DB::query("SELECT ID FROM SiteTree_Live WHERE URLSegment = '$obj->URLSegment'")->value();
$this->assertEquals($obj->ID, $createdID);
}
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);
}
function testParentModelReturnType() {
$parent = new SiteTreeTest_PageNode();
$child = new SiteTreeTest_PageNode();
$child->setParent($parent);
$this->assertType('SiteTreeTest_PageNode', $child->Parent);
}
/**
* 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);
}
/**
* Test that saving changes creates a new version with the correct data in it.
*/
}
class SiteTreeTest_PageNode extends SiteTree implements TestOnly { }
?>