Skip to content

Commit

Permalink
FIX: Speed up tests by simplifying fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Minnee committed May 11, 2017
1 parent ff66ad7 commit 50d9281
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 179 deletions.
36 changes: 18 additions & 18 deletions tests/BlogCategoryTest.php
Expand Up @@ -54,12 +54,12 @@ public function testBlogPosts()
$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');
}
Expand All @@ -69,7 +69,7 @@ public function testBlogPosts()
*/
public function testAllowMultibyteUrlSegment()
{
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$blog = $this->objFromFixture('SiteTree', 'FirstBlog');
$cat = new BlogCategory();
$cat->BlogID = $blog->ID;
$cat->Title = 'تست';
Expand All @@ -84,10 +84,10 @@ public function testCanView()
{
$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.');
}
Expand All @@ -99,20 +99,20 @@ public function testCanEdit()
{
$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.');
Expand All @@ -122,8 +122,8 @@ public function testCanCreate()
{
$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);

Expand All @@ -135,19 +135,19 @@ public function testCanDelete()
{
$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.');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/BlogPostFilterTest.php
Expand Up @@ -47,7 +47,7 @@ public function testFilter()
/**
* @var Blog $blog
*/
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$blog = $this->objFromFixture('SiteTree', 'FirstBlog');

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

Expand Down
4 changes: 2 additions & 2 deletions tests/BlogPostNotificationsTest.php
Expand Up @@ -19,7 +19,7 @@ public function testUpdateNotificationRecipients()
$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();
Expand All @@ -44,7 +44,7 @@ public function testUpdateNotificationSubject()
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();
Expand Down
16 changes: 8 additions & 8 deletions tests/BlogPostTest.php
Expand Up @@ -30,8 +30,8 @@ public function tearDown()
*/
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));
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public function canViewProvider()

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

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

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

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

Expand All @@ -105,10 +105,10 @@ public function testCanViewFuturePost()
*/
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());
}
}
38 changes: 19 additions & 19 deletions tests/BlogTagTest.php
Expand Up @@ -54,12 +54,12 @@ public function testBlogPosts()
$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');
}
Expand All @@ -69,7 +69,7 @@ public function testBlogPosts()
*/
public function testAllowMultibyteUrlSegment()
{
$blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$blog = $this->objFromFixture('SiteTree', '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::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.');
Expand All @@ -105,20 +105,20 @@ public function testCanEdit()
{
$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.');
Expand All @@ -128,8 +128,8 @@ public function testCanCreate()
{
$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);

Expand All @@ -141,20 +141,20 @@ public function testCanDelete()
{
$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.');
Expand Down
2 changes: 1 addition & 1 deletion tests/BlogTagsCloudWidgetTest.php
Expand Up @@ -38,7 +38,7 @@ public function testGetTags()
$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();
Expand Down

0 comments on commit 50d9281

Please sign in to comment.