|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @todo Write Tests for doPostMessageForm() |
|
5
|
|
|
*/ |
|
6
|
|
|
class ForumTest extends FunctionalTest { |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
static $fixture_file = "forum/tests/ForumTest.yml"; |
|
|
|
|
|
|
9
|
|
|
static $use_draft_site = true; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
View Code Duplication |
function testCanView() { |
|
|
|
|
|
|
12
|
|
|
// test viewing not logged in |
|
13
|
|
|
if($member = Member::currentUser()) $member->logOut(); |
|
14
|
|
|
|
|
15
|
|
|
$public = $this->objFromFixture('Forum', 'general'); |
|
16
|
|
|
$private = $this->objFromFixture('Forum', 'loggedInOnly'); |
|
17
|
|
|
$limited = $this->objFromFixture('Forum', 'limitedToGroup'); |
|
18
|
|
|
$noposting = $this->objFromFixture('Forum', 'noPostingForum'); |
|
19
|
|
|
$inherited = $this->objFromFixture('Forum', 'inheritedForum'); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertTrue($public->canView()); |
|
|
|
|
|
|
22
|
|
|
$this->assertFalse($private->canView()); |
|
|
|
|
|
|
23
|
|
|
$this->assertFalse($limited->canView()); |
|
|
|
|
|
|
24
|
|
|
$this->assertTrue($noposting->canView()); |
|
|
|
|
|
|
25
|
|
|
$this->assertFalse($inherited->canView()); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
// try logging in a member |
|
28
|
|
|
$member = $this->objFromFixture('Member', 'test1'); |
|
29
|
|
|
$member->logIn(); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertTrue($public->canView()); |
|
|
|
|
|
|
32
|
|
|
$this->assertTrue($private->canView()); |
|
|
|
|
|
|
33
|
|
|
$this->assertFalse($limited->canView()); |
|
|
|
|
|
|
34
|
|
|
$this->assertTrue($noposting->canView()); |
|
|
|
|
|
|
35
|
|
|
$this->assertFalse($inherited->canView()); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
// login as a person with access to restricted forum |
|
38
|
|
|
$member = $this->objFromFixture('Member', 'test2'); |
|
39
|
|
|
$member->logIn(); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertTrue($public->canView()); |
|
|
|
|
|
|
42
|
|
|
$this->assertTrue($private->canView()); |
|
|
|
|
|
|
43
|
|
|
$this->assertTrue($limited->canView()); |
|
|
|
|
|
|
44
|
|
|
$this->assertTrue($noposting->canView()); |
|
|
|
|
|
|
45
|
|
|
$this->assertFalse($inherited->canView()); |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
// Moderator should be able to view his own forums |
|
48
|
|
|
$member = $this->objFromFixture('Member', 'moderator'); |
|
49
|
|
|
$member->logIn(); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertTrue($public->canView()); |
|
|
|
|
|
|
52
|
|
|
$this->assertTrue($private->canView()); |
|
|
|
|
|
|
53
|
|
|
$this->assertTrue($limited->canView()); |
|
|
|
|
|
|
54
|
|
|
$this->assertTrue($noposting->canView()); |
|
|
|
|
|
|
55
|
|
|
$this->assertTrue($inherited->canView()); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
View Code Duplication |
function testCanPost() { |
|
|
|
|
|
|
59
|
|
|
// test viewing not logged in |
|
60
|
|
|
if($member = Member::currentUser()) $member->logOut(); |
|
61
|
|
|
|
|
62
|
|
|
$public = $this->objFromFixture('Forum', 'general'); |
|
63
|
|
|
$private = $this->objFromFixture('Forum', 'loggedInOnly'); |
|
64
|
|
|
$limited = $this->objFromFixture('Forum', 'limitedToGroup'); |
|
65
|
|
|
$noposting = $this->objFromFixture('Forum', 'noPostingForum'); |
|
66
|
|
|
$inherited = $this->objFromFixture('Forum', 'inheritedForum'); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertTrue($public->canPost()); |
|
|
|
|
|
|
69
|
|
|
$this->assertFalse($private->canPost()); |
|
|
|
|
|
|
70
|
|
|
$this->assertFalse($limited->canPost()); |
|
|
|
|
|
|
71
|
|
|
$this->assertFalse($noposting->canPost()); |
|
|
|
|
|
|
72
|
|
|
$this->assertFalse($inherited->canPost()); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
// try logging in a member |
|
75
|
|
|
$member = $this->objFromFixture('Member', 'test1'); |
|
76
|
|
|
$member->logIn(); |
|
77
|
|
|
|
|
78
|
|
|
$this->assertTrue($public->canPost()); |
|
|
|
|
|
|
79
|
|
|
$this->assertTrue($private->canPost()); |
|
|
|
|
|
|
80
|
|
|
$this->assertFalse($limited->canPost()); |
|
|
|
|
|
|
81
|
|
|
$this->assertFalse($noposting->canPost()); |
|
|
|
|
|
|
82
|
|
|
$this->assertFalse($inherited->canPost()); |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
// login as a person with access to restricted forum |
|
85
|
|
|
$member = $this->objFromFixture('Member', 'test2'); |
|
86
|
|
|
$member->logIn(); |
|
87
|
|
|
|
|
88
|
|
|
$this->assertTrue($public->canPost()); |
|
|
|
|
|
|
89
|
|
|
$this->assertTrue($private->canPost()); |
|
|
|
|
|
|
90
|
|
|
$this->assertTrue($limited->canPost()); |
|
|
|
|
|
|
91
|
|
|
$this->assertFalse($noposting->canPost()); |
|
|
|
|
|
|
92
|
|
|
$this->assertFalse($inherited->canPost()); |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
// Moderator should be able to view his own forums |
|
95
|
|
|
$member = $this->objFromFixture('Member', 'moderator'); |
|
96
|
|
|
$member->logIn(); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertTrue($public->canPost()); |
|
|
|
|
|
|
99
|
|
|
$this->assertTrue($private->canPost()); |
|
|
|
|
|
|
100
|
|
|
$this->assertFalse($limited->canPost()); |
|
|
|
|
|
|
101
|
|
|
$this->assertFalse($noposting->canPost()); |
|
|
|
|
|
|
102
|
|
|
$this->assertFalse($inherited->canPost()); |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
function testSuspended() { |
|
|
|
|
|
|
106
|
|
|
$private = $this->objFromFixture('Forum', 'loggedInOnly'); |
|
107
|
|
|
$limited = $this->objFromFixture('Forum', 'limitedToGroup'); |
|
108
|
|
|
$inheritedForum_loggedInOnly = $this->objFromFixture('Forum', 'inheritedForum_loggedInOnly'); |
|
109
|
|
|
SS_Datetime::set_mock_now('2011-10-10 12:00:00'); |
|
110
|
|
|
|
|
111
|
|
|
// try logging in a member suspendedexpired |
|
112
|
|
|
$suspendedexpired = $this->objFromFixture('Member', 'suspendedexpired'); |
|
113
|
|
|
$this->assertFalse($suspendedexpired->IsSuspended()); |
|
|
|
|
|
|
114
|
|
|
$suspendedexpired->logIn(); |
|
115
|
|
|
$this->assertTrue($private->canPost()); |
|
|
|
|
|
|
116
|
|
|
$this->assertTrue($limited->canPost()); |
|
|
|
|
|
|
117
|
|
|
$this->assertTrue($inheritedForum_loggedInOnly->canPost()); |
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
// try logging in a member suspended |
|
120
|
|
|
$suspended = $this->objFromFixture('Member', 'suspended'); |
|
121
|
|
|
$this->assertTrue($suspended->IsSuspended()); |
|
|
|
|
|
|
122
|
|
|
$suspended->logIn(); |
|
123
|
|
|
$this->assertFalse($private->canPost()); |
|
|
|
|
|
|
124
|
|
|
$this->assertFalse($limited->canPost()); |
|
|
|
|
|
|
125
|
|
|
$this->assertFalse($inheritedForum_loggedInOnly->canPost()); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
View Code Duplication |
function testCanModerate() { |
|
|
|
|
|
|
129
|
|
|
// test viewing not logged in |
|
130
|
|
|
if($member = Member::currentUser()) $member->logOut(); |
|
131
|
|
|
|
|
132
|
|
|
$public = $this->objFromFixture('Forum', 'general'); |
|
133
|
|
|
$private = $this->objFromFixture('Forum', 'loggedInOnly'); |
|
134
|
|
|
$limited = $this->objFromFixture('Forum', 'limitedToGroup'); |
|
135
|
|
|
$noposting = $this->objFromFixture('Forum', 'noPostingForum'); |
|
136
|
|
|
$inherited = $this->objFromFixture('Forum', 'inheritedForum'); |
|
137
|
|
|
|
|
138
|
|
|
$this->assertFalse($public->canModerate()); |
|
|
|
|
|
|
139
|
|
|
$this->assertFalse($private->canModerate()); |
|
|
|
|
|
|
140
|
|
|
$this->assertFalse($limited->canModerate()); |
|
|
|
|
|
|
141
|
|
|
$this->assertFalse($noposting->canModerate()); |
|
|
|
|
|
|
142
|
|
|
$this->assertFalse($inherited->canModerate()); |
|
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
// try logging in a member |
|
145
|
|
|
$member = $this->objFromFixture('Member', 'test1'); |
|
146
|
|
|
$member->logIn(); |
|
147
|
|
|
|
|
148
|
|
|
$this->assertFalse($public->canModerate()); |
|
|
|
|
|
|
149
|
|
|
$this->assertFalse($private->canModerate()); |
|
|
|
|
|
|
150
|
|
|
$this->assertFalse($limited->canModerate()); |
|
|
|
|
|
|
151
|
|
|
$this->assertFalse($noposting->canModerate()); |
|
|
|
|
|
|
152
|
|
|
$this->assertFalse($inherited->canModerate()); |
|
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
// login as a person with access to restricted forum |
|
155
|
|
|
$member = $this->objFromFixture('Member', 'test2'); |
|
156
|
|
|
$member->logIn(); |
|
157
|
|
|
|
|
158
|
|
|
$this->assertFalse($public->canModerate()); |
|
|
|
|
|
|
159
|
|
|
$this->assertFalse($private->canModerate()); |
|
|
|
|
|
|
160
|
|
|
$this->assertFalse($limited->canModerate()); |
|
|
|
|
|
|
161
|
|
|
$this->assertFalse($noposting->canModerate()); |
|
|
|
|
|
|
162
|
|
|
$this->assertFalse($inherited->canModerate()); |
|
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
// Moderator should be able to view his own forums |
|
165
|
|
|
$member = $this->objFromFixture('Member', 'moderator'); |
|
166
|
|
|
$member->logIn(); |
|
167
|
|
|
|
|
168
|
|
|
$this->assertTrue($public->canModerate()); |
|
|
|
|
|
|
169
|
|
|
$this->assertTrue($private->canModerate()); |
|
|
|
|
|
|
170
|
|
|
$this->assertTrue($limited->canModerate()); |
|
|
|
|
|
|
171
|
|
|
$this->assertTrue($noposting->canModerate()); |
|
|
|
|
|
|
172
|
|
|
$this->assertTrue($inherited->canModerate()); |
|
|
|
|
|
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
function testCanAttach() { |
|
|
|
|
|
|
176
|
|
|
$canAttach = $this->objFromFixture('Forum', 'general'); |
|
177
|
|
|
$this->assertTrue($canAttach->canAttach()); |
|
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
$noAttach = $this->objFromFixture('Forum', 'forum1cat2'); |
|
180
|
|
|
$this->assertFalse($noAttach->canAttach()); |
|
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
function testgetForbiddenWords(){ |
|
|
|
|
|
|
184
|
|
|
$forum = $this->objFromFixture("Forum", "general"); |
|
185
|
|
|
$f_controller = new Forum_Controller($forum); |
|
186
|
|
|
$this->assertEquals($f_controller->getForbiddenWords(), "shit,fuck"); |
|
|
|
|
|
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
function testfilterLanguage(){ |
|
|
|
|
|
|
190
|
|
|
$forum = $this->objFromFixture("Forum", "general"); |
|
191
|
|
|
$f_controller = new Forum_Controller($forum); |
|
192
|
|
|
$this->assertEquals($f_controller->filterLanguage('shit'), "*"); |
|
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
$this->assertEquals($f_controller->filterLanguage('shit and fuck'), "* and *"); |
|
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
$this->assertEquals($f_controller->filterLanguage('hello'), "hello"); |
|
|
|
|
|
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
function testGetStickyTopics() { |
|
|
|
|
|
|
200
|
|
|
$forumWithSticky = $this->objFromFixture("Forum", "general"); |
|
201
|
|
|
$stickies = $forumWithSticky->getStickyTopics(); |
|
202
|
|
|
$this->assertEquals($stickies->Count(), '2'); |
|
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
// TODO: Sorts by Created, which is all equal on all Posts in test, and can't be overridden, so can't rely on order |
|
205
|
|
|
//$this->assertEquals($stickies->First()->Title, 'Global Sticky Thread'); |
|
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
$stickies = $forumWithSticky->getStickyTopics($include_global = false); |
|
208
|
|
|
$this->assertEquals($stickies->Count(), '1'); |
|
|
|
|
|
|
209
|
|
|
$this->assertEquals($stickies->First()->Title, 'Sticky Thread'); |
|
|
|
|
|
|
210
|
|
|
|
|
211
|
|
|
$forumWithGlobalOnly = $this->objFromFixture("Forum", "forum1cat2"); |
|
212
|
|
|
$stickies = $forumWithGlobalOnly->getStickyTopics(); |
|
213
|
|
|
$this->assertEquals($stickies->Count(), '1'); |
|
|
|
|
|
|
214
|
|
|
$this->assertEquals($stickies->First()->Title, 'Global Sticky Thread'); |
|
|
|
|
|
|
215
|
|
|
$stickies = $forumWithGlobalOnly->getStickyTopics($include_global = false); |
|
216
|
|
|
$this->assertEquals($stickies->Count(), '0'); |
|
|
|
|
|
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
View Code Duplication |
function testTopics() { |
|
|
|
|
|
|
220
|
|
|
$forumWithPosts = $this->objFromFixture("Forum", "general"); |
|
221
|
|
|
|
|
222
|
|
|
$this->assertEquals($forumWithPosts->getTopics()->Count(), '4'); |
|
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
$forumWithoutPosts = $this->objFromFixture("Forum", "forum1cat2"); |
|
225
|
|
|
$result = $forumWithoutPosts->getTopics(); |
|
226
|
|
|
$this->assertEquals(0, $result->count()); |
|
|
|
|
|
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
function testGetLatestPost() { |
|
|
|
|
|
|
230
|
|
|
$forumWithPosts = $this->objFromFixture("Forum", "general"); |
|
231
|
|
|
|
|
232
|
|
|
$this->assertEquals($forumWithPosts->getLatestPost()->Content, 'This is the last post to a long thread'); |
|
|
|
|
|
|
233
|
|
|
|
|
234
|
|
|
$forumWithoutPosts = $this->objFromFixture("Forum", "forum1cat2"); |
|
235
|
|
|
|
|
236
|
|
|
$this->assertNull($forumWithoutPosts->getLatestPost()); |
|
|
|
|
|
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
View Code Duplication |
function testGetNumTopics() { |
|
|
|
|
|
|
240
|
|
|
$forumWithPosts = $this->objFromFixture("Forum", "general"); |
|
241
|
|
|
|
|
242
|
|
|
$this->assertEquals($forumWithPosts->getNumTopics(), 6); |
|
|
|
|
|
|
243
|
|
|
|
|
244
|
|
|
$forumWithoutPosts = $this->objFromFixture("Forum", "forum1cat2"); |
|
245
|
|
|
|
|
246
|
|
|
$this->assertEquals($forumWithoutPosts->getNumTopics(), 0); |
|
|
|
|
|
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
View Code Duplication |
function testGetTotalAuthors() { |
|
|
|
|
|
|
250
|
|
|
$forumWithPosts = $this->objFromFixture("Forum", "general"); |
|
251
|
|
|
|
|
252
|
|
|
$this->assertEquals($forumWithPosts->getNumAuthors(), 4); |
|
|
|
|
|
|
253
|
|
|
|
|
254
|
|
|
$forumWithoutPosts = $this->objFromFixture("Forum", "forum1cat2"); |
|
255
|
|
|
|
|
256
|
|
|
$this->assertEquals($forumWithoutPosts->getNumAuthors(), 0); |
|
|
|
|
|
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Note: See {@link testCanModerate()} for detailed permission tests. |
|
261
|
|
|
*/ |
|
262
|
|
|
public function testMarkAsSpamLink() { |
|
263
|
|
|
$spampost = $this->objFromFixture('Post', 'SpamSecondPost'); |
|
264
|
|
|
$this->assertFalse($spampost->isFirstPost()); |
|
|
|
|
|
|
265
|
|
|
$forum = $spampost->Forum(); |
|
266
|
|
|
$author = $spampost->Author(); |
|
267
|
|
|
$moderator = $this->objFromFixture('Member', 'moderator'); // moderator for "general" forum |
|
268
|
|
|
|
|
269
|
|
|
// without a logged-in moderator |
|
270
|
|
|
$this->assertFalse($spampost->MarkAsSpamLink(), 'Link not present by default'); |
|
|
|
|
|
|
271
|
|
|
|
|
272
|
|
|
$c = new Forum_Controller($forum); |
|
273
|
|
|
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'markasspam/'. $spampost->ID), DataModel::inst()); |
|
274
|
|
|
$this->assertEquals(403, $response->getStatusCode()); |
|
|
|
|
|
|
275
|
|
|
|
|
276
|
|
|
// with logged-in moderator |
|
277
|
|
|
$moderator->logIn(); |
|
278
|
|
|
$this->assertNotEquals(false, $spampost->MarkAsSpamLink(), 'Link present for moderators on this forum'); |
|
|
|
|
|
|
279
|
|
|
|
|
280
|
|
|
$this->assertNull($author->SuspendedUntil); |
|
|
|
|
|
|
281
|
|
|
|
|
282
|
|
|
$c = new Forum_Controller($forum); |
|
283
|
|
|
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'markasspam/'. $spampost->ID), DataModel::inst()); |
|
284
|
|
|
$this->assertFalse($response->isError()); |
|
|
|
|
|
|
285
|
|
|
|
|
286
|
|
|
// removes the post |
|
287
|
|
|
$this->assertNull(Post::get()->byID($spampost->ID)); |
|
|
|
|
|
|
288
|
|
|
|
|
289
|
|
|
// suspends the member |
|
290
|
|
|
$author = Member::get()->byID($author->ID); |
|
291
|
|
|
$this->assertNotNull($author->SuspendedUntil); |
|
|
|
|
|
|
292
|
|
|
|
|
293
|
|
|
// does not effect the thread |
|
294
|
|
|
$thread = ForumThread::get()->byID($spampost->Thread()->ID); |
|
295
|
|
|
$this->assertEquals('1', $thread->getNumPosts()); |
|
|
|
|
|
|
296
|
|
|
|
|
297
|
|
|
// mark the first post in that now as spam |
|
298
|
|
|
$spamfirst = $this->objFromFixture('Post', 'SpamFirstPost'); |
|
299
|
|
|
|
|
300
|
|
|
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'markasspam/'. $spamfirst->ID), DataModel::inst()); |
|
|
|
|
|
|
301
|
|
|
|
|
302
|
|
|
// removes the thread |
|
303
|
|
|
$this->assertNull(ForumThread::get()->byID($spamfirst->Thread()->ID)); |
|
|
|
|
|
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
function testBanLink() { |
|
|
|
|
|
|
307
|
|
|
$spampost = $this->objFromFixture('Post', 'SpamSecondPost'); |
|
308
|
|
|
$forum = $spampost->Forum(); |
|
309
|
|
|
$author = $spampost->Author(); |
|
310
|
|
|
$moderator = $this->objFromFixture('Member', 'moderator'); // moderator for "general" forum |
|
311
|
|
|
|
|
312
|
|
|
// without a logged-in moderator |
|
313
|
|
|
$this->assertFalse($spampost->BanLink(), 'Link not present by default'); |
|
|
|
|
|
|
314
|
|
|
|
|
315
|
|
|
$c = new Forum_Controller($forum); |
|
316
|
|
|
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'ban/'. $spampost->AuthorID), DataModel::inst()); |
|
317
|
|
|
$this->assertEquals(403, $response->getStatusCode()); |
|
|
|
|
|
|
318
|
|
|
|
|
319
|
|
|
// with logged-in moderator |
|
320
|
|
|
$moderator->logIn(); |
|
321
|
|
|
$this->assertNotEquals(false, $spampost->BanLink(), 'Link present for moderators on this forum'); |
|
|
|
|
|
|
322
|
|
|
|
|
323
|
|
|
$c = new Forum_Controller($forum); |
|
324
|
|
|
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'ban/'. $spampost->AuthorID), DataModel::inst()); |
|
325
|
|
|
$this->assertFalse($response->isError()); |
|
|
|
|
|
|
326
|
|
|
|
|
327
|
|
|
// user is banned |
|
328
|
|
|
$author = Member::get()->byId($author->ID); |
|
329
|
|
|
$this->assertTrue($author->IsBanned()); |
|
|
|
|
|
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
function testGhostLink() { |
|
|
|
|
|
|
333
|
|
|
$spampost = $this->objFromFixture('Post', 'SpamSecondPost'); |
|
334
|
|
|
$forum = $spampost->Forum(); |
|
335
|
|
|
$author = $spampost->Author(); |
|
336
|
|
|
$moderator = $this->objFromFixture('Member', 'moderator'); // moderator for "general" forum |
|
337
|
|
|
|
|
338
|
|
|
// without a logged-in moderator |
|
339
|
|
|
$this->assertFalse($spampost->GhostLink(), 'Link not present by default'); |
|
|
|
|
|
|
340
|
|
|
|
|
341
|
|
|
$c = new Forum_Controller($forum); |
|
342
|
|
|
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'ghost/'. $spampost->AuthorID), DataModel::inst()); |
|
343
|
|
|
$this->assertEquals(403, $response->getStatusCode()); |
|
|
|
|
|
|
344
|
|
|
|
|
345
|
|
|
// with logged-in moderator |
|
346
|
|
|
$moderator->logIn(); |
|
347
|
|
|
$this->assertNotEquals(false, $spampost->GhostLink(), 'Link present for moderators on this forum'); |
|
|
|
|
|
|
348
|
|
|
|
|
349
|
|
|
$c = new Forum_Controller($forum); |
|
350
|
|
|
$response = $c->handleRequest(new SS_HTTPRequest('GET', 'ghost/'. $spampost->AuthorID), DataModel::inst()); |
|
351
|
|
|
$this->assertFalse($response->isError()); |
|
|
|
|
|
|
352
|
|
|
|
|
353
|
|
|
// post isn't available anymore in normal queries. {@link ForumSpamPostExtension} |
|
354
|
|
|
$post = Post::get()->byId($spampost->ID); |
|
355
|
|
|
$this->assertNull($post); |
|
|
|
|
|
|
356
|
|
|
|
|
357
|
|
|
// user is banned |
|
358
|
|
|
$author = Member::get()->byId($author->ID); |
|
359
|
|
|
$this->assertTrue($author->IsGhost()); |
|
|
|
|
|
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
function testNotifyModerators() { |
|
|
|
|
|
|
363
|
|
|
SecurityToken::disable(); |
|
364
|
|
|
$notifyModerators = Forum::$notify_moderators; |
|
|
|
|
|
|
365
|
|
|
Forum::$notify_moderators = true; |
|
|
|
|
|
|
366
|
|
|
|
|
367
|
|
|
$forum = $this->objFromFixture('Forum', 'general'); |
|
368
|
|
|
$controller = new Forum_Controller($forum); |
|
|
|
|
|
|
369
|
|
|
$user = $this->objFromFixture('Member', 'test1'); |
|
370
|
|
|
$this->session()->inst_set('loggedInAs', $user->ID); |
|
371
|
|
|
|
|
372
|
|
|
// New thread |
|
373
|
|
|
$this->post( |
|
374
|
|
|
$forum->RelativeLink('PostMessageForm'), |
|
375
|
|
|
array( |
|
376
|
|
|
'Title' => 'New thread', |
|
377
|
|
|
'Content' => 'Meticulously crafted content', |
|
378
|
|
|
'action_doPostMessageForm' => 1 |
|
379
|
|
|
) |
|
380
|
|
|
); |
|
381
|
|
|
|
|
382
|
|
|
$adminEmail = Config::inst()->get('Email', 'admin_email'); |
|
383
|
|
|
|
|
384
|
|
|
$this->assertEmailSent('[email protected]', $adminEmail, "New thread \"New thread\" in forum [General Discussion]"); |
|
385
|
|
|
$this->clearEmails(); |
|
386
|
|
|
|
|
387
|
|
|
// New response |
|
388
|
|
|
$thread = DataObject::get_one('ForumThread', "\"ForumThread\".\"Title\"='New thread'"); |
|
389
|
|
|
$this->post( |
|
390
|
|
|
$forum->RelativeLink('PostMessageForm'), |
|
391
|
|
|
array( |
|
392
|
|
|
'Title' => 'Re: New thread', |
|
393
|
|
|
'Content' => 'Rough response', |
|
394
|
|
|
'ThreadID' => $thread->ID, |
|
395
|
|
|
'action_doPostMessageForm' => 1 |
|
396
|
|
|
) |
|
397
|
|
|
); |
|
398
|
|
|
$this->assertEmailSent('[email protected]', $adminEmail, "New post \"Re: New thread\" in forum [General Discussion]"); |
|
399
|
|
|
$this->clearEmails(); |
|
400
|
|
|
|
|
401
|
|
|
// Edit |
|
402
|
|
|
$post = $thread->Posts()->Last(); |
|
403
|
|
|
$this->post( |
|
404
|
|
|
$forum->RelativeLink('PostMessageForm'), |
|
405
|
|
|
array( |
|
406
|
|
|
'Title' => 'Re: New thread', |
|
407
|
|
|
'Content' => 'Pleasant response', |
|
408
|
|
|
'ThreadID' => $thread->ID, |
|
409
|
|
|
'ID' => $post->ID, |
|
410
|
|
|
'action_doPostMessageForm' => 1 |
|
411
|
|
|
) |
|
412
|
|
|
); |
|
413
|
|
|
$this->assertEmailSent('[email protected]', $adminEmail, "New post \"Re: New thread\" in forum [General Discussion]"); |
|
414
|
|
|
$this->clearEmails(); |
|
415
|
|
|
|
|
416
|
|
|
Forum::$notify_moderators = $notifyModerators; |
|
|
|
|
|
|
417
|
|
|
} |
|
418
|
|
|
} |
|
419
|
|
|
|
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.