silverstripe-blog/tests/BlogCategoryTest.php

119 lines
3.6 KiB
PHP
Raw Normal View History

2014-03-23 15:40:53 +01:00
<?php
2015-05-09 16:33:12 +02:00
/**
* @mixin PHPUnit_Framework_TestCase
*/
class BlogCategoryTest extends FunctionalTest {
2015-05-09 16:33:12 +02:00
/**
* @var string
*/
static $fixture_file = 'blog.yml';
2014-03-23 15:40:53 +01:00
2015-05-09 16:33:12 +02:00
/**
* {@inheritdoc}
*/
2014-03-23 15:40:53 +01: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');
2014-03-23 15:40:53 +01: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
/**
* Tests that any blog posts returned from $category->BlogPosts() many_many are published,
* both by normal 'save & publish' functionality and by publish date.
2015-05-09 16:33:12 +02:00
*/
2014-03-23 15:40:53 +01:00
public function testBlogPosts() {
$member = Member::currentUser();
2015-05-09 16:33:12 +02:00
if($member) {
$member->logout();
}
$this->objFromFixture('BlogPost', 'FirstBlogPost');
2014-03-23 15:40:53 +01:00
2015-05-09 16:33:12 +02:00
/**
* @var BlogCategory $category
*/
$category = $this->objFromFixture('BlogCategory', 'FirstCategory');
2015-05-09 16:33:12 +02:00
$this->assertEquals(1, $category->BlogPosts()->count(), 'Category blog post count');
}
public function testCanView() {
$this->useDraftSite();
2015-05-09 16:33:12 +02:00
$this->objFromFixture('Member', 'Admin');
2015-05-09 16:33:12 +02:00
$editor = $this->objFromFixture('Member', 'Editor');
$category = $this->objFromFixture('BlogCategory', 'SecondCategory');
2015-05-09 16:33:12 +02:00
$this->assertFalse($category->canView($editor), 'Editor should not be able to view category.');
}
2015-05-09 16:33:12 +02:00
/**
* The first blog can be viewed by anybody.
*/
public function testCanEdit() {
$this->useDraftSite();
2015-05-09 16:33:12 +02:00
$admin = $this->objFromFixture('Member', 'Admin');
$editor = $this->objFromFixture('Member', 'Editor');
2015-05-09 16:33:12 +02:00
$category = $this->objFromFixture('BlogCategory', 'FirstCategory');
2015-05-09 16:33:12 +02:00
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.');
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
2015-05-09 16:33:12 +02:00
$category = $this->objFromFixture('BlogCategory', 'SecondCategory');
2015-05-09 16:33:12 +02:00
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.');
$this->assertFalse($category->canEdit($editor), 'Editor should not be able to edit category.');
2015-05-09 16:33:12 +02:00
$category = $this->objFromFixture('BlogCategory', 'ThirdCategory');
$this->assertTrue($category->canEdit($admin), 'Admin should always be able to edit category.');
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
}
public function testCanCreate() {
$this->useDraftSite();
2015-05-09 16:33:12 +02:00
$admin = $this->objFromFixture('Member', 'Admin');
$editor = $this->objFromFixture('Member', 'Editor');
$category = singleton('BlogCategory');
2015-05-09 16:33:12 +02:00
$this->assertTrue($category->canCreate($admin), 'Admin should be able to create category.');
$this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.');
}
public function testCanDelete() {
$this->useDraftSite();
2015-05-09 16:33:12 +02:00
$admin = $this->objFromFixture('Member', 'Admin');
$editor = $this->objFromFixture('Member', 'Editor');
2015-05-09 16:33:12 +02:00
$category = $this->objFromFixture('BlogCategory', 'FirstCategory');
2015-05-09 16:33:12 +02:00
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.');
$this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.');
2015-05-09 16:33:12 +02:00
$category = $this->objFromFixture('BlogCategory', 'SecondCategory');
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.');
$this->assertFalse($category->canDelete($editor), 'Editor should not be able to delete category.');
2015-05-09 16:33:12 +02:00
$category = $this->objFromFixture('BlogCategory', 'ThirdCategory');
$this->assertTrue($category->canDelete($admin), 'Admin should always be able to delete category.');
$this->assertTrue($category->canDelete($editor), 'Editor should be able to delete category.');
}
2014-03-23 15:40:53 +01:00
}