silverstripe-blog/tests/BlogHolderTest.php
Damian Mooyman 477f857acf API Updated blog module to adhere to new rules around configuration. Static configurable properties (db, has_one, etc) are now private.
Also removed trailing ?>(newline) from various files, and cleaned up some redundant code (empty has_ones, etc).
Also noted in the code are places where various static properties should be refactored out in favour of using the Silverstripe configuration system instead. For now the bare mimimum work has been done in order to make the module work in 3.1
2013-04-02 11:38:09 +13:00

76 lines
1.8 KiB
PHP

<?php
class BlogHolderTest extends SapphireTest {
static $fixture_file = 'blog/tests/BlogTest.yml';
function testGetAllBlogEntries() {
$mainblog = $this->objFromFixture('BlogHolder', 'mainblog');
$this->assertNotNull($mainblog->Entries());
$this->assertEquals($mainblog->Entries()->Count(), 3);
}
function testEntriesByMonth() {
$mainblog = $this->objFromFixture('BlogHolder', 'mainblog');
$entries = $mainblog->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() {
$mainblog = $this->objFromFixture('BlogHolder', 'mainblog');
$entries = $mainblog->Entries('', '', '2007');
$this->assertEquals($entries->Count(), 1);
$expectedEntries = array(
'test-post'
);
foreach($entries as $entry) {
$this->assertContains($entry->URLSegment, $expectedEntries);
}
}
function testEntriesByTag() {
$mainblog = $this->objFromFixture('BlogHolder', 'mainblog');
$entries = $mainblog->Entries('', 'tag1');
$this->assertEquals($entries->Count(), 2);
$expectedEntries = array(
'test-post',
'test-post-3'
);
foreach($entries as $entry) {
$this->assertContains($entry->URLSegment, $expectedEntries);
}
}
function testBlogOwners() {
$mainblog = $this->objFromFixture('BlogHolder', 'mainblog');
$actualMembers = array_values($mainblog->blogOwners()->map('ID', 'Name')->toArray());
$expectedMembers = array(
'Admin One',
'Admin Two',
'ADMIN User', // test default admin
'Blog Owner One',
'Blog Owner Three',
'Blog Owner Two',
);
sort($actualMembers);
sort($expectedMembers);
$this->assertEquals($expectedMembers, $actualMembers);
}
}