silverstripe-blog/tests/BlogPostTest.php

98 lines
3.1 KiB
PHP
Raw Normal View History

2015-07-08 07:42:00 +02:00
<?php
2015-11-21 07:17:29 +01:00
class BlogPostTest extends SapphireTest
{
/**
* @var string
*/
public static $fixture_file = 'blog.yml';
2015-07-08 07:42:00 +02:00
2015-11-21 07:17:29 +01:00
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
}
2015-07-08 07:42:00 +02:00
2015-11-21 07:17:29 +01:00
/**
* {@inheritdoc}
*/
public function tearDown()
{
SS_Datetime::clear_mock_now();
parent::tearDown();
}
2015-07-08 07:42:00 +02:00
2015-11-21 07:17:29 +01:00
/**
* @dataProvider canViewProvider
*/
public function testCanView($date, $user, $page, $canView)
{
$userRecord = $this->objFromFixture('Member', $user);
$pageRecord = $this->objFromFixture('BlogPost', $page);
SS_Datetime::set_mock_now($date);
$this->assertEquals($canView, $pageRecord->canView($userRecord));
}
2015-11-21 07:17:29 +01:00
public function canViewProvider()
{
$someFutureDate = '2013-10-10 20:00:00';
$somePastDate = '2009-10-10 20:00:00';
return array(
// Check this post given the date has passed
array($someFutureDate, 'Editor', 'PostA', true),
array($someFutureDate, 'Contributor', 'PostA', true),
array($someFutureDate, 'BlogEditor', 'PostA', true),
array($someFutureDate, 'Writer', 'PostA', true),
2015-11-21 07:17:29 +01:00
// Check unpublished pages
array($somePastDate, 'Editor', 'PostA', true),
array($somePastDate, 'Contributor', 'PostA', true),
array($somePastDate, 'BlogEditor', 'PostA', true),
array($somePastDate, 'Writer', 'PostA', true),
2015-11-21 07:17:29 +01:00
// Test a page that was authored by another user
2015-11-21 07:17:29 +01:00
// Check this post given the date has passed
array($someFutureDate, 'Editor', 'FirstBlogPost', true),
array($someFutureDate, 'Contributor', 'FirstBlogPost', true),
array($someFutureDate, 'BlogEditor', 'FirstBlogPost', true),
array($someFutureDate, 'Writer', 'FirstBlogPost', true),
2015-11-21 07:17:29 +01:00
// Check future pages - non-editors shouldn't be able to see this
array($somePastDate, 'Editor', 'FirstBlogPost', true),
array($somePastDate, 'Contributor', 'FirstBlogPost', false),
array($somePastDate, 'BlogEditor', 'FirstBlogPost', false),
array($somePastDate, 'Writer', 'FirstBlogPost', false),
);
}
2015-11-21 07:17:29 +01:00
public function testCandidateAuthors()
{
$blogpost = $this->objFromFixture('BlogPost', 'PostC');
2015-11-21 07:17:29 +01:00
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count());
2015-11-21 07:17:29 +01:00
//Set the group to draw Members from
Config::inst()->update('BlogPost', 'restrict_authors_to_group', 'blogusers');
2015-11-21 07:17:29 +01:00
$this->assertEquals(3, $blogpost->getCandidateAuthors()->count());
2015-11-23 03:43:27 +01:00
// Test cms field is generated
$fields = $blogpost->getCMSFields();
$this->assertNotEmpty($fields->dataFieldByName('Authors'));
2015-11-21 07:17:29 +01:00
}
public function testCanViewFuturePost()
{
$blogPost = $this->objFromFixture('BlogPost', 'NullPublishDate');
$editor = $this->objFromFixture('Member', 'BlogEditor');
$this->assertTrue($blogPost->canView($editor));
$visitor = $this->objFromFixture('Member', 'Visitor');
$this->assertFalse($blogPost->canView($visitor));
}
2015-07-08 07:42:00 +02:00
}