mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
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:
parent
11c99e74c8
commit
aaf3aacd9e
@ -26,16 +26,26 @@ class BlogArchiveWidgetTest extends SapphireTest
|
|||||||
|
|
||||||
public function testArchiveMonthlyFromStage()
|
public function testArchiveMonthlyFromStage()
|
||||||
{
|
{
|
||||||
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
|
$widgetA = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly-a');
|
||||||
$archive = $widget->getArchive();
|
$archiveA = $widgetA->getArchive();
|
||||||
|
|
||||||
$this->assertInstanceOf('SS_List', $archive);
|
$this->assertInstanceOf('SS_List', $archiveA);
|
||||||
$this->assertCount(3, $archive);
|
$this->assertCount(3, $archiveA);
|
||||||
$this->assertDOSContains(array(
|
$this->assertDOSContains(array(
|
||||||
array('Title' => 'August 2017'),
|
array('Title' => 'August 2017'),
|
||||||
array('Title' => 'September 2017'),
|
array('Title' => 'September 2017'),
|
||||||
array('Title' => 'May 2015'),
|
array('Title' => 'May 2015'),
|
||||||
), $archive);
|
), $archiveA);
|
||||||
|
|
||||||
|
$widgetB = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly-b');
|
||||||
|
$archiveB = $widgetB->getArchive();
|
||||||
|
|
||||||
|
$this->assertInstanceOf('SS_List', $archiveB);
|
||||||
|
$this->assertCount(2, $archiveB);
|
||||||
|
$this->assertDOSContains(array(
|
||||||
|
array('Title' => 'March 2016'),
|
||||||
|
array('Title' => 'June 2016'),
|
||||||
|
), $archiveB);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testArchiveMonthlyFromLive()
|
public function testArchiveMonthlyFromLive()
|
||||||
@ -45,7 +55,7 @@ class BlogArchiveWidgetTest extends SapphireTest
|
|||||||
$this->objFromFixture('BlogPost', 'post-b')->doPublish();
|
$this->objFromFixture('BlogPost', 'post-b')->doPublish();
|
||||||
Versioned::reading_stage('Live');
|
Versioned::reading_stage('Live');
|
||||||
|
|
||||||
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
|
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly-a');
|
||||||
$archive = $widget->getArchive();
|
$archive = $widget->getArchive();
|
||||||
|
|
||||||
$this->assertCount(1, $archive);
|
$this->assertCount(1, $archive);
|
||||||
@ -60,15 +70,24 @@ class BlogArchiveWidgetTest extends SapphireTest
|
|||||||
|
|
||||||
public function testArchiveYearly()
|
public function testArchiveYearly()
|
||||||
{
|
{
|
||||||
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-yearly');
|
$widgetA = $this->objFromFixture('BlogArchiveWidget', 'archive-yearly-a');
|
||||||
$archive = $widget->getArchive();
|
$archiveA = $widgetA->getArchive();
|
||||||
|
|
||||||
$this->assertInstanceOf('SS_List', $archive);
|
$this->assertInstanceOf('SS_List', $archiveA);
|
||||||
$this->assertCount(2, $archive);
|
$this->assertCount(2, $archiveA);
|
||||||
$this->assertDOSContains(array(
|
$this->assertDOSContains(array(
|
||||||
array('Title' => '2017'),
|
array('Title' => '2017'),
|
||||||
array('Title' => '2015'),
|
array('Title' => '2015'),
|
||||||
), $archive);
|
), $archiveA);
|
||||||
|
|
||||||
|
$widgetB = $this->objFromFixture('BlogArchiveWidget', 'archive-yearly-b');
|
||||||
|
$archiveB = $widgetB->getArchive();
|
||||||
|
|
||||||
|
$this->assertInstanceOf('SS_List', $archiveB);
|
||||||
|
$this->assertCount(1, $archiveB);
|
||||||
|
$this->assertDOSContains(array(
|
||||||
|
array('Title' => '2016'),
|
||||||
|
), $archiveB);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testArchiveMonthlyWithNewPostsAdded()
|
public function testArchiveMonthlyWithNewPostsAdded()
|
||||||
@ -76,7 +95,7 @@ class BlogArchiveWidgetTest extends SapphireTest
|
|||||||
$original = Versioned::current_stage();
|
$original = Versioned::current_stage();
|
||||||
Versioned::reading_stage('Stage');
|
Versioned::reading_stage('Stage');
|
||||||
|
|
||||||
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
|
$widget = $this->objFromFixture('BlogArchiveWidget', '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');
|
||||||
@ -84,7 +103,7 @@ class BlogArchiveWidgetTest extends SapphireTest
|
|||||||
SS_Datetime::set_mock_now('2018-01-01 12:00:00');
|
SS_Datetime::set_mock_now('2018-01-01 12:00:00');
|
||||||
|
|
||||||
$newPost = new BlogPost;
|
$newPost = new BlogPost;
|
||||||
$newPost->ParentID = $this->objFromFixture('Blog', 'my-blog')->ID;
|
$newPost->ParentID = $this->objFromFixture('Blog', '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();
|
||||||
|
Loading…
Reference in New Issue
Block a user