mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 09:05:58 +00:00
MINOR improve test coverage
This commit is contained in:
parent
5d2019f246
commit
c31bb7e6b6
@ -36,11 +36,16 @@ class BlogTree extends Page {
|
|||||||
* - If this page is a BlogTree, use that
|
* - If this page is a BlogTree, use that
|
||||||
* - If this page is a BlogEntry, use the parent Holder
|
* - If this page is a BlogEntry, use the parent Holder
|
||||||
* - Otherwise, try and find a 'top-level' BlogTree
|
* - 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) {
|
||||||
|
|
||||||
|
if (!$page) {
|
||||||
$controller = Controller::curr();
|
$controller = Controller::curr();
|
||||||
if($controller) $page = $controller->data();
|
if($controller) $page = $controller->data();
|
||||||
|
}
|
||||||
|
|
||||||
// If we _are_ a BlogTree, use us
|
// If we _are_ a BlogTree, use us
|
||||||
if ($page instanceof BlogTree) return $page;
|
if ($page instanceof BlogTree) return $page;
|
||||||
|
@ -21,10 +21,88 @@ class BlogTreeTest extends SapphireTest {
|
|||||||
|
|
||||||
$node = $this->objFromFixture('BlogTree', 'levelba');
|
$node = $this->objFromFixture('BlogTree', 'levelba');
|
||||||
$this->assertEquals($node->Entries()->Count(), 1);
|
$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() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
BlogTree:
|
BlogTree:
|
||||||
root:
|
root:
|
||||||
Title: Root BlogTree
|
Title: Root BlogTree
|
||||||
|
LandingPageFreshness: 7 DAYS
|
||||||
|
otherroot:
|
||||||
|
Title: Other root BlogTree
|
||||||
levela:
|
levela:
|
||||||
Title: Level A
|
Title: Level A
|
||||||
Parent: =>BlogTree.root
|
Parent: =>BlogTree.root
|
||||||
|
LandingPageFreshness: 2 DAYS
|
||||||
levelb:
|
levelb:
|
||||||
Title: Level B
|
Title: Level B
|
||||||
Parent: =>BlogTree.root
|
Parent: =>BlogTree.root
|
||||||
|
LandingPageFreshness: INHERIT
|
||||||
levelaa:
|
levelaa:
|
||||||
Title: Level AA
|
Title: Level AA
|
||||||
Parent: =>BlogTree.levela
|
Parent: =>BlogTree.levela
|
||||||
@ -17,9 +22,12 @@ BlogTree:
|
|||||||
Title: Level BA
|
Title: Level BA
|
||||||
Parent: =>BlogTree.levelb
|
Parent: =>BlogTree.levelb
|
||||||
BlogHolder:
|
BlogHolder:
|
||||||
|
otherroot_holder:
|
||||||
|
Title: other root holder
|
||||||
levelaa_blog1:
|
levelaa_blog1:
|
||||||
Title: Level AA Blog 1
|
Title: Level AA Blog 1
|
||||||
Parent: =>BlogTree.levelaa
|
Parent: =>BlogTree.levelaa
|
||||||
|
LandingPageFreshness: 1 DAY
|
||||||
levelaa_blog2:
|
levelaa_blog2:
|
||||||
Title: Level AA Blog 2
|
Title: Level AA Blog 2
|
||||||
Parent: =>BlogTree.levelaa
|
Parent: =>BlogTree.levelaa
|
||||||
|
Loading…
x
Reference in New Issue
Block a user