Adding tests

Adding tests to check that archive widget correctly only shows blog posts from the related blog and not any other blog.
This commit is contained in:
3Dgoo 2018-06-29 21:30:38 +09:30 committed by Robbie Averill
parent ebd135b029
commit 317729604d

View File

@ -37,16 +37,26 @@ class BlogArchiveWidgetTest extends SapphireTest
public function testArchiveMonthlyFromStage() public function testArchiveMonthlyFromStage()
{ {
$widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly'); $widgetA = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-a');
$archive = $widget->getArchive(); $archiveA = $widgetA->getArchive();
$this->assertInstanceOf(SS_List::class, $archive); $this->assertInstanceOf(SS_List::class, $archiveA);
$this->assertCount(3, $archive); $this->assertCount(3, $archiveA);
$this->assertListContains([ $this->assertListContains([
['Title' => 'August 2017'], ['Title' => 'August 2017'],
['Title' => 'September 2017'], ['Title' => 'September 2017'],
['Title' => 'May 2015'], ['Title' => 'May 2015'],
], $archive); ], $archiveA);
$widgetB = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-b');
$archiveB = $widgetB->getArchive();
$this->assertInstanceOf(SS_List::class, $archiveB);
$this->assertCount(2, $archiveB);
$this->assertListContains([
['Title' => 'March 2016'],
['Title' => 'June 2016'],
], $archiveB);
} }
public function testArchiveMonthlyFromLive() public function testArchiveMonthlyFromLive()
@ -57,7 +67,7 @@ class BlogArchiveWidgetTest extends SapphireTest
$this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly')->publishRecursive(); $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly')->publishRecursive();
Versioned::set_stage(Versioned::LIVE); Versioned::set_stage(Versioned::LIVE);
$widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly'); $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-a');
$archive = $widget->getArchive(); $archive = $widget->getArchive();
$this->assertCount(1, $archive); $this->assertCount(1, $archive);
@ -72,15 +82,24 @@ class BlogArchiveWidgetTest extends SapphireTest
public function testArchiveYearly() public function testArchiveYearly()
{ {
$widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly'); $widgetA = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly-a');
$archive = $widget->getArchive(); $archiveA = $widgetA->getArchive();
$this->assertInstanceOf(SS_List::class, $archive); $this->assertInstanceOf(SS_List::class, $archiveA);
$this->assertCount(2, $archive); $this->assertCount(2, $archiveA);
$this->assertListContains([ $this->assertListContains([
['Title' => '2017'], ['Title' => '2017'],
['Title' => '2015'], ['Title' => '2015'],
], $archive); ], $archiveA);
$widgetB = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly-b');
$archiveB = $widgetB->getArchive();
$this->assertInstanceOf('SS_List', $archiveB);
$this->assertCount(1, $archiveB);
$this->assertListContains([
['Title' => '2016'],
], $archiveB);
} }
public function testArchiveMonthlyWithNewPostsAdded() public function testArchiveMonthlyWithNewPostsAdded()
@ -88,7 +107,7 @@ class BlogArchiveWidgetTest extends SapphireTest
$original = Versioned::get_stage(); $original = Versioned::get_stage();
Versioned::set_stage('Stage'); Versioned::set_stage('Stage');
$widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly'); $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-a');
$archive = $widget->getArchive(); $archive = $widget->getArchive();
$this->assertCount(3, $archive, 'Three months are shown in the blog archive list from fixtures'); $this->assertCount(3, $archive, 'Three months are shown in the blog archive list from fixtures');
@ -96,7 +115,7 @@ class BlogArchiveWidgetTest extends SapphireTest
DBDatetime::set_mock_now('2018-01-01 12:00:00'); DBDatetime::set_mock_now('2018-01-01 12:00:00');
$newPost = new BlogPost; $newPost = new BlogPost;
$newPost->ParentID = $this->objFromFixture(Blog::class, 'my-blog')->ID; $newPost->ParentID = $this->objFromFixture(Blog::class, 'blog-a')->ID;
$newPost->Title = 'My new blog post'; $newPost->Title = 'My new blog post';
$newPost->PublishDate = '2018-01-01 08:00:00'; // Same day as the mocked now, but slightly earlier $newPost->PublishDate = '2018-01-01 08:00:00'; // Same day as the mocked now, but slightly earlier
$newPost->write(); $newPost->write();