Skip to content

Commit

Permalink
Merge pull request #451 from andrewandante/FIX/tests
Browse files Browse the repository at this point in the history
total refactor of blog.yml for tests, use classes properly
  • Loading branch information
dhensby authored Jul 5, 2017
2 parents a62ce10 + ffc12f5 commit 6c1e6a9
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 360 deletions.
36 changes: 18 additions & 18 deletions tests/BlogCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public function testBlogPosts()
$member->logout();
}

$this->objFromFixture('SiteTree', 'FirstBlogPost');
$this->objFromFixture(BlogPost::class, 'FirstBlogPost');

/**
* @var BlogCategory $category
*/
$category = $this->objFromFixture('BlogCategory', 'FirstCategory');
$category = $this->objFromFixture(BlogCategory::class, 'FirstCategory');

$this->assertEquals(5, $category->BlogPosts()->count(), 'Category blog post count');
}
Expand All @@ -69,7 +69,7 @@ public function testBlogPosts()
*/
public function testAllowMultibyteUrlSegment()
{
$blog = $this->objFromFixture('SiteTree', 'FirstBlog');
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$cat = new BlogCategory();
$cat->BlogID = $blog->ID;
$cat->Title = 'تست';
Expand All @@ -84,10 +84,10 @@ public function testCanView()
{
$this->useDraftSite();

$this->objFromFixture('Member', 'Admin');
$this->objFromFixture(Member::class, 'Admin');

$editor = $this->objFromFixture('Member', 'Editor');
$category = $this->objFromFixture('BlogCategory', 'SecondCategory');
$editor = $this->objFromFixture(Member::class, 'Editor');
$category = $this->objFromFixture(BlogCategory::class, 'SecondCategory');

$this->assertFalse($category->canView($editor), 'Editor should not be able to view category.');
}
Expand All @@ -99,20 +99,20 @@ public function testCanEdit()
{
$this->useDraftSite();

$admin = $this->objFromFixture('Member', 'Admin');
$editor = $this->objFromFixture('Member', 'Editor');
$admin = $this->objFromFixture(Member::class, 'Admin');
$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($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->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($editor), 'Editor should be able to edit category.');
Expand All @@ -122,8 +122,8 @@ public function testCanCreate()
{
$this->useDraftSite();

$admin = $this->objFromFixture('Member', 'Admin');
$editor = $this->objFromFixture('Member', 'Editor');
$admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture(Member::class, 'Editor');

$category = singleton(BlogCategory::class);

Expand All @@ -135,19 +135,19 @@ public function testCanDelete()
{
$this->useDraftSite();

$admin = $this->objFromFixture('Member', 'Admin');
$editor = $this->objFromFixture('Member', 'Editor');
$admin = $this->objFromFixture(Member::class, 'Admin');
$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($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->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($editor), 'Editor should be able to delete category.');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/BlogPostFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testFilter()
/**
* @var Blog $blog
*/
$blog = $this->objFromFixture('SiteTree', 'FirstBlog');
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');

$this->assertEquals(3, $blog->AllChildren()->Count(), 'Filtered blog posts');

Expand Down
6 changes: 3 additions & 3 deletions tests/BlogPostNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testUpdateNotificationRecipients()
$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->Comment = 'This is a comment';
$comment->write();
Expand All @@ -44,8 +44,8 @@ public function testUpdateNotificationSubject()
if (!class_exists('CommentNotifier')) {
$this->markTestSkipped('Comments Notification module is not installed');
}
$blogPost = $this->objFromFixture('SiteTree', 'PostC');
$comment = new SilverStripe\Comments\Model\Comment();
$blogPost = $this->objFromFixture(BlogPost::class, 'PostC');
$comment = new \SilverStripe\Comments\Model\Comment();
$comment->Comment = 'This is a comment';
$comment->write();
$recipients = $blogPost->notificationRecipients(
Expand Down
16 changes: 8 additions & 8 deletions tests/BlogPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function tearDown()
*/
public function testCanView($date, $user, $page, $canView)
{
$userRecord = $this->objFromFixture('Member', $user);
$pageRecord = $this->objFromFixture('SiteTree', $page);
$userRecord = $this->objFromFixture(Member::class, $user);
$pageRecord = $this->objFromFixture(BlogPost::class, $page);
DBDatetime::set_mock_now($date);
$this->assertEquals($canView, $pageRecord->canView($userRecord));
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public function canViewProvider()

public function testCandidateAuthors()
{
$blogpost = $this->objFromFixture('SiteTree', 'PostC');
$blogpost = $this->objFromFixture(BlogPost::class, 'PostC');

$this->assertEquals(7, $blogpost->getCandidateAuthors()->count());

Expand All @@ -90,12 +90,12 @@ public function testCandidateAuthors()

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));

$visitor = $this->objFromFixture('Member', 'Visitor');
$visitor = $this->objFromFixture(Member::class, 'Visitor');
$this->assertFalse($blogPost->canView($visitor));
}

Expand All @@ -105,10 +105,10 @@ public function testCanViewFuturePost()
*/
public function testGetDate()
{
$blogPost = $this->objFromFixture('SiteTree', 'NullPublishDate');
$blogPost = $this->objFromFixture(BlogPost::class, 'NullPublishDate');
$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());
}
}
38 changes: 19 additions & 19 deletions tests/BlogTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public function testBlogPosts()
$member->logout();
}

$this->objFromFixture('SiteTree', 'FirstBlogPost');
$this->objFromFixture(BlogPost::class, 'FirstBlogPost');

/**
* @var BlogTag $tag
*/
$tag = $this->objFromFixture('BlogTag', 'FirstTag');
$tag = $this->objFromFixture(BlogTag::class, 'FirstTag');

$this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count');
}
Expand All @@ -69,7 +69,7 @@ public function testBlogPosts()
*/
public function testAllowMultibyteUrlSegment()
{
$blog = $this->objFromFixture('SiteTree', 'FirstBlog');
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$tag = new BlogTag();
$tag->BlogID = $blog->ID;
$tag->Title = 'تست';
Expand All @@ -87,15 +87,15 @@ public function testCanView()
{
$this->useDraftSite();

$admin = $this->objFromFixture('Member', 'Admin');
$editor = $this->objFromFixture('Member', 'Editor');
$admin = $this->objFromFixture(Member::class, 'Admin');
$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($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->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.');
Expand All @@ -105,20 +105,20 @@ public function testCanEdit()
{
$this->useDraftSite();

$admin = $this->objFromFixture('Member', 'Admin');
$editor = $this->objFromFixture('Member', 'Editor');
$admin = $this->objFromFixture(Member::class, 'Admin');
$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($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->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($editor), 'Editor should be able to edit tag.');
Expand All @@ -128,8 +128,8 @@ public function testCanCreate()
{
$this->useDraftSite();

$admin = $this->objFromFixture('Member', 'Admin');
$editor = $this->objFromFixture('Member', 'Editor');
$admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture(Member::class, 'Editor');

$tag = singleton(BlogTag::class);

Expand All @@ -141,20 +141,20 @@ public function testCanDelete()
{
$this->useDraftSite();

$admin = $this->objFromFixture('Member', 'Admin');
$editor = $this->objFromFixture('Member', 'Editor');
$admin = $this->objFromFixture(Member::class, 'Admin');
$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($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->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($editor), 'Editor should be able to delete tag.');
Expand Down
2 changes: 1 addition & 1 deletion tests/BlogTagsCloudWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testGetTags()
$this->markTestSkipped('Widgets module not installed');
}
$widget = new BlogTagsCloudWidget();
$blog = $this->objFromFixture('SiteTree', 'FourthBlog');
$blog = $this->objFromFixture(Blog::class, 'FourthBlog');
$widget->BlogID = $blog->ID;
$widget->write();
$tags = $widget->getTags()->toArray();
Expand Down
Loading

0 comments on commit 6c1e6a9

Please sign in to comment.