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
|
|
|
/** |
56
|
|
|
* @see https://github.com/silverstripe/silverstripe-blog/issues/376 |
57
|
|
|
*/ |
58
|
|
View Code Duplication |
public function testAllowMultibyteUrlSegment() |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$blog = $this->objFromFixture('Blog', 'FirstBlog'); |
61
|
|
|
$cat = new BlogCategory(); |
62
|
|
|
$cat->BlogID = $blog->ID; |
63
|
|
|
$cat->Title = 'تست'; |
|
|
|
|
64
|
|
|
$cat->write(); |
65
|
|
|
// urlencoded |
66
|
|
|
$this->assertEquals('%D8%AA%D8%B3%D8%AA', $cat->URLSegment); |
|
|
|
|
67
|
|
|
$link = Controller::join_links($cat->Blog()->Link(), 'category', '%D8%AA%D8%B3%D8%AA'); |
68
|
|
|
$this->assertEquals($link, $cat->getLink()); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testCanView() |
72
|
|
|
{ |
73
|
|
|
$this->useDraftSite(); |
74
|
|
|
|
75
|
|
|
$this->objFromFixture('Member', 'Admin'); |
76
|
|
|
|
77
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
78
|
|
|
$category = $this->objFromFixture('BlogCategory', 'SecondCategory'); |
79
|
|
|
|
80
|
|
|
$this->assertFalse($category->canView($editor), 'Editor should not be able to view category.'); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* The first blog can be viewed by anybody. |
85
|
|
|
*/ |
86
|
|
View Code Duplication |
public function testCanEdit() |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
$this->useDraftSite(); |
89
|
|
|
|
90
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
91
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
92
|
|
|
|
93
|
|
|
$category = $this->objFromFixture('BlogCategory', 'FirstCategory'); |
94
|
|
|
|
95
|
|
|
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); |
|
|
|
|
96
|
|
|
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); |
|
|
|
|
97
|
|
|
|
98
|
|
|
$category = $this->objFromFixture('BlogCategory', 'SecondCategory'); |
99
|
|
|
|
100
|
|
|
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); |
|
|
|
|
101
|
|
|
$this->assertFalse($category->canEdit($editor), 'Editor should not be able to edit category.'); |
|
|
|
|
102
|
|
|
|
103
|
|
|
$category = $this->objFromFixture('BlogCategory', 'ThirdCategory'); |
104
|
|
|
|
105
|
|
|
$this->assertTrue($category->canEdit($admin), 'Admin should always be able to edit category.'); |
|
|
|
|
106
|
|
|
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
View Code Duplication |
public function testCanCreate() |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
$this->useDraftSite(); |
112
|
|
|
|
113
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
114
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
115
|
|
|
|
116
|
|
|
$category = singleton('BlogCategory'); |
117
|
|
|
|
118
|
|
|
$this->assertTrue($category->canCreate($admin), 'Admin should be able to create category.'); |
|
|
|
|
119
|
|
|
$this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.'); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
View Code Duplication |
public function testCanDelete() |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
$this->useDraftSite(); |
125
|
|
|
|
126
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
127
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
128
|
|
|
|
129
|
|
|
$category = $this->objFromFixture('BlogCategory', 'FirstCategory'); |
130
|
|
|
|
131
|
|
|
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); |
|
|
|
|
132
|
|
|
$this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.'); |
|
|
|
|
133
|
|
|
|
134
|
|
|
$category = $this->objFromFixture('BlogCategory', 'SecondCategory'); |
135
|
|
|
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); |
|
|
|
|
136
|
|
|
$this->assertFalse($category->canDelete($editor), 'Editor should not be able to delete category.'); |
|
|
|
|
137
|
|
|
|
138
|
|
|
$category = $this->objFromFixture('BlogCategory', 'ThirdCategory'); |
139
|
|
|
$this->assertTrue($category->canDelete($admin), 'Admin should always be able to delete category.'); |
|
|
|
|
140
|
|
|
$this->assertTrue($category->canDelete($editor), 'Editor should be able to delete category.'); |
|
|
|
|
141
|
|
|
} |
142
|
|
|
|
143
|
|
View Code Duplication |
public function testDuplicateCategories() { |
|
|
|
|
144
|
|
|
$blog = new Blog(); |
145
|
|
|
$blog->Title = 'Testing for duplicate categories'; |
146
|
|
|
$blog->write(); |
147
|
|
|
|
148
|
|
|
$category = new BlogCategory(); |
149
|
|
|
$category->Title = 'Test'; |
|
|
|
|
150
|
|
|
$category->BlogID = $blog->ID; |
151
|
|
|
$category->write(); |
152
|
|
|
|
153
|
|
|
$category = new BlogCategory(); |
154
|
|
|
$category->Title = 'Test'; |
|
|
|
|
155
|
|
|
$category->BlogID = $blog->ID; |
156
|
|
|
try { |
157
|
|
|
$category->write(); |
158
|
|
|
$this->fail('Duplicate BlogCategory written'); |
|
|
|
|
159
|
|
|
} catch (ValidationException $e) { |
160
|
|
|
$codeList = $e->getResult()->codeList(); |
161
|
|
|
$this->assertCount(1, $codeList); |
|
|
|
|
162
|
|
|
$this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $codeList[0]); |
|
|
|
|
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
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.