MINOR improve test coverage

This commit is contained in:
Tom Rix 2010-03-19 00:15:41 +00:00
parent 5d2019f246
commit c31bb7e6b6
3 changed files with 94 additions and 3 deletions

View File

@ -36,11 +36,16 @@ class BlogTree extends Page {
* - If this page is a BlogTree, use that
* - If this page is a BlogEntry, use the parent Holder
* - Otherwise, try and find a 'top-level' BlogTree
*
* @param $page allows you to force a specific page, otherwise,
* uses current
*/
static function current() {
static function current($page = null) {
$controller = Controller::curr();
if($controller) $page = $controller->data();
if (!$page) {
$controller = Controller::curr();
if($controller) $page = $controller->data();
}
// If we _are_ a BlogTree, use us
if ($page instanceof BlogTree) return $page;

View File

@ -21,10 +21,88 @@ class BlogTreeTest extends SapphireTest {
$node = $this->objFromFixture('BlogTree', 'levelba');
$this->assertEquals($node->Entries()->Count(), 1);
$this->assertTrue($node->getCMSFields() instanceof FieldSet);
}
function testEntriesByMonth() {
$node = $this->objFromFixture('BlogTree', 'root');
$entries = $node->Entries('', '', '2008-01');
$this->assertEquals($entries->Count(), 2);
$expectedEntries = array(
'test-post-2',
'test-post-3'
);
foreach($entries as $entry) {
$this->assertContains($entry->URLSegment, $expectedEntries);
}
}
function textEntriesByYear() {
$node = $this->objFromFixture('BlogTree', 'root');
$entries = $node->Entries('', '', '2008');
$this->assertEquals($entries->Count(), 2);
$expectedEntries = array(
'test-post-2',
'test-post-3'
);
foreach($entries as $entry) {
$this->assertContains($entry->URLSegment, $expectedEntries);
}
}
function testEntriesByTag() {
$node = $this->objFromFixture('BlogTree', 'root');
$entries = $node->Entries('', 'tag3', '');
$this->assertEquals($entries->Count(), 2);
$expectedEntries = array(
'test-post-2',
'test-post-3'
);
foreach($entries as $entry) {
$this->assertContains($entry->URLSegment, $expectedEntries);
}
}
function testLandingPageFreshness() {
$node = $this->objFromFixture('BlogTree', 'root');
$this->assertEquals($node->LandingPageFreshness, '7 DAYS');
$node = $this->objFromFixture('BlogTree', 'levela');
$this->assertEquals($node->LandingPageFreshness, '2 DAYS');
$node = $this->objFromFixture('BlogTree', 'levelb');
$this->assertEquals($node->LandingPageFreshness, '7 DAYS');
}
function testGettingAssociatedBlogTree() {
$this->assertEquals(BlogTree::current($this->objFromFixture('BlogTree', 'root'))->Title, 'Root BlogTree');
$this->assertEquals(BlogTree::current($this->objFromFixture('BlogHolder', 'levelaa_blog2'))->Title, 'Level AA Blog 2');
$this->assertEquals(BlogTree::current($this->objFromFixture('BlogEntry', 'testpost3'))->Title, 'Level BA Blog');
}
function testGettingBlogHolderIDs() {
$node = $this->objFromFixture('BlogTree', 'root');
$expectedIds = array();
$expectedIds[] = $this->objFromFixture('BlogHolder', 'levelaa_blog1')->ID;
$expectedIds[] = $this->objFromFixture('BlogHolder', 'levelaa_blog2')->ID;
$expectedIds[] = $this->objFromFixture('BlogHolder', 'levelab_blog')->ID;
$expectedIds[] = $this->objFromFixture('BlogHolder', 'levelba_blog')->ID;
foreach($node->BlogHolderIDs() as $holderId) {
$this->assertContains($holderId, $expectedIds);
}
$this->assertEquals(count($node->BlogHolderIDs()), count($expectedIds));
}
function testBlogTreeURLFuctions() {
}
}
?>

View File

@ -1,12 +1,17 @@
BlogTree:
root:
Title: Root BlogTree
LandingPageFreshness: 7 DAYS
otherroot:
Title: Other root BlogTree
levela:
Title: Level A
Parent: =>BlogTree.root
LandingPageFreshness: 2 DAYS
levelb:
Title: Level B
Parent: =>BlogTree.root
LandingPageFreshness: INHERIT
levelaa:
Title: Level AA
Parent: =>BlogTree.levela
@ -17,9 +22,12 @@ BlogTree:
Title: Level BA
Parent: =>BlogTree.levelb
BlogHolder:
otherroot_holder:
Title: other root holder
levelaa_blog1:
Title: Level AA Blog 1
Parent: =>BlogTree.levelaa
LandingPageFreshness: 1 DAY
levelaa_blog2:
Title: Level AA Blog 2
Parent: =>BlogTree.levelaa