Completed
Pull Request — master (#330)
by
unknown
01:53
created

testItDoesFilterWithFolderByDefaultInSearch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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