|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class BlogPostTest extends SapphireTest { |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @var string |
|
7
|
|
|
*/ |
|
8
|
|
|
static $fixture_file = 'blog.yml'; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* {@inheritdoc} |
|
12
|
|
|
*/ |
|
13
|
|
|
public function setUp() { |
|
14
|
|
|
parent::setUp(); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritdoc} |
|
19
|
|
|
*/ |
|
20
|
|
|
public function tearDown() { |
|
21
|
|
|
SS_Datetime::clear_mock_now(); |
|
22
|
|
|
parent::tearDown(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @dataProvider canViewProvider |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testCanView($date, $user, $page, $canView) { |
|
29
|
|
|
$userRecord = $this->objFromFixture('Member', $user); |
|
30
|
|
|
$pageRecord = $this->objFromFixture('BlogPost', $page); |
|
31
|
|
|
SS_Datetime::set_mock_now($date); |
|
32
|
|
|
$this->assertEquals($canView, $pageRecord->canView($userRecord)); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function canViewProvider() { |
|
36
|
|
|
$someFutureDate = '2013-10-10 20:00:00'; |
|
37
|
|
|
$somePastDate = '2009-10-10 20:00:00'; |
|
38
|
|
|
return array( |
|
39
|
|
|
// Check this post given the date has passed |
|
40
|
|
|
array($someFutureDate, 'Editor', 'PostA', true), |
|
41
|
|
|
array($someFutureDate, 'Contributor', 'PostA', true), |
|
42
|
|
|
array($someFutureDate, 'BlogEditor', 'PostA', true), |
|
43
|
|
|
array($someFutureDate, 'Writer', 'PostA', true), |
|
44
|
|
|
|
|
45
|
|
|
// Check unpublished pages |
|
46
|
|
|
array($somePastDate, 'Editor', 'PostA', true), |
|
47
|
|
|
array($somePastDate, 'Contributor', 'PostA', true), |
|
48
|
|
|
array($somePastDate, 'BlogEditor', 'PostA', true), |
|
49
|
|
|
array($somePastDate, 'Writer', 'PostA', true), |
|
50
|
|
|
|
|
51
|
|
|
// Test a page that was authored by another user |
|
52
|
|
|
|
|
53
|
|
|
// Check this post given the date has passed |
|
54
|
|
|
array($someFutureDate, 'Editor', 'FirstBlogPost', true), |
|
55
|
|
|
array($someFutureDate, 'Contributor', 'FirstBlogPost', true), |
|
56
|
|
|
array($someFutureDate, 'BlogEditor', 'FirstBlogPost', true), |
|
57
|
|
|
array($someFutureDate, 'Writer', 'FirstBlogPost', true), |
|
58
|
|
|
|
|
59
|
|
|
// Check future pages - non-editors shouldn't be able to see this |
|
60
|
|
|
array($somePastDate, 'Editor', 'FirstBlogPost', true), |
|
61
|
|
|
array($somePastDate, 'Contributor', 'FirstBlogPost', false), |
|
62
|
|
|
array($somePastDate, 'BlogEditor', 'FirstBlogPost', false), |
|
63
|
|
|
array($somePastDate, 'Writer', 'FirstBlogPost', false), |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testCandidateAuthors() { |
|
68
|
|
|
$blogpost = $this->objFromFixture('BlogPost', 'PostC'); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count()); |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
//Set the group to draw Members from |
|
73
|
|
|
Config::inst()->update('BlogPost', 'restrict_authors_to_group','BlogUsers'); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEquals(3, $blogpost->getCandidateAuthors()->count()); |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
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.