mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
FIX merge conflicts
This commit is contained in:
commit
993846b98c
@ -117,18 +117,18 @@ class BlogArchiveWidget extends Widget
|
||||
$query = SQLSelect::create($fields, '"BlogPost' . $suffix . '"')
|
||||
->addGroupBy($publishDate)
|
||||
->addOrderBy('"PublishDate" DESC')
|
||||
->addWhere(['"PublishDate" < ?' => DBDatetime::now()->Format(DBDatetime::ISO_DATETIME)]);
|
||||
->addWhere(['"PublishDate" <= ?' => DBDatetime::now()->Format(DBDatetime::ISO_DATETIME)]);
|
||||
|
||||
$posts = $query->execute();
|
||||
$result = ArrayList::create();
|
||||
while ($next = $posts->next()) {
|
||||
foreach ($posts as $post) {
|
||||
if ($this->ArchiveType == 'Yearly') {
|
||||
$year = $next['PublishDate'];
|
||||
$year = $post['PublishDate'];
|
||||
$month = null;
|
||||
$title = $year;
|
||||
} else {
|
||||
$date = DBDate::create();
|
||||
$date->setValue(strtotime($next['PublishDate']));
|
||||
$date->setValue(strtotime($post['PublishDate']));
|
||||
|
||||
$year = $date->Format('y');
|
||||
$month = $date->Format('MM');
|
||||
|
@ -22,7 +22,7 @@ class BlogArchiveWidgetTest extends SapphireTest
|
||||
$this->markTestSkipped('Test requires silverstripe/widgets to be installed.');
|
||||
}
|
||||
|
||||
DBDatetime::set_mock_now('2017-09-20 00:00:00');
|
||||
DBDatetime::set_mock_now('2017-09-20 12:00:00');
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
@ -80,4 +80,29 @@ class BlogArchiveWidgetTest extends SapphireTest
|
||||
['Title' => '2015'],
|
||||
], $archive);
|
||||
}
|
||||
|
||||
public function testArchiveMonthlyWithNewPostsAdded()
|
||||
{
|
||||
$original = Versioned::current_stage();
|
||||
Versioned::reading_stage('Stage');
|
||||
|
||||
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
|
||||
$archive = $widget->getArchive();
|
||||
|
||||
$this->assertCount(3, $archive, 'Three months are shown in the blog archive list from fixtures');
|
||||
|
||||
SS_Datetime::set_mock_now('2018-01-01 12:00:00');
|
||||
|
||||
$newPost = new BlogPost;
|
||||
$newPost->ParentID = $this->objFromFixture('Blog', 'my-blog')->ID;
|
||||
$newPost->Title = 'My new blog post';
|
||||
$newPost->PublishDate = '2018-01-01 08:00:00'; // Same day as the mocked now, but slightly earlier
|
||||
$newPost->write();
|
||||
|
||||
$archive = $widget->getArchive();
|
||||
|
||||
$this->assertCount(4, $archive, 'Four months are shown in the blog archive list after new post added');
|
||||
|
||||
Versioned::reading_stage($original);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user