diff --git a/model/Blog.php b/model/Blog.php index 45df979..39c33d4 100755 --- a/model/Blog.php +++ b/model/Blog.php @@ -203,11 +203,11 @@ class Blog_Controller extends Page_Controller { // If an invalid month has been passed, we can return a 404. if($this->request->param("Month") && !$month) { return $this->httpError(404, "Not Found"); + } - // Check for valid day - if($this->request->param("Day") && !$day) { - return $this->httpError(404, "Not Found"); - } + // Check for valid day + if($month && $this->request->param("Day") && !$day) { + return $this->httpError(404, "Not Found"); } if($year) { diff --git a/tests/BlogTest.php b/tests/BlogTest.php index 34f73bc..c584be7 100755 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -7,6 +7,8 @@ class BlogTest extends SapphireTest { public function setUp() { SS_Datetime::set_mock_now("2013-10-10 20:00:00"); parent::setUp(); + + $this->objFromFixture("Blog", "firstblog")->publish("Stage", "Live"); } public function testGetExcludedSiteTreeClassNames() { @@ -47,4 +49,47 @@ class BlogTest extends SapphireTest { $this->assertEquals(1, $archive->count(), "Incorrect daily archive count."); } + + public function testArchiveLinks() { + $blog = $this->objFromFixture("Blog", "firstblog"); + + // Test valid links + $archiveLink = Controller::join_links($blog->Link("archive"), 2013, 10, 01); + $response = Director::test($archiveLink); + $this->assertEquals(200, $response->getStatusCode(), "HTTP Status should be 200"); + + $archiveLink = Controller::join_links($blog->Link("archive"), 2013, 10); + $response = Director::test($archiveLink); + $this->assertEquals(200, $response->getStatusCode(), "HTTP Status should be 200"); + + $archiveLink = Controller::join_links($blog->Link("archive"), 2013); + $response = Director::test($archiveLink); + $this->assertEquals(200, $response->getStatusCode(), "HTTP Status should be 200"); + + $archiveLink = Controller::join_links($blog->Link("archive"), 2011, 10, 01); + $response = Director::test($archiveLink); // No posts on this date, but a valid entry. + $this->assertEquals(200, $response->getStatusCode(), "HTTP Status should be 200"); + + + // Test invalid links & dates + $response = Director::test($blog->Link("archive")); // 404 when no date is set + $this->assertEquals(404, $response->getStatusCode(), "HTTP Status should be 404"); + + // Invalid year + $archiveLink = Controller::join_links($blog->Link("archive"), "invalid-year"); + $response = Director::test($archiveLink); // 404 when an invalid yer is set + $this->assertEquals(404, $response->getStatusCode(), "HTTP Status should be 404"); + + // Invalid month + $archiveLink = Controller::join_links($blog->Link("archive"), "2013", "99"); + $response = Director::test($archiveLink); // 404 when an invalid month is set + $this->assertEquals(404, $response->getStatusCode(), "HTTP Status should be 404"); + + // Invalid day + $archiveLink = Controller::join_links($blog->Link("archive"), "2013", "10", "99"); + $response = Director::test($archiveLink); // 404 when an invalid day is set + $this->assertEquals(404, $response->getStatusCode(), "HTTP Status should be 404"); + + } + } \ No newline at end of file