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

CommentsTest::testCanPostComment()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 61
Code Lines 42

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 61
rs 8.9392
cc 4
eloc 42
nc 8
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @package comments
5
 */
6
class CommentsTest extends FunctionalTest
0 ignored issues
show
Coding Style Compatibility introduced by Will Rossiter
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...
7
{
8
9
    public static $fixture_file = 'comments/tests/CommentsTest.yml';
10
11
    protected $extraDataObjects = array(
12
        'CommentableItem',
13
        'CommentableItemEnabled',
14
        'CommentableItemDisabled'
15
    );
16
17 View Code Duplication
    public function setUp()
0 ignored issues
show
Duplication introduced by Will Rossiter
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...
18
    {
19
        parent::setUp();
20
        Config::nest();
21
22
        // Set good default values
23
        Config::inst()->update('CommentsExtension', 'comments', array(
24
            'enabled' => true,
25
            'enabled_cms' => false,
26
            'require_login' => false,
27
            'require_login_cms' => false,
28
            'required_permission' => false,
29
            'require_moderation_nonmembers' => false,
30
            'require_moderation' => false,
31
            'require_moderation_cms' => false,
32
            'frontend_moderation' => false,
33
            'frontend_spam' => false,
34
        ));
35
36
        // Configure this dataobject
37
        Config::inst()->update('CommentableItem', 'comments', array(
38
            'enabled_cms' => true
39
        ));
40
    }
41
42
    public function tearDown()
43
    {
44
        Config::unnest();
45
        parent::tearDown();
46
    }
47
48
    public function testCommentsList()
49
    {
50
        // comments don't require moderation so unmoderated comments can be
51
        // shown but not spam posts
52
        Config::inst()->update('CommentableItem', 'comments', array(
53
            'require_moderation_nonmembers' => false,
54
            'require_moderation' => false,
55
            'require_moderation_cms' => false,
56
        ));
57
58
        $item = $this->objFromFixture('CommentableItem', 'spammed');
59
        $this->assertEquals('None', $item->ModerationRequired);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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
61
        $this->assertDOSEquals(array(
62
            array('Name' => 'Comment 1'),
63
            array('Name' => 'Comment 3')
64
        ), $item->Comments(), 'Only 2 non spam posts should be shown');
0 ignored issues
show
Unused Code introduced by Damian Mooyman
The call to CommentsTest::assertDOSEquals() has too many arguments starting with 'Only 2 non spam posts should be shown'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
65
66
        // when moderated, only moderated, non spam posts should be shown.
67
        Config::inst()->update('CommentableItem', 'comments', array('require_moderation_nonmembers' => true));
68
        $this->assertEquals('NonMembersOnly', $item->ModerationRequired);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
69
70
        // Check that require_moderation overrides this option
71
        Config::inst()->update('CommentableItem', 'comments', array('require_moderation' => true));
72
        $this->assertEquals('Required', $item->ModerationRequired);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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
        $this->assertDOSEquals(array(
75
            array('Name' => 'Comment 3')
76
        ), $item->Comments(), 'Only 1 non spam, moderated post should be shown');
0 ignored issues
show
Unused Code introduced by Damian Mooyman
The call to CommentsTest::assertDOSEquals() has too many arguments starting with 'Only 1 non spam, moderated post should be shown'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
77
        $this->assertEquals(1, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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
        // require_moderation_nonmembers still filters out unmoderated comments
80
        Config::inst()->update('CommentableItem', 'comments', array('require_moderation' => false));
81
        $this->assertEquals(1, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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
        Config::inst()->update('CommentableItem', 'comments', array('require_moderation_nonmembers' => false));
84
        $this->assertEquals(2, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
85
86
        // With unmoderated comments set to display in frontend
87
        Config::inst()->update('CommentableItem', 'comments', array(
88
            'require_moderation' => true,
89
            'frontend_moderation' => true
90
        ));
91
        $this->assertEquals(1, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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
        $this->logInWithPermission('ADMIN');
94
        $this->assertEquals(2, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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
96
        // With spam comments set to display in frontend
97
        Config::inst()->update('CommentableItem', 'comments', array(
98
            'require_moderation' => true,
99
            'frontend_moderation' => false,
100
            'frontend_spam' => true,
101
        ));
102
        if ($member = Member::currentUser()) {
103
            $member->logOut();
104
        }
105
        $this->assertEquals(1, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
106
107
        $this->logInWithPermission('ADMIN');
108
        $this->assertEquals(2, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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
110
111
        // With spam and unmoderated comments set to display in frontend
112
        Config::inst()->update('CommentableItem', 'comments', array(
113
            'require_moderation' => true,
114
            'frontend_moderation' => true,
115
            'frontend_spam' => true,
116
        ));
117
        if ($member = Member::currentUser()) {
118
            $member->logOut();
119
        }
120
        $this->assertEquals(1, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
121
122
        $this->logInWithPermission('ADMIN');
123
        $this->assertEquals(4, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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
126
    /**
127
     * Test moderation options configured via the CMS
128
     */
129
    public function testCommentCMSModerationList()
130
    {
131
        // comments don't require moderation so unmoderated comments can be
132
        // shown but not spam posts
133
        Config::inst()->update('CommentableItem', 'comments', array(
134
            'require_moderation' => true,
135
            'require_moderation_cms' => true,
136
        ));
137
138
        $item = $this->objFromFixture('CommentableItem', 'spammed');
139
        $this->assertEquals('None', $item->ModerationRequired);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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
141
        $this->assertDOSEquals(array(
142
            array('Name' => 'Comment 1'),
143
            array('Name' => 'Comment 3')
144
        ), $item->Comments(), 'Only 2 non spam posts should be shown');
0 ignored issues
show
Unused Code introduced by Damian Mooyman
The call to CommentsTest::assertDOSEquals() has too many arguments starting with 'Only 2 non spam posts should be shown'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
145
146
        // when moderated, only moderated, non spam posts should be shown.
147
        $item->ModerationRequired = 'NonMembersOnly';
148
        $item->write();
149
        $this->assertEquals('NonMembersOnly', $item->ModerationRequired);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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
        // Check that require_moderation overrides this option
152
        $item->ModerationRequired = 'Required';
153
        $item->write();
154
        $this->assertEquals('Required', $item->ModerationRequired);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
155
156
        $this->assertDOSEquals(array(
157
            array('Name' => 'Comment 3')
158
        ), $item->Comments(), 'Only 1 non spam, moderated post should be shown');
0 ignored issues
show
Unused Code introduced by Damian Mooyman
The call to CommentsTest::assertDOSEquals() has too many arguments starting with 'Only 1 non spam, moderated post should be shown'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
159
        $this->assertEquals(1, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
160
161
        // require_moderation_nonmembers still filters out unmoderated comments
162
        $item->ModerationRequired = 'NonMembersOnly';
163
        $item->write();
164
        $this->assertEquals(1, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
165
166
        $item->ModerationRequired = 'None';
167
        $item->write();
168
        $this->assertEquals(2, $item->Comments()->Count());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
169
    }
170
171
    public function testCanPostComment()
172
    {
173
        Config::inst()->update('CommentableItem', 'comments', array(
174
            'require_login' => false,
175
            'require_login_cms' => false,
176
            'required_permission' => false,
177
        ));
178
        $item = $this->objFromFixture('CommentableItem', 'first');
179
        $item2 = $this->objFromFixture('CommentableItem', 'second');
180
181
        // Test restriction free commenting
182
        if ($member = Member::currentUser()) {
183
            $member->logOut();
184
        }
185
        $this->assertFalse($item->CommentsRequireLogin);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertFalse() does not seem to exist on object<CommentsTest>.

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...
186
        $this->assertTrue($item->canPostComment());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
187
188
        // Test permission required to post
189
        Config::inst()->update('CommentableItem', 'comments', array(
190
            'require_login' => true,
191
            'required_permission' => 'POSTING_PERMISSION',
192
        ));
193
        $this->assertTrue($item->CommentsRequireLogin);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
194
        $this->assertFalse($item->canPostComment());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertFalse() does not seem to exist on object<CommentsTest>.

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...
195
        $this->logInWithPermission('WRONG_ONE');
196
        $this->assertFalse($item->canPostComment());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertFalse() does not seem to exist on object<CommentsTest>.

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...
197
        $this->logInWithPermission('POSTING_PERMISSION');
198
        $this->assertTrue($item->canPostComment());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
199
        $this->logInWithPermission('ADMIN');
200
        $this->assertTrue($item->canPostComment());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
201
202
        // Test require login to post, but not any permissions
203
        Config::inst()->update('CommentableItem', 'comments', array(
204
            'required_permission' => false,
205
        ));
206
        $this->assertTrue($item->CommentsRequireLogin);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
207
        if ($member = Member::currentUser()) {
208
            $member->logOut();
209
        }
210
        $this->assertFalse($item->canPostComment());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertFalse() does not seem to exist on object<CommentsTest>.

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...
211
        $this->logInWithPermission('ANY_PERMISSION');
212
        $this->assertTrue($item->canPostComment());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
213
214
        // Test options set via CMS
215
        Config::inst()->update('CommentableItem', 'comments', array(
216
            'require_login' => true,
217
            'require_login_cms' => true,
218
        ));
219
        $this->assertFalse($item->CommentsRequireLogin);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertFalse() does not seem to exist on object<CommentsTest>.

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...
220
        $this->assertTrue($item2->CommentsRequireLogin);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
221
        if ($member = Member::currentUser()) {
222
            $member->logOut();
223
        }
224
        $this->assertTrue($item->canPostComment());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
225
        $this->assertFalse($item2->canPostComment());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertFalse() does not seem to exist on object<CommentsTest>.

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...
226
227
        // Login grants permission to post
228
        $this->logInWithPermission('ANY_PERMISSION');
229
        $this->assertTrue($item->canPostComment());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
230
        $this->assertTrue($item2->canPostComment());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
231
    }
232
    public function testDeleteComment()
233
    {
234
        // Test anonymous user
235
        if ($member = Member::currentUser()) {
236
            $member->logOut();
237
        }
238
        $comment = $this->objFromFixture('Comment', 'firstComA');
239
        $commentID = $comment->ID;
240
        $this->assertNull($comment->DeleteLink(), 'No permission to see delete link');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNull() does not seem to exist on object<CommentsTest>.

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...
241
        $delete = $this->get('CommentingController/delete/'.$comment->ID.'?ajax=1');
242
        $this->assertEquals(403, $delete->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
243
        $check = DataObject::get_by_id('Comment', $commentID);
244
        $this->assertTrue($check && $check->exists());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
245
246
        // Test non-authenticated user
247
        $this->logInAs('visitor');
248
        $this->assertNull($comment->DeleteLink(), 'No permission to see delete link');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNull() does not seem to exist on object<CommentsTest>.

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...
249
250
        // Test authenticated user
251
        $this->logInAs('commentadmin');
252
        $comment = $this->objFromFixture('Comment', 'firstComA');
253
        $commentID = $comment->ID;
254
        $adminComment1Link = $comment->DeleteLink();
255
        $this->assertContains('CommentingController/delete/'.$commentID.'?t=', $adminComment1Link);
256
257
        // Test that this link can't be shared / XSS exploited
258
        $this->logInAs('commentadmin2');
259
        $delete = $this->get($adminComment1Link);
260
        $this->assertEquals(400, $delete->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
261
        $check = DataObject::get_by_id('Comment', $commentID);
262
        $this->assertTrue($check && $check->exists());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertTrue() does not seem to exist on object<CommentsTest>.

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...
263
264
        // Test that this other admin can delete the comment with their own link
265
        $adminComment2Link = $comment->DeleteLink();
266
        $this->assertNotEquals($adminComment2Link, $adminComment1Link);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNotEquals() does not seem to exist on object<CommentsTest>.

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...
267
        $this->autoFollowRedirection = false;
268
        $delete = $this->get($adminComment2Link);
269
        $this->assertEquals(302, $delete->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
270
        $check = DataObject::get_by_id('Comment', $commentID);
271
        $this->assertFalse($check && $check->exists());
0 ignored issues
show
Bug introduced by Will Rossiter
The method assertFalse() does not seem to exist on object<CommentsTest>.

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...
272
    }
273
274 View Code Duplication
    public function testSpamComment()
0 ignored issues
show
Duplication introduced by Will Rossiter
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...
275
    {
276
        // Test anonymous user
277
        if ($member = Member::currentUser()) {
278
            $member->logOut();
279
        }
280
        $comment = $this->objFromFixture('Comment', 'firstComA');
281
        $commentID = $comment->ID;
282
        $this->assertNull($comment->SpamLink(), 'No permission to see mark as spam link');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNull() does not seem to exist on object<CommentsTest>.

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...
283
        $spam = $this->get('CommentingController/spam/'.$comment->ID.'?ajax=1');
284
        $this->assertEquals(403, $spam->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
285
        $check = DataObject::get_by_id('Comment', $commentID);
286
        $this->assertEquals(0, $check->IsSpam, 'No permission to mark as spam');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
287
288
        // Test non-authenticated user
289
        $this->logInAs('visitor');
290
        $this->assertNull($comment->SpamLink(), 'No permission to see mark as spam link');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNull() does not seem to exist on object<CommentsTest>.

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...
291
292
        // Test authenticated user
293
        $this->logInAs('commentadmin');
294
        $comment = $this->objFromFixture('Comment', 'firstComA');
295
        $commentID = $comment->ID;
296
        $adminComment1Link = $comment->SpamLink();
297
        $this->assertContains('CommentingController/spam/'.$commentID.'?t=', $adminComment1Link);
298
299
        // Test that this link can't be shared / XSS exploited
300
        $this->logInAs('commentadmin2');
301
        $spam = $this->get($adminComment1Link);
302
        $this->assertEquals(400, $spam->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
303
        $check = DataObject::get_by_id('Comment', $comment->ID);
304
        $this->assertEquals(0, $check->IsSpam, 'No permission to mark as spam');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
305
306
        // Test that this other admin can spam the comment with their own link
307
        $adminComment2Link = $comment->SpamLink();
308
        $this->assertNotEquals($adminComment2Link, $adminComment1Link);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNotEquals() does not seem to exist on object<CommentsTest>.

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...
309
        $this->autoFollowRedirection = false;
310
        $spam = $this->get($adminComment2Link);
311
        $this->assertEquals(302, $spam->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
312
        $check = DataObject::get_by_id('Comment', $commentID);
313
        $this->assertEquals(1, $check->IsSpam);
0 ignored issues
show
Bug introduced by Will Rossiter
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
314
315
        // Cannot re-spam spammed comment
316
        $this->assertNull($check->SpamLink());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNull() does not seem to exist on object<CommentsTest>.

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...
317
    }
318
319 View Code Duplication
    public function testHamComment()
0 ignored issues
show
Duplication introduced by Will Rossiter
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...
320
    {
321
        // Test anonymous user
322
        if ($member = Member::currentUser()) {
323
            $member->logOut();
324
        }
325
        $comment = $this->objFromFixture('Comment', 'secondComC');
326
        $commentID = $comment->ID;
327
        $this->assertNull($comment->HamLink(), 'No permission to see mark as ham link');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNull() does not seem to exist on object<CommentsTest>.

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...
328
        $ham = $this->get('CommentingController/ham/'.$comment->ID.'?ajax=1');
329
        $this->assertEquals(403, $ham->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
330
        $check = DataObject::get_by_id('Comment', $commentID);
331
        $this->assertEquals(1, $check->IsSpam, 'No permission to mark as ham');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
332
333
        // Test non-authenticated user
334
        $this->logInAs('visitor');
335
        $this->assertNull($comment->HamLink(), 'No permission to see mark as ham link');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNull() does not seem to exist on object<CommentsTest>.

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...
336
337
        // Test authenticated user
338
        $this->logInAs('commentadmin');
339
        $comment = $this->objFromFixture('Comment', 'secondComC');
340
        $commentID = $comment->ID;
341
        $adminComment1Link = $comment->HamLink();
342
        $this->assertContains('CommentingController/ham/'.$commentID.'?t=', $adminComment1Link);
343
344
        // Test that this link can't be shared / XSS exploited
345
        $this->logInAs('commentadmin2');
346
        $ham = $this->get($adminComment1Link);
347
        $this->assertEquals(400, $ham->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
348
        $check = DataObject::get_by_id('Comment', $comment->ID);
349
        $this->assertEquals(1, $check->IsSpam, 'No permission to mark as ham');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
350
351
        // Test that this other admin can ham the comment with their own link
352
        $adminComment2Link = $comment->HamLink();
353
        $this->assertNotEquals($adminComment2Link, $adminComment1Link);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNotEquals() does not seem to exist on object<CommentsTest>.

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...
354
        $this->autoFollowRedirection = false;
355
        $ham = $this->get($adminComment2Link);
356
        $this->assertEquals(302, $ham->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
357
        $check = DataObject::get_by_id('Comment', $commentID);
358
        $this->assertEquals(0, $check->IsSpam);
0 ignored issues
show
Bug introduced by Will Rossiter
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
359
360
        // Cannot re-ham hammed comment
361
        $this->assertNull($check->HamLink());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNull() does not seem to exist on object<CommentsTest>.

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...
362
    }
363
364 View Code Duplication
    public function testApproveComment()
0 ignored issues
show
Duplication introduced by Will Rossiter
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...
365
    {
366
        // Test anonymous user
367
        if ($member = Member::currentUser()) {
368
            $member->logOut();
369
        }
370
        $comment = $this->objFromFixture('Comment', 'secondComB');
371
        $commentID = $comment->ID;
372
        $this->assertNull($comment->ApproveLink(), 'No permission to see approve link');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNull() does not seem to exist on object<CommentsTest>.

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...
373
        $approve = $this->get('CommentingController/approve/'.$comment->ID.'?ajax=1');
374
        $this->assertEquals(403, $approve->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
375
        $check = DataObject::get_by_id('Comment', $commentID);
376
        $this->assertEquals(0, $check->Moderated, 'No permission to approve');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
377
378
        // Test non-authenticated user
379
        $this->logInAs('visitor');
380
        $this->assertNull($comment->ApproveLink(), 'No permission to see approve link');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNull() does not seem to exist on object<CommentsTest>.

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...
381
382
        // Test authenticated user
383
        $this->logInAs('commentadmin');
384
        $comment = $this->objFromFixture('Comment', 'secondComB');
385
        $commentID = $comment->ID;
386
        $adminComment1Link = $comment->ApproveLink();
387
        $this->assertContains('CommentingController/approve/'.$commentID.'?t=', $adminComment1Link);
388
389
        // Test that this link can't be shared / XSS exploited
390
        $this->logInAs('commentadmin2');
391
        $approve = $this->get($adminComment1Link);
392
        $this->assertEquals(400, $approve->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
393
        $check = DataObject::get_by_id('Comment', $comment->ID);
394
        $this->assertEquals(0, $check->Moderated, 'No permission to approve');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
395
396
        // Test that this other admin can approve the comment with their own link
397
        $adminComment2Link = $comment->ApproveLink();
398
        $this->assertNotEquals($adminComment2Link, $adminComment1Link);
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNotEquals() does not seem to exist on object<CommentsTest>.

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...
399
        $this->autoFollowRedirection = false;
400
        $approve = $this->get($adminComment2Link);
401
        $this->assertEquals(302, $approve->getStatusCode());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
402
        $check = DataObject::get_by_id('Comment', $commentID);
403
        $this->assertEquals(1, $check->Moderated);
0 ignored issues
show
Bug introduced by Will Rossiter
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
404
405
        // Cannot re-approve approved comment
406
        $this->assertNull($check->ApproveLink());
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertNull() does not seem to exist on object<CommentsTest>.

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...
407
    }
408
409
    public function testCommenterURLWrite()
410
    {
411
        $comment = new Comment();
412
        // We only care about the CommenterURL, so only set that
413
        // Check a http and https URL. Add more test urls here as needed.
414
        $protocols = array(
415
            'Http',
416
            'Https',
417
        );
418
        $url = '://example.com';
419
420
        foreach ($protocols as $protocol) {
421
            $comment->CommenterURL = $protocol . $url;
0 ignored issues
show
Bug introduced by Will Rossiter
The property CommenterURL does not seem to exist. Did you mean Comment?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
422
            // The protocol should stay as if, assuming it is valid
423
            $comment->write();
424
            $this->assertEquals($comment->CommenterURL, $protocol . $url, $protocol . ':// is a valid protocol');
0 ignored issues
show
Bug introduced by Will Rossiter
The property CommenterURL does not seem to exist. Did you mean Comment?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by Will Rossiter
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
425
        }
426
    }
427
428
    public function testSanitizesWithAllowHtml()
429
    {
430
        if (!class_exists('HTMLPurifier')) {
431
            $this->markTestSkipped('HTMLPurifier class not found');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method markTestSkipped() does not seem to exist on object<CommentsTest>.

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...
432
            return;
433
        }
434
435
        // Add p for paragraph
436
        // NOTE: The config method appears to append to the existing array
437
        Config::inst()->update('CommentableItem', 'comments', array(
438
            'html_allowed_elements' => array('p'),
439
        ));
440
441
        // Without HTML allowed
442
        $comment1 = new Comment();
443
        $comment1->AllowHtml = false;
444
        $comment1->BaseClass = 'CommentableItem';
445
        $comment1->Comment = '<p><script>alert("w00t")</script>my comment</p>';
446
        $comment1->write();
447
        $this->assertEquals(
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
448
            '<p><script>alert("w00t")</script>my comment</p>',
449
            $comment1->Comment,
450
            'Does not remove HTML tags with html_allowed=false, ' .
451
            'which is correct behaviour because the HTML will be escaped'
452
        );
453
454
        // With HTML allowed
455
        $comment2 = new Comment();
456
        $comment2->AllowHtml = true;
457
        $comment2->BaseClass = 'CommentableItem';
458
        $comment2->Comment = '<p><script>alert("w00t")</script>my comment</p>';
459
        $comment2->write();
460
        $this->assertEquals(
0 ignored issues
show
Bug introduced by Damian Mooyman
The method assertEquals() does not seem to exist on object<CommentsTest>.

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...
461
            '<p>my comment</p>',
462
            $comment2->Comment,
463
            'Removes HTML tags which are not on the whitelist'
464
        );
465
    }
466
467
    public function testDefaultTemplateRendersHtmlWithAllowHtml()
468
    {
469
        if (!class_exists('HTMLPurifier')) {
470
            $this->markTestSkipped('HTMLPurifier class not found');
0 ignored issues
show
Bug introduced by Damian Mooyman
The method markTestSkipped() does not seem to exist on object<CommentsTest>.

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...
471
        }
472
473
        Config::inst()->update('CommentableItem', 'comments', array(
474
            'html_allowed_elements' => array('p'),
475
        ));
476
477
        $item = new CommentableItem();
478
        $item->write();
479
480
        // Without HTML allowed
481
        $comment = new Comment();
482
        $comment->Comment = '<p>my comment</p>';
483
        $comment->AllowHtml = false;
484
        $comment->ParentID = $item->ID;
485
        $comment->BaseClass = 'CommentableItem';
486
        $comment->write();
487
488
        $html = $item->customise(array('CommentsEnabled&