Added category tests

This commit is contained in:
micmania1 2014-03-23 14:40:53 +00:00
parent 34f708fb40
commit 96e5a75db2
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(); 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() { public function testBlogPosts() {
// Ensure the user is not logged in as admin (or anybody)
$member = Member::currentUser(); $member = Member::currentUser();
if($member) $member->logout(); if($member) $member->logout();
$post = $this->objFromFixture("BlogPost", "blogpost1"); $post = $this->objFromFixture("BlogPost", "blogpost1");
$tag = $this->objFromFixture("BlogTag", "firsttag"); $tag = $this->objFromFixture("BlogTag", "firsttag");
$posts = $tag->BlogPosts(); $this->assertEquals(1, $tag->BlogPosts()->count(), "Tag blog post count");
$this->assertEquals(1, $posts->count(), "Tag blog post count");
} }
} }

View File

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