Completed
Push — master ( 691103...b765dd )
by Daniel
11:12 queued 08:42
created

ForumHolderTest::testGlobalAnnouncements()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 14
rs 9.4286
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
/**
4
 * @todo Write tests to cover the RSS feeds
5
 */
6
class ForumHolderTest extends FunctionalTest {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
7
	
8
	static $fixture_file = "forum/tests/ForumTest.yml";
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $fixture_file.
Loading history...
Coding Style introduced by
The visibility should be declared for property $fixture_file.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
		$this->assertTrue($fh_controller->Categories()->Last()->Forums()->Count() == 2, "fh second category has 2 forums");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
		$this->assertTrue($fh2_controller->Categories()->Last()->Forums()->Count() == 1, "fh second category has 1 forums");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
		
47
		
48
		// plain forums (not nested in categories)
49
		$forumHolder = $this->objFromFixture("ForumHolder", "fhNoCategories");
50
		
51
		$this->assertEquals($forumHolder->Forums()->Count(), 1);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
		$this->assertEquals($forumHolder->Forums()->First()->Title, "Forum Without Category");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
		$this->assertEquals($forumHolder->Forums()->First()->Title, "Forum Without Category");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
62
	}
63
64 View Code Duplication
	function testGetNumPosts() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
		// test holder with posts
66
		$fh = $this->objFromFixture("ForumHolder", "fh");
67
		$this->assertEquals($fh->getNumPosts(), 24);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
		
69
		// test holder that doesn't have posts
70
		$fh2 = $this->objFromFixture("ForumHolder", "fh2");
71
		$this->assertEquals($fh2->getNumPosts(), 0);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
	}
73
	
74 View Code Duplication
	function testGetNumTopics() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
		// test holder with posts
76
		$fh = $this->objFromFixture("ForumHolder", "fh");
77
		$this->assertEquals($fh->getNumTopics(), 6);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
		
79
		// test holder that doesn't have posts
80
		$fh2 = $this->objFromFixture("ForumHolder", "fh2");
81
		$this->assertEquals($fh2->getNumTopics(), 0);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
	}
83
	
84 View Code Duplication
	function testGetNumAuthors() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
		// test holder with posts
86
		$fh = $this->objFromFixture("ForumHolder", "fh");
87
		$this->assertEquals($fh->getNumAuthors(), 4);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
		
89
		// test holder that doesn't have posts
90
		$fh2 = $this->objFromFixture("ForumHolder", "fh2");
91
		$this->assertEquals($fh2->getNumAuthors(), 0);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
92
	}
93
	
94
	function testGetRecentPosts() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
103
		
104
		// test holder that doesn't have posts
105
		$fh2 = $this->objFromFixture("ForumHolder", "fh2");
106
		$this->assertNull($fh2->getRecentPosts());
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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));
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
116
		$this->assertEquals($fh->getRecentPosts(50, $forum->ID)->First()->Content, "This is the last post to a long thread");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
122
		$this->assertEquals($fh->getRecentPosts(10, null, $thread->ID)->Count(), 10);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123
		$this->assertEquals($fh->getRecentPosts(50, null, $thread->ID)->First()->Content, 'This is the last post to a long thread');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
124
		
125
		// test limiting the response
126
		$this->assertEquals($fh->getRecentPosts(1)->Count(), 1);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
127
	}
128
	
129
	function testGlobalAnnouncements() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
142
	}
143
	
144
	function testGetNewPostsAvailable() {		
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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')))));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
156
		$this->assertFalse(ForumHolder::new_posts_available($fh->ID, $data, null, $lastPostID));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
161
		$this->assertFalse(ForumHolder::new_posts_available($fh->ID, $data, null, $lastPostID, $forum->ID));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
166
		$this->assertFalse(ForumHolder::new_posts_available($fh->ID, $data, null, $lastPostID, null, $thread->ID));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumHolderTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
167
	}
168
}
169