Completed
Push — master ( 02d548...e42a4c )
by Damian
02:25
created

CommentingTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5
Metric Value
wmc 10
lcom 0
cbo 5
dl 0
loc 171
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpOnce() 0 3 1
A testDeprecatedMethods() 0 12 3
B test_set_config_value() 0 34 1
B test_get_config_value() 0 28 1
A test_config_value_equals() 0 23 1
B test_add() 0 31 1
B test_can_member_post() 0 29 2
1
<?php
2
3
class CommentingTest extends SapphireTest {
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...
4
5
    public function setUpOnce() {
6
        parent::setUpOnce();
7
    }
8
9
    public function testDeprecatedMethods() {
10
        $methods = array('add', 'remove', 'has_commenting');
11
        foreach ($methods as $methodName) {
12
            try {
13
                Commenting::$methodName('Member');
14
            } catch (PHPUnit_Framework_Error_Deprecated $e) {
15
                $expected = 'Using Commenting:' . $methodName .' is deprecated.'
16
                          . ' Please use the config API instead';
17
                $this->assertEquals($expected, $e->getMessage());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CommentingTest>.

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
    }
21
22
23
	public function test_set_config_value() {
24
		//    public static function set_config_value($class, $key, $value = false) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
25
        Commenting::set_config_value(
0 ignored issues
show
Deprecated Code introduced by
The method Commenting::set_config_value() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
26
            'CommentableItem',
27
            'comments_holder_id',
28
            'commentable_item'
29
        );
30
31
        $config = Config::inst()->get(
32
            'CommentableItem',
33
            'comments'
34
        );
35
        $actual = $config['comments_holder_id'];
36
37
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CommentingTest>.

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...
38
            'commentable_item',
39
            $actual
40
        );
41
        Commenting::set_config_value(
0 ignored issues
show
Deprecated Code introduced by
The method Commenting::set_config_value() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
42
            'all',
43
            'comments_holder_id',
44
            'all_items_actually_commentsextension'
45
        );
46
47
         $config = Config::inst()->get(
48
            'CommentsExtension',
49
            'comments'
50
        );
51
        $actual = $config['comments_holder_id'];
52
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CommentingTest>.

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
            'all_items_actually_commentsextension',
54
            $actual
55
        );
56
	}
57
58
	public function test_get_config_value() {
59
		Config::inst()->update('CommentableItem', 'comments',
60
            array(
61
            'comments_holder_id' => 'commentable_item'
62
            )
63
        );
64
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CommentingTest>.

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...
65
            'commentable_item',
66
            Commenting::get_config_value('CommentableItem', 'comments_holder_id')
0 ignored issues
show
Deprecated Code introduced by
The method Commenting::get_config_value() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
67
        );
68
69
        Config::inst()->update('CommentsExtension', 'comments',
70
            array(
71
            'comments_holder_id' => 'comments_extension'
72
            )
73
        );
74
        // if class is null, method uses the CommentsExtension property
75
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CommentingTest>.

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...
76
            'comments_extension',
77
            Commenting::get_config_value(null, 'comments_holder_id')
0 ignored issues
show
Deprecated Code introduced by
The method Commenting::get_config_value() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
78
        );
79
80
        $this->setExpectedException(
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<CommentingTest>.

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...
81
            'InvalidArgumentException',
82
            'Member does not have commenting enabled'
83
        );
84
        Commenting::get_config_value('Member', 'comments_holder_id');
0 ignored issues
show
Deprecated Code introduced by
The method Commenting::get_config_value() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
85
	}
86
87
	public function test_config_value_equals() {
88
		Config::inst()->update('CommentableItem', 'comments',
89
            array(
90
            'comments_holder_id' => 'some_value'
91
            )
92
        );
93
94
        $this->assertTrue(
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<CommentingTest>.

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
            Commenting::config_value_equals(
0 ignored issues
show
Deprecated Code introduced by
The method Commenting::config_value_equals() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
96
                'CommentableItem',
97
                'comments_holder_id',
98
                'some_value'
99
            )
100
        );
101
102
        $this->assertNull(
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<CommentingTest>.

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
            Commenting::config_value_equals(
0 ignored issues
show
Deprecated Code introduced by
The method Commenting::config_value_equals() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
104
                'CommentableItem',
105
                'comments_holder_id',
106
                'not_some_value'
107
            )
108
        );
109
	}
110
111
    public function test_add() {
112
        Commenting::add('Member', array('comments_holder_id' => 'test_add_value'));
0 ignored issues
show
Deprecated Code introduced by
The method Commenting::add() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
113
114
        $config = Config::inst()->get(
115
                'Member',
116
                'comments'
117
            );
118
        $actual = $config['comments_holder_id'];
119
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CommentingTest>.

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...
120
            'test_add_value',
121
            $actual
122
        );
123
124
        Commenting::add('Member');
0 ignored issues
show
Deprecated Code introduced by
The method Commenting::add() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
125
126
        $config = Config::inst()->get(
127
                'Member',
128
                'comments'
129
            );
130
        $actual = $config['comments_holder_id'];
131
        // no settings updated
132
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<CommentingTest>.

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...
133
            'test_add_value',
134
            $actual
135
        );
136
137
        $this->setExpectedException('InvalidArgumentException', "\$settings needs to be an array or null");
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<CommentingTest>.

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...
138
        Commenting::add('Member', 'illegal format, not an array');
0 ignored issues
show
Documentation introduced by
'illegal format, not an array' is of type string, but the function expects a false|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The method Commenting::add() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
139
140
141
    }
142
143
	public function test_can_member_post() {
144
        // logout
145
        if($member = Member::currentUser()) $member->logOut();
146
147
        Config::inst()->update('CommentableItem', 'comments',
148
            array(
149
            'require_login' => false
150
            )
151
        );
152
        $this->assertTrue(Commenting::can_member_post('CommentableItem'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<CommentingTest>.

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...
Deprecated Code introduced by
The method Commenting::can_member_post() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
153
154
        Config::inst()->update('CommentableItem', 'comments',
155
            array(
156
            'require_login' => true
157
            )
158
        );
159
        $this->assertFalse(Commenting::can_member_post('CommentableItem'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<CommentingTest>.

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...
Deprecated Code introduced by
The method Commenting::can_member_post() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
160
161
        $this->logInWithPermission('CMS_ACCESS_CommentAdmin');
162
        $this->assertTrue(Commenting::can_member_post('CommentableItem'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<CommentingTest>.

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...
Deprecated Code introduced by
The method Commenting::can_member_post() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
163
164
        Config::inst()->update('CommentableItem', 'comments',
165
            array(
166
            'require_login' => false
167
            )
168
        );
169
170
        $this->assertTrue(Commenting::can_member_post('CommentableItem'));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<CommentingTest>.

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...
Deprecated Code introduced by
The method Commenting::can_member_post() has been deprecated with message: since version 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
171
	}
172
173
}
174