Issues (93)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/php/SiteTreeContentReviewTest.php (26 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SilverStripe\ContentReview\Tests;
4
5
use Page;
6
use SilverStripe\CMS\Controllers\CMSPageEditController;
7
use SilverStripe\CMS\Model\SiteTree;
8
use SilverStripe\ContentReview\Extensions\SiteTreeContentReview;
9
use SilverStripe\ContentReview\Extensions\ContentReviewOwner;
10
use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension;
11
use SilverStripe\ContentReview\Extensions\ContentReviewDefaultSettings;
12
use SilverStripe\Forms\LiteralField;
13
use SilverStripe\Security\Group;
14
use SilverStripe\Security\Member;
15
use SilverStripe\SiteConfig\SiteConfig;
16
use SilverStripe\ORM\FieldType\DBDatetime;
17
use SilverStripe\Versioned\Versioned;
18
19
/**
20
 * @mixin PHPUnit_Framework_TestCase
21
 */
22
class SiteTreeContentReviewTest extends ContentReviewBaseTest
23
{
24
    /**
25
     * @var string
26
     */
27
    protected static $fixture_file = 'ContentReviewTest.yml';
28
29
    /**
30
     * @var array
31
     */
32
    protected static $required_extensions = [
33
        SiteTree::class              => [SiteTreeContentReview::class],
34
        Group::class                 => [ContentReviewOwner::class],
35
        Member::class                => [ContentReviewOwner::class],
36
        CMSPageEditController::class => [ContentReviewCMSExtension::class],
37
        SiteConfig::class            => [ContentReviewDefaultSettings::class],
38
    ];
39
40
    public function testOwnerNames()
41
    {
42
        /** @var Member $editor */
43
        $editor = $this->objFromFixture(Member::class, "editor");
44
45
        $this->logInAs($editor);
46
47
        /** @var Page|SiteTreeContentReview $page */
48
        $page = new Page();
49
        $page->ReviewPeriodDays = 10;
50
        $page->ContentReviewType = "Custom";
51
52
        $page->ContentReviewUsers()->push($editor);
53
        $page->write();
0 ignored issues
show
The method write() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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

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

Loading history...
54
55
        $this->assertTrue($page->canPublish());
0 ignored issues
show
The method canPublish() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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

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

Loading history...
56
        $this->assertTrue($page->doPublish());
0 ignored issues
show
The method doPublish() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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

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

Loading history...
57
        $this->assertEquals($page->OwnerNames, "Test Editor", "Test Editor should be the owner");
58
59
        /** @var Page|SiteTreeContentReview $page */
60
        $page = $this->objFromFixture(Page::class, "about");
61
62
        $page->OwnerUsers()->removeAll();
63
        $page->write();
0 ignored issues
show
The method write() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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...
64
65
        $this->assertTrue($page->canPublish());
0 ignored issues
show
The method canPublish() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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($page->doPublish());
0 ignored issues
show
The method doPublish() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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->assertEquals("", $page->OwnerNames);
68
    }
69
70
    public function testPermissionsExists()
71
    {
72
        $perms = singleton(SiteTreeContentReview::class)->providePermissions();
73
74
        $this->assertTrue(isset($perms["EDIT_CONTENT_REVIEW_FIELDS"]));
75
    }
76
77 View Code Duplication
    public function testUserWithPermissionCanEdit()
0 ignored issues
show
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...
78
    {
79
        /** @var Member $editor */
80
        $editor = $this->objFromFixture(Member::class, "editor");
81
82
        $this->logInAs($editor);
83
84
        /** @var Page|SiteTreeContentReview $page */
85
        $page = new Page();
86
87
        $fields = $page->getSettingsFields();
0 ignored issues
show
The method getSettingsFields() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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

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

Loading history...
88
89
        $this->assertNotNull($fields->dataFieldByName("NextReviewDate"));
90
    }
91
92 View Code Duplication
    public function testUserWithoutPermissionCannotEdit()
0 ignored issues
show
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...
93
    {
94
        /** @var Member $author */
95
        $author = $this->objFromFixture(Member::class, "author");
96
97
        $this->logInAs($author);
98
99
        /** @var Page|SiteTreeContentReview $page */
100
        $page = new Page();
101
102
        $fields = $page->getSettingsFields();
0 ignored issues
show
The method getSettingsFields() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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

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

Loading history...
103
104
        $this->assertNull($fields->dataFieldByName("NextReviewDate"));
105
    }
106
107
    public function testAutomaticallyToNotSetReviewDate()
108
    {
109
        /** @var Member $editor */
110
        $editor = $this->objFromFixture(Member::class, "editor");
111
112
        $this->logInAs($editor);
113
114
        /** @var Page|SiteTreeContentReview $page */
115
        $page = new Page();
116
117
        $page->ReviewPeriodDays = 10;
118
        $page->write();
0 ignored issues
show
The method write() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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...
119
120
        $this->assertTrue($page->doPublish());
0 ignored issues
show
The method doPublish() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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
        $this->assertEquals(null, $page->NextReviewDate);
122
    }
123
124
    public function testAddReviewNote()
125
    {
126
        /** @var Member $author */
127
        $author = $this->objFromFixture(Member::class, "author");
128
129
        /** @var Page|SiteTreeContentReview $page */
130
        $page = $this->objFromFixture(Page::class, "home");
131
132
        $page->addReviewNote($author, "This is a message");
133
134
        /** @var Page|SiteTreeContentReview $page */
135
        $homepage = $this->objFromFixture(Page::class, "home");
136
137
        $this->assertEquals(1, $homepage->ReviewLogs()->count());
138
        $this->assertEquals("This is a message", $homepage->ReviewLogs()->first()->Note);
139
    }
140
141
    public function testGetContentReviewOwners()
142
    {
143
        /** @var Page|SiteTreeContentReview $page */
144
        $page = $this->objFromFixture(Page::class, "group-owned");
145
146
        $owners = $page->ContentReviewOwners();
147
148
        $this->assertEquals(1, $owners->count());
149
        $this->assertEquals("[email protected]", $owners->first()->Email);
150
    }
151
152 View Code Duplication
    public function testCanNotBeReviewBecauseNoReviewDate()
0 ignored issues
show
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...
153
    {
154
        DBDatetime::set_mock_now("2010-01-01 12:00:00");
155
156
        /** @var Member $author */
157
        $author = $this->objFromFixture(Member::class, "author");
158
159
        /** @var Page|SiteTreeContentReview $page */
160
        $page = $this->objFromFixture(Page::class, "no-review");
161
162
        $this->assertFalse($page->canBeReviewedBy($author));
163
164
        DBDatetime::clear_mock_now();
165
    }
166
167 View Code Duplication
    public function testCanNotBeReviewedBecauseInFuture()
0 ignored issues
show
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...
168
    {
169
        DBDatetime::set_mock_now("2010-01-01 12:00:00");
170
171
        /** @var Member $author */
172
        $author = $this->objFromFixture(Member::class, "author");
173
174
        /** @var Page|SiteTreeContentReview $page */
175
        $page = $this->objFromFixture(Page::class, "staff");
176
177
        $this->assertFalse($page->canBeReviewedBy($author));
178
179
        DBDatetime::clear_mock_now();
180
    }
181
182 View Code Duplication
    public function testCanNotBeReviewedByUser()
0 ignored issues
show
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...
183
    {
184
        DBDatetime::set_mock_now("2010-03-01 12:00:00");
185
186
        /** @var Member $author */
187
        $author = $this->objFromFixture(Member::class, "author");
188
189
        /** @var Page|SiteTreeContentReview $page */
190
        $page = $this->objFromFixture(Page::class, "home");
191
192
        $this->assertFalse($page->canBeReviewedBy($author));
193
194
        DBDatetime::clear_mock_now();
195
    }
196
197 View Code Duplication
    public function testCanBeReviewedByUser()
0 ignored issues
show
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...
198
    {
199
        DBDatetime::set_mock_now("2010-03-01 12:00:00");
200
201
        /** @var Member $author */
202
        $author = $this->objFromFixture(Member::class, "author");
203
204
        /** @var Page|SiteTreeContentReview $page */
205
        $page = $this->objFromFixture(Page::class, "staff");
206
207
        $this->assertTrue($page->canBeReviewedBy($author));
208
209
        DBDatetime::clear_mock_now();
210
    }
211
212 View Code Duplication
    public function testCanNotBeReviewedByGroup()
0 ignored issues
show
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...
213
    {
214
        DBDatetime::set_mock_now("2010-03-01 12:00:00");
215
216
        /** @var Member $author */
217
        $author = $this->objFromFixture(Member::class, "editor");
218
219
        /** @var Page|SiteTreeContentReview $page */
220
        $page = $this->objFromFixture(Page::class, "contact");
221
222
        $this->assertFalse($page->canBeReviewedBy($author));
223
224
        DBDatetime::clear_mock_now();
225
    }
226
227 View Code Duplication
    public function testCanBeReviewedByGroup()
0 ignored issues
show
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...
228
    {
229
        DBDatetime::set_mock_now("2010-03-01 12:00:00");
230
231
        /** @var Member $author */
232
        $author = $this->objFromFixture(Member::class, "author");
233
234
        /** @var Page|SiteTreeContentReview $page */
235
        $page = $this->objFromFixture(Page::class, "contact");
236
237
        $this->assertTrue($page->canBeReviewedBy($author));
238
239
        DBDatetime::clear_mock_now();
240
    }
241
242 View Code Duplication
    public function testCanBeReviewedFromInheritedSetting()
0 ignored issues
show
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...
243
    {
244
        DBDatetime::set_mock_now("2013-03-01 12:00:00");
245
246
        /** @var Member $author */
247
        $author = $this->objFromFixture(Member::class, "author");
248
249
        /** @var Page|SiteTreeContentReview $parentPage */
250
        $parentPage = $this->objFromFixture(Page::class, "contact");
251
252
        $parentPage->NextReviewDate = "2013-01-01";
253
        $parentPage->write();
0 ignored issues
show
The method write() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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...
254
255
        /** @var Page|SiteTreeContentReview $page */
256
        $page = $this->objFromFixture(Page::class, "contact-child");
257
258
        $this->assertTrue($page->canBeReviewedBy($author));
259
260
        DBDatetime::clear_mock_now();
261
    }
262
263
    public function testUnModifiedPagesDontChangeEditor()
264
    {
265
        DBDatetime::set_mock_now("2013-03-01 12:00:00");
266
267
        /** @var Member $author */
268
        $author = $this->objFromFixture(Member::class, "author");
269
        $this->logInAs($author);
270
271
        // Page which is un-modified doesn't advance version of have an editor assigned
272
        $contactPage = $this->objFromFixture(Page::class, "contact");
273
        $contactPageVersion = $contactPage->Version;
274
        $contactPage->write();
275
        $this->assertEmpty($contactPage->LastEditedByName);
0 ignored issues
show
The property LastEditedByName does not seem to exist. Did you mean LastEdited?

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...
276
        $this->assertEquals(
277
            $contactPageVersion,
278
            Versioned::get_versionnumber_by_stage(SiteTree::class, 'Stage', $contactPage->ID, false)
279
        );
280
281
        // Page with modifications gets marked
282
        $homePage = $this->objFromFixture(Page::class, "home");
283
        $homePageVersion = $homePage->Version;
284
        $homePage->Content = '<p>Welcome!</p>';
285
        $homePage->write();
286
        $this->assertNotEmpty($homePage->LastEditedByName);
0 ignored issues
show
The property LastEditedByName does not seem to exist. Did you mean LastEdited?

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...
287
        $this->assertEquals($author->getTitle(), $homePage->LastEditedByName);
0 ignored issues
show
The property LastEditedByName does not seem to exist. Did you mean LastEdited?

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...
288
        $this->assertGreaterThan(
289
            $homePageVersion,
290
            Versioned::get_versionnumber_by_stage(SiteTree::class, 'Stage', $homePage->ID, false)
291
        );
292
293
        DBDatetime::clear_mock_now();
294
    }
295
296
    public function testReviewActionVisibleForAuthor()
297
    {
298
        DBDatetime::set_mock_now('2020-03-01 12:00:00');
299
300
        /** @var Page|SiteTreeContentReview $page */
301
        $page = $this->objFromFixture(Page::class, 'contact');
302
303
        /** @var Member $author */
304
        $author = $this->objFromFixture(Member::class, 'author');
305
306
        $this->logInAs($author);
307
308
        $fields = $page->getCMSActions();
0 ignored issues
show
The method getCMSActions() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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
310
        $this->assertInstanceOf(LiteralField::class, $fields->fieldByName('ContentReviewButton'));
311
312
        DBDatetime::clear_mock_now();
313
    }
314
315 View Code Duplication
    public function testReviewActionNotVisibleForEditor()
0 ignored issues
show
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...
316
    {
317
        DBDatetime::set_mock_now("2020-03-01 12:00:00");
318
319
        /** @var Page|SiteTreeContentReview $page */
320
        $page = $this->objFromFixture(Page::class, "contact");
321
322
        /** @var Member $author */
323
        $author = $this->objFromFixture(Member::class, "editor");
324
325
        $this->logInAs($author);
326
327
        $fields = $page->getCMSActions();
0 ignored issues
show
The method getCMSActions() does not seem to exist on object<SilverStripe\Cont...\SiteTreeContentReview>.

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
329
        $this->assertNull($fields->fieldByName("ActionMenus.ReviewContent"));
330
331
        DBDatetime::clear_mock_now();
332
    }
333
334
    public function testSiteConfigSettingsAreUsedAsDefaults()
335
    {
336
        DBDatetime::set_mock_now("2020-03-01 12:00:00");
337
338
        /** @var Member $author */
339
        $author = $this->objFromFixture(Member::class, 'editor');
340
341
        /** @var SiteConfig $siteConfig */
342
        $siteConfig = SiteConfig::current_site_config();
343
344
        // Set the author to a default user for reviewing
345
        $siteConfig->OwnerUsers()->add($author);
346
347
        $emptyPage = new Page;
348
        $emptyPage->NextReviewDate = '2020-02-20 12:00:00';
349
350
        $this->assertTrue($emptyPage->canBeReviewedBy($author));
351
352
        DBDatetime::clear_mock_now();
353
    }
354
}
355