Completed
Push — master ( b765dd...e454df )
by Daniel
13:34 queued 10:58
created

PostTest::testEditLink()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 25
rs 8.8571
cc 2
eloc 12
nc 2
nop 0
1
<?php
2
3
class PostTest extends FunctionalTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

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

namespace YourVendor;

class YourClass { }

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

Loading history...
4
{
5
    public static $fixture_file = "forum/tests/ForumTest.yml";
6
7
    // fixes permission issues with these tests, we don't need to test versioning anyway.
8
    // without this, SiteTree::canView() would always return false even though CanViewType == Anyone.
9
    public static $use_draft_site = true;
10
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        //track the default state of tokens
16
        $this->useToken = SecurityToken::is_enabled();
0 ignored issues
show
Bug introduced by
The property useToken does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17
    }
18
19
    public function tearDown()
20
    {
21
        parent::tearDown();
22
23
        //if the token is turned on reset it before the next test run
24
        if ($this->useToken) {
25
            SecurityToken::enable();
26
        } else {
27
            SecurityToken::disable();
28
        }
29
    }
30
31
    public function testPermissions()
32
    {
33
        $member1 = $this->objFromFixture('Member', 'test1');
34
        $member2 = $this->objFromFixture('Member', 'test2');
35
        $moderator = $this->objFromFixture('Member', 'moderator');
36
        $admin = $this->objFromFixture('Member', 'admin');
37
        
38
        $postMember2 = $this->objFromFixture('Post', 'Post18');
39
        
40
        // read only thread post
41
        $member1->logIn();
42
        $postReadonly = $this->objFromFixture('Post', 'ReadonlyThreadPost');
43
        $this->assertFalse($postReadonly->canEdit()); // Even though it's user's own
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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

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

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

Loading history...
45
        $this->assertFalse($postReadonly->canCreate());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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

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

Loading history...
46
        $this->assertFalse($postReadonly->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
47
        
48
        // normal thread. They can post to these
49
        $member1->logIn();
50
        $this->assertFalse($postMember2->canEdit()); // Not user's post
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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

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

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

Loading history...
52
        $this->assertTrue($postMember2->canCreate());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<PostTest>.

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

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

Loading history...
53
        $this->assertFalse($postMember2->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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

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

Loading history...
54
        
55
        // Check the user has full rights on his own post
56
        $member2->logIn();
57
        $this->assertTrue($postMember2->canEdit()); // User's post
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<PostTest>.

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

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

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

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

Loading history...
60
        $this->assertTrue($postMember2->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<PostTest>.

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

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

Loading history...
61
62
        // Moderator can delete posts, even if he doesn't own them
63
        $moderator->logIn();
64
        $this->assertFalse($postMember2->canEdit());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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

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

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

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

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

Loading history...
68
69
        // Admins should have full rights, even if they're not moderators or own the post
70
        $admin->logIn();
71
        $this->assertTrue($postMember2->canEdit());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<PostTest>.

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

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

Loading history...
72
        $this->assertTrue($postMember2->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<PostTest>.

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

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

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...
75
    }
76
    
77
    public function testGetTitle()
78
    {
79
        $post = $this->objFromFixture('Post', 'Post1');
80
        $reply = $this->objFromFixture('Post', 'Post2');
81
        
82
        $this->assertEquals($post->Title, "Test Thread");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<PostTest>.

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

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

Loading history...
83
        $this->assertEquals($reply->Title, "Re: Test Thread");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<PostTest>.

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

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

Loading history...
84
        
85
        $first = $this->objFromFixture('Post', 'Post3');
86
        $this->assertEquals($first->Title, 'Another Test Thread');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<PostTest>.

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...
87
    }
88
    
89
    public function testIssFirstPost()
90
    {
91
        $first = $this->objFromFixture('Post', 'Post1');
92
        $this->assertTrue($first->isFirstPost());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<PostTest>.

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...
93
        
94
        $notFirst = $this->objFromFixture('Post', 'Post2');
95
        $this->assertFalse($notFirst->isFirstPost());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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

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

Loading history...
96
    }
97
    
98
    public function testReplyLink()
99
    {
100
        $post = $this->objFromFixture('Post', 'Post1');
101
        $this->assertContains($post->Thread()->URLSegment .'/reply/'.$post->ThreadID, $post->ReplyLink());
102
    }
103
    
104
    public function testShowLink()
105
    {
106
        $post = $this->objFromFixture('Post', 'Post1');
107
        Forum::$posts_per_page = 8;
108
        
109
        // test for show link on first page
110
        $this->assertContains($post->Thread()->URLSegment .'/show/'.$post->ThreadID, $post->ShowLink());
111
        
112
        // test for link that should be last post on the first page
113
        $eighthPost = $this->objFromFixture('Post', 'Post9');
114
        $this->assertContains($eighthPost->Thread()->URLSegment .'/show/'.$eighthPost->ThreadID.'#post'.$eighthPost->ID, $eighthPost->ShowLink());
115
        
116
        // test for a show link on a subpage
117
        $lastPost = $this->objFromFixture('Post', 'Post10');
118
        $this->assertContains($lastPost->Thread()->URLSegment .'/show/'. $lastPost->ThreadID . '?start=8#post'.$lastPost->ID, $lastPost->ShowLink());
119
        
120
        // this is the last post on page 2
121
        $lastPost = $this->objFromFixture('Post', 'Post17');
122
        $this->assertContains($lastPost->Thread()->URLSegment .'/show/'. $lastPost->ThreadID . '?start=8#post'.$lastPost->ID, $lastPost->ShowLink());
123
            
124
        // test for a show link on the last subpage
125
        $lastPost = $this->objFromFixture('Post', 'Post18');
126
        $this->assertContains($lastPost->Thread()->URLSegment .'/show/'. $lastPost->ThreadID . '?start=16#post'.$lastPost->ID, $lastPost->ShowLink());
127
    }
128
    
129
    public function testEditLink()
130
    {
131
        $post = $this->objFromFixture('Post', 'Post1');
132
133
        // should be false since we're not logged in.
134
        if ($member = Member::currentUser()) {
135
            $member->logOut();
136
        }
137
        
138
        $this->assertFalse($post->EditLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
139
        
140
        // logged in as the member. Should be able to edit it
141
        $member = $this->objFromFixture('Member', 'test1');
142
        $member->logIn();
143
        
144
        $this->assertContains($post->Thread()->URLSegment .'/editpost/'. $post->ID, $post->EditLink());
145
        
146
        // log in as another member who is not
147
        $member->logOut();
148
        
149
        $memberOther = $this->objFromFixture('Member', 'test2');
150
        $memberOther->logIn();
151
        
152
        $this->assertFalse($post->EditLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
153
    }
154
    
155 View Code Duplication
    public function testDeleteLink()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
156
    {
157
        $post = $this->objFromFixture('Post', 'Post1');
158
159
        //enable token
160
        SecurityToken::enable();
161
162
        // should be false since we're not logged in.
163
        if ($member = Member::currentUser()) {
164
            $member->logOut();
165
        }
166
        
167
        $this->assertFalse($post->EditLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
168
        $this->assertFalse($post->DeleteLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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
        // logged in as the moderator. Should be able to delete the post.
171
        $member = $this->objFromFixture('Member', 'moderator');
172
        $member->logIn();
173
        
174
        $this->assertContains($post->Thread()->URLSegment .'/deletepost/'. $post->ID, $post->DeleteLink());
175
        
176
        // because this is the first post test for the class which is used in javascript
177
        $this->assertContains("class=\"deleteLink firstPost\"", $post->DeleteLink());
178
179
        $member->logOut();
180
        
181
        // log in as another member who is not in a position to delete this post
182
        $member = $this->objFromFixture('Member', 'test2');
183
        $member->logIn();
184
        
185
        $this->assertFalse($post->DeleteLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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
        
187
        // log in as someone who can moderate this post (and therefore delete it)
188
        $member = $this->objFromFixture('Member', 'moderator');
189
        $member->logIn();
190
191
192
        //check for the existance of a CSRF token
193
        $this->assertContains("SecurityID=", $post->DeleteLink());
194
195
        // should be able to edit post since they're moderators
196
        $this->assertContains($post->Thread()->URLSegment .'/deletepost/'. $post->ID, $post->DeleteLink());
197
        
198
        // test that a 2nd post doesn't have the first post ID hook
199
        $memberOthersPost = $this->objFromFixture('Post', 'Post2');
200
        
201
        $this->assertFalse(strstr($memberOthersPost->DeleteLink(), "firstPost"));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
202
    }
203
204 View Code Duplication
    public function testMarkAsSpamLink()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
205
    {
206
        $post = $this->objFromFixture('Post', 'Post1');
207
208
        //enable token
209
        SecurityToken::enable();
210
211
        // should be false since we're not logged in.
212
        if ($member = Member::currentUser()) {
213
            $member->logOut();
214
        }
215
216
        $this->assertFalse($post->EditLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
217
        $this->assertFalse($post->MarkAsSpamLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
218
219
        // logged in as the moderator. Should be able to mark the post as spam.
220
        $member = $this->objFromFixture('Member', 'moderator');
221
        $member->logIn();
222
223
        $this->assertContains($post->Thread()->URLSegment .'/markasspam/'. $post->ID, $post->MarkAsSpamLink());
224
225
        // because this is the first post test for the class which is used in javascript
226
        $this->assertContains("class=\"markAsSpamLink firstPost\"", $post->MarkAsSpamLink());
227
228
        $member->logOut();
229
230
        // log in as another member who is not in a position to mark post as spam this post
231
        $member = $this->objFromFixture('Member', 'test2');
232
        $member->logIn();
233
234
        $this->assertFalse($post->MarkAsSpamLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
235
236
        // log in as someone who can moderate this post (and therefore mark as spam)
237
        $member = $this->objFromFixture('Member', 'moderator');
238
        $member->logIn();
239
240
241
        //check for the existance of a CSRF token
242
        $this->assertContains("SecurityID=", $post->MarkAsSpamLink());
243
244
        // should be able to edit post since they're moderators
245
        $this->assertContains($post->Thread()->URLSegment .'/markasspam/'. $post->ID, $post->MarkAsSpamLink());
246
247
        // test that a 2nd post doesn't have the first post ID hook
248
        $memberOthersPost = $this->objFromFixture('Post', 'Post2');
249
250
        $this->assertFalse(strstr($memberOthersPost->MarkAsSpamLink(), "firstPost"));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
251
    }
252
253
    public function testBanAndGhostLink()
254
    {
255
        $post = $this->objFromFixture('Post', 'Post1');
256
257
        // should be false since we're not logged in.
258
        if ($member = Member::currentUser()) {
259
            $member->logOut();
260
        }
261
262
        $this->assertFalse($post->EditLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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

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...
264
        $this->assertFalse($post->GhostLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
265
266
        // logged in as the moderator. Should be able to mark the post as spam.
267
        $member = $this->objFromFixture('Member', 'moderator');
268
        $member->logIn();
269
270
        $forum = $post->Thread()->Forum();
271
        $this->assertContains($forum->URLSegment . '/ban/' . $post->AuthorID, $post->BanLink());
272
        $this->assertContains($forum->URLSegment . '/ghost/' . $post->AuthorID, $post->GhostLink());
273
274
        $member->logOut();
275
276
        // log in as another member who is not in a position to mark post as spam this post
277
        $member = $this->objFromFixture('Member', 'test2');
278
        $member->logIn();
279
280
        $this->assertFalse($post->BanLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
281
        $this->assertFalse($post->GhostLink());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<PostTest>.

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...
282
    }
283
    
284
    public function testGetUpdated()
285
    {
286
        $post = new Post();
287
        $post->Content = "Original Content";
0 ignored issues
show
Documentation introduced by
The property Content does not exist on object<Post>. Since you implemented __set, maybe consider adding a @property annotation.

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

<?php

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

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

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

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

}

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

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

See also the PhpDoc documentation for @property.

Loading history...
288
        $post->write();
289
290
        $this->assertNull($post->Updated);
0 ignored issues
show
Documentation introduced by
The property Updated does not exist on object<Post>. Since you implemented __get, maybe consider adding a @property annotation.

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

<?php

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

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

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

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

}

If the property has read access only, you can use the @property-read annotation instead.

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

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method assertNull() does not seem to exist on object<PostTest>.

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
        sleep(2);
292
        $post->Content = "Some Content Now";
0 ignored issues
show
Documentation introduced by
The property Content does not exist on object<Post>. Since you implemented __set, maybe consider adding a @property annotation.

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

<?php

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

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

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

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

}

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

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

See also the PhpDoc documentation for @property.

Loading history...
293
        $post->write();
294
        
295
        $this->assertNotNull($post->Updated);
0 ignored issues
show
Documentation introduced by
The property Updated does not exist on object<Post>. Since you implemented __get, maybe consider adding a @property annotation.

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

<?php

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

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

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

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

}

If the property has read access only, you can use the @property-read annotation instead.

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

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method assertNotNull() does not seem to exist on object<PostTest>.

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...
296
    }
297
    
298
    public function testRSSContent()
299
    {
300
        // @todo escaping tests. They are handled by bbcode parser tests?
301
    }
302
    
303
    public function testRSSAuthor()
304
    {
305
        // @todo 
306
    }
307
}
308