Merge pull request #10 from micmania1/added-blog-tests

Added category test
This commit is contained in:
Michael Strong 2014-03-23 15:18:04 +00:00
commit 6ee356158b
4 changed files with 42 additions and 2 deletions

View File

@ -406,3 +406,9 @@ class Blog_Controller extends Page_Controller {
}
}
class ExtendedBlogPost extends BlogPost implements TestOnly {
private static $show_in_sitetree = true;
}

27
tests/BlogCategoryTest.php Executable file
View File

@ -0,0 +1,27 @@
<?php
class BlogCategoryTest extends SapphireTest {
static $fixture_file = "blog.yml";
public function setUp() {
SS_Datetime::set_mock_now("2013-10-10 20:00:00");
parent::setUp();
}
/**
* Tests that any blog posts returned from $category->BlogPosts() many_many are published,
* both by normal 'save & publish' functionality and by publish date.
**/
public function testBlogPosts() {
// Ensure the user is not logged in as admin (or anybody)
$member = Member::currentUser();
if($member) $member->logout();
$post = $this->objFromFixture("BlogPost", "blogpost1");
$category = $this->objFromFixture("BlogCategory", "firstcategory");
$this->assertEquals(1, $category->BlogPosts()->count(), "Category blog post count");
}
}

View File

@ -9,14 +9,18 @@ class BlogTagTest extends SapphireTest {
parent::setUp();
}
/**
* Tests that any blog posts returned from $tag->BlogPosts() many_many are published,
* both by normal 'save & publish' functionality and by publish date.
**/
public function testBlogPosts() {
// Ensure the user is not logged in as admin (or anybody)
$member = Member::currentUser();
if($member) $member->logout();
$post = $this->objFromFixture("BlogPost", "blogpost1");
$tag = $this->objFromFixture("BlogTag", "firsttag");
$posts = $tag->BlogPosts();
$this->assertEquals(1, $posts->count(), "Tag blog post count");
$this->assertEquals(1, $tag->BlogPosts()->count(), "Tag blog post count");
}
}

View File

@ -25,6 +25,7 @@ BlogPost:
PublishDate: '2013-10-01 15:00:00'
Parent: =>Blog.firstblog
Tags: =>BlogTag.firsttag
Categories: =>BlogCategory.firstcategory
blogpost2:
Title: 'Second post'
URLSegment: second-post
@ -40,8 +41,10 @@ BlogPost:
URLSegment: future-post
PublishDate: '2015-01-01 00:00:00'
Tags: =>BlogTag.firsttag
Categories: =>BlogCategory.firstcategory
futurepost2:
Title: 'Future Post 2'
URLSegment: future-post-2
PublishDate: '2013-11-01 00:00:00'
Tags: =>BlogTag.firsttag
Categories: =>BlogCategory.firstcategory