Skip to content

Commit

Permalink
Merge pull request #320 from camfindlay/feature/defaultarchiveyear
Browse files Browse the repository at this point in the history
ENHANCEMENT Default archive year
  • Loading branch information
Damian Mooyman committed Nov 9, 2015
2 parents a87e0f7 + 43bb224 commit dd33bbf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions code/model/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,17 @@ public function archive() {
/**
* Fetches the archive year from the url.
*
* @return null|int
* @return int
*/
public function getArchiveYear() {
$year = $this->request->param('Year');

if(preg_match('/^[0-9]{4}$/', $year)) {
return (int) $year;
if($this->request->param('Year')){

if(preg_match('/^[0-9]{4}$/', $year = $this->request->param('Year'))) {
return (int) $year;
}
} else {
return SS_Datetime::now()->Year();
}

return null;
Expand Down
5 changes: 3 additions & 2 deletions tests/BlogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public function testArchiveLinks() {
$this->assertEquals(200, $this->getStatusOf($link), 'HTTP Status should be 200');

$link = Controller::join_links($blog->Link('archive'));

$this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404');
$this->assertEquals(200, $this->getStatusOf($link), 'HTTP Status should be 200');
$this->assertEquals(SS_Datetime::now()->Year(), ModelAsController::controller_for($blog)->getArchiveYear(), 'Defaults to current year');

$link = Controller::join_links($blog->Link('archive'), 'invalid-year');

Expand All @@ -123,6 +123,7 @@ public function testArchiveLinks() {
$link = Controller::join_links($blog->Link('archive'), '2013', '10', '99');

$this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404');

}

/**
Expand Down

0 comments on commit dd33bbf

Please sign in to comment.