|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @mixin PHPUnit_Framework_TestCase |
|
5
|
|
|
*/ |
|
6
|
|
|
class BlogTagTest 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 $tag->BlogPosts() many_many are published, both by |
|
35
|
|
|
* 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 BlogTag $tag |
|
49
|
|
|
*/ |
|
50
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag 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
|
|
|
$tag = new BlogTag(); |
|
62
|
|
|
$tag->BlogID = $blog->ID; |
|
63
|
|
|
$tag->Title = 'تست'; |
|
64
|
|
|
$tag->write(); |
|
65
|
|
|
// urlencoded |
|
66
|
|
|
$this->assertEquals('%D8%AA%D8%B3%D8%AA', $tag->URLSegment); |
|
|
|
|
|
|
67
|
|
|
$link = Controller::join_links($tag->Blog()->Link(), 'tag', '%D8%AA%D8%B3%D8%AA'); |
|
68
|
|
|
$this->assertEquals($link, $tag->getLink()); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* The first blog can be viewed by anybody. |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testCanView() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->useDraftSite(); |
|
77
|
|
|
|
|
78
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
|
79
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
|
80
|
|
|
|
|
81
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); |
|
|
|
|
|
|
84
|
|
|
$this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.'); |
|
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
$tag = $this->objFromFixture('BlogTag', 'SecondTag'); |
|
87
|
|
|
|
|
88
|
|
|
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); |
|
|
|
|
|
|
89
|
|
|
$this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.'); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
View Code Duplication |
public function testCanEdit() |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
$this->useDraftSite(); |
|
95
|
|
|
|
|
96
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
|
97
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
|
98
|
|
|
|
|
99
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); |
|
100
|
|
|
|
|
101
|
|
|
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); |
|
|
|
|
|
|
102
|
|
|
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
$tag = $this->objFromFixture('BlogTag', 'SecondTag'); |
|
105
|
|
|
|
|
106
|
|
|
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); |
|
|
|
|
|
|
107
|
|
|
$this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.'); |
|
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
$tag = $this->objFromFixture('BlogTag', 'ThirdTag'); |
|
110
|
|
|
|
|
111
|
|
|
$this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.'); |
|
|
|
|
|
|
112
|
|
|
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
View Code Duplication |
public function testCanCreate() |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
$this->useDraftSite(); |
|
118
|
|
|
|
|
119
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
|
120
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
|
121
|
|
|
|
|
122
|
|
|
$tag = singleton('BlogTag'); |
|
123
|
|
|
|
|
124
|
|
|
$this->assertTrue($tag->canCreate($admin), 'Admin should be able to create tag.'); |
|
|
|
|
|
|
125
|
|
|
$this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.'); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
View Code Duplication |
public function testCanDelete() |
|
|
|
|
|
|
129
|
|
|
{ |
|
130
|
|
|
$this->useDraftSite(); |
|
131
|
|
|
|
|
132
|
|
|
$admin = $this->objFromFixture('Member', 'Admin'); |
|
133
|
|
|
$editor = $this->objFromFixture('Member', 'Editor'); |
|
134
|
|
|
|
|
135
|
|
|
$tag = $this->objFromFixture('BlogTag', 'FirstTag'); |
|
136
|
|
|
|
|
137
|
|
|
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); |
|
|
|
|
|
|
138
|
|
|
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); |
|
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
$tag = $this->objFromFixture('BlogTag', 'SecondTag'); |
|
141
|
|
|
|
|
142
|
|
|
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); |
|
|
|
|
|
|
143
|
|
|
$this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.'); |
|
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
$tag = $this->objFromFixture('BlogTag', 'ThirdTag'); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.'); |
|
|
|
|
|
|
148
|
|
|
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); |
|
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function testDuplicateTagsForURLSegment() { |
|
152
|
|
|
$blog = new Blog(); |
|
153
|
|
|
$blog->Title = 'Testing for duplicates blog'; |
|
154
|
|
|
$blog->write(); |
|
155
|
|
|
$tag1 = new BlogTag(); |
|
156
|
|
|
$tag1->Title = 'cat-test'; |
|
157
|
|
|
$tag1->BlogID = $blog->ID; |
|
158
|
|
|
$tag1->write(); |
|
159
|
|
|
$this->assertEquals('cat-test', $tag1->URLSegment); |
|
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
$tag2 = new BlogTag(); |
|
162
|
|
|
$tag2->Title = 'cat test'; |
|
163
|
|
|
$tag2->BlogID = $blog->ID; |
|
164
|
|
|
$tag2->write(); |
|
165
|
|
|
$this->assertEquals('cat-test-0', $tag2->URLSegment); |
|
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
View Code Duplication |
public function testDuplicateTags() { |
|
|
|
|
|
|
170
|
|
|
$blog = new Blog(); |
|
171
|
|
|
$blog->Title = 'Testing for duplicate tags'; |
|
172
|
|
|
$blog->write(); |
|
173
|
|
|
|
|
174
|
|
|
$tag = new BlogTag(); |
|
175
|
|
|
$tag->Title = 'Test'; |
|
176
|
|
|
$tag->BlogID = $blog->ID; |
|
177
|
|
|
$tag->write(); |
|
178
|
|
|
|
|
179
|
|
|
$tag = new BlogTag(); |
|
180
|
|
|
$tag->Title = 'Test'; |
|
181
|
|
|
$tag->BlogID = $blog->ID; |
|
182
|
|
|
try { |
|
183
|
|
|
$tag->write(); |
|
184
|
|
|
$this->fail('Duplicate BlogTag written'); |
|
|
|
|
|
|
185
|
|
|
} catch (ValidationException $e) { |
|
186
|
|
|
$codeList = $e->getResult()->codeList(); |
|
187
|
|
|
$this->assertCount(1, $codeList); |
|
|
|
|
|
|
188
|
|
|
$this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $codeList[0]); |
|
|
|
|
|
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
} |
|
193
|
|
|
|
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.