mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
NEW Add tests for blog archive links and tidy up code re-use a little
This commit is contained in:
parent
078c877cbb
commit
dd8e401dbf
@ -609,18 +609,15 @@ class BlogPost extends Page
|
|||||||
* Returns a monthly archive link for the current blog post.
|
* Returns a monthly archive link for the current blog post.
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getMonthlyArchiveLink($type = 'day')
|
public function getMonthlyArchiveLink($type = 'day')
|
||||||
{
|
{
|
||||||
/**
|
/** @var DBDatetime $date */
|
||||||
* @var DBDatetime $date
|
|
||||||
*/
|
|
||||||
$date = $this->dbObject('PublishDate');
|
$date = $this->dbObject('PublishDate');
|
||||||
|
|
||||||
if ($type != 'year') {
|
if ($type !== 'year') {
|
||||||
if ($type == 'day') {
|
if ($type === 'day') {
|
||||||
return Controller::join_links(
|
return Controller::join_links(
|
||||||
$this->Parent()->Link('archive'),
|
$this->Parent()->Link('archive'),
|
||||||
$date->format('Y'),
|
$date->format('Y'),
|
||||||
@ -642,12 +639,7 @@ class BlogPost extends Page
|
|||||||
*/
|
*/
|
||||||
public function getYearlyArchiveLink()
|
public function getYearlyArchiveLink()
|
||||||
{
|
{
|
||||||
/**
|
return $this->getMonthlyArchiveLink('year');
|
||||||
* @var DBDatetime $date
|
|
||||||
*/
|
|
||||||
$date = $this->dbObject('PublishDate');
|
|
||||||
|
|
||||||
return Controller::join_links($this->Parent()->Link('archive'), $date->format('Y'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,4 +146,42 @@ class BlogPostTest extends SapphireTest
|
|||||||
$this->expectException(\InvalidArgumentException::class);
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
$blogPost->MinutesToRead('not-a-number');
|
$blogPost->MinutesToRead('not-a-number');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $type
|
||||||
|
* @param string $expected
|
||||||
|
* @dataProvider monthlyArchiveLinkProvider
|
||||||
|
* @group wip
|
||||||
|
*/
|
||||||
|
public function testGetMonthlyArchiveLink($type, $expected)
|
||||||
|
{
|
||||||
|
/** @var BlogPost $blogPost */
|
||||||
|
$blogPost = $this->objFromFixture(BlogPost::class, 'FirstBlogPost');
|
||||||
|
|
||||||
|
$archiveLink = $blogPost->getMonthlyArchiveLink($type);
|
||||||
|
$this->assertContains('archive/', $archiveLink);
|
||||||
|
$this->assertContains($expected, $archiveLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array[]
|
||||||
|
*/
|
||||||
|
public function monthlyArchiveLinkProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['day', '/2013/10/1'],
|
||||||
|
['month', '/2013/10'],
|
||||||
|
['year', '/2013'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetYearlyArchiveLink()
|
||||||
|
{
|
||||||
|
/** @var BlogPost $blogPost */
|
||||||
|
$blogPost = $this->objFromFixture(BlogPost::class, 'FirstBlogPost');
|
||||||
|
|
||||||
|
$archiveLink = $blogPost->getYearlyArchiveLink();
|
||||||
|
$this->assertContains('archive/', $archiveLink);
|
||||||
|
$this->assertContains('/2013', $archiveLink);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user