1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @todo Write some more complex tests for testing the can*() functionality |
5
|
|
|
*/ |
6
|
|
|
class ForumThreadTest extends FunctionalTest { |
|
|
|
|
7
|
|
|
|
8
|
|
|
static $fixture_file = "forum/tests/ForumTest.yml"; |
|
|
|
|
9
|
|
|
|
10
|
|
|
// fixes permission issues with these tests, we don't need to test versioning anyway. |
11
|
|
|
// without this, SiteTree::canView() would always return false even though CanViewType == Anyone. |
12
|
|
|
static $use_draft_site = true; |
|
|
|
|
13
|
|
|
|
14
|
|
|
function testGetNumPosts() { |
|
|
|
|
15
|
|
|
$thread = $this->objFromFixture("ForumThread", "Thread1"); |
16
|
|
|
|
17
|
|
|
$this->assertEquals($thread->getNumPosts(), 17); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
function testIncViews() { |
|
|
|
|
21
|
|
|
$thread = $this->objFromFixture("ForumThread", "Thread1"); |
22
|
|
|
|
23
|
|
|
// clear session |
24
|
|
|
Session::clear('ForumViewed-'.$thread->ID); |
25
|
|
|
|
26
|
|
|
$this->assertEquals($thread->NumViews, '10'); |
|
|
|
|
27
|
|
|
|
28
|
|
|
$thread->incNumViews(); |
29
|
|
|
|
30
|
|
|
$this->assertEquals($thread->NumViews, '11'); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function testGetLatestPost() { |
|
|
|
|
34
|
|
|
$thread = $this->objFromFixture("ForumThread", "Thread1"); |
35
|
|
|
|
36
|
|
|
$this->assertEquals($thread->getLatestPost()->Content, "This is the last post to a long thread"); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function testGetFirstPost() { |
|
|
|
|
40
|
|
|
$thread = $this->objFromFixture("ForumThread", "Thread1"); |
41
|
|
|
|
42
|
|
|
$this->assertEquals($thread->getFirstPost()->Content, "This is my first post"); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function testSubscription() { |
|
|
|
|
46
|
|
|
$thread = $this->objFromFixture("ForumThread", "Thread1"); |
47
|
|
|
$thread2 = $this->objFromFixture("ForumThread", "Thread2"); |
48
|
|
|
|
49
|
|
|
$member = $this->objFromFixture("Member", "test1"); |
50
|
|
|
$member2 = $this->objFromFixture("Member", "test2"); |
51
|
|
|
|
52
|
|
|
$this->assertTrue(ForumThread_Subscription::already_subscribed($thread->ID, $member->ID)); |
|
|
|
|
53
|
|
|
$this->assertTrue(ForumThread_Subscription::already_subscribed($thread->ID, $member2->ID)); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$this->assertFalse(ForumThread_Subscription::already_subscribed($thread2->ID, $member->ID)); |
|
|
|
|
56
|
|
|
$this->assertFalse(ForumThread_Subscription::already_subscribed($thread2->ID, $member2->ID)); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function testOnBeforeDelete() { |
|
|
|
|
60
|
|
|
$thread = new ForumThread(); |
61
|
|
|
$thread->write(); |
62
|
|
|
|
63
|
|
|
$post = new Post(); |
64
|
|
|
$post->ThreadID = $thread->ID; |
|
|
|
|
65
|
|
|
$post->write(); |
66
|
|
|
|
67
|
|
|
$postID = $post->ID; |
68
|
|
|
|
69
|
|
|
$thread->delete(); |
70
|
|
|
|
71
|
|
|
$this->assertFalse(DataObject::get_by_id('Post', $postID)); |
|
|
|
|
72
|
|
|
$this->assertFalse(DataObject::get_by_id('ForumThread', $thread->ID)); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
function testPermissions() { |
|
|
|
|
76
|
|
|
$member = $this->objFromFixture('Member', 'test1'); |
77
|
|
|
$this->session()->inst_set('loggedInAs', $member->ID); |
78
|
|
|
|
79
|
|
|
// read only thread. No one should be able to post to this (apart from the ) |
80
|
|
|
$readonly = $this->objFromFixture('ForumThread', 'ReadonlyThread'); |
81
|
|
|
$this->assertFalse($readonly->canPost()); |
|
|
|
|
82
|
|
|
$this->assertTrue($readonly->canView()); |
|
|
|
|
83
|
|
|
$this->assertFalse($readonly->canModerate()); |
|
|
|
|
84
|
|
|
|
85
|
|
|
// normal thread. They can post to these |
86
|
|
|
$thread = $this->objFromFixture('ForumThread', 'Thread1'); |
87
|
|
|
$this->assertTrue($thread->canPost()); |
|
|
|
|
88
|
|
|
$this->assertTrue($thread->canView()); |
|
|
|
|
89
|
|
|
$this->assertFalse($thread->canModerate()); |
|
|
|
|
90
|
|
|
|
91
|
|
|
// normal thread in a read only |
92
|
|
|
$disabledforum = $this->objFromFixture('ForumThread', 'ThreadWhichIsInInheritedForum'); |
93
|
|
|
$this->assertFalse($disabledforum->canPost()); |
|
|
|
|
94
|
|
|
$this->assertFalse($disabledforum->canView()); |
|
|
|
|
95
|
|
|
$this->assertFalse($disabledforum->canModerate()); |
|
|
|
|
96
|
|
|
|
97
|
|
|
// Moderator can access threads nevertheless |
98
|
|
|
$member = $this->objFromFixture('Member', 'moderator'); |
99
|
|
|
$member->logIn(); |
100
|
|
|
|
101
|
|
|
$this->assertFalse($disabledforum->canPost()); |
|
|
|
|
102
|
|
|
$this->assertTrue($disabledforum->canView()); |
|
|
|
|
103
|
|
|
$this->assertTrue($disabledforum->canModerate()); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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.