Completed
Pull Request — master (#306)
by Will
02:12
created

testItRestrictsCreateFolderByCanCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 17
Ratio 100 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
c 2
b 2
f 0
dl 17
loc 17
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace SilverStripe\AssetAdmin\Tests;
4
5
use SilverStripe\Assets\File;
6
use SilverStripe\Assets\Folder;
7
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
8
use SilverStripe\Control\Director;
9
use SilverStripe\Control\Session;
10
use SilverStripe\Dev\FunctionalTest;
11
use SilverStripe\Dev\TestOnly;
12
use SilverStripe\ORM\DataExtension;
13
use SilverStripe\ORM\Versioning\Versioned;
14
use SilverStripe\Security\SecurityToken;
15
16
/**
17
 * Tests {@see AssetAdmin}
18
 */
19
class AssetAdminTest extends FunctionalTest
20
{
21
22
    protected static $fixture_file = 'AssetAdminTest.yml';
23
24
    /**
25
     * @var Session
26
     */
27
    protected $session = null;
28
29
    public function setUp()
30
    {
31
        parent::setUp();
32
33
        TestAssetStore::activate('AssetAdminTest');
34
        $memberID = $this->logInWithPermission('ADMIN');
35
        $this->session = Session::create(array('loggedInAs' => $memberID));
36
37
        File::add_extension(AssetAdminTest_File::class);
38
        Folder::add_extension(AssetAdminTest_Folder::class);
39
40
        // Create a test folders for each of the fixture references
41
        foreach (File::get()->filter('ClassName', Folder::class) as $folder) {
42
            /** @var Folder $folder */
43
            $folder->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
44
        }
45
46
        // Create a test files for each of the fixture references
47
        $content = str_repeat('x', 1000000);
48
        foreach (File::get()->exclude('ClassName', Folder::class) as $file) {
49
            /** @var File $file */
50
            $file->setFromString($content, $file->generateFilename());
51
            $file->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
52
        }
53
54
        // Override FunctionalTest defaults
55
        SecurityToken::enable();
56
        $this->session->inst_set('SecurityID', SecurityToken::inst()->getValue());
57
    }
58
59
    public function tearDown()
60
    {
61
        File::remove_extension(AssetAdminTest_File::class);
62
        Folder::remove_extension(AssetAdminTest_Folder::class);
63
64
        TestAssetStore::reset();
65
        parent::tearDown();
66
    }
67
68
69
    public function testApiHistory() {
70
        $file = $this->objFromFixture(
71
            'SilverStripe\\Assets\\File',
72
            'file1'
73
        );
74
        $response = Director::test(
75
            'admin/assets/api/history?fileId='. $file->ID,
76
            null,
77
            $this->session,
78
            'GET'
79
        );
80
81
        $this->assertFalse($response->isError());
82
83
        $body = json_decode($response->getBody());
84
85
        $this->assertArrayHasKey('summary', $body[0]);
86
        $this->assertArrayHasKey('versionid', $body[0]);
87
        $this->assertArrayHasKey('summary', $body[0]);
88
89
        // test permission filtering and
90
    }
91
92
93
    public function testItCreatesFolder()
94
    {
95
        $folder1 = $this->objFromFixture(Folder::class, 'folder1');
96
97
        $response = Director::test(
98
            'admin/assets/api/createFolder',
99
            [
100
                'ParentID' => $folder1->ID,
101
                'Name' => 'testItCreatesFolder',
102
                'SecurityID' => SecurityToken::inst()->getValue(),
103
            ],
104
            $this->session,
105
            'POST'
106
        );
107
        $this->assertFalse($response->isError());
108
        $responseData = json_decode($response->getBody(), true);
109
        $newFolder = Folder::get()->byID($responseData['id']);
110
        $this->assertNotNull($newFolder);
111
        $this->assertEquals($folder1->ID, $newFolder->ParentID);
112
        $this->assertEquals('testItCreatesFolder', $newFolder->Name);
113
    }
114
115 View Code Duplication
    public function testItRestrictsCreateFolderByCanCreate()
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...
116
    {
117
        $folder = $this->objFromFixture(Folder::class, 'folder1');
118
119
        $response = Director::test(
120
            'admin/assets/api/createFolder',
121
            [
122
                'ParentID' => $folder->ID,
123
                'Name' => 'disallowCanCreate',
124
                'SecurityID' => SecurityToken::inst()->getValue(),
125
            ],
126
            $this->session,
127
            'POST'
128
        );
129
        $this->assertTrue($response->isError());
130
        $this->assertEquals(403, $response->getStatusCode());
131
    }
132
133 View Code Duplication
    public function testItRestrictsCreateFolderByCanAddChildren()
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...
134
    {
135
        $folder = $this->objFromFixture(Folder::class, 'disallowCanAddChildren');
136
137
        $response = Director::test(
138
            'admin/assets/api/createFolder',
139
            [
140
                'ParentID' => $folder->ID,
141
                'Name' => 'testItRestrictsCreateFolderByCanAddChildren',
142
                'SecurityID' => SecurityToken::inst()->getValue(),
143
            ],
144
            $this->session,
145
            'POST'
146
        );
147
        $this->assertTrue($response->isError());
148
        $this->assertEquals(403, $response->getStatusCode());
149
    }
150
151
    public function testItCreatesFile()
0 ignored issues
show
Coding Style introduced by
testItCreatesFile uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
152
    {
153
        $folder1 = $this->objFromFixture(Folder::class, 'folder1');
154
155
        /** @skipUpgrade */
156
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'testItCreatesFile.txt'));
157
        $_FILES = $fileData;
158
        $postedData = array_merge(
159
                $fileData,
160
                [
161
                    'ParentID' => $folder1->ID,
162
                    'SecurityID' => SecurityToken::inst()->getValue(),
163
                ]
164
        );
165
        $response = Director::test(
166
            'admin/assets/api/createFile',
167
            $postedData,
168
            $this->session,
169
            'POST'
170
        );
171
        $this->assertFalse($response->isError());
172
        $responseData = json_decode($response->getBody(), true);
173
        $newFile = File::get()->byID($responseData[0]['id']);
174
        $this->assertNotNull($newFile);
175
        $this->assertEquals($folder1->ID, $newFile->ParentID);
176
        $this->assertEquals('testItCreatesFile.txt', $newFile->Name);
177
178
        // Test that duplicate uploads are renamed
179
        $response = Director::test(
180
            'admin/assets/api/createFile',
181
            $postedData,
182
            $this->session,
183
            'POST'
184
        );
185
        $this->assertFalse($response->isError());
186
        $responseData = json_decode($response->getBody(), true);
187
        $newFile2 = File::get()->byID($responseData[0]['id']);
188
        $this->assertNotNull($newFile2);
189
        $this->assertEquals($folder1->ID, $newFile2->ParentID);
190
        $this->assertNotEquals($newFile->ID, $newFile2->ID);
191
        $this->assertEquals('testItCreatesFile-v2.txt', $newFile2->Name);
192
    }
193
194 View Code Duplication
    public function testItRestrictsCreateFileOnCanCreate()
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...
Coding Style introduced by
testItRestrictsCreateFileOnCanCreate uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
195
    {
196
        $folder = $this->objFromFixture(Folder::class, 'folder1');
197
198
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'disallowCanCreate.txt'));
199
        $_FILES = $fileData;
200
        $response = Director::test(
201
            'admin/assets/api/createFile',
202
            array_merge(
203
                $fileData,
204
                [
205
                    'ParentID' => $folder->ID,
206
                    'SecurityID' => SecurityToken::inst()->getValue(),
207
                ]
208
            ),
209
            $this->session,
210
            'POST'
211
        );
212
        $this->assertTrue($response->isError());
213
        $this->assertEquals(403, $response->getStatusCode());
214
    }
215
216 View Code Duplication
    public function testItRestrictsCreateFileOnCanAddChildren()
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...
Coding Style introduced by
testItRestrictsCreateFileOnCanAddChildren uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
217
    {
218
        $folder = $this->objFromFixture(Folder::class, 'disallowCanAddChildren');
219
220
        /** @skipUpgrade */
221
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'test.txt'));
222
        $_FILES = $fileData;
223
        $response = Director::test(
224
            'admin/assets/api/createFile',
225
            array_merge(
226
                $fileData,
227
                [
228
                    'ParentID' => $folder->ID,
229
                    'SecurityID' => SecurityToken::inst()->getValue(),
230
                ]
231
            ),
232
            $this->session,
233
            'POST'
234
        );
235
        $this->assertTrue($response->isError());
236
        $this->assertEquals(403, $response->getStatusCode());
237
    }
238
239
    public function testItRestrictsCreateFileOnExtension()
0 ignored issues
show
Coding Style introduced by
testItRestrictsCreateFileOnExtension uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
240
    {
241
        $folder1 = $this->objFromFixture(
242
            Folder::class,
243
            'folder1'
244
        );
245
246
        /** @skipUpgrade */
247
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'disallowed.php'));
248
        $_FILES = $fileData;
249
        $response = Director::test(
250
            'admin/assets/api/createFile',
251
            array_merge(
252
                $fileData,
253
                [
254
                    'ParentID' => $folder1->ID,
255
                    'SecurityID' => SecurityToken::inst()->getValue(),
256
                ]
257
            ),
258
            $this->session,
259
            'POST'
260
        );
261
        $this->assertTrue($response->isError());
262
        $this->assertEquals(400, $response->getStatusCode());
263
        $responseData = json_decode($response->getBody(), true);
264
        $this->assertContains(
265
            'Extension is not allowed',
266
            $responseData['message']['value']
267
        );
268
    }
269
270
    public function testItFiltersByDateInSearch()
271
    {
272
        $file1 = $this->objFromFixture(File::class, 'file1');
273
        $file2 = $this->objFromFixture(File::class, 'file2');
274
275
        // Force creation times
276
        $file1->Created = '2014-01-05 23:11:39';
277
        $file1->write();
278
        $file2->Created = '2014-01-06 12:00:00';
279
        $file2->write();
280
281
        // Mock searches for 4th Jan
282
        $results = $this->getResultsForSearch([
283
            'CreatedFrom' => '2014-01-04',
284
            'CreatedTo' => '2014-01-04'
285
        ]);
286
        $this->assertEquals(count($results['files']), 0);
287
288
        // Mock searches for 5th Jan
289
        $results = $this->getResultsForSearch([
290
            'CreatedFrom' => '2014-01-05',
291
            'CreatedTo' => '2014-01-05'
292
        ]);
293
        $this->assertEquals(count($results['files']), 1);
294
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
295
296
297
        // Mock searches for 5th-6th Jan
298
        $results = $this->getResultsForSearch([
299
            'CreatedFrom' => '2014-01-05',
300
            'CreatedTo' => '2014-01-06'
301
        ]);
302
        $this->assertEquals(count($results['files']), 2);
303
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
304
        $this->assertContains($file2->ID, array_column($results['files'], 'id'));
305
306
        // Mock searches for 6th Jan
307
        $results = $this->getResultsForSearch([
308
            'CreatedFrom' => '2014-01-06',
309
            'CreatedTo' => '2014-01-06'
310
        ]);
311
        $this->assertEquals(count($results['files']), 1);
312
        $this->assertContains($file2->ID, array_column($results['files'], 'id'));
313
314
        // Mock searches for 7th Jan
315
        $results = $this->getResultsForSearch([
316
            'CreatedFrom' => '2014-01-07',
317
            'CreatedTo' => '2014-01-07'
318
        ]);
319
        $this->assertEquals(count($results['files']), 0);
320
    }
321
322
323
    public function testItDoesNotFilterByDefaultInSearch()
324
    {
325
        $rootfile = $this->objFromFixture(File::class, 'rootfile');
326
        $file1 = $this->objFromFixture(File::class, 'file1');
327
        $folder1 = $this->objFromFixture(Folder::class, 'folder1');
328
329
        $results = $this->getResultsForSearch();
330
        $this->assertContains($rootfile->ID, array_column($results['files'], 'id'),
331
            'Contains top level file'
332
        );
333
        $this->assertContains($folder1->ID, array_column($results['files'], 'id'),
334
            'Contains top level folder'
335
        );
336
        $this->assertContains($file1->ID, array_column($results['files'], 'id'),
337
            'Contains files in subfolder'
338
        );
339
    }
340
341
    public function testItFiltersByParentInSearch()
342
    {
343
        /** @var File $file1 */
344
        $file1 = $this->objFromFixture(File::class, 'file1');
345
        /** @var File $file2 */
346
        $file2 = $this->objFromFixture(File::class, 'file2');
347
        $file1Folder = $file1->Parent();
348
        $file2Folder = $file2->Parent();
349
350
        $results = $this->getResultsForSearch(['Name' => $file1->Name, 'ParentID' => $file1Folder->ID]);
351
        $this->assertEquals(count($results['files']), 1);
352
        $this->assertContains($file1->ID, array_column($results['files'], 'id'),
353
            'Returns file when contained in correct folder'
354
        );
355
356
        $results = $this->getResultsForSearch(['Name' => $file1->Name, 'ParentID' => $file2Folder->ID]);
357
        $this->assertEquals(count($results['files']), 0,
358
            'Does not return file when contained in different folder'
359
        );
360
    }
361
362
    public function testItFiltersByNameInSearch()
363
    {
364
        $file1 = $this->objFromFixture(File::class, 'file1');
365
366
        $results = $this->getResultsForSearch(['Name' => $file1->Name]);
367
        $this->assertEquals(count($results['files']), 1,
368
            'Finds by Name property'
369
        );
370
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
371
372
        $results = $this->getResultsForSearch(['Name' => 'First']);
373
        $this->assertEquals(count($results['files']), 1,
374
            'Finds by Title property'
375
        );
376
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
377
    }
378
379
    public function testItRestrictsViewInSearch()
380
    {
381
        $allowedFile = $this->objFromFixture(File::class, 'file1');
382
        $disallowedFile = $this->objFromFixture(File::class, 'disallowCanView');
383
384
        $results = $this->getResultsForSearch(['Name' => $allowedFile->Name]);
385
        $this->assertEquals(count($results['files']), 1);
386
        $this->assertContains($allowedFile->ID, array_column($results['files'], 'id'));
387
388
        $results = $this->getResultsForSearch(['Name' => $disallowedFile->Name]);
389
        $this->assertEquals(count($results['files']), 0);
390
    }
391
392
    public function testItRestrictsViewInReadFolder()
393
    {
394
        $folder1 = $this->objFromFixture(Folder::class, 'folder1');
395
        $allowedFile = $this->objFromFixture(File::class, 'file1');
396
        $disallowedFile = $this->objFromFixture(File::class, 'disallowCanView');
397
398
        $response = $this->get('admin/assets/api/readFolder?' . http_build_query(['id' => $folder1->ID]));
399
        $files = json_decode($response->getBody(), true);
400
        $this->assertArrayHasKey('files', $files);
401
        $ids = array_map(function ($file) {
402
            return $file['id'];
403
        }, $files['files']);
404
        $this->assertContains($allowedFile->ID, $ids);
405
        $this->assertEquals($allowedFile->ParentID, $folder1->ID);
406
        $this->assertNotContains($disallowedFile->ID, $ids);
407
        $this->assertEquals($disallowedFile->ParentID, $folder1->ID);
408
    }
409
410
    public function testItRestrictsUpdateFile()
411
    {
412
        $allowedFile = $this->objFromFixture(File::class, 'file1');
413
        $disallowedFile = $this->objFromFixture(File::class, 'disallowCanEdit');
414
415
        $response = Director::test(
416
            'admin/assets/FileEditForm',
417
            [
418
                'action_save' => 1,
419
                'ID' => $allowedFile->ID,
420
                'Name' => 'disallowCanEdit.txt',
421
                'Title' => 'new',
422
                'SecurityID' => SecurityToken::inst()->getValue(),
423
            ],
424
            $this->session
425
        );
426
        $this->assertFalse($response->isError());
427
428
        $response = Director::test(
429
            'admin/assets/FileEditForm',
430
            [
431
                'action_save' => 1,
432
                'ID' => $disallowedFile->ID,
433
                'Title' => 'new',
434
                'SecurityID' => SecurityToken::inst()->getValue(),
435
            ],
436
            $this->session
437
        );
438
        $this->assertTrue($response->isError());
439
    }
440
441
    public function testItRestrictsDelete()
442
    {
443
        $allowedFile = $this->objFromFixture(File::class, 'file1');
444
        $disallowedFile = $this->objFromFixture(File::class, 'disallowCanDelete');
445
446
        $response = Director::test(
447
            'admin/assets/api/delete',
448
            null,
449
            $this->session,
450
            'DELETE',
451
            http_build_query([
452
                'ids' => [$allowedFile->ID, $disallowedFile->ID],
453
                'SecurityID' => SecurityToken::inst()->getValue(),
454
            ])
455
        );
456
        $this->assertTrue($response->isError());
457
458
        $response = Director::test(
459
            'admin/assets/api/delete',
460
            null,
461
            $this->session,
462
            'DELETE',
463
            http_build_query([
464
                'ids' => [$allowedFile->ID],
465
                'SecurityID' => SecurityToken::inst()->getValue(),
466
            ])
467
        );
468
        $this->assertFalse($response->isError());
469
    }
470
471
    /**
472
     * @param array $params
473
     * @return array
474
     */
475
    protected function getResultsForSearch($params = array())
476
    {
477
        $response = $this->get('admin/assets/api/search?' . http_build_query($params));
478
        $this->assertFalse($response->isError());
479
480
        return json_decode($response->getBody(), true);
481
    }
482
483
    /**
484
     * @param string $paramName
485
     * @param string $tmpFileName
486
     * @return array Emulating an entry in the $_FILES superglobal
487
     */
488
    protected function getUploadFile($paramName, $tmpFileName = 'AssetAdminTest.txt')
0 ignored issues
show
Unused Code introduced by
The parameter $paramName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
489
    {
490
        $tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName;
491
        $tmpFileContent = '';
492
        for ($i = 0; $i < 10000; $i++) {
493
            $tmpFileContent .= '0';
494
        }
495
        file_put_contents($tmpFilePath, $tmpFileContent);
496
497
        // emulates the $_FILES array
498
        return array(
499
            'name' => $tmpFileName,
500
            'type' => 'text/plaintext',
501
            'size' => filesize($tmpFilePath),
502
            'tmp_name' => $tmpFilePath,
503
            'error' => UPLOAD_ERR_OK,
504
        );
505
    }
506
}
507
508
class AssetAdminTest_File extends DataExtension implements TestOnly
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
509
{
510
    public function canView($member = null)
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
511
    {
512
        if ($this->owner->Name === 'disallowCanView.txt') {
513
            return false;
514
        }
515
        return null;
516
    }
517
518
    public function canEdit($member = null)
519
    {
520
        if ($this->owner->Name === 'disallowCanEdit.txt') {
521
            return false;
522
        }
523
        return null;
524
    }
525
526
    public function canDelete($member = null)
527
    {
528
        if ($this->owner->Name === 'disallowCanDelete.txt') {
529
            return false;
530
        }
531
        return null;
532
    }
533
534
    public function canArchive($member = null)
535
    {
536
        if ($this->owner->Name === 'disallowCanDelete.txt') {
537
            return false;
538
        }
539
        return $this->owner->canDelete($member);
540
    }
541
542
    public function canCreate($member = null, $context = [])
543
    {
544
        if (isset($context['Parent']) && $context['Parent']->Name === 'disallowCanAddChildren') {
545
            return false;
546
        }
547
        if (isset($context['Upload']['name']) && $context['Upload']['name'] === 'disallowCanCreate.txt') {
548
            return false;
549
        }
550
        return null;
551
    }
552
}
553
554
class AssetAdminTest_Folder extends DataExtension implements TestOnly
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
555
{
556
    public function canView($member = null, $context = array())
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
557
    {
558
        if ($this->owner->Name === 'disallowCanView') {
559
            return false;
560
        }
561
        return null;
562
    }
563
564
    public function canEdit($member = null, $context = array())
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
565
    {
566
        if ($this->owner->Name === 'disallowCanEdit') {
567
            return false;
568
        }
569
        return null;
570
    }
571
572
    public function canDelete($member = null, $context = array())
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
573
    {
574
        if ($this->owner->Name === 'disallowCanDelete') {
575
            return false;
576
        }
577
        return null;
578
    }
579
580
    public function canCreate($member = null, $context = array())
581
    {
582
        if (isset($context['Name']) && $context['Name'] === 'disallowCanCreate') {
583
            return false;
584
        }
585
        return null;
586
    }
587
}
588