MINOR: Added some more tests

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@76254 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-05-06 05:45:28 +00:00
parent 6cdc1feab6
commit 1a996a776f
4 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,57 @@
<?php
class HierarchyTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/model/HierarchyTest.yml';
/**
* Test Hierarchy::AllHistoricalChildren().
*/
function testAllHistoricalChildren() {
// Delete some pages
$this->objFromFixture('Page', 'page2b')->delete();
$this->objFromFixture('Page', 'page3a')->delete();
$this->objFromFixture('Page', 'page3')->delete();
// Check that page1-3 appear at the top level of the AllHistoricalChildren tree
$this->assertEquals(array("Page 1", "Page 2", "Page 3"),
singleton('Page')->AllHistoricalChildren()->column('Title'));
// Check that both page 2 children are returned
$page2 = $this->objFromFixture('Page', 'page2');
$this->assertEquals(array("Page 2a", "Page 2b"),
$page2->AllHistoricalChildren()->column('Title'));
// Page 3 has been deleted; let's bring it back from the grave
$page3 = Versioned::get_including_deleted("SiteTree", "Title = 'Page 3'")->First();
// Check that both page 3 children are returned
$this->assertEquals(array("Page 3a", "Page 3b"),
$page3->AllHistoricalChildren()->column('Title'));
}
/**
* Test that you can call Hierarchy::markExpanded/Unexpanded/Open() on a page, and that
* calling Hierarchy::isMarked() on a different instance of that object will return true.
*/
function testItemMarkingIsntRestrictedToSpecificInstance() {
// Mark a few pages
$this->objFromFixture('Page', 'page2')->markExpanded();
$this->objFromFixture('Page', 'page2a')->markExpanded();
$this->objFromFixture('Page', 'page2b')->markExpanded();
$this->objFromFixture('Page', 'page3')->markUnexpanded();
// Query some pages in a different context and check their m
$pages = DataObject::get("Page");
$marked = $expanded = array();
foreach($pages as $page) {
if($page->isMarked()) $marked[] = $page->Title;
if($page->isExpanded()) $expanded[] = $page->Title;
}
$this->assertEquals(array('Page 2', 'Page 3', 'Page 2a', 'Page 2b'), $marked);
$this->assertEquals(array('Page 2', 'Page 2a', 'Page 2b'), $expanded);
}
}

View File

@ -0,0 +1,19 @@
Page:
page1:
Title: Page 1
page2:
Title: Page 2
page3:
Title: Page 3
page2a:
Parent: =>Page.page2
Title: Page 2a
page2b:
Parent: =>Page.page2
Title: Page 2b
page3a:
Parent: =>Page.page3
Title: Page 3a
page3b:
Parent: =>Page.page3
Title: Page 3b

View File

@ -0,0 +1,30 @@
<?php
class VersionedTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/model/VersionedTest.yml';
/**
* Test Versioned::get_including_deleted()
*/
function testGetIncludingDeleted() {
// Delete a page
$this->objFromFixture('Page', 'page3')->delete();
// Get all items, ignoring deleted
$remainingPages = DataObject::get("SiteTree", "ParentID = 0");
// Check that page 3 has gone
$this->assertEquals(array("Page 1", "Page 2"), $remainingPages->column('Title'));
// Get all including deleted
$allPages = Versioned::get_including_deleted("SiteTree", "ParentID = 0");
// Check that page 3 is still there
$this->assertEquals(array("Page 1", "Page 2", "Page 3"), $allPages->column('Title'));
// Check that this still works if we switch to reading the other stage
Versioned::reading_stage("Live");
$allPages = Versioned::get_including_deleted("SiteTree", "ParentID = 0");
$this->assertEquals(array("Page 1", "Page 2", "Page 3"), $allPages->column('Title'));
}
}

View File

@ -0,0 +1,19 @@
Page:
page1:
Title: Page 1
page2:
Title: Page 2
page3:
Title: Page 3
page2a:
Parent: =>Page.page2
Title: Page 2a
page2b:
Parent: =>Page.page2
Title: Page 2b
page3a:
Parent: =>Page.page3
Title: Page 3a
page3b:
Parent: =>Page.page3
Title: Page 3b