2013-10-10 00:09:28 +02:00
|
|
|
<?php
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @mixin PHPUnit_Framework_TestCase
|
|
|
|
*/
|
2014-07-27 10:40:08 +02:00
|
|
|
class BlogTagTest extends FunctionalTest {
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
static $fixture_file = 'blog.yml';
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2013-10-10 00:09:28 +02:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
|
|
|
SS_Datetime::set_mock_now('2013-10-10 20:00:00');
|
2013-10-10 00:09:28 +02:00
|
|
|
}
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2015-02-08 08:03:55 +01:00
|
|
|
public function tearDown() {
|
|
|
|
SS_Datetime::clear_mock_now();
|
2015-05-09 16:33:12 +02:00
|
|
|
|
2015-02-08 08:03:55 +01:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
2014-03-23 15:40:53 +01:00
|
|
|
/**
|
2015-05-09 16:33:12 +02:00
|
|
|
* Tests that any blog posts returned from $tag->BlogPosts() many_many are published, both by
|
|
|
|
* normal 'save & publish' functionality and by publish date.
|
|
|
|
*/
|
2013-10-10 00:09:28 +02:00
|
|
|
public function testBlogPosts() {
|
|
|
|
$member = Member::currentUser();
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
if($member) {
|
|
|
|
$member->logout();
|
|
|
|
}
|
2013-10-10 00:09:28 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$this->objFromFixture('BlogPost', 'FirstBlogPost');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
/**
|
|
|
|
* @var BlogTag $tag
|
|
|
|
*/
|
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The first blog can be viewed by anybody.
|
|
|
|
*/
|
2014-07-27 10:40:08 +02:00
|
|
|
public function testCanView() {
|
|
|
|
$this->useDraftSite();
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$admin = $this->objFromFixture('Member', 'Admin');
|
|
|
|
$editor = $this->objFromFixture('Member', 'Editor');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
|
|
|
|
$this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$tag = $this->objFromFixture('BlogTag', 'SecondTag');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
|
|
|
|
$this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.');
|
|
|
|
}
|
2014-07-27 10:40:08 +02:00
|
|
|
|
|
|
|
public function testCanEdit() {
|
|
|
|
$this->useDraftSite();
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$admin = $this->objFromFixture('Member', 'Admin');
|
|
|
|
$editor = $this->objFromFixture('Member', 'Editor');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
|
|
|
|
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$tag = $this->objFromFixture('BlogTag', 'SecondTag');
|
|
|
|
|
|
|
|
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
|
|
|
|
$this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$tag = $this->objFromFixture('BlogTag', 'ThirdTag');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.');
|
|
|
|
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
|
|
|
|
}
|
2014-07-27 10:40:08 +02:00
|
|
|
|
|
|
|
public function testCanCreate() {
|
|
|
|
$this->useDraftSite();
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$admin = $this->objFromFixture('Member', 'Admin');
|
|
|
|
$editor = $this->objFromFixture('Member', 'Editor');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$tag = singleton('BlogTag');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$this->assertTrue($tag->canCreate($admin), 'Admin should be able to create tag.');
|
|
|
|
$this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.');
|
|
|
|
}
|
2014-07-27 10:40:08 +02:00
|
|
|
|
|
|
|
public function testCanDelete() {
|
|
|
|
$this->useDraftSite();
|
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$admin = $this->objFromFixture('Member', 'Admin');
|
|
|
|
$editor = $this->objFromFixture('Member', 'Editor');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
|
|
|
|
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$tag = $this->objFromFixture('BlogTag', 'SecondTag');
|
|
|
|
|
|
|
|
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
|
|
|
|
$this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.');
|
2014-07-27 10:40:08 +02:00
|
|
|
|
2015-05-09 16:33:12 +02:00
|
|
|
$tag = $this->objFromFixture('BlogTag', 'ThirdTag');
|
|
|
|
|
|
|
|
$this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.');
|
|
|
|
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
|
|
|
|
}
|
2013-10-10 00:09:28 +02:00
|
|
|
}
|