Completed
Push — master ( e42a4c...f187a0 )
by Daniel
03:17
created

CommentingTest::test_config_value_equals()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 24
rs 8.9713
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
class CommentingTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by Gordon Anderson
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
6
    public function setUpOnce()
7
    {
8
        parent::setUpOnce();
9
    }
10
11
    public function testDeprecatedMethods()
12
    {
13
        $methods = array('add', 'remove', 'has_commenting');
14
        foreach ($methods as $methodName) {
15
            try {
16
                Commenting::$methodName('Member');
17
            } catch (PHPUnit_Framework_Error_Deprecated $e) {
18
                $expected = 'Using Commenting:' . $methodName .' is deprecated.'
19
                          . ' Please use the config API instead';
20
                $this->assertEquals($expected, $e->getMessage());
0 ignored issues
show
Bug introduced by Gordon Anderson
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...
21
            }
22
        }
23
    }
24
25
26
    public function test_set_config_value()
27
    {
28
        //    public static function set_config_value($class, $key, $value = false) {
0 ignored issues
show
Unused Code Comprehensibility introduced by Gordon Anderson
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...
29
        Commenting::set_config_value(
0 ignored issues
show
Deprecated Code introduced by Gordon Anderson
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...
30
            'CommentableItem',
31
            'comments_holder_id',
32
            'commentable_item'
33
        );
34
35
        $config = Config::inst()->get(
36
            'CommentableItem',
37
            'comments'
38
        );
39
        $actual = $config['comments_holder_id'];
40
41
        $this->assertEquals(
0 ignored issues
show
Bug introduced by Gordon Anderson
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...
42
            'commentable_item',
43
            $actual
44
        );
45
        Commenting::set_config_value(
0 ignored issues
show
Deprecated Code introduced by Gordon Anderson
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...
46
            'all',
47
            'comments_holder_id',
48
            'all_items_actually_commentsextension'
49
        );
50
51
        $config = Config::inst()->get(
52
            'CommentsExtension',
53
            'comments'
54
        );
55
        $actual = $config['comments_holder_id'];
56
        $this->assertEquals(
0 ignored issues
show
Bug introduced by Gordon Anderson
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...
57
            'all_items_actually_commentsextension',
58
            $actual
59
        );
60
    }
61
62
    public function test_get_config_value()
63
    {
64
        Config::inst()->update('CommentableItem', 'comments',
65
            array(
66
            'comments_holder_id' => 'commentable_item'
67
            )
68
        );
69
        $this->assertEquals(
0 ignored issues
show
Bug introduced by Gordon Anderson
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...
70
            'commentable_item',
71
            Commenting::get_config_value('CommentableItem', 'comments_holder_id')
0 ignored issues
show
Deprecated Code introduced by Gordon Anderson
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...
72
        );
73
74
        Config::inst()->update('CommentsExtension', 'comments',
75
            array(
76
            'comments_holder_id' => 'comments_extension'
77
            )
78
        );
79
        // if class is null, method uses the CommentsExtension property
80
        $this->assertEquals(
0 ignored issues
show
Bug introduced by Gordon Anderson
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...
81
            'comments_extension',
82
            Commenting::get_config_value(null, 'comments_holder_id')
0 ignored issues
show
Deprecated Code introduced by Gordon Anderson
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...
83
        );
84
85
        $this->setExpectedException(
0 ignored issues
show
Bug introduced by Gordon Anderson
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...
86
            'InvalidArgumentException',
87
            'Member does not have commenting enabled'
88
        );
89
        Commenting::get_config_value('Member', 'comments_holder_id');
0 ignored issues
show
Deprecated Code introduced by Gordon Anderson
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...
90
    }
91
92
    public function test_config_value_equals()
93
    {
94
        Config::inst()->update('CommentableItem', 'comments',
95
            array(
96
            'comments_holder_id' => 'some_value'
97
            )
98
        );
99
100
        $this->assertTrue(
0 ignored issues
show
Bug introduced by Gordon Anderson
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...
101
            Commenting::config_value_equals(
0 ignored issues
show
Deprecated Code introduced by Gordon Anderson
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...
102
                'CommentableItem',
103
                'comments_holder_id',
104
                'some_value'
105
            )
106
        );
107
108
        $this->assertNull(
0 ignored issues
show
Bug introduced by Gordon Anderson
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...
109
            Commenting::config_value_equals(
0 ignored issues
show
Deprecated Code introduced by Gordon Anderson
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...
110
                'CommentableItem',
111
                'comments_holder_id',
112
                'not_some_value'
113
            )
114
        );
115
    }
116
117
    public function test_add()
118
    {
119
        Commenting::add('Member', array('comments_holder_id' => 'test_add_value'));
0 ignored issues
show
Deprecated Code introduced by Gordon Anderson
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...
120
121
        $config = Config::inst()->get(
122
                'Member',
123
                'comments'
124
            );
125
        $actual = $config['comments_holder_id'];
126
        $this->assertEquals(
0 ignored issues
show
Bug introduced by Gordon Anderson
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...
127
            'test_add_value',
128
            $actual
129
        );
130
131
        Commenting::add('Member');
0 ignored issues
show
Deprecated Code introduced by Gordon Anderson
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...
132
133
        $config = Config::inst()->get(
134
                'Member',
135
                'comments'
136
            );
137
        $actual = $config['comments_holder_id'];
138
        // no settings updated
139
        $this->assertEquals(
0 ignored issues
show
Bug introduced by Gordon Anderson
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...
140
            'test_add_value',
141
            $actual
142
        );
143
144
        $this->setExpectedException('InvalidArgumentException', "\$settings needs to be an array or null");
0 ignored issues
show
Bug introduced by Gordon Anderson
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...
145
        Commenting::add('Member', 'illegal format, not an array');
0 ignored issues
show
Documentation introduced by Gordon Anderson
'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 Gordon Anderson
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...
146
    }
147
148
    public function test_can_member_post()
149
    {
150
        // logout
151
        if ($member = Member::currentUser()) {
152
            $member->logOut();
153
        }
154
155
        Config::inst()->update('CommentableItem', 'comments',
156
            array(
157
            'require_login' => false
158
            )
159
        );
160
        $this->assertTrue(Commenting::can_member_post('CommentableItem'));
0 ignored issues
show
Bug introduced by Gordon Anderson
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 Gordon Anderson
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...
161
162
        Config::inst()->update('CommentableItem', 'comments',
163
            array(
164
            'require_login' => true
165
            )
166
        );
167
        $this->assertFalse(Commenting::can_member_post('CommentableItem'));
0 ignored issues
show
Bug introduced by Gordon Anderson
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 Gordon Anderson
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...
168
169
        $this->logInWithPermission('CMS_ACCESS_CommentAdmin');
170
        $this->assertTrue(Commenting::can_member_post('CommentableItem'));
0 ignored issues
show
Bug introduced by Gordon Anderson
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 Gordon Anderson
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
        Config::inst()->update('CommentableItem', 'comments',
173
            array(
174
            'require_login' => false
175
            )
176
        );
177
178
        $this->assertTrue(Commenting::can_member_post('CommentableItem'));
0 ignored issues
show
Bug introduced by Gordon Anderson
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 Gordon Anderson
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...
179
    }
180
}
181