From ff66ad791d68bbdb60bc806049b0bfb924eca1de Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 4 May 2017 16:29:43 +1200 Subject: [PATCH 1/3] FIX: updated test suite to cover supported versions --- .travis.yml | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index f64e3c1..76a6629 100755 --- a/.travis.yml +++ b/.travis.yml @@ -20,20 +20,11 @@ env: matrix: include: - - php: 7.1 + - php: 5.6 env: DB=MYSQL CORE_RELEASE=4 COVERAGE=1 - - - php: 5.5 - env: DB=MYSQL CORE_RELEASE=4 - - - php: 5.6 - env: DB=MYSQL CORE_RELEASE=4 - - php: 5.6 - env: DB=PGSQL CORE_RELEASE=4 - - php: 5.6 - env: DB=SQLITE CORE_RELEASE=4 - - php: 7.0 + env: DB=PGSQL CORE_RELEASE=4 + - php: 7.1.2 env: DB=MYSQL CORE_RELEASE=4 before_script: From 50d928101c208cd1ec3030b2d2832cc500ea2f80 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 4 May 2017 18:10:20 +1200 Subject: [PATCH 2/3] FIX: Speed up tests by simplifying fixture Requires https://github.com/silverstripe/silverstripe-framework/pull/6872 --- tests/BlogCategoryTest.php | 36 +-- tests/BlogPostFilterTest.php | 2 +- tests/BlogPostNotificationsTest.php | 4 +- tests/BlogPostTest.php | 16 +- tests/BlogTagTest.php | 38 +-- tests/BlogTagsCloudWidgetTest.php | 2 +- tests/BlogTest.php | 38 +-- tests/blog.yml | 407 ++++++++++++++++++++-------- 8 files changed, 361 insertions(+), 182 deletions(-) diff --git a/tests/BlogCategoryTest.php b/tests/BlogCategoryTest.php index d9de583..d4840f1 100755 --- a/tests/BlogCategoryTest.php +++ b/tests/BlogCategoryTest.php @@ -54,12 +54,12 @@ class BlogCategoryTest extends FunctionalTest $member->logout(); } - $this->objFromFixture(BlogPost::class, 'FirstBlogPost'); + $this->objFromFixture('SiteTree', 'FirstBlogPost'); /** * @var BlogCategory $category */ - $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory'); + $category = $this->objFromFixture('BlogCategory', 'FirstCategory'); $this->assertEquals(5, $category->BlogPosts()->count(), 'Category blog post count'); } @@ -69,7 +69,7 @@ class BlogCategoryTest extends FunctionalTest */ public function testAllowMultibyteUrlSegment() { - $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); + $blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $cat = new BlogCategory(); $cat->BlogID = $blog->ID; $cat->Title = 'تست'; @@ -84,10 +84,10 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $this->objFromFixture(Member::class, 'Admin'); + $this->objFromFixture('Member', 'Admin'); - $editor = $this->objFromFixture(Member::class, 'Editor'); - $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory'); + $editor = $this->objFromFixture('Member', 'Editor'); + $category = $this->objFromFixture('BlogCategory', 'SecondCategory'); $this->assertFalse($category->canView($editor), 'Editor should not be able to view category.'); } @@ -99,20 +99,20 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture(Member::class, 'Admin'); - $editor = $this->objFromFixture(Member::class, 'Editor'); + $admin = $this->objFromFixture('Member', 'Admin'); + $editor = $this->objFromFixture('Member', 'Editor'); - $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory'); + $category = $this->objFromFixture('BlogCategory', 'FirstCategory'); $this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); $this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); - $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory'); + $category = $this->objFromFixture('BlogCategory', 'SecondCategory'); $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.'); - $category = $this->objFromFixture(BlogCategory::class, 'ThirdCategory'); + $category = $this->objFromFixture('BlogCategory', 'ThirdCategory'); $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.'); @@ -122,8 +122,8 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture(Member::class, 'Admin'); - $editor = $this->objFromFixture(Member::class, 'Editor'); + $admin = $this->objFromFixture('Member', 'Admin'); + $editor = $this->objFromFixture('Member', 'Editor'); $category = singleton(BlogCategory::class); @@ -135,19 +135,19 @@ class BlogCategoryTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture(Member::class, 'Admin'); - $editor = $this->objFromFixture(Member::class, 'Editor'); + $admin = $this->objFromFixture('Member', 'Admin'); + $editor = $this->objFromFixture('Member', 'Editor'); - $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory'); + $category = $this->objFromFixture('BlogCategory', 'FirstCategory'); $this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); $this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.'); - $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory'); + $category = $this->objFromFixture('BlogCategory', 'SecondCategory'); $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.'); - $category = $this->objFromFixture(BlogCategory::class, 'ThirdCategory'); + $category = $this->objFromFixture('BlogCategory', 'ThirdCategory'); $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.'); } diff --git a/tests/BlogPostFilterTest.php b/tests/BlogPostFilterTest.php index c78fbc9..f627581 100755 --- a/tests/BlogPostFilterTest.php +++ b/tests/BlogPostFilterTest.php @@ -47,7 +47,7 @@ class BlogPostFilterTest extends SapphireTest /** * @var Blog $blog */ - $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); + $blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $this->assertEquals(3, $blog->AllChildren()->Count(), 'Filtered blog posts'); diff --git a/tests/BlogPostNotificationsTest.php b/tests/BlogPostNotificationsTest.php index 4129388..7757ace 100644 --- a/tests/BlogPostNotificationsTest.php +++ b/tests/BlogPostNotificationsTest.php @@ -19,7 +19,7 @@ class BlogPostNotificationsTest extends SapphireTest $this->markTestSkipped('Comments Notification module is not installed'); } - $blogPost = $this->objFromFixture(BlogPost::class, 'PostC'); + $blogPost = $this->objFromFixture('SiteTree', 'PostC'); $comment = new \SilverStripe\Comments\Model\Comment(); $comment->Comment = 'This is a comment'; $comment->write(); @@ -44,7 +44,7 @@ class BlogPostNotificationsTest extends SapphireTest if (!class_exists('CommentNotifier')) { $this->markTestSkipped('Comments Notification module is not installed'); } - $blogPost = $this->objFromFixture(BlogPost::class, 'PostC'); + $blogPost = $this->objFromFixture('SiteTree', 'PostC'); $comment = new SilverStripe\Comments\Model\Comment(); $comment->Comment = 'This is a comment'; $comment->write(); diff --git a/tests/BlogPostTest.php b/tests/BlogPostTest.php index 09bacba..b1afffa 100644 --- a/tests/BlogPostTest.php +++ b/tests/BlogPostTest.php @@ -30,8 +30,8 @@ class BlogPostTest extends SapphireTest */ public function testCanView($date, $user, $page, $canView) { - $userRecord = $this->objFromFixture(Member::class, $user); - $pageRecord = $this->objFromFixture(BlogPost::class, $page); + $userRecord = $this->objFromFixture('Member', $user); + $pageRecord = $this->objFromFixture('SiteTree', $page); DBDatetime::set_mock_now($date); $this->assertEquals($canView, $pageRecord->canView($userRecord)); } @@ -74,7 +74,7 @@ class BlogPostTest extends SapphireTest public function testCandidateAuthors() { - $blogpost = $this->objFromFixture(BlogPost::class, 'PostC'); + $blogpost = $this->objFromFixture('SiteTree', 'PostC'); $this->assertEquals(7, $blogpost->getCandidateAuthors()->count()); @@ -90,12 +90,12 @@ class BlogPostTest extends SapphireTest public function testCanViewFuturePost() { - $blogPost = $this->objFromFixture(BlogPost::class, 'NullPublishDate'); + $blogPost = $this->objFromFixture('SiteTree', 'NullPublishDate'); - $editor = $this->objFromFixture(Member::class, 'BlogEditor'); + $editor = $this->objFromFixture('Member', 'BlogEditor'); $this->assertTrue($blogPost->canView($editor)); - $visitor = $this->objFromFixture(Member::class, 'Visitor'); + $visitor = $this->objFromFixture('Member', 'Visitor'); $this->assertFalse($blogPost->canView($visitor)); } @@ -105,10 +105,10 @@ class BlogPostTest extends SapphireTest */ public function testGetDate() { - $blogPost = $this->objFromFixture(BlogPost::class, 'NullPublishDate'); + $blogPost = $this->objFromFixture('SiteTree', 'NullPublishDate'); $this->assertNull($blogPost->getDate()); - $blogPost = $this->objFromFixture(BlogPost::class, 'PostA'); + $blogPost = $this->objFromFixture('SiteTree', 'PostA'); $this->assertEquals('2012-01-09 15:00:00', $blogPost->getDate()); } } diff --git a/tests/BlogTagTest.php b/tests/BlogTagTest.php index 464a918..2a6f35f 100755 --- a/tests/BlogTagTest.php +++ b/tests/BlogTagTest.php @@ -54,12 +54,12 @@ class BlogTagTest extends FunctionalTest $member->logout(); } - $this->objFromFixture(BlogPost::class, 'FirstBlogPost'); + $this->objFromFixture('SiteTree', 'FirstBlogPost'); /** * @var BlogTag $tag */ - $tag = $this->objFromFixture(BlogTag::class, 'FirstTag'); + $tag = $this->objFromFixture('BlogTag', 'FirstTag'); $this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count'); } @@ -69,7 +69,7 @@ class BlogTagTest extends FunctionalTest */ public function testAllowMultibyteUrlSegment() { - $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); + $blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $tag = new BlogTag(); $tag->BlogID = $blog->ID; $tag->Title = 'تست'; @@ -87,15 +87,15 @@ class BlogTagTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture(Member::class, 'Admin'); - $editor = $this->objFromFixture(Member::class, 'Editor'); + $admin = $this->objFromFixture('Member', 'Admin'); + $editor = $this->objFromFixture('Member', 'Editor'); - $tag = $this->objFromFixture(BlogTag::class, 'FirstTag'); + $tag = $this->objFromFixture('BlogTag', 'FirstTag'); $this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); $this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.'); - $tag = $this->objFromFixture(BlogTag::class, 'SecondTag'); + $tag = $this->objFromFixture('BlogTag', 'SecondTag'); $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.'); @@ -105,20 +105,20 @@ class BlogTagTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture(Member::class, 'Admin'); - $editor = $this->objFromFixture(Member::class, 'Editor'); + $admin = $this->objFromFixture('Member', 'Admin'); + $editor = $this->objFromFixture('Member', 'Editor'); - $tag = $this->objFromFixture(BlogTag::class, 'FirstTag'); + $tag = $this->objFromFixture('BlogTag', 'FirstTag'); $this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); - $tag = $this->objFromFixture(BlogTag::class, 'SecondTag'); + $tag = $this->objFromFixture('BlogTag', 'SecondTag'); $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.'); - $tag = $this->objFromFixture(BlogTag::class, 'ThirdTag'); + $tag = $this->objFromFixture('BlogTag', 'ThirdTag'); $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.'); @@ -128,8 +128,8 @@ class BlogTagTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture(Member::class, 'Admin'); - $editor = $this->objFromFixture(Member::class, 'Editor'); + $admin = $this->objFromFixture('Member', 'Admin'); + $editor = $this->objFromFixture('Member', 'Editor'); $tag = singleton(BlogTag::class); @@ -141,20 +141,20 @@ class BlogTagTest extends FunctionalTest { $this->useDraftSite(); - $admin = $this->objFromFixture(Member::class, 'Admin'); - $editor = $this->objFromFixture(Member::class, 'Editor'); + $admin = $this->objFromFixture('Member', 'Admin'); + $editor = $this->objFromFixture('Member', 'Editor'); - $tag = $this->objFromFixture(BlogTag::class, 'FirstTag'); + $tag = $this->objFromFixture('BlogTag', 'FirstTag'); $this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); $this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); - $tag = $this->objFromFixture(BlogTag::class, 'SecondTag'); + $tag = $this->objFromFixture('BlogTag', 'SecondTag'); $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.'); - $tag = $this->objFromFixture(BlogTag::class, 'ThirdTag'); + $tag = $this->objFromFixture('BlogTag', 'ThirdTag'); $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.'); diff --git a/tests/BlogTagsCloudWidgetTest.php b/tests/BlogTagsCloudWidgetTest.php index 315706e..3459cc8 100644 --- a/tests/BlogTagsCloudWidgetTest.php +++ b/tests/BlogTagsCloudWidgetTest.php @@ -38,7 +38,7 @@ class BlogTagsCloudWidgetTest extends SapphireTest $this->markTestSkipped('Widgets module not installed'); } $widget = new BlogTagsCloudWidget(); - $blog = $this->objFromFixture(Blog::class, 'FourthBlog'); + $blog = $this->objFromFixture('SiteTree', 'FourthBlog'); $widget->BlogID = $blog->ID; $widget->write(); $tags = $widget->getTags()->toArray(); diff --git a/tests/BlogTest.php b/tests/BlogTest.php index 386769b..07a317f 100755 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -39,7 +39,7 @@ class BlogTest extends SapphireTest /** * @var Blog $blog */ - $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); + $blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $blog->publish('Stage', 'Live'); } @@ -66,7 +66,7 @@ class BlogTest extends SapphireTest /** * @var Blog $blog */ - $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); + $blog = $this->objFromFixture('SiteTree', 'FirstBlog'); Config::inst()->update(BlogPost::class, 'show_in_sitetree', true); $classes = $blog->getExcludedSiteTreeClassNames(); @@ -90,7 +90,7 @@ class BlogTest extends SapphireTest /** * @var Blog $blog */ - $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); + $blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $archive = $blog->getArchivedBlogPosts(2013); @@ -112,7 +112,7 @@ class BlogTest extends SapphireTest /** * @var Blog $blog */ - $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); + $blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $link = Controller::join_links($blog->Link('archive'), '2013', '10', '01'); @@ -151,7 +151,7 @@ class BlogTest extends SapphireTest */ public function testArchiveYear() { - $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); + $blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $controller = new BlogController($blog); $this->requestURL($controller, 'first-post/archive/'); $this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013'); @@ -172,47 +172,47 @@ class BlogTest extends SapphireTest /** * @var Blog $firstBlog */ - $firstBlog = $this->objFromFixture(Blog::class, 'FirstBlog'); + $firstBlog = $this->objFromFixture('SiteTree', 'FirstBlog'); /** * @var Blog $fourthBlog */ - $fourthBlog = $this->objFromFixture(Blog::class, 'FourthBlog'); + $fourthBlog = $this->objFromFixture('SiteTree', 'FourthBlog'); /** * @var BlogPost $postA */ - $postA = $this->objFromFixture(BlogPost::class, 'PostA'); + $postA = $this->objFromFixture('SiteTree', 'PostA'); /** * @var BlogPost $postB */ - $postB = $this->objFromFixture(BlogPost::class, 'PostB'); + $postB = $this->objFromFixture('SiteTree', 'PostB'); /** * @var BlogPost $postC */ - $postC = $this->objFromFixture(BlogPost::class, 'PostC'); + $postC = $this->objFromFixture('SiteTree', 'PostC'); /** * @var Member $editor */ - $editor = $this->objFromFixture(Member::class, 'BlogEditor'); + $editor = $this->objFromFixture('Member', 'BlogEditor'); /** * @var Member $writer */ - $writer = $this->objFromFixture(Member::class, 'Writer'); + $writer = $this->objFromFixture('Member', 'Writer'); /** * @var Member $contributor */ - $contributor = $this->objFromFixture(Member::class, 'Contributor'); + $contributor = $this->objFromFixture('Member', 'Contributor'); /** * @var Member $visitor */ - $visitor = $this->objFromFixture(Member::class, 'Visitor'); + $visitor = $this->objFromFixture('Member', 'Visitor'); $this->assertEquals('Editor', $fourthBlog->RoleOf($editor)); $this->assertEquals('Contributor', $fourthBlog->RoleOf($contributor)); @@ -290,7 +290,7 @@ class BlogTest extends SapphireTest public function testFilteredCategories() { - $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); + $blog = $this->objFromFixture('SiteTree', 'FirstBlog'); $controller = new BlogController($blog); // Root url @@ -309,10 +309,10 @@ class BlogTest extends SapphireTest ); // Posts - $firstPostID = $this->idFromFixture(BlogPost::class, 'FirstBlogPost'); - $secondPostID = $this->idFromFixture(BlogPost::class, 'SecondBlogPost'); - $firstFuturePostID = $this->idFromFixture(BlogPost::class, 'FirstFutureBlogPost'); - $secondFuturePostID = $this->idFromFixture(BlogPost::class, 'SecondFutureBlogPost'); + $firstPostID = $this->idFromFixture('SiteTree', 'FirstBlogPost'); + $secondPostID = $this->idFromFixture('SiteTree', 'SecondBlogPost'); + $firstFuturePostID = $this->idFromFixture('SiteTree', 'FirstFutureBlogPost'); + $secondFuturePostID = $this->idFromFixture('SiteTree', 'SecondFutureBlogPost'); // Request first tag $this->requestURL($controller, 'first-post/tag/first-tag'); diff --git a/tests/blog.yml b/tests/blog.yml index 79a09f3..b2d55b6 100755 --- a/tests/blog.yml +++ b/tests/blog.yml @@ -1,6 +1,7 @@ # Mock date is set to 2013-10-01 20:00:00 +# Write to tables rather than dataobjects for performance -SilverStripe\Security\Group: +Group: Administrators: Title: Administrators Editors: @@ -9,193 +10,371 @@ SilverStripe\Security\Group: Title: Blog Users Code: blogusers -SilverStripe\Security\Permission: +Permission: Administrators: Code: ADMIN - Group: =>SilverStripe\Security\Group.Administrators + GroupID: =>Group.Administrators Editors: Code: CMS_ACCESS_CMSMain - Group: =>SilverStripe\Security\Group.Editors + GroupID: =>Group.Editors BlogUsers: Code: CMS_ACCESS_CMSMain - Group: =>SilverStripe\Security\Group.BlogUsers + GroupID: =>Group.BlogUsers -SilverStripe\SiteConfig\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\Security\Member: +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: FirstName: Test Surname: Administrator - Groups: =>SilverStripe\Security\Group.Administrators Editor: FirstName: Test Surname: Editor - Groups: =>SilverStripe\Security\Group.Editors BlogEditor: FirstName: Blog Surname: Editor - Groups: =>SilverStripe\Security\Group.BlogUsers Writer: FirstName: Blog Surname: Writer - Groups: =>SilverStripe\Security\Group.BlogUsers Contributor: FirstName: Blog Surname: Contributor - Groups: =>SilverStripe\Security\Group.BlogUsers Visitor: FirstName: Blog Surname: Visitor -SilverStripe\Blog\Model\Blog: +Group_Members: + Admin: + MemberID: =>Member.Admin + GroupID: =>Group.Administrators + Editor: + MemberID: =>Member.Editor + GroupID: =>Group.Editors + BlogEditor: + MemberID: =>Member.BlogEditor + GroupID: =>Group.BlogUsers + Writer: + MemberID: =>Member.Writer + GroupID: =>Group.BlogUsers + Contributor: + MemberID: =>Member.Contributor + GroupID: =>Group.BlogUsers + +SiteTree: FirstBlog: + ClassName: SilverStripe\Blog\Model\Blog Title: 'First Blog' + URLSegment: 'first-blog' SecondBlog: + ClassName: SilverStripe\Blog\Model\Blog Title: 'Second Blog' CanViewType: 'OnlyTheseUsers' CanEditType: 'OnlyTheseUsers' - ViewerGroups: =>SilverStripe\Security\Group.Administrators - EditorGroups: =>SilverStripe\Security\Group.Administrators + URLSegment: 'second-blog' ThirdBlog: + ClassName: SilverStripe\Blog\Model\Blog Title: 'Third Blog' CanEditType: 'OnlyTheseUsers' - EditorGroups: =>SilverStripe\Security\Group.Editors + URLSegment: 'third-blog' FourthBlog: + ClassName: SilverStripe\Blog\Model\Blog Title: 'Fourth Blog' - Editors: =>SilverStripe\Security\Member.BlogEditor - Writers: =>SilverStripe\Security\Member.Writer - Contributors: =>SilverStripe\Security\Member.Contributor + URLSegment: 'fourth-blog' -SilverStripe\Blog\Model\BlogTag: + FirstBlogPost: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'First Post' + URLSegment: first-post + ParentID: =>SiteTree.FirstBlog + SecondBlogPost: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'Second Post' + URLSegment: second-post + ParentID: =>SiteTree.FirstBlog + ThirdBlogPost: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'Old Post' + URLSegment: old-post + ParentID: =>SiteTree.FirstBlog + FirstFutureBlogPost: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'Future Post' + URLSegment: future-post + ParentID: =>SiteTree.FirstBlog + SecondFutureBlogPost: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'Future Post 2' + URLSegment: future-post-2 + ParentID: =>SiteTree.FirstBlog + PostA: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'One Post' + ParentID: =>SiteTree.FourthBlog + PostB: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'Second Post' + ParentID: =>SiteTree.FourthBlog + PostC: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'Third Post' + ParentID: =>SiteTree.FourthBlog + NullPublishDate: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'No publish date' + ParentID: =>SiteTree.FourthBlog + + #Posts for the tag cloud widget test + TaggedPost1: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'Tagged Post 1' + URLSegment: tagged-post-1 + ParentID: =>SiteTree.FourthBlog + TaggedPost2: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'Tagged Post 2' + URLSegment: tagged-post-2 + ParentID: =>SiteTree.FourthBlog + TaggedPost3: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'Tagged Post 3' + URLSegment: tagged-post-3 + ParentID: =>SiteTree.FourthBlog + TaggedPost4: + ClassName: SilverStripe\Blog\Model\BlogPost + Title: 'Tagged Post 4' + URLSegment: tagged-post-4 + ParentID: =>SiteTree.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' + +Blog_Editors: + 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' - Blog: =>SilverStripe\Blog\Model\Blog.FirstBlog + BlogID: =>SiteTree.FirstBlog SecondTag: Title: 'Second Tag' URLSegment: 'second-tag' - Blog: =>SilverStripe\Blog\Model\Blog.SecondBlog + BlogID: =>SiteTree.SecondBlog ThirdTag: Title: 'Third Tag' URLSegment: 'third-tag' - Blog: =>SilverStripe\Blog\Model\Blog.ThirdBlog + BlogID: =>SiteTree.ThirdBlog #Tags for Tag Cloud widget PopularTag: Title: 'Popular' - URLSegment: 'popular-tag' - Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog + URLSegment: 'popular' + BlogID: =>SiteTree.FourthBlog CoolTag: Title: 'Cool' - URLSegment: 'cool-tag' - Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog + URLSegment: 'cool' + BlogID: =>SiteTree.FourthBlog CatTag: Title: 'Cat' - URLSegment: 'cat-tag' - Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog + URLSegment: 'cat' + BlogID: =>SiteTree.FourthBlog KiwiTag: Title: 'Kiwi' - URLSegment: 'kiwi-tag' - Blog: =>SilverStripe\Blog\Model\Blog.FourthBlog + URLSegment: 'kiwi' + BlogID: =>SiteTree.FourthBlog -SilverStripe\Blog\Model\BlogCategory: +BlogCategory: FirstCategory: Title: 'First Category' URLSegment: 'first-category' - Blog: =>SilverStripe\Blog\Model\Blog.FirstBlog + BlogID: =>SiteTree.FirstBlog SecondCategory: Title: 'Second Category' URLSegment: 'second-category' - Blog: =>SilverStripe\Blog\Model\Blog.SecondBlog + BlogID: =>SiteTree.SecondBlog ThirdCategory: Title: 'Third Category' URLSegment: 'third-category' - Blog: =>SilverStripe\Blog\Model\Blog.ThirdBlog + BlogID: =>SiteTree.ThirdBlog -SilverStripe\Blog\Model\BlogPost: +BlogPost_Tags: FirstBlogPost: - Title: 'First Post' - URLSegment: first-post - PublishDate: '2013-10-01 15:00:00' - Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog - Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag - Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory - SecondBlogPost: - Title: 'Second Post' - URLSegment: second-post - PublishDate: '2013-09-01 15:00:00' - Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog - ThirdBlogPost: - Title: 'Old Post' - URLSegment: old-post - PublishDate: '2012-01-09 15:00:00' - Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog + BlogPostID: =>SiteTree.FirstBlogPost + BlogTagID: =>BlogTag.FirstTag FirstFutureBlogPost: - Title: 'Future Post' - URLSegment: future-post - PublishDate: '2015-01-01 00:00:00' - Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag - Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory - Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog + BlogPostID: =>SiteTree.FirstFutureBlogPost + BlogTagID: =>BlogTag.FirstTag SecondFutureBlogPost: - Title: 'Future Post 2' - URLSegment: future-post-2 - PublishDate: '2013-11-01 00:00:00' - Tags: =>SilverStripe\Blog\Model\BlogTag.FirstTag - Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory - Parent: =>SilverStripe\Blog\Model\Blog.FirstBlog - PostA: - Title: 'One Post' - PublishDate: '2012-01-09 15:00:00' - Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog - Authors: =>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor - PostB: - Title: 'Second Post' - PublishDate: '2012-01-09 15:00:00' - Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog - Authors: =>SilverStripe\Security\Member.BlogEditor - PostC: - Title: 'Third Post' - PublishDate: '2012-01-09 15:00:00' - Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog - Authors: =>SilverStripe\Security\Member.BlogEditor,=>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor - NullPublishDate: - Title: 'No publish date' - PublishDate: '' - Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog - Authors: =>SilverStripe\Security\Member.BlogEditor,=>SilverStripe\Security\Member.Writer,=>SilverStripe\Security\Member.Contributor + 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 - #Posts for the tag cloud widget test - TaggedPost1: - Title: 'Tagged Post 1' - URLSegment: tagged-post-1 - PublishDate: '2012-01-09 15:00:00' - Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag,=>SilverStripe\Blog\Model\BlogTag.CoolTag - Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory - Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog - TaggedPost2: - Title: 'Tagged Post 2' - URLSegment: tagged-post-2 - 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 - Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog - TaggedPost3: - Title: 'Tagged Post 3' - URLSegment: tagged-post-3 - 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 - Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog TaggedPost4: - Title: 'Tagged Post 4' - URLSegment: tagged-post-4 - PublishDate: '2012-04-09 15:00:00' - Tags: =>SilverStripe\Blog\Model\BlogTag.PopularTag - Categories: =>SilverStripe\Blog\Model\BlogCategory.FirstCategory - Parent: =>SilverStripe\Blog\Model\Blog.FourthBlog + 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 + From f5c2537c03dfe4191715369b39f8dae8f79a1fa7 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 11 May 2017 12:29:44 +1200 Subject: [PATCH 3/3] MINOR: Add test to for blog tag urlsegment generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This behaviour confused me so adding a test to clarify that it’s intentional. --- tests/BlogTagTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/BlogTagTest.php b/tests/BlogTagTest.php index 2a6f35f..3ab1194 100755 --- a/tests/BlogTagTest.php +++ b/tests/BlogTagTest.php @@ -203,4 +203,17 @@ class BlogTagTest extends FunctionalTest $this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $messages[0]['messageType']); } } + + public function testBlogTagUrlSegmentsAreAutomaticallyUpdated() + { + $tag = new BlogTag; + $tag->Title = "a test"; + $tag->write(); + $this->assertEquals($tag->URLSegment, "a-test"); + + $tag->Title = "another test"; + $tag->write(); + $this->assertEquals($tag->URLSegment, "another-test"); + } + }