diff --git a/code/model/Blog.php b/code/model/Blog.php index a662d72..ceea732 100644 --- a/code/model/Blog.php +++ b/code/model/Blog.php @@ -736,7 +736,7 @@ class Blog_Controller extends Page_Controller { if(preg_match('/^[0-9]{4}$/', $year = $this->request->param('Year'))) { return (int) $year; } - } else { + } elseif($this->request->param('Action') == 'archive') { return SS_Datetime::now()->Year(); } diff --git a/tests/BlogTest.php b/tests/BlogTest.php index 79931fb..860d93c 100755 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -110,7 +110,6 @@ class BlogTest extends SapphireTest { $link = Controller::join_links($blog->Link('archive')); $this->assertEquals(200, $this->getStatusOf($link), 'HTTP Status should be 200'); - $this->assertEquals('2013', ModelAsController::controller_for($blog)->getArchiveYear(), 'Defaults to current year'); $link = Controller::join_links($blog->Link('archive'), 'invalid-year'); @@ -126,6 +125,16 @@ class BlogTest extends SapphireTest { } + /* + * Test archive year + */ + public function testArchiveYear(){ + $blog = $this->objFromFixture('Blog', 'FirstBlog'); + $controller = new Blog_Controller($blog); + $this->requestURL($controller, 'first-post/archive/'); + $this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013'); + } + /** * @param string $link *