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

ForumThreadTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6
Metric Value
wmc 7
lcom 1
cbo 6
dl 0
loc 100
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetNumPosts() 0 5 1
A testIncViews() 0 12 1
A testGetLatestPost() 0 5 1
A testGetFirstPost() 0 5 1
A testSubscription() 0 13 1
A testOnBeforeDelete() 0 15 1
B testPermissions() 0 30 1
1
<?php
2
3
/**
4
 * @todo Write some more complex tests for testing the can*() functionality
5
 */
6
class ForumThreadTest 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
	// 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;
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $use_draft_site.
Loading history...
Coding Style introduced by
The visibility should be declared for property $use_draft_site.

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...
13
14
	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...
15
		$thread = $this->objFromFixture("ForumThread", "Thread1");
16
		
17
		$this->assertEquals($thread->getNumPosts(), 17);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumThreadTest>.

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...
18
	}
19
	
20
	function testIncViews() {
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...
21
		$thread = $this->objFromFixture("ForumThread", "Thread1");
22
		
23
		// clear session
24
		Session::clear('ForumViewed-'.$thread->ID);
25
		
26
		$this->assertEquals($thread->NumViews, '10');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumThreadTest>.

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...
27
		
28
		$thread->incNumViews();
29
		
30
		$this->assertEquals($thread->NumViews, '11');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumThreadTest>.

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...
31
	}
32
	
33
	function testGetLatestPost() {
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...
34
		$thread = $this->objFromFixture("ForumThread", "Thread1");
35
		
36
		$this->assertEquals($thread->getLatestPost()->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<ForumThreadTest>.

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
	
39
	function testGetFirstPost() {
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...
40
		$thread = $this->objFromFixture("ForumThread", "Thread1");
41
		
42
		$this->assertEquals($thread->getFirstPost()->Content, "This is my first post");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ForumThreadTest>.

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...
43
	}
44
	
45
	function testSubscription() {
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...
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));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumThreadTest>.

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
		$this->assertTrue(ForumThread_Subscription::already_subscribed($thread->ID, $member2->ID));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumThreadTest>.

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...
54
		
55
		$this->assertFalse(ForumThread_Subscription::already_subscribed($thread2->ID, $member->ID));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumThreadTest>.

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...
56
		$this->assertFalse(ForumThread_Subscription::already_subscribed($thread2->ID, $member2->ID));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumThreadTest>.

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...
57
	}
58
	
59
	function testOnBeforeDelete() {
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...
60
		$thread = new ForumThread();
61
		$thread->write();
62
		
63
		$post = new Post();
64
		$post->ThreadID = $thread->ID;
0 ignored issues
show
Documentation introduced by
The property ThreadID does not exist on object<Post>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
65
		$post->write();
66
		
67
		$postID = $post->ID;
68
		
69
		$thread->delete();
70
		
71
		$this->assertFalse(DataObject::get_by_id('Post', $postID));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumThreadTest>.

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
		$this->assertFalse(DataObject::get_by_id('ForumThread', $thread->ID));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumThreadTest>.

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...
73
	}
74
	
75
	function testPermissions() {
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...
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());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumThreadTest>.

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
		$this->assertTrue($readonly->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumThreadTest>.

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...
83
		$this->assertFalse($readonly->canModerate());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumThreadTest>.

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...
84
		
85
		// normal thread. They can post to these
86
		$thread = $this->objFromFixture('ForumThread', 'Thread1');
87
		$this->assertTrue($thread->canPost());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumThreadTest>.

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
		$this->assertTrue($thread->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumThreadTest>.

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...
89
		$this->assertFalse($thread->canModerate());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumThreadTest>.

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...
90
		
91
		// normal thread in a read only 
92
		$disabledforum = $this->objFromFixture('ForumThread', 'ThreadWhichIsInInheritedForum');
93
		$this->assertFalse($disabledforum->canPost());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumThreadTest>.

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...
94
		$this->assertFalse($disabledforum->canView());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumThreadTest>.

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...
95
		$this->assertFalse($disabledforum->canModerate());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumThreadTest>.

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...
96
97
		// Moderator can access threads nevertheless
98
		$member = $this->objFromFixture('Member', 'moderator');
99
		$member->logIn();
100
101
		$this->assertFalse($disabledforum->canPost());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ForumThreadTest>.

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...
102
		$this->assertTrue($disabledforum->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumThreadTest>.

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
		$this->assertTrue($disabledforum->canModerate());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ForumThreadTest>.

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...
104
	}
105
}
106