Merge pull request #320 from camfindlay/feature/defaultarchiveyear

ENHANCEMENT Default archive year
This commit is contained in:
Damian Mooyman 2015-11-09 14:30:02 +13:00
commit dd33bbfa50
2 changed files with 11 additions and 6 deletions

View File

@ -727,14 +727,18 @@ class Blog_Controller extends Page_Controller {
/** /**
* Fetches the archive year from the url. * Fetches the archive year from the url.
* *
* @return null|int * @return int
*/ */
public function getArchiveYear() { public function getArchiveYear() {
$year = $this->request->param('Year');
if(preg_match('/^[0-9]{4}$/', $year)) { if($this->request->param('Year')){
if(preg_match('/^[0-9]{4}$/', $year = $this->request->param('Year'))) {
return (int) $year; return (int) $year;
} }
} else {
return SS_Datetime::now()->Year();
}
return null; return null;
} }

View File

@ -109,8 +109,8 @@ class BlogTest extends SapphireTest {
$this->assertEquals(200, $this->getStatusOf($link), 'HTTP Status should be 200'); $this->assertEquals(200, $this->getStatusOf($link), 'HTTP Status should be 200');
$link = Controller::join_links($blog->Link('archive')); $link = Controller::join_links($blog->Link('archive'));
$this->assertEquals(200, $this->getStatusOf($link), 'HTTP Status should be 200');
$this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404'); $this->assertEquals(SS_Datetime::now()->Year(), ModelAsController::controller_for($blog)->getArchiveYear(), 'Defaults to current year');
$link = Controller::join_links($blog->Link('archive'), 'invalid-year'); $link = Controller::join_links($blog->Link('archive'), 'invalid-year');
@ -123,6 +123,7 @@ class BlogTest extends SapphireTest {
$link = Controller::join_links($blog->Link('archive'), '2013', '10', '99'); $link = Controller::join_links($blog->Link('archive'), '2013', '10', '99');
$this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404'); $this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404');
} }
/** /**