1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @mixin PHPUnit_Framework_TestCase |
5
|
|
|
*/ |
6
|
|
|
class BlogCategoryTest extends FunctionalTest |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @var string |
10
|
|
|
*/ |
11
|
|
|
public static $fixture_file = 'blog.yml'; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* {@inheritdoc} |
15
|
|
|
*/ |
16
|
|
|
public function setUp() |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
|
20
|
|
|
SS_Datetime::set_mock_now('2013-10-10 20:00:00'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function tearDown() |
27
|
|
|
{ |
28
|
|
|
SS_Datetime::clear_mock_now(); |
29
|
|
|
|
30
|
|
|
parent::tearDown(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Tests that any blog posts returned from $category->BlogPosts() many_many are published, |
35
|
|
|
* both by normal 'save & publish' functionality and by publish date. |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function testBlogPosts() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$member = Member::currentUser(); |
40
|
|
|
|
41
|
|
|
if ($member) { |
42
|
|
|
$member->logout(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->objFromFixture('BlogPost', 'FirstBlogPost'); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var BlogCategory $category |
49
|
|
|
*/ |
50
|
|
|
$category = $this->objFromFixture('BlogCategory', 'FirstCategory'); |
51
|
|
|
|
52
|
|
|
$this->assertEquals(5, $category->BlogPosts()->count(), 'Category blog post count'); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testCanView() |
56
|
|
|
{ |
57
|
|
|
$this->useDraftSite(); |
58
|
|
|
|
59
|
|
|
$this->objFromFixture('Member', 'Admin'); |
60
|
|
|
|
61
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
62
|
|
|
$category = $this->objFromFixture('BlogCategory', 'SecondCategory'); |
63
|
|
|
|
64
|
|
|
$this->assertFalse($category->canView($editor), 'Editor should not be able to view category.'); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* The first blog can be viewed by anybody. |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public function testCanEdit() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$this->useDraftSite(); |
73
|
|
|
|
74
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
75
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
76
|
|
|
|
77
|
|
|
$category = $this->objFromFixture('BlogCategory', 'FirstCategory'); |
78
|
|
|
|
79
|
|
|
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); |
|
|
|
|
80
|
|
|
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); |
|
|
|
|
81
|
|
|
|
82
|
|
|
$category = $this->objFromFixture('BlogCategory', 'SecondCategory'); |
83
|
|
|
|
84
|
|
|
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); |
|
|
|
|
85
|
|
|
$this->assertFalse($category->canEdit($editor), 'Editor should not be able to edit category.'); |
|
|
|
|
86
|
|
|
|
87
|
|
|
$category = $this->objFromFixture('BlogCategory', 'ThirdCategory'); |
88
|
|
|
|
89
|
|
|
$this->assertTrue($category->canEdit($admin), 'Admin should always be able to edit category.'); |
|
|
|
|
90
|
|
|
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
View Code Duplication |
public function testCanCreate() |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$this->useDraftSite(); |
96
|
|
|
|
97
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
98
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
99
|
|
|
|
100
|
|
|
$category = singleton('BlogCategory'); |
101
|
|
|
|
102
|
|
|
$this->assertTrue($category->canCreate($admin), 'Admin should be able to create category.'); |
|
|
|
|
103
|
|
|
$this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.'); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
View Code Duplication |
public function testCanDelete() |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
$this->useDraftSite(); |
109
|
|
|
|
110
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
111
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
112
|
|
|
|
113
|
|
|
$category = $this->objFromFixture('BlogCategory', 'FirstCategory'); |
114
|
|
|
|
115
|
|
|
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); |
|
|
|
|
116
|
|
|
$this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.'); |
|
|
|
|
117
|
|
|
|
118
|
|
|
$category = $this->objFromFixture('BlogCategory', 'SecondCategory'); |
119
|
|
|
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); |
|
|
|
|
120
|
|
|
$this->assertFalse($category->canDelete($editor), 'Editor should not be able to delete category.'); |
|
|
|
|
121
|
|
|
|
122
|
|
|
$category = $this->objFromFixture('BlogCategory', 'ThirdCategory'); |
123
|
|
|
$this->assertTrue($category->canDelete($admin), 'Admin should always be able to delete category.'); |
|
|
|
|
124
|
|
|
$this->assertTrue($category->canDelete($editor), 'Editor should be able to delete category.'); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
View Code Duplication |
public function testDuplicateCategories() { |
|
|
|
|
128
|
|
|
$blog = new Blog(); |
129
|
|
|
$blog->Title = 'Testing for duplicate categories'; |
130
|
|
|
$blog->write(); |
131
|
|
|
|
132
|
|
|
$category = new BlogCategory(); |
133
|
|
|
$category->Title = 'Test'; |
|
|
|
|
134
|
|
|
$category->BlogID = $blog->ID; |
135
|
|
|
$category->write(); |
136
|
|
|
|
137
|
|
|
$category = new BlogCategory(); |
138
|
|
|
$category->Title = 'Test'; |
|
|
|
|
139
|
|
|
$category->BlogID = $blog->ID; |
140
|
|
|
try { |
141
|
|
|
$category->write(); |
142
|
|
|
$this->fail('Duplicate BlogCategory written'); |
|
|
|
|
143
|
|
|
} catch (ValidationException $e) { |
144
|
|
|
$codeList = $e->getResult()->codeList(); |
145
|
|
|
$this->assertCount(1, $codeList); |
|
|
|
|
146
|
|
|
$this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $codeList[0]); |
|
|
|
|
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
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.