|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class BlogPostTest extends SapphireTest |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
/** |
|
6
|
|
|
* @var string |
|
7
|
|
|
*/ |
|
8
|
|
|
public static $fixture_file = 'blog.yml'; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* {@inheritdoc} |
|
12
|
|
|
*/ |
|
13
|
|
|
public function setUp() |
|
14
|
|
|
{ |
|
15
|
|
|
parent::setUp(); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
|
|
public function tearDown() |
|
22
|
|
|
{ |
|
23
|
|
|
SS_Datetime::clear_mock_now(); |
|
24
|
|
|
parent::tearDown(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @dataProvider canViewProvider |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testCanView($date, $user, $page, $canView) |
|
31
|
|
|
{ |
|
32
|
|
|
$userRecord = $this->objFromFixture('Member', $user); |
|
33
|
|
|
$pageRecord = $this->objFromFixture('BlogPost', $page); |
|
34
|
|
|
SS_Datetime::set_mock_now($date); |
|
35
|
|
|
$this->assertEquals($canView, $pageRecord->canView($userRecord)); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function canViewProvider() |
|
39
|
|
|
{ |
|
40
|
|
|
$someFutureDate = '2013-10-10 20:00:00'; |
|
41
|
|
|
$somePastDate = '2009-10-10 20:00:00'; |
|
42
|
|
|
return array( |
|
43
|
|
|
// Check this post given the date has passed |
|
44
|
|
|
array($someFutureDate, 'Editor', 'PostA', true), |
|
45
|
|
|
array($someFutureDate, 'Contributor', 'PostA', true), |
|
46
|
|
|
array($someFutureDate, 'BlogEditor', 'PostA', true), |
|
47
|
|
|
array($someFutureDate, 'Writer', 'PostA', true), |
|
48
|
|
|
|
|
49
|
|
|
// Check unpublished pages |
|
50
|
|
|
array($somePastDate, 'Editor', 'PostA', true), |
|
51
|
|
|
array($somePastDate, 'Contributor', 'PostA', true), |
|
52
|
|
|
array($somePastDate, 'BlogEditor', 'PostA', true), |
|
53
|
|
|
array($somePastDate, 'Writer', 'PostA', true), |
|
54
|
|
|
|
|
55
|
|
|
// Test a page that was authored by another user |
|
56
|
|
|
|
|
57
|
|
|
// Check this post given the date has passed |
|
58
|
|
|
array($someFutureDate, 'Editor', 'FirstBlogPost', true), |
|
59
|
|
|
array($someFutureDate, 'Contributor', 'FirstBlogPost', true), |
|
60
|
|
|
array($someFutureDate, 'BlogEditor', 'FirstBlogPost', true), |
|
61
|
|
|
array($someFutureDate, 'Writer', 'FirstBlogPost', true), |
|
62
|
|
|
|
|
63
|
|
|
// Check future pages - non-editors shouldn't be able to see this |
|
64
|
|
|
array($somePastDate, 'Editor', 'FirstBlogPost', true), |
|
65
|
|
|
array($somePastDate, 'Contributor', 'FirstBlogPost', false), |
|
66
|
|
|
array($somePastDate, 'BlogEditor', 'FirstBlogPost', false), |
|
67
|
|
|
array($somePastDate, 'Writer', 'FirstBlogPost', false), |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testCandidateAuthors() |
|
72
|
|
|
{ |
|
73
|
|
|
$blogpost = $this->objFromFixture('BlogPost', 'PostC'); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count()); |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
//Set the group to draw Members from |
|
78
|
|
|
Config::inst()->update('BlogPost', 'restrict_authors_to_group', 'blogusers'); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertEquals(3, $blogpost->getCandidateAuthors()->count()); |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
// Test cms field is generated |
|
83
|
|
|
$fields = $blogpost->getCMSFields(); |
|
84
|
|
|
$this->assertNotEmpty($fields->dataFieldByName('Authors')); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testCanViewFuturePost() |
|
88
|
|
|
{ |
|
89
|
|
|
$blogpost = $this->objFromFixture('BlogPost', 'NullPublishDate'); |
|
90
|
|
|
$blogpost->PublishDate = null; |
|
91
|
|
|
|
|
92
|
|
|
$editor = $this->objFromFixture('Member', 'BlogEditor'); |
|
93
|
|
|
$this->assertTrue($blogPost->canView($editor)); |
|
|
|
|
|
|
94
|
|
|
$this->assertFalse($blogPost->canView()); |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.