|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @mixin PHPUnit_Framework_TestCase |
|
5
|
|
|
*/ |
|
6
|
|
|
class BlogTagTest extends FunctionalTest { |
|
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @var string |
|
9
|
|
|
*/ |
|
10
|
|
|
static $fixture_file = 'blog.yml'; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* {@inheritdoc} |
|
14
|
|
|
*/ |
|
15
|
|
|
public function setUp() { |
|
16
|
|
|
parent::setUp(); |
|
17
|
|
|
|
|
18
|
|
|
SS_Datetime::set_mock_now('2013-10-10 20:00:00'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
*/ |
|
24
|
|
|
public function tearDown() { |
|
25
|
|
|
SS_Datetime::clear_mock_now(); |
|
26
|
|
|
|
|
27
|
|
|
parent::tearDown(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Tests that any blog posts returned from $tag->BlogPosts() many_many are published, both by |
|
32
|
|
|
* normal 'save & publish' functionality and by publish date. |
|
33
|
|
|
*/ |
|
34
|
|
View Code Duplication |
public function testBlogPosts() { |
|
|
|
|
|
|
35
|
|
|
$member = Member::currentUser(); |
|
36
|
|
|
|
|
37
|
|
|
if($member) { |
|
38
|
|
|
$member->logout(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$this->objFromFixture('BlogPost', 'FirstBlogPost'); |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var BlogTag $tag |
|
45
|
|
|
*/ |
|
46
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count'); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* The first blog can be viewed by anybody. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testCanView() { |
|
55
|
|
|
$this->useDraftSite(); |
|
56
|
|
|
|
|
57
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
|
58
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
|
59
|
|
|
|
|
60
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); |
|
|
|
|
|
|
63
|
|
|
$this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.'); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$tag = $this->objFromFixture('BlogTag', 'SecondTag'); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); |
|
|
|
|
|
|
68
|
|
|
$this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.'); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
View Code Duplication |
public function testCanEdit() { |
|
|
|
|
|
|
72
|
|
|
$this->useDraftSite(); |
|
73
|
|
|
|
|
74
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
|
75
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
|
76
|
|
|
|
|
77
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); |
|
|
|
|
|
|
80
|
|
|
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
$tag = $this->objFromFixture('BlogTag', 'SecondTag'); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); |
|
|
|
|
|
|
85
|
|
|
$this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.'); |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
$tag = $this->objFromFixture('BlogTag', 'ThirdTag'); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.'); |
|
|
|
|
|
|
90
|
|
|
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
View Code Duplication |
public function testCanCreate() { |
|
|
|
|
|
|
94
|
|
|
$this->useDraftSite(); |
|
95
|
|
|
|
|
96
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
|
97
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
|
98
|
|
|
|
|
99
|
|
|
$tag = singleton('BlogTag'); |
|
100
|
|
|
|
|
101
|
|
|
$this->assertTrue($tag->canCreate($admin), 'Admin should be able to create tag.'); |
|
|
|
|
|
|
102
|
|
|
$this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.'); |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
View Code Duplication |
public function testCanDelete() { |
|
|
|
|
|
|
106
|
|
|
$this->useDraftSite(); |
|
107
|
|
|
|
|
108
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
|
109
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
|
110
|
|
|
|
|
111
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); |
|
112
|
|
|
|
|
113
|
|
|
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); |
|
|
|
|
|
|
114
|
|
|
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
$tag = $this->objFromFixture('BlogTag', 'SecondTag'); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); |
|
|
|
|
|
|
119
|
|
|
$this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.'); |
|
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
$tag = $this->objFromFixture('BlogTag', 'ThirdTag'); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.'); |
|
|
|
|
|
|
124
|
|
|
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); |
|
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
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.