Completed
Pull Request — master (#245)
by Damian
02:35
created

AssetAdminTest   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 459
Duplicated Lines 19.17 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 7
Bugs 4 Features 1
Metric Value
wmc 22
c 7
b 4
f 1
lcom 1
cbo 10
dl 88
loc 459
rs 10

19 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 29 3
A tearDown() 0 8 1
A testItCreatesFolder() 0 21 1
A testItRestrictsCreateFolderByCanCreate() 17 17 1
A testItRestrictsCreateFolderByCanAddChildren() 19 17 1
B testItCreatesFile() 2 41 1
A testItRestrictsCreateFileOnCanCreate() 21 21 1
A testItRestrictsCreateFileOnCanAddChildren() 23 21 1
B testItRestrictsCreateFileOnExtension() 2 29 1
A testItFiltersByDateInSearch() 0 51 1
A testItDoesNotFilterByDefaultInSearch() 0 17 1
A testItFiltersByParentInSearch() 0 18 1
A testItFiltersByNameInSearch() 0 16 1
A testItRestrictsViewInSearch() 0 12 1
A testItRestrictsViewInReadFolder() 0 17 1
B testItRestrictsUpdateFile() 0 30 1
B testItRestrictsDelete() 0 30 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\ORM\DataExtension;
6
use SilverStripe\ORM\Versioning\Versioned;
7
use SilverStripe\Security\SecurityToken;
8
use FunctionalTest;
9
use File;
10
use Folder;
11
use AssetStoreTest_SpyStore;
12
use Director;
13
use Injector;
14
use Session;
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
        AssetStoreTest_SpyStore::activate('AssetAdminTest');
34
        $memberID = $this->logInWithPermission('ADMIN');
35
        $this->session = Injector::inst()->create('Session', array('loggedInAs' => $memberID));
36
37
        File::add_extension('SilverStripe\\AssetAdmin\\Tests\\AssetAdminTest_File');
38
        Folder::add_extension('SilverStripe\\AssetAdmin\\Tests\\AssetAdminTest_Folder');
39
40
        // Create a test folders for each of the fixture references
41
        foreach (File::get()->filter('ClassName', 'Folder') 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') 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('SilverStripe\\AssetAdmin\\Tests\\AssetAdminTest_File');
62
        Folder::remove_extension('SilverStripe\\AssetAdmin\\Tests\\AssetAdminTest_Folder');
63
64
        AssetStoreTest_SpyStore::reset();
65
        parent::tearDown();
66
    }
67
68
    public function testItCreatesFolder()
69
    {
70
        $folder1 = $this->objFromFixture('Folder', 'folder1');
71
72
        $response = Director::test(
73
            'admin/assets/api/createFolder',
74
            [
75
                'ParentID' => $folder1->ID,
76
                'Name' => 'testItCreatesFolder',
77
                'SecurityID' => SecurityToken::inst()->getValue(),
78
            ],
79
            $this->session,
80
            'POST'
81
        );
82
        $this->assertFalse($response->isError());
83
        $responseData = json_decode($response->getBody(), true);
84
        $newFolder = \Folder::get()->byID($responseData['id']);
85
        $this->assertNotNull($newFolder);
86
        $this->assertEquals($folder1->ID, $newFolder->ParentID);
87
        $this->assertEquals('testItCreatesFolder', $newFolder->Name);
88
    }
89
90 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...
91
    {
92
        $folder = $this->objFromFixture('Folder', 'folder1');
93
94
        $response = Director::test(
95
            'admin/assets/api/createFolder',
96
            [
97
                'ParentID' => $folder->ID,
98
                'Name' => 'disallowCanCreate',
99
                'SecurityID' => SecurityToken::inst()->getValue(),
100
            ],
101
            $this->session,
102
            'POST'
103
        );
104
        $this->assertTrue($response->isError());
105
        $this->assertEquals(403, $response->getStatusCode());
106
    }
107
108 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...
109
    {
110
        $folder = $this->objFromFixture('Folder', 'disallowCanAddChildren');
111
112
        $response = Director::test(
113
            'admin/assets/api/createFolder',
114
            [
115
                'ParentID' => $folder->ID,
116
                'Name' => 'testItRestrictsCreateFolderByCanAddChildren',
117
                'SecurityID' => SecurityToken::inst()->getValue(),
118
            ],
119
            $this->session,
120
            'POST'
121
        );
122
        $this->assertTrue($response->isError());
123
        $this->assertEquals(403, $response->getStatusCode());
124
    }
125
126
    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...
127
    {
128
        $folder1 = $this->objFromFixture('Folder', 'folder1');
129
130
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'testItCreatesFile.txt'));
131
        $_FILES = $fileData;
132
        $postedData = array_merge(
133
            $fileData,
134
            [
135
                'ParentID' => $folder1->ID,
136
                'SecurityID' => SecurityToken::inst()->getValue(),
137
            ]
138
        );
139
        $response = Director::test(
140
            'admin/assets/api/createFile',
141
            $postedData,
142
            $this->session,
143
            'POST'
144
        );
145
        $this->assertFalse($response->isError());
146
        $responseData = json_decode($response->getBody(), true);
147
        $newFile = \File::get()->byID($responseData[0]['id']);
148
        $this->assertNotNull($newFile);
149
        $this->assertEquals($folder1->ID, $newFile->ParentID);
150
        $this->assertEquals('testItCreatesFile.txt', $newFile->Name);
151
152
        // Test that duplicate uploads are renamed
153
        $response = Director::test(
154
            'admin/assets/api/createFile',
155
            $postedData,
156
            $this->session,
157
            'POST'
158
        );
159
        $this->assertFalse($response->isError());
160
        $responseData = json_decode($response->getBody(), true);
161
        $newFile2 = \File::get()->byID($responseData[0]['id']);
162
        $this->assertNotNull($newFile2);
163
        $this->assertEquals($folder1->ID, $newFile2->ParentID);
164
        $this->assertNotEquals($newFile->ID, $newFile2->ID);
165
        $this->assertEquals('testItCreatesFile-v2.txt', $newFile2->Name);
166
    }
167
168 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...
169
    {
170
        $folder = $this->objFromFixture('Folder', 'folder1');
171
172
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'disallowCanCreate.txt'));
173
        $_FILES = $fileData;
174
        $response = Director::test(
175
            'admin/assets/api/createFile',
176
            array_merge(
177
                $fileData,
178
                [
179
                    'ParentID' => $folder->ID,
180
                    'SecurityID' => SecurityToken::inst()->getValue(),
181
                ]
182
            ),
183
            $this->session,
184
            'POST'
185
        );
186
        $this->assertTrue($response->isError());
187
        $this->assertEquals(403, $response->getStatusCode());
188
    }
189
190 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...
191
    {
192
        $folder = $this->objFromFixture('Folder', 'disallowCanAddChildren');
193
194
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'test.txt'));
195
        $_FILES = $fileData;
196
        $response = Director::test(
197
            'admin/assets/api/createFile',
198
            array_merge(
199
                $fileData,
200
                [
201
                    'ParentID' => $folder->ID,
202
                    'SecurityID' => SecurityToken::inst()->getValue(),
203
                ]
204
            ),
205
            $this->session,
206
            'POST'
207
        );
208
        $this->assertTrue($response->isError());
209
        $this->assertEquals(403, $response->getStatusCode());
210
    }
211
212
    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...
213
    {
214
        $folder1 = $this->objFromFixture(
215
            'Folder',
216
            'folder1'
217
        );
218
219
        $fileData = array('Upload' => $this->getUploadFile('Upload', 'disallowed.php'));
220
        $_FILES = $fileData;
221
        $response = Director::test(
222
            'admin/assets/api/createFile',
223
            array_merge(
224
                $fileData,
225
                [
226
                    'ParentID' => $folder1->ID,
227
                    'SecurityID' => SecurityToken::inst()->getValue(),
228
                ]
229
            ),
230
            $this->session,
231
            'POST'
232
        );
233
        $this->assertTrue($response->isError());
234
        $this->assertEquals(400, $response->getStatusCode());
235
        $responseData = json_decode($response->getBody(), true);
236
        $this->assertContains(
237
            'Extension is not allowed',
238
            $responseData['error'][0]
239
        );
240
    }
241
242
    public function testItFiltersByDateInSearch()
243
    {
244
        $file1 = $this->objFromFixture('File', 'file1');
245
        $file2 = $this->objFromFixture('File', 'file2');
246
247
        // Force creation times
248
        $file1->Created = '2014-01-05 23:11:39';
249
        $file1->write();
250
        $file2->Created = '2014-01-06 12:00:00';
251
        $file2->write();
252
253
        // Mock searches for 4th Jan
254
        $results = $this->getResultsForSearch([
255
            'CreatedFrom' => '2014-01-04',
256
            'CreatedTo' => '2014-01-04'
257
        ]);
258
        $this->assertEquals(count($results['files']), 0);
259
260
        // Mock searches for 5th Jan
261
        $results = $this->getResultsForSearch([
262
            'CreatedFrom' => '2014-01-05',
263
            'CreatedTo' => '2014-01-05'
264
        ]);
265
        $this->assertEquals(count($results['files']), 1);
266
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
267
268
269
        // Mock searches for 5th-6th Jan
270
        $results = $this->getResultsForSearch([
271
            'CreatedFrom' => '2014-01-05',
272
            'CreatedTo' => '2014-01-06'
273
        ]);
274
        $this->assertEquals(count($results['files']), 2);
275
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
276
        $this->assertContains($file2->ID, array_column($results['files'], 'id'));
277
278
        // Mock searches for 6th Jan
279
        $results = $this->getResultsForSearch([
280
            'CreatedFrom' => '2014-01-06',
281
            'CreatedTo' => '2014-01-06'
282
        ]);
283
        $this->assertEquals(count($results['files']), 1);
284
        $this->assertContains($file2->ID, array_column($results['files'], 'id'));
285
286
        // Mock searches for 7th Jan
287
        $results = $this->getResultsForSearch([
288
            'CreatedFrom' => '2014-01-07',
289
            'CreatedTo' => '2014-01-07'
290
        ]);
291
        $this->assertEquals(count($results['files']), 0);
292
    }
293
294
295
    public function testItDoesNotFilterByDefaultInSearch()
296
    {
297
        $rootfile = $this->objFromFixture('File', 'rootfile');
298
        $file1 = $this->objFromFixture('File', 'file1');
299
        $folder1 = $this->objFromFixture('Folder', 'folder1');
300
301
        $results = $this->getResultsForSearch();
302
        $this->assertContains($rootfile->ID, array_column($results['files'], 'id'),
303
            'Contains top level file'
304
        );
305
        $this->assertContains($folder1->ID, array_column($results['files'], 'id'),
306
            'Contains top level folder'
307
        );
308
        $this->assertContains($file1->ID, array_column($results['files'], 'id'),
309
            'Contains files in subfolder'
310
        );
311
    }
312
313
    public function testItFiltersByParentInSearch()
314
    {
315
        $file1 = $this->objFromFixture('File', 'file1');
316
        $file2 = $this->objFromFixture('File', 'file2');
317
        $file1Folder = $file1->Parent();
0 ignored issues
show
Bug introduced by
The method Parent() does not exist on SilverStripe\ORM\DataObject. Did you maybe mean parentClass()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
318
        $file2Folder = $file2->Parent();
0 ignored issues
show
Bug introduced by
The method Parent() does not exist on SilverStripe\ORM\DataObject. Did you maybe mean parentClass()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
319
320
        $results = $this->getResultsForSearch(['Name' => $file1->Name, 'ParentID' => $file1Folder->ID]);
321
        $this->assertEquals(count($results['files']), 1);
322
        $this->assertContains($file1->ID, array_column($results['files'], 'id'),
323
            'Returns file when contained in correct folder'
324
        );
325
326
        $results = $this->getResultsForSearch(['Name' => $file1->Name, 'ParentID' => $file2Folder->ID]);
327
        $this->assertEquals(count($results['files']), 0,
328
            'Does not return file when contained in different folder'
329
        );
330
    }
331
332
    public function testItFiltersByNameInSearch()
333
    {
334
        $file1 = $this->objFromFixture('File', 'file1');
335
336
        $results = $this->getResultsForSearch(['Name' => $file1->Name]);
337
        $this->assertEquals(count($results['files']), 1,
338
            'Finds by Name property'
339
        );
340
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
341
342
        $results = $this->getResultsForSearch(['Name' => 'First']);
343
        $this->assertEquals(count($results['files']), 1,
344
            'Finds by Title property'
345
        );
346
        $this->assertContains($file1->ID, array_column($results['files'], 'id'));
347
    }
348
349
    public function testItRestrictsViewInSearch()
350
    {
351
        $allowedFile = $this->objFromFixture('File', 'file1');
352
        $disallowedFile = $this->objFromFixture('File', 'disallowCanView');
353
354
        $results = $this->getResultsForSearch(['Name' => $allowedFile->Name]);
355
        $this->assertEquals(count($results['files']), 1);
356
        $this->assertContains($allowedFile->ID, array_column($results['files'], 'id'));
357
358
        $results = $this->getResultsForSearch(['Name' => $disallowedFile->Name]);
359
        $this->assertEquals(count($results['files']), 0);
360
    }
361
362
    public function testItRestrictsViewInReadFolder()
363
    {
364
        $folder1 = $this->objFromFixture('Folder', 'folder1');
365
        $allowedFile = $this->objFromFixture('File', 'file1');
366
        $disallowedFile = $this->objFromFixture('File', 'disallowCanView');
367
368
        $response = $this->get('admin/assets/api/readFolder?' . http_build_query(['id' => $folder1->ID]));
369
        $files = json_decode($response->getBody(), true);
370
        $this->assertArrayHasKey('files', $files);
371
        $ids = array_map(function ($file) {
372
            return $file['id'];
373
        }, $files['files']);
374
        $this->assertContains($allowedFile->ID, $ids);
375
        $this->assertEquals($allowedFile->ParentID, $folder1->ID);
376
        $this->assertNotContains($disallowedFile->ID, $ids);
377
        $this->assertEquals($disallowedFile->ParentID, $folder1->ID);
378
    }
379
380
    public function testItRestrictsUpdateFile()
381
    {
382
        $allowedFile = $this->objFromFixture('File', 'file1');
383
        $disallowedFile = $this->objFromFixture('File', 'disallowCanEdit');
384
385
        $response = Director::test(
386
            'admin/assets/FileEditForm',
387
            [
388
                'action_save' => 1,
389
                'ID' => $allowedFile->ID,
390
                'Name' => 'disallowCanEdit.txt',
391
                'Title' => 'new',
392
                'SecurityID' => SecurityToken::inst()->getValue(),
393
            ],
394
            $this->session
395
        );
396
        $this->assertFalse($response->isError());
397
398
        $response = Director::test(
399
            'admin/assets/FileEditForm',
400
            [
401
                'action_save' => 1,
402
                'ID' => $disallowedFile->ID,
403
                'Title' => 'new',
404
                'SecurityID' => SecurityToken::inst()->getValue(),
405
            ],
406
            $this->session
407
        );
408
        $this->assertTrue($response->isError());
409
    }
410
411
    public function testItRestrictsDelete()
412
    {
413
        $allowedFile = $this->objFromFixture('File', 'file1');
414
        $disallowedFile = $this->objFromFixture('File',
415
            'disallowCanDelete');
416
417
        $response = Director::test(
418
            'admin/assets/api/delete',
419
            null,
420
            $this->session,
421
            'DELETE',
422
            http_build_query([
423
                'ids' => [$allowedFile->ID, $disallowedFile->ID],
424
                'SecurityID' => SecurityToken::inst()->getValue(),
425
            ])
426
        );
427
        $this->assertTrue($response->isError());
428
429
        $response = Director::test(
430
            'admin/assets/api/delete',
431
            null,
432
            $this->session,
433
            'DELETE',
434
            http_build_query([
435
                'ids' => [$allowedFile->ID],
436
                'SecurityID' => SecurityToken::inst()->getValue(),
437
            ])
438
        );
439
        $this->assertFalse($response->isError());
440
    }
441
442
    /**
443
     * @param array $params
444
     * @return array
445
     */
446
    protected function getResultsForSearch($params = array())
447
    {
448
        $response = $this->get('admin/assets/api/search?' . http_build_query($params));
449
        $this->assertFalse($response->isError());
450
451
        return json_decode($response->getBody(), true);
452
    }
453
454
    /**
455
     * @param string $paramName
456
     * @param string $tmpFileName
457
     * @return array Emulating an entry in the $_FILES superglobal
458
     */
459
    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...
460
    {
461
        $tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName;
462
        $tmpFileContent = '';
463
        for ($i = 0; $i < 10000; $i++) {
464
            $tmpFileContent .= '0';
465
        }
466
        file_put_contents($tmpFilePath, $tmpFileContent);
467
468
        // emulates the $_FILES array
469
        return array(
470
            'name' => $tmpFileName,
471
            'type' => 'text/plaintext',
472
            'size' => filesize($tmpFilePath),
473
            'tmp_name' => $tmpFilePath,
474
            'error' => UPLOAD_ERR_OK,
475
        );
476
    }
477
}
478
479
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...
480
{
481
    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...
482
    {
483
        if ($this->owner->Name === 'disallowCanView.txt') {
484
            return false;
485
        }
486
    }
487
488
    public function canEdit($member = null)
489
    {
490
        if ($this->owner->Name === 'disallowCanEdit.txt') {
491
            return false;
492
        }
493
    }
494
495
    public function canDelete($member = null)
496
    {
497
        if ($this->owner->Name === 'disallowCanDelete.txt') {
498
            return false;
499
        }
500
    }
501
502
    public function canCreate($member = null, $context = [])
503
    {
504
        if (isset($context['Parent']) && $context['Parent']->Name === 'disallowCanAddChildren') {
505
            return false;
506
        }
507
        if (isset($context['Upload']['name']) && $context['Upload']['name'] === 'disallowCanCreate.txt') {
508
            return false;
509
        }
510
    }
511
}
512
513
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...
514
{
515
    public function canView($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...
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...
516
    {
517
        if ($this->owner->Name === 'disallowCanView') {
518
            return false;
519
        }
520
    }
521
522
    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...
523
    {
524
        if ($this->owner->Name === 'disallowCanEdit') {
525
            return false;
526
        }
527
    }
528
529
    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...
530
    {
531
        if ($this->owner->Name === 'disallowCanDelete') {
532
            return false;
533
        }
534
    }
535
536
    public function canCreate($member = null, $context = array())
537
    {
538
        if (isset($context['Name']) && $context['Name'] === 'disallowCanCreate') {
539
            return false;
540
        }
541
    }
542
}
543