mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
FIX Update BlogArchiveWidget and tests for SS4
This commit is contained in:
parent
75f5042d60
commit
6525f1c109
@ -127,12 +127,12 @@ class BlogArchiveWidget extends Widget
|
||||
$month = null;
|
||||
$title = $year;
|
||||
} else {
|
||||
$date = Date::create();
|
||||
$date = DBDate::create();
|
||||
$date->setValue(strtotime($next['PublishDate']));
|
||||
|
||||
$year = $date->Format('Y');
|
||||
$month = $date->Format('m');
|
||||
$title = $date->FormatI18N('%B %Y');
|
||||
$year = $date->Format('y');
|
||||
$month = $date->Format('MM');
|
||||
$title = $date->Format('MMMM y');
|
||||
}
|
||||
|
||||
$result->push(ArrayData::create([
|
||||
|
@ -1,71 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Blog\Tests;
|
||||
|
||||
use SilverStripe\Blog\Model\BlogPost;
|
||||
use SilverStripe\Blog\Widgets\BlogArchiveWidget;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\ORM\SS_List;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\Widgets\Model\Widget;
|
||||
|
||||
class BlogArchiveWidgetTest extends SapphireTest
|
||||
{
|
||||
protected static $fixture_file = 'BlogArchiveWidgetTest.yml';
|
||||
|
||||
public function setUp()
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Widget')) {
|
||||
if (!class_exists(Widget::class)) {
|
||||
self::$fixture_file = null;
|
||||
parent::setUp();
|
||||
$this->markTestSkipped('Test requires silverstripe/widgets to be installed.');
|
||||
}
|
||||
|
||||
SS_Datetime::set_mock_now('2017-09-20 00:00:00');
|
||||
DBDatetime::set_mock_now('2017-09-20 00:00:00');
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
SS_Datetime::clear_mock_now();
|
||||
DBDatetime::clear_mock_now();
|
||||
}
|
||||
|
||||
public function testArchiveMonthlyFromStage()
|
||||
{
|
||||
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
|
||||
$widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly');
|
||||
$archive = $widget->getArchive();
|
||||
|
||||
$this->assertInstanceOf('SS_List', $archive);
|
||||
$this->assertInstanceOf(SS_List::class, $archive);
|
||||
$this->assertCount(3, $archive);
|
||||
$this->assertDOSContains(array(
|
||||
array('Title' => 'August 2017'),
|
||||
array('Title' => 'September 2017'),
|
||||
array('Title' => 'May 2015'),
|
||||
), $archive);
|
||||
$this->assertDOSContains([
|
||||
['Title' => 'August 2017'],
|
||||
['Title' => 'September 2017'],
|
||||
['Title' => 'May 2015'],
|
||||
], $archive);
|
||||
}
|
||||
|
||||
public function testArchiveMonthlyFromLive()
|
||||
{
|
||||
$original = Versioned::current_stage();
|
||||
$original = Versioned::get_stage();
|
||||
|
||||
$this->objFromFixture('BlogPost', 'post-b')->doPublish();
|
||||
Versioned::reading_stage('Live');
|
||||
$this->objFromFixture(BlogPost::class, 'post-b')->publishRecursive();
|
||||
Versioned::set_stage(Versioned::LIVE);
|
||||
|
||||
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
|
||||
$widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly');
|
||||
$archive = $widget->getArchive();
|
||||
|
||||
$this->assertCount(1, $archive);
|
||||
$this->assertDOSContains(array(
|
||||
array('Title' => 'August 2017'),
|
||||
), $archive);
|
||||
$this->assertDOSContains([
|
||||
['Title' => 'August 2017'],
|
||||
], $archive);
|
||||
|
||||
Versioned::reading_stage($original);
|
||||
if ($original) {
|
||||
Versioned::set_stage($original);
|
||||
}
|
||||
}
|
||||
|
||||
public function testArchiveYearly()
|
||||
{
|
||||
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-yearly');
|
||||
$widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly');
|
||||
$archive = $widget->getArchive();
|
||||
|
||||
$this->assertInstanceOf('SS_List', $archive);
|
||||
$this->assertInstanceOf(SS_List::class, $archive);
|
||||
$this->assertCount(2, $archive);
|
||||
$this->assertDOSContains(array(
|
||||
array('Title' => '2017'),
|
||||
array('Title' => '2015'),
|
||||
), $archive);
|
||||
$this->assertDOSContains([
|
||||
['Title' => '2017'],
|
||||
['Title' => '2015'],
|
||||
], $archive);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user