-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #480 from creative-commoners/pulls/2.4/archived-wi…
…dget-years FIX Display individual years in blog archive widget when set to "Yearly"
- Loading branch information
Showing
5 changed files
with
116 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
class BlogArchiveWidgetTest extends SapphireTest | ||
{ | ||
protected static $fixture_file = 'BlogArchiveWidgetTest.yml'; | ||
|
||
public function setUp() | ||
{ | ||
if (!class_exists('Widget')) { | ||
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'); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
parent::tearDown(); | ||
|
||
SS_Datetime::clear_mock_now(); | ||
} | ||
|
||
public function testArchiveMonthlyFromStage() | ||
{ | ||
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly'); | ||
$archive = $widget->getArchive(); | ||
|
||
$this->assertInstanceOf('SS_List', $archive); | ||
$this->assertCount(3, $archive); | ||
$this->assertDOSContains(array( | ||
array('Title' => 'August 2017'), | ||
array('Title' => 'September 2017'), | ||
array('Title' => 'May 2015'), | ||
), $archive); | ||
} | ||
|
||
public function testArchiveMonthlyFromLive() | ||
{ | ||
$original = Versioned::current_stage(); | ||
|
||
$this->objFromFixture('BlogPost', 'post-b')->doPublish(); | ||
Versioned::reading_stage('Live'); | ||
|
||
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly'); | ||
$archive = $widget->getArchive(); | ||
|
||
$this->assertCount(1, $archive); | ||
$this->assertDOSContains(array( | ||
array('Title' => 'August 2017'), | ||
), $archive); | ||
|
||
Versioned::reading_stage($original); | ||
} | ||
|
||
public function testArchiveYearly() | ||
{ | ||
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-yearly'); | ||
$archive = $widget->getArchive(); | ||
|
||
$this->assertInstanceOf('SS_List', $archive); | ||
$this->assertCount(2, $archive); | ||
$this->assertDOSContains(array( | ||
array('Title' => '2017'), | ||
array('Title' => '2015'), | ||
), $archive); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Blog: | ||
my-blog: | ||
Title: My Blog | ||
|
||
BlogPost: | ||
post-a: | ||
Title: September Digest | ||
PublishDate: 2017-09-01 00:00:00 | ||
ParentID: =>Blog.my-blog | ||
post-b: | ||
Title: August is Awesome | ||
PublishDate: 2017-08-01 00:00:00 | ||
ParentID: =>Blog.my-blog | ||
post-c: | ||
Title: 2015 is so two years ago | ||
PublishDate: 2015-05-02 00:01:02 | ||
ParentID: =>Blog.my-blog | ||
|
||
BlogArchiveWidget: | ||
archive-monthly: | ||
NumberToDisplay: 5 | ||
ArchiveType: Monthly | ||
BlogID: =>Blog.my-blog | ||
archive-yearly: | ||
NumberToDisplay: 5 | ||
ArchiveType: Yearly | ||
BlogID: =>Blog.my-blog |