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
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-06 03:52:07 +01:00
|
|
|
public function testRoles() {
|
|
|
|
$blog = $this->objFromFixture('Blog', 'fourthblog');
|
|
|
|
$blog2 = $this->objFromFixture('Blog', 'firstblog');
|
|
|
|
$postA = $this->objFromFixture('BlogPost', 'post-a');
|
|
|
|
$postB = $this->objFromFixture('BlogPost', 'post-b');
|
|
|
|
$postC = $this->objFromFixture('BlogPost', 'post-c');
|
|
|
|
$editor = $this->objFromFixture('Member', 'blogeditor');
|
|
|
|
$writer = $this->objFromFixture('Member', 'writer');
|
|
|
|
$contributor = $this->objFromFixture('Member', 'contributor');
|
|
|
|
$visitor = $this->objFromFixture('Member', 'visitor');
|
|
|
|
|
|
|
|
// Check that editors have all permissions on their own blog
|
|
|
|
$this->assertTrue($blog->canEdit($editor));
|
|
|
|
Debug::dump($blog2->Editors()->count());
|
|
|
|
$this->assertFalse($blog2->canEdit($editor));
|
|
|
|
$this->assertTrue($blog->canAddChildren($editor));
|
|
|
|
$this->assertFalse($blog2->canAddChildren($editor));
|
|
|
|
$this->assertTrue($postA->canEdit($editor));
|
|
|
|
$this->assertTrue($postB->canEdit($editor));
|
|
|
|
$this->assertTrue($postC->canEdit($editor));
|
|
|
|
$this->assertTrue($postA->canPublish($editor));
|
|
|
|
$this->assertTrue($postB->canPublish($editor));
|
|
|
|
$this->assertTrue($postC->canPublish($editor));
|
|
|
|
|
|
|
|
// check rights of writers
|
|
|
|
$this->assertFalse($blog->canEdit($writer));
|
|
|
|
$this->assertFalse($blog2->canEdit($writer));
|
|
|
|
$this->assertTrue($blog->canAddChildren($writer));
|
|
|
|
$this->assertFalse($blog2->canAddChildren($writer));
|
|
|
|
$this->assertTrue($postA->canEdit($writer));
|
|
|
|
$this->assertFalse($postB->canEdit($writer));
|
|
|
|
$this->assertTrue($postC->canEdit($writer));
|
|
|
|
$this->assertTrue($postA->canPublish($writer));
|
|
|
|
$this->assertFalse($postB->canPublish($writer));
|
|
|
|
$this->assertTrue($postC->canPublish($writer));
|
|
|
|
|
|
|
|
// Check rights of contributors
|
|
|
|
$this->assertFalse($blog->canEdit($contributor));
|
|
|
|
$this->assertFalse($blog2->canEdit($contributor));
|
|
|
|
$this->assertTrue($blog->canAddChildren($contributor));
|
|
|
|
$this->assertFalse($blog2->canAddChildren($contributor));
|
|
|
|
$this->assertTrue($postA->canEdit($contributor));
|
|
|
|
$this->assertFalse($postB->canEdit($contributor));
|
|
|
|
$this->assertTrue($postC->canEdit($contributor));
|
|
|
|
$this->assertFalse($postA->canPublish($contributor));
|
|
|
|
$this->assertFalse($postB->canPublish($contributor));
|
|
|
|
$this->assertFalse($postC->canPublish($contributor));
|
|
|
|
|
|
|
|
// Check rights of non-cms user
|
|
|
|
$this->assertFalse($blog->canEdit($visitor));
|
|
|
|
$this->assertFalse($blog2->canEdit($visitor));
|
|
|
|
$this->assertFalse($blog->canAddChildren($visitor));
|
|
|
|
$this->assertFalse($blog2->canAddChildren($visitor));
|
|
|
|
$this->assertFalse($postA->canEdit($visitor));
|
|
|
|
$this->assertFalse($postB->canEdit($visitor));
|
|
|
|
$this->assertFalse($postC->canEdit($visitor));
|
|
|
|
$this->assertFalse($postA->canPublish($visitor));
|
|
|
|
$this->assertFalse($postB->canPublish($visitor));
|
|
|
|
$this->assertFalse($postC->canPublish($visitor));
|
|
|
|
}
|
|
|
|
|
2013-10-10 00:09:28 +02:00
|
|
|
}
|