1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @todo Write tests to cover the RSS feeds |
5
|
|
|
*/ |
6
|
|
|
class ForumHolderTest extends FunctionalTest { |
|
|
|
|
7
|
|
|
|
8
|
|
|
static $fixture_file = "forum/tests/ForumTest.yml"; |
|
|
|
|
9
|
|
|
|
10
|
|
|
public function setUp() { |
11
|
|
|
parent::setUp(); |
12
|
|
|
|
13
|
|
|
// these assertions assume we're logged in with full permissions |
14
|
|
|
$this->logInWithPermission('ADMIN'); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Tests around multiple forum holders, to ensure that given a forum holder, methods only retrieve |
19
|
|
|
* categories and forums relevant to that holder. |
20
|
|
|
* |
21
|
|
|
* @return unknown_type |
22
|
|
|
*/ |
23
|
|
|
function testGetForums() { |
|
|
|
|
24
|
|
|
$fh = $this->objFromFixture("ForumHolder", "fh"); |
25
|
|
|
$fh_controller = new ForumHolder_Controller($fh); |
26
|
|
|
|
27
|
|
|
// one forum which is viewable. |
28
|
|
|
$this->assertEquals('1', $fh_controller->Forums()->Count(), "Forum holder has 1 forum"); |
|
|
|
|
29
|
|
|
|
30
|
|
|
// Test ForumHolder::Categories() on 'fh', from which we expect 2 categories |
31
|
|
|
$this->assertTrue($fh_controller->Categories()->Count() == 2, "fh has two categories"); |
|
|
|
|
32
|
|
|
|
33
|
|
|
// Test what we got back from the two categories. The first expects 2 forums, the second |
34
|
|
|
// expects none. |
35
|
|
|
$this->assertTrue($fh_controller->Categories()->First()->Forums()->Count() == 0, "fh first category has 0 forums"); |
|
|
|
|
36
|
|
|
$this->assertTrue($fh_controller->Categories()->Last()->Forums()->Count() == 2, "fh second category has 2 forums"); |
|
|
|
|
37
|
|
|
|
38
|
|
|
// Test ForumHolder::Categories() on 'fh2', from which we expect 2 categories |
39
|
|
|
$fh2 = $this->objFromFixture("ForumHolder", "fh2"); |
40
|
|
|
$fh2_controller = new ForumHolder_Controller($fh2); |
41
|
|
|
$this->assertTrue($fh2_controller->Categories()->Count() == 2, "fh first forum has two categories"); |
|
|
|
|
42
|
|
|
|
43
|
|
|
// Test what we got back from the two categories. Each expects 1. |
44
|
|
|
$this->assertTrue($fh2_controller->Categories()->First()->Forums()->Count() == 1, "fh first category has 1 forums"); |
|
|
|
|
45
|
|
|
$this->assertTrue($fh2_controller->Categories()->Last()->Forums()->Count() == 1, "fh second category has 1 forums"); |
|
|
|
|
46
|
|
|
|
47
|
|
|
|
48
|
|
|
// plain forums (not nested in categories) |
49
|
|
|
$forumHolder = $this->objFromFixture("ForumHolder", "fhNoCategories"); |
50
|
|
|
|
51
|
|
|
$this->assertEquals($forumHolder->Forums()->Count(), 1); |
|
|
|
|
52
|
|
|
$this->assertEquals($forumHolder->Forums()->First()->Title, "Forum Without Category"); |
|
|
|
|
53
|
|
|
|
54
|
|
|
// plain forums with nested in categories enabled (but shouldn't effect it) |
55
|
|
|
$forumHolder = $this->objFromFixture("ForumHolder", "fhNoCategories"); |
56
|
|
|
$forumHolder->ShowInCategories = true; |
57
|
|
|
$forumHolder->write(); |
58
|
|
|
|
59
|
|
|
$this->assertEquals($forumHolder->Forums()->Count(), 1); |
|
|
|
|
60
|
|
|
$this->assertEquals($forumHolder->Forums()->First()->Title, "Forum Without Category"); |
|
|
|
|
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
function testGetNumPosts() { |
|
|
|
|
65
|
|
|
// test holder with posts |
66
|
|
|
$fh = $this->objFromFixture("ForumHolder", "fh"); |
67
|
|
|
$this->assertEquals($fh->getNumPosts(), 24); |
|
|
|
|
68
|
|
|
|
69
|
|
|
// test holder that doesn't have posts |
70
|
|
|
$fh2 = $this->objFromFixture("ForumHolder", "fh2"); |
71
|
|
|
$this->assertEquals($fh2->getNumPosts(), 0); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
View Code Duplication |
function testGetNumTopics() { |
|
|
|
|
75
|
|
|
// test holder with posts |
76
|
|
|
$fh = $this->objFromFixture("ForumHolder", "fh"); |
77
|
|
|
$this->assertEquals($fh->getNumTopics(), 6); |
|
|
|
|
78
|
|
|
|
79
|
|
|
// test holder that doesn't have posts |
80
|
|
|
$fh2 = $this->objFromFixture("ForumHolder", "fh2"); |
81
|
|
|
$this->assertEquals($fh2->getNumTopics(), 0); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
View Code Duplication |
function testGetNumAuthors() { |
|
|
|
|
85
|
|
|
// test holder with posts |
86
|
|
|
$fh = $this->objFromFixture("ForumHolder", "fh"); |
87
|
|
|
$this->assertEquals($fh->getNumAuthors(), 4); |
|
|
|
|
88
|
|
|
|
89
|
|
|
// test holder that doesn't have posts |
90
|
|
|
$fh2 = $this->objFromFixture("ForumHolder", "fh2"); |
91
|
|
|
$this->assertEquals($fh2->getNumAuthors(), 0); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
function testGetRecentPosts() { |
|
|
|
|
95
|
|
|
// test holder with posts |
96
|
|
|
$fh = $this->objFromFixture("ForumHolder", "fh"); |
97
|
|
|
|
98
|
|
|
// make sure all the posts are included |
99
|
|
|
$this->assertEquals($fh->getRecentPosts()->Count(), 24); |
|
|
|
|
100
|
|
|
|
101
|
|
|
// check they're in the right order (well if the first and last are right its fairly safe) |
102
|
|
|
$this->assertEquals($fh->getRecentPosts()->First()->Content, "This is the last post to a long thread"); |
|
|
|
|
103
|
|
|
|
104
|
|
|
// test holder that doesn't have posts |
105
|
|
|
$fh2 = $this->objFromFixture("ForumHolder", "fh2"); |
106
|
|
|
$this->assertNull($fh2->getRecentPosts()); |
|
|
|
|
107
|
|
|
|
108
|
|
|
// test trying to get recent posts specific forum without posts |
109
|
|
|
$forum = $this->objFromFixture("Forum", "forum1cat2"); |
110
|
|
|
$this->assertNull($fh->getRecentPosts(50, $forum->ID)); |
|
|
|
|
111
|
|
|
|
112
|
|
|
// test trying to get recent posts specific to a forum which has posts |
113
|
|
|
$forum = $this->objFromFixture("Forum", "general"); |
114
|
|
|
|
115
|
|
|
$this->assertEquals($fh->getRecentPosts(50, $forum->ID)->Count(), 24); |
|
|
|
|
116
|
|
|
$this->assertEquals($fh->getRecentPosts(50, $forum->ID)->First()->Content, "This is the last post to a long thread"); |
|
|
|
|
117
|
|
|
|
118
|
|
|
// test trying to filter by a specific thread |
119
|
|
|
$thread = $this->objFromFixture("ForumThread","Thread1"); |
120
|
|
|
|
121
|
|
|
$this->assertEquals($fh->getRecentPosts(50, null, $thread->ID)->Count(), 17); |
|
|
|
|
122
|
|
|
$this->assertEquals($fh->getRecentPosts(10, null, $thread->ID)->Count(), 10); |
|
|
|
|
123
|
|
|
$this->assertEquals($fh->getRecentPosts(50, null, $thread->ID)->First()->Content, 'This is the last post to a long thread'); |
|
|
|
|
124
|
|
|
|
125
|
|
|
// test limiting the response |
126
|
|
|
$this->assertEquals($fh->getRecentPosts(1)->Count(), 1); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
function testGlobalAnnouncements() { |
|
|
|
|
130
|
|
|
// test holder with posts |
131
|
|
|
$fh = $this->objFromFixture("ForumHolder", "fh"); |
132
|
|
|
$controller = new ForumHolder_Controller($fh); |
133
|
|
|
|
134
|
|
|
// make sure all the announcements are included |
135
|
|
|
$this->assertEquals($controller->GlobalAnnouncements()->Count(), 1); |
|
|
|
|
136
|
|
|
|
137
|
|
|
// test holder that doesn't have posts |
138
|
|
|
$fh2 = $this->objFromFixture("ForumHolder", "fh2"); |
139
|
|
|
$controller2 = new ForumHolder_Controller($fh2); |
140
|
|
|
|
141
|
|
|
$this->assertEquals($controller2->GlobalAnnouncements()->Count(), 0); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
function testGetNewPostsAvailable() { |
|
|
|
|
145
|
|
|
$fh = $this->objFromFixture("ForumHolder", "fh"); |
146
|
|
|
|
147
|
|
|
// test last visit. we can assume that these tests have been reloaded in the past 24 hours |
148
|
|
|
$data = array(); |
149
|
|
|
$this->assertTrue(ForumHolder::new_posts_available($fh->ID, $data, date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), date('d')-1, date('Y'))))); |
|
|
|
|
150
|
|
|
|
151
|
|
|
// set the last post ID (test the first post - so there should be a post, last post (false)) |
152
|
|
|
$fixtureIDs = $this->allFixtureIDs('Post'); |
153
|
|
|
$lastPostID = end($fixtureIDs); |
154
|
|
|
|
155
|
|
|
$this->assertTrue(ForumHolder::new_posts_available($fh->ID, $data,null, 1)); |
|
|
|
|
156
|
|
|
$this->assertFalse(ForumHolder::new_posts_available($fh->ID, $data, null, $lastPostID)); |
|
|
|
|
157
|
|
|
|
158
|
|
|
// limit to a specific forum |
159
|
|
|
$forum = $this->objFromFixture("Forum", "general"); |
160
|
|
|
$this->assertTrue(ForumHolder::new_posts_available($fh->ID, $data, null, null, $forum->ID)); |
|
|
|
|
161
|
|
|
$this->assertFalse(ForumHolder::new_posts_available($fh->ID, $data, null, $lastPostID, $forum->ID)); |
|
|
|
|
162
|
|
|
|
163
|
|
|
// limit to a specific thread |
164
|
|
|
$thread = $this->objFromFixture("ForumThread", "Thread1"); |
165
|
|
|
$this->assertTrue(ForumHolder::new_posts_available($fh->ID, $data, null, null, null, $thread->ID)); |
|
|
|
|
166
|
|
|
$this->assertFalse(ForumHolder::new_posts_available($fh->ID, $data, null, $lastPostID, null, $thread->ID)); |
|
|
|
|
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
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.