mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
FIX: Corrected checks for date validation in archive method and added supporting tests
This commit is contained in:
parent
7511cb02ee
commit
0d098ff231
@ -203,11 +203,11 @@ class Blog_Controller extends Page_Controller {
|
|||||||
// If an invalid month has been passed, we can return a 404.
|
// If an invalid month has been passed, we can return a 404.
|
||||||
if($this->request->param("Month") && !$month) {
|
if($this->request->param("Month") && !$month) {
|
||||||
return $this->httpError(404, "Not Found");
|
return $this->httpError(404, "Not Found");
|
||||||
|
}
|
||||||
|
|
||||||
// Check for valid day
|
// Check for valid day
|
||||||
if($this->request->param("Day") && !$day) {
|
if($month && $this->request->param("Day") && !$day) {
|
||||||
return $this->httpError(404, "Not Found");
|
return $this->httpError(404, "Not Found");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($year) {
|
if($year) {
|
||||||
|
@ -7,6 +7,8 @@ class BlogTest extends SapphireTest {
|
|||||||
public function setUp() {
|
public function setUp() {
|
||||||
SS_Datetime::set_mock_now("2013-10-10 20:00:00");
|
SS_Datetime::set_mock_now("2013-10-10 20:00:00");
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->objFromFixture("Blog", "firstblog")->publish("Stage", "Live");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetExcludedSiteTreeClassNames() {
|
public function testGetExcludedSiteTreeClassNames() {
|
||||||
@ -47,4 +49,47 @@ class BlogTest extends SapphireTest {
|
|||||||
$this->assertEquals(1, $archive->count(), "Incorrect daily archive count.");
|
$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");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user