total refactor of blog.yml for tests, use classes properly

This commit is contained in:
Andrew Aitken-Fincham 2017-07-04 18:01:39 +01:00
parent a62ce1081a
commit ffc12f53bc
8 changed files with 237 additions and 360 deletions

View File

@ -54,12 +54,12 @@ class BlogCategoryTest extends FunctionalTest
$member->logout(); $member->logout();
} }
$this->objFromFixture('SiteTree', 'FirstBlogPost'); $this->objFromFixture(BlogPost::class, 'FirstBlogPost');
/** /**
* @var BlogCategory $category * @var BlogCategory $category
*/ */
$category = $this->objFromFixture('BlogCategory', 'FirstCategory'); $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory');
$this->assertEquals(5, $category->BlogPosts()->count(), 'Category blog post count'); $this->assertEquals(5, $category->BlogPosts()->count(), 'Category blog post count');
} }
@ -69,7 +69,7 @@ class BlogCategoryTest extends FunctionalTest
*/ */
public function testAllowMultibyteUrlSegment() public function testAllowMultibyteUrlSegment()
{ {
$blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$cat = new BlogCategory(); $cat = new BlogCategory();
$cat->BlogID = $blog->ID; $cat->BlogID = $blog->ID;
$cat->Title = 'تست'; $cat->Title = 'تست';
@ -84,10 +84,10 @@ class BlogCategoryTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$this->objFromFixture('Member', 'Admin'); $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$category = $this->objFromFixture('BlogCategory', 'SecondCategory'); $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory');
$this->assertFalse($category->canView($editor), 'Editor should not be able to view category.'); $this->assertFalse($category->canView($editor), 'Editor should not be able to view category.');
} }
@ -99,20 +99,20 @@ class BlogCategoryTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$category = $this->objFromFixture('BlogCategory', 'FirstCategory'); $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory');
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); $this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.');
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); $this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
$category = $this->objFromFixture('BlogCategory', 'SecondCategory'); $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory');
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); $this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.');
$this->assertFalse($category->canEdit($editor), 'Editor should not be able to edit category.'); $this->assertFalse($category->canEdit($editor), 'Editor should not be able to edit category.');
$category = $this->objFromFixture('BlogCategory', 'ThirdCategory'); $category = $this->objFromFixture(BlogCategory::class, 'ThirdCategory');
$this->assertTrue($category->canEdit($admin), 'Admin should always be able to edit category.'); $this->assertTrue($category->canEdit($admin), 'Admin should always be able to edit category.');
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); $this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
@ -122,8 +122,8 @@ class BlogCategoryTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$category = singleton(BlogCategory::class); $category = singleton(BlogCategory::class);
@ -135,19 +135,19 @@ class BlogCategoryTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$category = $this->objFromFixture('BlogCategory', 'FirstCategory'); $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory');
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); $this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.');
$this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.'); $this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.');
$category = $this->objFromFixture('BlogCategory', 'SecondCategory'); $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory');
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); $this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.');
$this->assertFalse($category->canDelete($editor), 'Editor should not be able to delete category.'); $this->assertFalse($category->canDelete($editor), 'Editor should not be able to delete category.');
$category = $this->objFromFixture('BlogCategory', 'ThirdCategory'); $category = $this->objFromFixture(BlogCategory::class, 'ThirdCategory');
$this->assertTrue($category->canDelete($admin), 'Admin should always be able to delete category.'); $this->assertTrue($category->canDelete($admin), 'Admin should always be able to delete category.');
$this->assertTrue($category->canDelete($editor), 'Editor should be able to delete category.'); $this->assertTrue($category->canDelete($editor), 'Editor should be able to delete category.');
} }

View File

@ -47,7 +47,7 @@ class BlogPostFilterTest extends SapphireTest
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
$blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$this->assertEquals(3, $blog->AllChildren()->Count(), 'Filtered blog posts'); $this->assertEquals(3, $blog->AllChildren()->Count(), 'Filtered blog posts');

View File

@ -19,7 +19,7 @@ class BlogPostNotificationsTest extends SapphireTest
$this->markTestSkipped('Comments Notification module is not installed'); $this->markTestSkipped('Comments Notification module is not installed');
} }
$blogPost = $this->objFromFixture('SiteTree', 'PostC'); $blogPost = $this->objFromFixture(BlogPost::class, 'PostC');
$comment = new \SilverStripe\Comments\Model\Comment(); $comment = new \SilverStripe\Comments\Model\Comment();
$comment->Comment = 'This is a comment'; $comment->Comment = 'This is a comment';
$comment->write(); $comment->write();
@ -44,8 +44,8 @@ class BlogPostNotificationsTest extends SapphireTest
if (!class_exists('CommentNotifier')) { if (!class_exists('CommentNotifier')) {
$this->markTestSkipped('Comments Notification module is not installed'); $this->markTestSkipped('Comments Notification module is not installed');
} }
$blogPost = $this->objFromFixture('SiteTree', 'PostC'); $blogPost = $this->objFromFixture(BlogPost::class, 'PostC');
$comment = new SilverStripe\Comments\Model\Comment(); $comment = new \SilverStripe\Comments\Model\Comment();
$comment->Comment = 'This is a comment'; $comment->Comment = 'This is a comment';
$comment->write(); $comment->write();
$recipients = $blogPost->notificationRecipients( $recipients = $blogPost->notificationRecipients(

View File

@ -30,8 +30,8 @@ class BlogPostTest extends SapphireTest
*/ */
public function testCanView($date, $user, $page, $canView) public function testCanView($date, $user, $page, $canView)
{ {
$userRecord = $this->objFromFixture('Member', $user); $userRecord = $this->objFromFixture(Member::class, $user);
$pageRecord = $this->objFromFixture('SiteTree', $page); $pageRecord = $this->objFromFixture(BlogPost::class, $page);
DBDatetime::set_mock_now($date); DBDatetime::set_mock_now($date);
$this->assertEquals($canView, $pageRecord->canView($userRecord)); $this->assertEquals($canView, $pageRecord->canView($userRecord));
} }
@ -74,7 +74,7 @@ class BlogPostTest extends SapphireTest
public function testCandidateAuthors() public function testCandidateAuthors()
{ {
$blogpost = $this->objFromFixture('SiteTree', 'PostC'); $blogpost = $this->objFromFixture(BlogPost::class, 'PostC');
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count()); $this->assertEquals(7, $blogpost->getCandidateAuthors()->count());
@ -90,12 +90,12 @@ class BlogPostTest extends SapphireTest
public function testCanViewFuturePost() public function testCanViewFuturePost()
{ {
$blogPost = $this->objFromFixture('SiteTree', 'NullPublishDate'); $blogPost = $this->objFromFixture(BlogPost::class, 'NullPublishDate');
$editor = $this->objFromFixture('Member', 'BlogEditor'); $editor = $this->objFromFixture(Member::class, 'BlogEditor');
$this->assertTrue($blogPost->canView($editor)); $this->assertTrue($blogPost->canView($editor));
$visitor = $this->objFromFixture('Member', 'Visitor'); $visitor = $this->objFromFixture(Member::class, 'Visitor');
$this->assertFalse($blogPost->canView($visitor)); $this->assertFalse($blogPost->canView($visitor));
} }
@ -105,10 +105,10 @@ class BlogPostTest extends SapphireTest
*/ */
public function testGetDate() public function testGetDate()
{ {
$blogPost = $this->objFromFixture('SiteTree', 'NullPublishDate'); $blogPost = $this->objFromFixture(BlogPost::class, 'NullPublishDate');
$this->assertNull($blogPost->getDate()); $this->assertNull($blogPost->getDate());
$blogPost = $this->objFromFixture('SiteTree', 'PostA'); $blogPost = $this->objFromFixture(BlogPost::class, 'PostA');
$this->assertEquals('2012-01-09 15:00:00', $blogPost->getDate()); $this->assertEquals('2012-01-09 15:00:00', $blogPost->getDate());
} }
} }

View File

@ -54,12 +54,12 @@ class BlogTagTest extends FunctionalTest
$member->logout(); $member->logout();
} }
$this->objFromFixture('SiteTree', 'FirstBlogPost'); $this->objFromFixture(BlogPost::class, 'FirstBlogPost');
/** /**
* @var BlogTag $tag * @var BlogTag $tag
*/ */
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); $tag = $this->objFromFixture(BlogTag::class, 'FirstTag');
$this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count'); $this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count');
} }
@ -69,7 +69,7 @@ class BlogTagTest extends FunctionalTest
*/ */
public function testAllowMultibyteUrlSegment() public function testAllowMultibyteUrlSegment()
{ {
$blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$tag = new BlogTag(); $tag = new BlogTag();
$tag->BlogID = $blog->ID; $tag->BlogID = $blog->ID;
$tag->Title = 'تست'; $tag->Title = 'تست';
@ -87,15 +87,15 @@ class BlogTagTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); $tag = $this->objFromFixture(BlogTag::class, 'FirstTag');
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); $this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
$this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.'); $this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.');
$tag = $this->objFromFixture('BlogTag', 'SecondTag'); $tag = $this->objFromFixture(BlogTag::class, 'SecondTag');
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); $this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
$this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.'); $this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.');
@ -105,20 +105,20 @@ class BlogTagTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); $tag = $this->objFromFixture(BlogTag::class, 'FirstTag');
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); $this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
$tag = $this->objFromFixture('BlogTag', 'SecondTag'); $tag = $this->objFromFixture(BlogTag::class, 'SecondTag');
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); $this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
$this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.'); $this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.');
$tag = $this->objFromFixture('BlogTag', 'ThirdTag'); $tag = $this->objFromFixture(BlogTag::class, 'ThirdTag');
$this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.'); $this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.');
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
@ -128,8 +128,8 @@ class BlogTagTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$tag = singleton(BlogTag::class); $tag = singleton(BlogTag::class);
@ -141,20 +141,20 @@ class BlogTagTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); $tag = $this->objFromFixture(BlogTag::class, 'FirstTag');
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); $this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); $this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
$tag = $this->objFromFixture('BlogTag', 'SecondTag'); $tag = $this->objFromFixture(BlogTag::class, 'SecondTag');
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); $this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
$this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.'); $this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.');
$tag = $this->objFromFixture('BlogTag', 'ThirdTag'); $tag = $this->objFromFixture(BlogTag::class, 'ThirdTag');
$this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.'); $this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.');
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); $this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');

View File

@ -38,7 +38,7 @@ class BlogTagsCloudWidgetTest extends SapphireTest
$this->markTestSkipped('Widgets module not installed'); $this->markTestSkipped('Widgets module not installed');
} }
$widget = new BlogTagsCloudWidget(); $widget = new BlogTagsCloudWidget();
$blog = $this->objFromFixture('SiteTree', 'FourthBlog'); $blog = $this->objFromFixture(Blog::class, 'FourthBlog');
$widget->BlogID = $blog->ID; $widget->BlogID = $blog->ID;
$widget->write(); $widget->write();
$tags = $widget->getTags()->toArray(); $tags = $widget->getTags()->toArray();

View File

@ -9,6 +9,7 @@ use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Session;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\DataModel; use SilverStripe\ORM\DataModel;
@ -39,7 +40,7 @@ class BlogTest extends SapphireTest
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
$blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$blog->publish('Stage', 'Live'); $blog->publish('Stage', 'Live');
} }
@ -66,7 +67,7 @@ class BlogTest extends SapphireTest
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
$blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
Config::inst()->update(BlogPost::class, 'show_in_sitetree', true); Config::inst()->update(BlogPost::class, 'show_in_sitetree', true);
$classes = $blog->getExcludedSiteTreeClassNames(); $classes = $blog->getExcludedSiteTreeClassNames();
@ -90,7 +91,7 @@ class BlogTest extends SapphireTest
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
$blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$archive = $blog->getArchivedBlogPosts(2013); $archive = $blog->getArchivedBlogPosts(2013);
@ -112,7 +113,7 @@ class BlogTest extends SapphireTest
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
$blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$link = Controller::join_links($blog->Link('archive'), '2013', '10', '01'); $link = Controller::join_links($blog->Link('archive'), '2013', '10', '01');
@ -151,7 +152,7 @@ class BlogTest extends SapphireTest
*/ */
public function testArchiveYear() public function testArchiveYear()
{ {
$blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$controller = new BlogController($blog); $controller = new BlogController($blog);
$this->requestURL($controller, 'first-post/archive/'); $this->requestURL($controller, 'first-post/archive/');
$this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013'); $this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013');
@ -172,47 +173,47 @@ class BlogTest extends SapphireTest
/** /**
* @var Blog $firstBlog * @var Blog $firstBlog
*/ */
$firstBlog = $this->objFromFixture('SiteTree', 'FirstBlog'); $firstBlog = $this->objFromFixture(Blog::class, 'FirstBlog');
/** /**
* @var Blog $fourthBlog * @var Blog $fourthBlog
*/ */
$fourthBlog = $this->objFromFixture('SiteTree', 'FourthBlog'); $fourthBlog = $this->objFromFixture(Blog::class, 'FourthBlog');
/** /**
* @var BlogPost $postA * @var BlogPost $postA
*/ */
$postA = $this->objFromFixture('SiteTree', 'PostA'); $postA = $this->objFromFixture(BlogPost::class, 'PostA');
/** /**
* @var BlogPost $postB * @var BlogPost $postB
*/ */
$postB = $this->objFromFixture('SiteTree', 'PostB'); $postB = $this->objFromFixture(BlogPost::class, 'PostB');
/** /**
* @var BlogPost $postC * @var BlogPost $postC
*/ */
$postC = $this->objFromFixture('SiteTree', 'PostC'); $postC = $this->objFromFixture(BlogPost::class, 'PostC');
/** /**
* @var Member $editor * @var Member $editor
*/ */
$editor = $this->objFromFixture('Member', 'BlogEditor'); $editor = $this->objFromFixture(Member::class, 'BlogEditor');
/** /**
* @var Member $writer * @var Member $writer
*/ */
$writer = $this->objFromFixture('Member', 'Writer'); $writer = $this->objFromFixture(Member::class, 'Writer');
/** /**
* @var Member $contributor * @var Member $contributor
*/ */
$contributor = $this->objFromFixture('Member', 'Contributor'); $contributor = $this->objFromFixture(Member::class, 'Contributor');
/** /**
* @var Member $visitor * @var Member $visitor
*/ */
$visitor = $this->objFromFixture('Member', 'Visitor'); $visitor = $this->objFromFixture(Member::class, 'Visitor');
$this->assertEquals('Editor', $fourthBlog->RoleOf($editor)); $this->assertEquals('Editor', $fourthBlog->RoleOf($editor));
$this->assertEquals('Contributor', $fourthBlog->RoleOf($contributor)); $this->assertEquals('Contributor', $fourthBlog->RoleOf($contributor));
@ -288,31 +289,37 @@ class BlogTest extends SapphireTest
$this->assertFalse($postC->canPublish($visitor)); $this->assertFalse($postC->canPublish($visitor));
} }
public function testFilteredCategories() public function testFilteredCategoriesRoot()
{ {
$blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$controller = new BlogController($blog); $controller = new BlogController($blog);
// Root url
$this->requestURL($controller, 'first-post'); $this->requestURL($controller, 'first-post');
$this->assertIDsEquals( $this->assertIDsEquals(
$blog->AllChildren()->column('ID'), $blog->AllChildren()->column('ID'),
$controller->PaginatedList()->column('ID') $controller->PaginatedList()->column('ID')
); );
}
public function testFilteredCategoriesRSS()
// RSS {
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$controller = new BlogController($blog);
$this->requestURL($controller, 'first-post/rss'); $this->requestURL($controller, 'first-post/rss');
$this->assertIDsEquals( $this->assertIDsEquals(
$blog->AllChildren()->column('ID'), $blog->AllChildren()->column('ID'),
$controller->PaginatedList()->column('ID') $controller->PaginatedList()->column('ID')
); );
}
public function testFilteredCategoriesTags()
{
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$controller = new BlogController($blog);
// Posts // Posts
$firstPostID = $this->idFromFixture('SiteTree', 'FirstBlogPost'); $firstPostID = $this->idFromFixture(BlogPost::class, 'FirstBlogPost');
$secondPostID = $this->idFromFixture('SiteTree', 'SecondBlogPost'); $firstFuturePostID = $this->idFromFixture(BlogPost::class, 'FirstFutureBlogPost');
$firstFuturePostID = $this->idFromFixture('SiteTree', 'FirstFutureBlogPost'); $secondFuturePostID = $this->idFromFixture(BlogPost::class, 'SecondFutureBlogPost');
$secondFuturePostID = $this->idFromFixture('SiteTree', 'SecondFutureBlogPost');
// Request first tag // Request first tag
$this->requestURL($controller, 'first-post/tag/first-tag'); $this->requestURL($controller, 'first-post/tag/first-tag');
@ -320,6 +327,17 @@ class BlogTest extends SapphireTest
array($firstPostID, $firstFuturePostID, $secondFuturePostID), array($firstPostID, $firstFuturePostID, $secondFuturePostID),
$controller->PaginatedList() $controller->PaginatedList()
); );
}
public function testFilteredCategoriesArchive()
{
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$controller = new BlogController($blog);
// Posts
$firstPostID = $this->idFromFixture(BlogPost::class, 'FirstBlogPost');
$secondPostID = $this->idFromFixture(BlogPost::class, 'SecondBlogPost');
$secondFuturePostID = $this->idFromFixture(BlogPost::class, 'SecondFutureBlogPost');
// Request 2013 posts // Request 2013 posts
$this->requestURL($controller, 'first-post/archive/2013'); $this->requestURL($controller, 'first-post/archive/2013');
@ -340,8 +358,13 @@ class BlogTest extends SapphireTest
$request = new HTTPRequest('get', $url); $request = new HTTPRequest('get', $url);
$request->match('$URLSegment//$Action/$ID/$OtherID'); $request->match('$URLSegment//$Action/$ID/$OtherID');
$request->shift(); $request->shift();
$session = new Session(null);
$session->start($request);
$request->setSession($session);
$controller->doInit(); $controller->doInit();
$controller->handleRequest($request, new DataModel()); $controller->handleRequest($request);
$session->clearAll();
$session->destroy();
} }
/** /**

View File

@ -1,47 +1,6 @@
# Mock date is set to 2013-10-01 20:00:00 # Mock date is set to 2013-10-01 20:00:00
# Write to tables rather than dataobjects for performance # Write to tables rather than dataobjects for performance
SilverStripe\Security\Member:
Group:
Administrators:
Title: Administrators
Editors:
Title: Editors
BlogUsers:
Title: Blog Users
Code: blogusers
Permission:
Administrators:
Code: ADMIN
GroupID: =>Group.Administrators
Editors:
Code: CMS_ACCESS_CMSMain
GroupID: =>Group.Editors
BlogUsers:
Code: CMS_ACCESS_CMSMain
GroupID: =>Group.BlogUsers
SiteConfig:
Default:
CanEditType: 'OnlyTheseUsers'
CanCreateTopLevelType: 'OnlyTheseUsers'
SiteConfig_EditorGroups:
A:
SiteConfigID: =>SiteConfig.Default
GroupID: =>Group.Administrators
B:
SiteConfigID: =>SiteConfig.Default
GroupID: =>Group.Editors
SiteConfig_CreateTopLevelGroups:
A:
SiteConfigID: =>SiteConfig.Default
GroupID: =>Group.Administrators
B:
SiteConfigID: =>SiteConfig.Default
GroupID: =>Group.Editors
Member:
Admin: Admin:
FirstName: Test FirstName: Test
Surname: Administrator Surname: Administrator
@ -61,24 +20,46 @@ Member:
FirstName: Blog FirstName: Blog
Surname: Visitor Surname: Visitor
Group_Members: SilverStripe\Security\Group:
Admin: Administrators:
MemberID: =>Member.Admin Title: Administrators
GroupID: =>Group.Administrators Members:
Editor: - =>SilverStripe\Security\Member.Admin
MemberID: =>Member.Editor Editors:
GroupID: =>Group.Editors Title: Editors
BlogEditor: Members:
MemberID: =>Member.BlogEditor - =>SilverStripe\Security\Member.Editor
GroupID: =>Group.BlogUsers BlogUsers:
Writer: Title: Blog Users
MemberID: =>Member.Writer Code: blogusers
GroupID: =>Group.BlogUsers Members:
Contributor: - =>SilverStripe\Security\Member.BlogEditor
MemberID: =>Member.Contributor - =>SilverStripe\Security\Member.Writer
GroupID: =>Group.BlogUsers - =>SilverStripe\Security\Member.Contributor
SiteTree: SilverStripe\Security\Permission:
Administrators:
Code: ADMIN
Group: =>SilverStripe\Security\Group.Administrators
Editors:
Code: CMS_ACCESS_CMSMain
Group: =>SilverStripe\Security\Group.Editors
BlogUsers:
Code: CMS_ACCESS_CMSMain
Group: =>SilverStripe\Security\Group.BlogUsers
SilverStripe\SiteConfig\SiteConfig:
Default:
CanEditType: 'OnlyTheseUsers'
CanCreateTopLevelType: 'OnlyTheseUsers'
EditorGroups:
- =>SilverStripe\Security\Group.Administrators
- =>SilverStripe\Security\Group.Editors
CreateTopLevelGroups:
- =>SilverStripe\Security\Group.Administrators
- =>SilverStripe\Security\Group.Editors
SilverStripe\Blog\Model\Blog:
FirstBlog: FirstBlog:
ClassName: SilverStripe\Blog\Model\Blog ClassName: SilverStripe\Blog\Model\Blog
Title: 'First Blog' Title: 'First Blog'
@ -89,292 +70,165 @@ SiteTree:
CanViewType: 'OnlyTheseUsers' CanViewType: 'OnlyTheseUsers'
CanEditType: 'OnlyTheseUsers' CanEditType: 'OnlyTheseUsers'
URLSegment: 'second-blog' URLSegment: 'second-blog'
ViewerGroups:
- =>SilverStripe\Security\Group.Administrators
EditorGroups:
- =>SilverStripe\Security\Group.Administrators
ThirdBlog: ThirdBlog:
ClassName: SilverStripe\Blog\Model\Blog ClassName: SilverStripe\Blog\Model\Blog
Title: 'Third Blog' Title: 'Third Blog'
CanEditType: 'OnlyTheseUsers' CanEditType: 'OnlyTheseUsers'
URLSegment: 'third-blog' URLSegment: 'third-blog'
EditorGroups:
- =>SilverStripe\Security\Group.Editors
FourthBlog: FourthBlog:
ClassName: SilverStripe\Blog\Model\Blog ClassName: SilverStripe\Blog\Model\Blog
Title: 'Fourth Blog' Title: 'Fourth Blog'
URLSegment: 'fourth-blog' URLSegment: 'fourth-blog'
Editors: =>SilverStripe\Security\Member.BlogEditor
Writers: =>SilverStripe\Security\Member.Writer
Contributors: =>SilverStripe\Security\Member.Contributor
SilverStripe\Blog\Model\BlogCategory:
FirstCategory:
Title: 'First Category'
URLSegment: 'first-category'
BlogID: =>SilverStripe\Blog\Model\Blog.FirstBlog
SecondCategory:
Title: 'Second Category'
URLSegment: 'second-category'
BlogID: =>SilverStripe\Blog\Model\Blog.SecondBlog
ThirdCategory:
Title: 'Third Category'
URLSegment: 'third-category'
BlogID: =>SilverStripe\Blog\Model\Blog.ThirdBlog
SilverStripe\Blog\Model\BlogTag:
FirstTag:
Title: 'First Tag'
URLSegment: 'first-tag'
BlogID: =>SilverStripe\Blog\Model\Blog.FirstBlog
SecondTag:
Title: 'Second Tag'
URLSegment: 'second-tag'
BlogID: =>SilverStripe\Blog\Model\Blog.SecondBlog
ThirdTag:
Title: 'Third Tag'
URLSegment: 'third-tag'
BlogID: =>SilverStripe\Blog\Model\Blog.ThirdBlog
#Tags for Tag Cloud widget
PopularTag:
Title: 'Popular'
URLSegment: 'popular'
BlogID: =>SilverStripe\Blog\Model\Blog.FourthBlog
CoolTag:
Title: 'Cool'
URLSegment: 'cool'
BlogID: =>SilverStripe\Blog\Model\Blog.FourthBlog
CatTag:
Title: 'Cat'
URLSegment: 'cat'
BlogID: =>SilverStripe\Blog\Model\Blog.FourthBlog
KiwiTag:
Title: 'Kiwi'
URLSegment: 'kiwi'
BlogID: =>SilverStripe\Blog\Model\Blog.FourthBlog
SilverStripe\Blog\Model\BlogPost:
FirstBlogPost: FirstBlogPost:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'First Post' Title: 'First Post'
URLSegment: first-post URLSegment: first-post
ParentID: =>SiteTree.FirstBlog ParentID: =>SilverStripe\Blog\Model\Blog.FirstBlog
PublishDate: '2013-10-01 15:00:00'
Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
SecondBlogPost: SecondBlogPost:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'Second Post' Title: 'Second Post'
URLSegment: second-post URLSegment: second-post
ParentID: =>SiteTree.FirstBlog ParentID: =>SilverStripe\Blog\Model\Blog.FirstBlog
PublishDate: '2013-09-01 15:00:00'
ThirdBlogPost: ThirdBlogPost:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'Old Post' Title: 'Old Post'
URLSegment: old-post URLSegment: old-post
ParentID: =>SiteTree.FirstBlog ParentID: =>SilverStripe\Blog\Model\Blog.FirstBlog
PublishDate: '2012-01-09 15:00:00'
FirstFutureBlogPost: FirstFutureBlogPost:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'Future Post' Title: 'Future Post'
URLSegment: future-post URLSegment: future-post
ParentID: =>SiteTree.FirstBlog ParentID: =>SilverStripe\Blog\Model\Blog.FirstBlog
PublishDate: '2015-01-01 00:00:00'
Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
SecondFutureBlogPost: SecondFutureBlogPost:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'Future Post 2' Title: 'Future Post 2'
URLSegment: future-post-2 URLSegment: future-post-2
ParentID: =>SiteTree.FirstBlog ParentID: =>SilverStripe\Blog\Model\Blog.FirstBlog
PublishDate: '2013-11-01 00:00:00'
Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
PostA: PostA:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'One Post' Title: 'One Post'
ParentID: =>SiteTree.FourthBlog ParentID: =>SilverStripe\Blog\Model\Blog.FourthBlog
Authors: =>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor
PublishDate: '2012-01-09 15:00:00'
PostB: PostB:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'Second Post' Title: 'Second Post'
ParentID: =>SiteTree.FourthBlog ParentID: =>SilverStripe\Blog\Model\Blog.FourthBlog
Authors: =>SilverStripe\Security\Member.BlogEditor
PublishDate: '2012-01-09 15:00:00'
PostC: PostC:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'Third Post' Title: 'Third Post'
ParentID: =>SiteTree.FourthBlog ParentID: =>SilverStripe\Blog\Model\Blog.FourthBlog
Authors: =>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor,=>SilverStripe\Security\Member.BlogEditor
PublishDate: '2012-01-09 15:00:00'
NullPublishDate: NullPublishDate:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'No publish date' Title: 'No publish date'
ParentID: =>SiteTree.FourthBlog ParentID: =>SilverStripe\Blog\Model\Blog.FourthBlog
Authors: =>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor,=>SilverStripe\Security\Member.BlogEditor
PublishDate: null
#Posts for the tag cloud widget test #Posts for the tag cloud widget test
TaggedPost1: TaggedPost1:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'Tagged Post 1' Title: 'Tagged Post 1'
URLSegment: tagged-post-1 URLSegment: tagged-post-1
ParentID: =>SiteTree.FourthBlog ParentID: =>SilverStripe\Blog\Model\Blog.FourthBlog
PublishDate: '2012-01-09 15:00:00'
Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag,=>SilverStripe\Blog\Model\BlogTag.CoolTag
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
TaggedPost2: TaggedPost2:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'Tagged Post 2' Title: 'Tagged Post 2'
URLSegment: tagged-post-2 URLSegment: tagged-post-2
ParentID: =>SiteTree.FourthBlog ParentID: =>SilverStripe\Blog\Model\Blog.FourthBlog
PublishDate: '2012-01-09 15:00:00'
Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag,=>SilverStripe\Blog\Model\BlogTag.CoolTag,=>SilverStripe\Blog\Model\BlogTag.CatTag
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
TaggedPost3: TaggedPost3:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'Tagged Post 3' Title: 'Tagged Post 3'
URLSegment: tagged-post-3 URLSegment: tagged-post-3
ParentID: =>SiteTree.FourthBlog ParentID: =>SilverStripe\Blog\Model\Blog.FourthBlog
PublishDate: '2012-01-09 17:20:00'
Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag,=>SilverStripe\Blog\Model\BlogTag.CoolTag,=>SilverStripe\Blog\Model\BlogTag.CatTag,=>SilverStripe\Blog\Model\BlogTag.KiwiTag
Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
TaggedPost4: TaggedPost4:
ClassName: SilverStripe\Blog\Model\BlogPost ClassName: SilverStripe\Blog\Model\BlogPost
Title: 'Tagged Post 4' Title: 'Tagged Post 4'
URLSegment: tagged-post-4 URLSegment: tagged-post-4
ParentID: =>SiteTree.FourthBlog ParentID: =>SilverStripe\Blog\Model\Blog.FourthBlog
BlogPost:
FirstBlogPost:
ID: =>SiteTree.FirstBlogPost
PublishDate: '2013-10-01 15:00:00'
SecondBlogPost:
ID: =>SiteTree.SecondBlogPost
PublishDate: '2013-09-01 15:00:00'
ThirdBlogPost:
ID: =>SiteTree.ThirdBlogPost
PublishDate: '2012-01-09 15:00:00'
FirstFutureBlogPost:
ID: =>SiteTree.FirstFutureBlogPost
PublishDate: '2015-01-01 00:00:00'
SecondFutureBlogPost:
ID: =>SiteTree.SecondFutureBlogPost
PublishDate: '2013-11-01 00:00:00'
PostA:
ID: =>SiteTree.PostA
PublishDate: '2012-01-09 15:00:00'
PostB:
ID: =>SiteTree.PostB
PublishDate: '2012-01-09 15:00:00'
PostC:
ID: =>SiteTree.PostC
PublishDate: '2012-01-09 15:00:00'
NullPublishDate:
ID: =>SiteTree.NullPublishDate
PublishDate: null
#Posts for the tag cloud widget test
TaggedPost1:
ID: =>SiteTree.TaggedPost1
PublishDate: '2012-01-09 15:00:00'
TaggedPost2:
ID: =>SiteTree.TaggedPost2
PublishDate: '2012-01-09 15:00:00'
TaggedPost3:
ID: =>SiteTree.TaggedPost3
PublishDate: '2012-01-09 17:20:00'
TaggedPost4:
ID: =>SiteTree.TaggedPost4
PublishDate: '2012-04-09 15:00:00' PublishDate: '2012-04-09 15:00:00'
Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag
Blog_Editors: Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory
FourthBlog:
BlogID: =>SiteTree.FourthBlog
MemberID: =>Member.BlogEditor
Blog_Writers:
FourthBlog:
BlogID: =>SiteTree.FourthBlog
MemberID: =>Member.Writer
Blog_Contributors:
FourthBlog:
BlogID: =>SiteTree.FourthBlog
MemberID: =>Member.Contributor
SiteTree_ViewerGroups:
SecondBlog:
SiteTreeID: =>SiteTree.SecondBlog
GroupID: =>Group.Administrators
SiteTree_EditorGroups:
SecondBlog:
SiteTreeID: =>SiteTree.SecondBlog
GroupID: =>Group.Administrators
ThirdBlog:
SiteTreeID: =>SiteTree.ThirdBlog
GroupID: =>Group.Editors
BlogTag:
FirstTag:
Title: 'First Tag'
URLSegment: 'first-tag'
BlogID: =>SiteTree.FirstBlog
SecondTag:
Title: 'Second Tag'
URLSegment: 'second-tag'
BlogID: =>SiteTree.SecondBlog
ThirdTag:
Title: 'Third Tag'
URLSegment: 'third-tag'
BlogID: =>SiteTree.ThirdBlog
#Tags for Tag Cloud widget
PopularTag:
Title: 'Popular'
URLSegment: 'popular'
BlogID: =>SiteTree.FourthBlog
CoolTag:
Title: 'Cool'
URLSegment: 'cool'
BlogID: =>SiteTree.FourthBlog
CatTag:
Title: 'Cat'
URLSegment: 'cat'
BlogID: =>SiteTree.FourthBlog
KiwiTag:
Title: 'Kiwi'
URLSegment: 'kiwi'
BlogID: =>SiteTree.FourthBlog
BlogCategory:
FirstCategory:
Title: 'First Category'
URLSegment: 'first-category'
BlogID: =>SiteTree.FirstBlog
SecondCategory:
Title: 'Second Category'
URLSegment: 'second-category'
BlogID: =>SiteTree.SecondBlog
ThirdCategory:
Title: 'Third Category'
URLSegment: 'third-category'
BlogID: =>SiteTree.ThirdBlog
BlogPost_Tags:
FirstBlogPost:
BlogPostID: =>SiteTree.FirstBlogPost
BlogTagID: =>BlogTag.FirstTag
FirstFutureBlogPost:
BlogPostID: =>SiteTree.FirstFutureBlogPost
BlogTagID: =>BlogTag.FirstTag
SecondFutureBlogPost:
BlogPostID: =>SiteTree.SecondFutureBlogPost
BlogTagID: =>BlogTag.FirstTag
TaggedPost1A:
BlogPostID: =>SiteTree.TaggedPost1
BlogTagID: =>BlogTag.PopularTag
TaggedPost1B:
BlogPostID: =>SiteTree.TaggedPost1
BlogTagID: =>BlogTag.CoolTag
TaggedPost2A:
BlogPostID: =>SiteTree.TaggedPost2
BlogTagID: =>BlogTag.PopularTag
TaggedPost2B:
BlogPostID: =>SiteTree.TaggedPost2
BlogTagID: =>BlogTag.CoolTag
TaggedPost2C:
BlogPostID: =>SiteTree.TaggedPost2
BlogTagID: =>BlogTag.CatTag
TaggedPost3A:
BlogPostID: =>SiteTree.TaggedPost3
BlogTagID: =>BlogTag.PopularTag
TaggedPost3B:
BlogPostID: =>SiteTree.TaggedPost3
BlogTagID: =>BlogTag.CoolTag
TaggedPost3C:
BlogPostID: =>SiteTree.TaggedPost3
BlogTagID: =>BlogTag.CatTag
TaggedPost3D:
BlogPostID: =>SiteTree.TaggedPost3
BlogTagID: =>BlogTag.KiwiTag
TaggedPost4:
BlogPostID: =>SiteTree.TaggedPost4
BlogTagID: =>BlogTag.PopularTag
BlogPost_Categories:
FirstBlogPost:
BlogPostID: =>SiteTree.FirstBlogPost
BlogCategoryID: =>BlogCategory.FirstCategory
FirstFutureBlogPost:
BlogPostID: =>SiteTree.FirstFutureBlogPost
BlogCategoryID: =>BlogCategory.FirstCategory
SecondFutureBlogPost:
BlogPostID: =>SiteTree.SecondFutureBlogPost
BlogCategoryID: =>BlogCategory.FirstCategory
TaggedPost1:
BlogPostID: =>SiteTree.TaggedPost1
BlogCategoryID: =>BlogCategory.FirstCategory
TaggedPost2:
BlogPostID: =>SiteTree.TaggedPost2
BlogCategoryID: =>BlogCategory.FirstCategory
TaggedPost3:
BlogPostID: =>SiteTree.TaggedPost3
BlogCategoryID: =>BlogCategory.FirstCategory
TaggedPost4:
BlogPostID: =>SiteTree.TaggedPost4
BlogCategoryID: =>BlogCategory.FirstCategory
BlogPost_Authors:
PostAA:
BlogPostID: =>SiteTree.PostA
MemberID: =>Member.Writer
PostAB:
BlogPostID: =>SiteTree.PostA
MemberID: =>Member.Contributor
PostB:
BlogPostID: =>SiteTree.PostB
MemberID: =>Member.BlogEditor
PostCA:
BlogPostID: =>SiteTree.PostC
MemberID: =>Member.BlogEditor
PostCB:
BlogPostID: =>SiteTree.PostC
MemberID: =>Member.Writer
PostCC:
BlogPostID: =>SiteTree.PostC
MemberID: =>Member.Contributor
NullPublishDateA:
BlogPostID: =>SiteTree.NullPublishDate
MemberID: =>Member.BlogEditor
NullPublishDateB:
BlogPostID: =>SiteTree.NullPublishDate
MemberID: =>Member.Writer
NullPublishDateC:
BlogPostID: =>SiteTree.NullPublishDate
MemberID: =>Member.Contributor