2013-10-10 00:09:28 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class BlogTest extends SapphireTest {
|
|
|
|
|
|
|
|
static $fixture_file = "blog.yml";
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2015-02-08 08:03:55 +01:00
|
|
|
Config::nest();
|
|
|
|
SS_Datetime::set_mock_now("2013-10-10 20:00:00");
|
2014-04-10 14:44:17 +02:00
|
|
|
$this->objFromFixture("Blog", "firstblog")->publish("Stage", "Live");
|
2013-10-10 00:09:28 +02:00
|
|
|
}
|
2015-02-08 08:03:55 +01:00
|
|
|
|
|
|
|
public function tearDown() {
|
|
|
|
SS_Datetime::clear_mock_now();
|
|
|
|
Config::unnest();
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
2013-10-10 00:09:28 +02:00
|
|
|
|
|
|
|
public function testGetExcludedSiteTreeClassNames() {
|
|
|
|
$member = Member::currentUser();
|
|
|
|
if($member) $member->logout();
|
|
|
|
|
|
|
|
$blog = $this->objFromFixture("Blog", 'firstblog');
|
|
|
|
|
|
|
|
Config::inst()->update("BlogPost", "show_in_sitetree", true);
|
|
|
|
$classes = $blog->getExcludedSiteTreeClassNames();
|
2015-02-08 08:03:55 +01:00
|
|
|
$this->assertNotContains('BlogPost', $classes, "BlogPost class should be hidden.");
|
2013-10-10 00:09:28 +02:00
|
|
|
|
|
|
|
Config::inst()->update("BlogPost", "show_in_sitetree", false);
|
|
|
|
$classes = $blog->getExcludedSiteTreeClassNames();
|
2015-02-08 08:03:55 +01:00
|
|
|
$this->assertContains('BlogPost', $classes, "BlogPost class should be hidden.");
|
2013-10-10 00:09:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetArchivedBlogPosts() {
|
|
|
|
$member = Member::currentUser();
|
|
|
|
if($member) $member->logout();
|
|
|
|
|
|
|
|
$blog = $this->objFromFixture("Blog", "firstblog");
|
|
|
|
|
|
|
|
// Test yearly
|
|
|
|
$archive = $blog->getArchivedBlogPosts(2013);
|
|
|
|
$this->assertEquals(2, $archive->count(), "Incorrect Yearly Archive count for 2013");
|
|
|
|
$this->assertEquals("First post", $archive->first()->Title, "Incorrect First Blog post");
|
|
|
|
$this->assertEquals("Second post", $archive->last()->Title, "Incorrect Last Blog post");
|
|
|
|
|
|
|
|
// Test monthly
|
|
|
|
$archive = $blog->getArchivedBlogPosts(2013, 10);
|
|
|
|
$this->assertEquals(1, $archive->count(), "Incorrect monthly acrhive count.");
|
|
|
|
|
|
|
|
// Test daily
|
|
|
|
$archive = $blog->getArchivedBlogPosts(2013, 10, 01);
|
|
|
|
$this->assertEquals(1, $archive->count(), "Incorrect daily archive count.");
|
|
|
|
}
|
|
|
|
|
2014-04-10 14:44:17 +02:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2014-11-13 10:06:48 +01:00
|
|
|
$archiveLink = Controller::join_links($blog->Link("archive"), 2013, 10);
|
|
|
|
$response = Director::test($archiveLink);
|
|
|
|
$this->assertEquals(200, $response->getStatusCode(), "HTTP Status should be 200");
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2014-11-13 10:06:48 +01:00
|
|
|
$archiveLink = Controller::join_links($blog->Link("archive"), 2013);
|
|
|
|
$response = Director::test($archiveLink);
|
|
|
|
$this->assertEquals(200, $response->getStatusCode(), "HTTP Status should be 200");
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2014-11-13 10:06:48 +01:00
|
|
|
$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");
|
2014-04-10 14:44:17 +02:00
|
|
|
|
|
|
|
|
2014-11-13 10:06:48 +01:00
|
|
|
// 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");
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2014-11-13 10:06:48 +01:00
|
|
|
// 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");
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2014-11-13 10:06:48 +01:00
|
|
|
// 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");
|
2014-04-10 14:44:17 +02:00
|
|
|
|
2014-11-13 10:06:48 +01:00
|
|
|
// 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");
|
2014-04-10 14:44:17 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-10 00:09:28 +02:00
|
|
|
}
|