Completed
Push — master ( 3b23c0...1ceb95 )
by Damian
9s
created

AssetAdminTest   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 485
Duplicated Lines 15.88 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 7
Bugs 2 Features 0
Metric Value
wmc 23
c 7
b 2
f 0
lcom 1
cbo 10
dl 77
loc 485
rs 10

20 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 29 3
A tearDown() 0 8 1
A testApiHistory() 0 19 1
A testItCreatesFolder() 0 21 1
A testItRestrictsCreateFolderByCanCreate() 17 17 1
A testItRestrictsCreateFolderByCanAddChildren() 17 17 1
B testItCreatesFile() 0 42 1
A testItRestrictsCreateFileOnCanCreate() 21 21 1
A testItRestrictsCreateFileOnCanAddChildren() 22 22 1
B testItRestrictsCreateFileOnExtension() 0 30 1
A testItFiltersByDateInSearch() 0 51 1
A testItDoesNotFilterByDefaultInSearch() 0 17 1
A testItFiltersByParentInSearch() 0 20 1
A testItFiltersByNameInSearch() 0 16 1
A testItRestrictsViewInSearch() 0 12 1
A testItRestrictsViewInReadFolder() 0 17 1
B testItRestrictsUpdateFile() 0 30 1
B testItRestrictsDelete() 0 29 1
A getResultsForSearch() 0 7 1
A getUploadFile() 0 18 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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(File::class, 'file1');
71
        $response = Director::test(
72
            'admin/assets/api/history?fileId='. $file->ID,
73
            null,
74
            $this->session,
75
            'GET'
76
        );
77
78
        $this->assertFalse($response->isError());
79
80
        $body = json_decode($response->getBody(), true);
81
82
        $this->assertArrayHasKey('summary', $body[0]);
83
        $this->assertArrayHasKey('versionid', $body[0]);
84
        $this->assertArrayHasKey('summary', $body[0]);
85
86
        // test permission filtering and
87
    }
88
89
90
    public function testItCreatesFolder()
91
    {
92
        $folder1 = $this->objFromFixture(Folder::class, 'folder1');
93
94
        $response = Director::test(
95
            'admin/assets/api/createFolder',
96
            [
97
                'ParentID' => $folder1->ID,
98
                'Name' => 'testItCreatesFolder',
99
                'SecurityID' => SecurityToken::inst()->getValue(),
100
            ],
101
            $this->session,
102
            'POST'
103
        );
104
        $this->assertFalse($response->isError());
105
        $responseData = json_decode($response->getBody(), true);
106
        $newFolder = Folder::get()->byID($responseData['id']);
107
        $this->assertNotNull($newFolder);
108
        $this->assertEquals($folder1->ID, $newFolder->ParentID);
109
        $this->assertEquals('testItCreatesFolder', $newFolder->Name);
110
    }
111
112 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...
113
    {
114
        $folder = $this->objFromFixture(Folder::class, 'folder1');
115
116
        $response = Director::test(
117
            'admin/assets/api/createFolder',
118
            [
119
                'ParentID' => $folder->ID,
120
                'Name' => 'disallowCanCreate',
121
                'SecurityID' => SecurityToken::inst()->getValue(),
122
            ],
123
            $this->session,
124
            'POST'
125
        );
126
        $this->assertTrue($response->isError());
127
        $this->assertEquals(403, $response->getStatusCode());
128
    }
129
130 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...
131
    {
132
        $folder = $this->objFromFixture(Folder::class, 'disallowCanAddChildren');
133
134
        $response = Director::test(
135
            'admin/assets/api/createFolder',
136
            [
137
                'ParentID' => $folder->ID,
138
                'Name' => 'testItRestrictsCreateFolderByCanAddChildren',
139
                'SecurityID' => SecurityToken::inst()->getValue(),
140
            ],
141
            $this->session,
142
            'POST'
143
        );
144
        $this->assertTrue($response->isError());
145
        $this->assertEquals(403, $response->getStatusCode());
146
    }
147
148
    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...
149
    {
150
        $folder1 = $this->objFromFixture(Folder::class, 'folder1');
151
152
        /** @skipUpgrade */
153
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'testItCreatesFile.txt'));
154
        $_FILES = $fileData;
155
        $postedData = array_merge(
156
                $fileData,
157
                [
158
                    'ParentID' => $folder1->ID,
159
                    'SecurityID' => SecurityToken::inst()->getValue(),
160
                ]
161
        );
162
        $response = Director::test(
163
            'admin/assets/api/createFile',
164
            $postedData,
165
            $this->session,
166
            'POST'
167
        );
168
        $this->assertFalse($response->isError());
169
        $responseData = json_decode($response->getBody(), true);
170
        $newFile = File::get()->byID($responseData[0]['id']);
171
        $this->assertNotNull($newFile);
172
        $this->assertEquals($folder1->ID, $newFile->ParentID);
173
        $this->assertEquals('testItCreatesFile.txt', $newFile->Name);
174
175
        // Test that duplicate uploads are renamed
176
        $response = Director::test(
177
            'admin/assets/api/createFile',
178
            $postedData,
179
            $this->session,
180
            'POST'
181
        );
182
        $this->assertFalse($response->isError());
183
        $responseData = json_decode($response->getBody(), true);
184
        $newFile2 = File::get()->byID($responseData[0]['id']);
185
        $this->assertNotNull($newFile2);
186
        $this->assertEquals($folder1->ID, $newFile2->ParentID);
187
        $this->assertNotEquals($newFile->ID, $newFile2->ID);
188
        $this->assertEquals('testItCreatesFile-v2.txt', $newFile2->Name);
189
    }
190
191 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...
192
    {
193
        $folder = $this->objFromFixture(Folder::class, 'folder1');
194
195
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'disallowCanCreate.txt'));
196
        $_FILES = $fileData;
197
        $response = Director::test(
198
            'admin/assets/api/createFile',
199
            array_merge(
200
                $fileData,
201
                [
202
                    'ParentID' => $folder->ID,
203
                    'SecurityID' => SecurityToken::inst()->getValue(),
204
                ]
205
            ),
206
            $this->session,
207
            'POST'
208
        );
209
        $this->assertTrue($response->isError());
210
        $this->assertEquals(403, $response->getStatusCode());
211
    }
212
213 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...
214
    {
215
        $folder = $this->objFromFixture(Folder::class, 'disallowCanAddChildren');
216
217
        /** @skipUpgrade */
218
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'test.txt'));
219
        $_FILES = $fileData;
220
        $response = Director::test(
221
            'admin/assets/api/createFile',
222
            array_merge(
223
                $fileData,
224
                [
225
                    'ParentID' => $folder->ID,
226
                    'SecurityID' => SecurityToken::inst()->getValue(),
227
                ]
228
            ),
229
            $this->session,
230
            'POST'
231
        );
232
        $this->assertTrue($response->isError());
233
        $this->assertEquals(403, $response->getStatusCode());
234
    }
235
236
    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...
237
    {
238
        $folder1 = $this->objFromFixture(
239
            Folder::class,
240
            'folder1'
241
        );
242
243
        /** @skipUpgrade */
244
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'disallowed.php'));
245
        $_FILES = $fileData;
246
        $response = Director::test(
247
            'admin/assets/api/createFile',
248
            array_merge(
249
                $fileData,
250
                [
251
                    'ParentID' => $folder1->ID,
252
                    'SecurityID' => SecurityToken::inst()->getValue(),
253
                ]
254
            ),
255
            $this->session,
256
            'POST'
257
        );
258
        $this->assertTrue($response->isError());
259
        $this->assertEquals(400, $response->getStatusCode());
260
        $responseData = json_decode($response->getBody(), true);
261
        $this->assertContains(
262
            'Extension is not allowed',
263
            $responseData['message']['value']
264
        );
265
    }
266
267
    public function testItFiltersByDateInSearch()
268
    {
269
        $file1 = $this->objFromFixture(File::class, 'file1');
270
        $file2 = $this->objFromFixture(File::class, 'file2');
271
272
        // Force creation times
273
        $file1->Created = '2014-01-05 23:11:39';
274
        $file1->write();
275
        $file2->Created = '2014-01-06 12:00:00';
276
        $file2->write();
277
278
        // Mock searches for 4th Jan
279
        $results = $this->getResultsForSearch([
280
            'CreatedFrom' => '2014-01-04',
281
            'CreatedTo' => '2014-01-04'
282
        ]);
283
        $this->assertEquals(count($results['files']), 0);
284
285
        // Mock searches for 5th Jan
286
        $results = $this->getResultsForSearch([
287
            'CreatedFrom' => '2014-01-05',
288
            'CreatedTo' => '2014-01-05'
289
        ]);
290
        $this->assertEquals(count($results['files']), 1);
291
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
292
293
294
        // Mock searches for 5th-6th Jan
295
        $results = $this->getResultsForSearch([
296
            'CreatedFrom' => '2014-01-05',
297
            'CreatedTo' => '2014-01-06'
298
        ]);
299
        $this->assertEquals(count($results['files']), 2);
300
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
301
        $this->assertContains($file2->ID, array_column($results['files'], 'id'));
302
303
        // Mock searches for 6th Jan
304
        $results = $this->getResultsForSearch([
305
            'CreatedFrom' => '2014-01-06',
306
            'CreatedTo' => '2014-01-06'
307
        ]);
308
        $this->assertEquals(count($results['files']), 1);
309
        $this->assertContains($file2->ID, array_column($results['files'], 'id'));
310
311
        // Mock searches for 7th Jan
312
        $results = $this->getResultsForSearch([
313
            'CreatedFrom' => '2014-01-07',
314
            'CreatedTo' => '2014-01-07'
315
        ]);
316
        $this->assertEquals(count($results['files']), 0);
317
    }
318
319
320
    public function testItDoesNotFilterByDefaultInSearch()
321
    {
322
        $rootfile = $this->objFromFixture(File::class, 'rootfile');
323
        $file1 = $this->objFromFixture(File::class, 'file1');
324
        $folder1 = $this->objFromFixture(Folder::class, 'folder1');
325
326
        $results = $this->getResultsForSearch();
327
        $this->assertContains($rootfile->ID, array_column($results['files'], 'id'),
328
            'Contains top level file'
329
        );
330
        $this->assertContains($folder1->ID, array_column($results['files'], 'id'),
331
            'Contains top level folder'
332
        );
333
        $this->assertContains($file1->ID, array_column($results['files'], 'id'),
334
            'Contains files in subfolder'
335
        );
336
    }
337
338
    public function testItFiltersByParentInSearch()
339
    {
340
        /** @var File $file1 */
341
        $file1 = $this->objFromFixture(File::class, 'file1');
342
        /** @var File $file2 */
343
        $file2 = $this->objFromFixture(File::class, 'file2');
344
        $file1Folder = $file1->Parent();
345
        $file2Folder = $file2->Parent();
346
347
        $results = $this->getResultsForSearch(['Name' => $file1->Name, 'ParentID' => $file1Folder->ID]);
348
        $this->assertEquals(count($results['files']), 1);
349
        $this->assertContains($file1->ID, array_column($results['files'], 'id'),
350
            'Returns file when contained in correct folder'
351
        );
352
353
        $results = $this->getResultsForSearch(['Name' => $file1->Name, 'ParentID' => $file2Folder->ID]);
354
        $this->assertEquals(count($results['files']), 0,
355
            'Does not return file when contained in different folder'
356
        );
357
    }
358
359
    public function testItFiltersByNameInSearch()
360
    {
361
        $file1 = $this->objFromFixture(File::class, 'file1');
362
363
        $results = $this->getResultsForSearch(['Name' => $file1->Name]);
364
        $this->assertEquals(count($results['files']), 1,
365
            'Finds by Name property'
366
        );
367
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
368
369
        $results = $this->getResultsForSearch(['Name' => 'First']);
370
        $this->assertEquals(count($results['files']), 1,
371
            'Finds by Title property'
372
        );
373
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
374
    }
375
376
    public function testItRestrictsViewInSearch()
377
    {
378
        $allowedFile = $this->objFromFixture(File::class, 'file1');
379
        $disallowedFile = $this->objFromFixture(File::class, 'disallowCanView');
380
381
        $results = $this->getResultsForSearch(['Name' => $allowedFile->Name]);
382
        $this->assertEquals(count($results['files']), 1);
383
        $this->assertContains($allowedFile->ID, array_column($results['files'], 'id'));
384
385
        $results = $this->getResultsForSearch(['Name' => $disallowedFile->Name]);
386
        $this->assertEquals(count($results['files']), 0);
387
    }
388
389
    public function testItRestrictsViewInReadFolder()
390
    {
391
        $folder1 = $this->objFromFixture(Folder::class, 'folder1');
392
        $allowedFile = $this->objFromFixture(File::class, 'file1');
393
        $disallowedFile = $this->objFromFixture(File::class, 'disallowCanView');
394
395
        $response = $this->get('admin/assets/api/readFolder?' . http_build_query(['id' => $folder1->ID]));
396
        $files = json_decode($response->getBody(), true);
397
        $this->assertArrayHasKey('files', $files);
398
        $ids = array_map(function ($file) {
399
            return $file['id'];
400
        }, $files['files']);
401
        $this->assertContains($allowedFile->ID, $ids);
402
        $this->assertEquals($allowedFile->ParentID, $folder1->ID);
403
        $this->assertNotContains($disallowedFile->ID, $ids);
404
        $this->assertEquals($disallowedFile->ParentID, $folder1->ID);
405
    }
406
407
    public function testItRestrictsUpdateFile()
408
    {
409
        $allowedFile = $this->objFromFixture(File::class, 'file1');
410
        $disallowedFile = $this->objFromFixture(File::class, 'disallowCanEdit');
411
412
        $response = Director::test(
413
            'admin/assets/FileEditForm',
414
            [
415
                'action_save' => 1,
416
                'ID' => $allowedFile->ID,
417
                'Name' => 'disallowCanEdit.txt',
418
                'Title' => 'new',
419
                'SecurityID' => SecurityToken::inst()->getValue(),
420
            ],
421
            $this->session
422
        );
423
        $this->assertFalse($response->isError());
424
425
        $response = Director::test(
426
            'admin/assets/FileEditForm',
427
            [
428
                'action_save' => 1,
429
                'ID' => $disallowedFile->ID,
430
                'Title' => 'new',
431
                'SecurityID' => SecurityToken::inst()->getValue(),
432
            ],
433
            $this->session
434
        );
435
        $this->assertTrue($response->isError());
436
    }
437
438
    public function testItRestrictsDelete()
439
    {
440
        $allowedFile = $this->objFromFixture(File::class, 'file1');
441
        $disallowedFile = $this->objFromFixture(File::class, 'disallowCanDelete');
442
443
        $response = Director::test(
444
            'admin/assets/api/delete',
445
            null,
446
            $this->session,
447
            'DELETE',
448
            http_build_query([
449
                'ids' => [$allowedFile->ID, $disallowedFile->ID],
450
                'SecurityID' => SecurityToken::inst()->getValue(),
451
            ])
452
        );
453
        $this->assertTrue($response->isError());
454
455
        $response = Director::test(
456
            'admin/assets/api/delete',
457
            null,
458
            $this->session,
459
            'DELETE',
460
            http_build_query([
461
                'ids' => [$allowedFile->ID],
462
                'SecurityID' => SecurityToken::inst()->getValue(),
463
            ])
464
        );
465
        $this->assertFalse($response->isError());
466
    }
467
468
    /**
469
     * @param array $params
470
     * @return array
471
     */
472
    protected function getResultsForSearch($params = array())
473
    {
474
        $response = $this->get('admin/assets/api/search?' . http_build_query($params));
475
        $this->assertFalse($response->isError());
476
477
        return json_decode($response->getBody(), true);
478
    }
479
480
    /**
481
     * @param string $paramName
482
     * @param string $tmpFileName
483
     * @return array Emulating an entry in the $_FILES superglobal
484
     */
485
    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...
486
    {
487
        $tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName;
488
        $tmpFileContent = '';
489
        for ($i = 0; $i < 10000; $i++) {
490
            $tmpFileContent .= '0';
491
        }
492
        file_put_contents($tmpFilePath, $tmpFileContent);
493
494
        // emulates the $_FILES array
495
        return array(
496
            'name' => $tmpFileName,
497
            'type' => 'text/plaintext',
498
            'size' => filesize($tmpFilePath),
499
            'tmp_name' => $tmpFilePath,
500
            'error' => UPLOAD_ERR_OK,
501
        );
502
    }
503
}
504
505
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...
506
{
507
    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...
508
    {
509
        if ($this->owner->Name === 'disallowCanView.txt') {
510
            return false;
511
        }
512
        return null;
513
    }
514
515
    public function canEdit($member = null)
516
    {
517
        if ($this->owner->Name === 'disallowCanEdit.txt') {
518
            return false;
519
        }
520
        return null;
521
    }
522
523
    public function canDelete($member = null)
524
    {
525
        if ($this->owner->Name === 'disallowCanDelete.txt') {
526
            return false;
527
        }
528
        return null;
529
    }
530
531
    public function canArchive($member = null)
532
    {
533
        if ($this->owner->Name === 'disallowCanDelete.txt') {
534
            return false;
535
        }
536
        return $this->owner->canDelete($member);
537
    }
538
539
    public function canCreate($member = null, $context = [])
540
    {
541
        if (isset($context['Parent']) && $context['Parent']->Name === 'disallowCanAddChildren') {
542
            return false;
543
        }
544
        if (isset($context['Upload']['name']) && $context['Upload']['name'] === 'disallowCanCreate.txt') {
545
            return false;
546
        }
547
        return null;
548
    }
549
}
550
551
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...
552
{
553
    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...
554
    {
555
        if ($this->owner->Name === 'disallowCanView') {
556
            return false;
557
        }
558
        return null;
559
    }
560
561
    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...
562
    {
563
        if ($this->owner->Name === 'disallowCanEdit') {
564
            return false;
565
        }
566
        return null;
567
    }
568
569
    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...
570
    {
571
        if ($this->owner->Name === 'disallowCanDelete') {
572
            return false;
573
        }
574
        return null;
575
    }
576
577
    public function canCreate($member = null, $context = array())
578
    {
579
        if (isset($context['Name']) && $context['Name'] === 'disallowCanCreate') {
580
            return false;
581
        }
582
        return null;
583
    }
584
}
585