forked from jolicode/MediaBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMediaAdminControllerTest.php
More file actions
613 lines (456 loc) · 24 KB
/
Copy pathMediaAdminControllerTest.php
File metadata and controls
613 lines (456 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
<?php
declare(strict_types=1);
namespace JoliCode\MediaBundle\Tests\Bridge\Sylius\Admin\Controller;
use JoliCode\MediaBundle\Bridge\Sylius\Admin\Controller\MediaAdminController;
use JoliCode\MediaBundle\Tests\Application\Kernel;
use PHPUnit\Framework\Attributes\CoversClass;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\DomCrawler\Form;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
#[CoversClass(MediaAdminController::class)]
final class MediaAdminControllerTest extends WebTestCase
{
private KernelBrowser $client;
protected function setUp(): void
{
$this->client = self::createClient();
if (self::$kernel instanceof Kernel) {
$application = new Application(self::$kernel);
$application->setAutoExit(false);
$application->run(new StringInput('doctrine:fixtures:load --purge-with-truncate --no-interaction --quiet'));
}
}
public function testExplore(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('title', 'Media library');
// Breadcrumbs
$this->assertSelectorTextContains('ol.breadcrumb li.breadcrumb-item:first-child', 'Dashboard');
$this->assertSelectorTextContains('ol.breadcrumb li.breadcrumb-item.active', 'Media library');
// List of directories
$this->assertSame(3, $this->getDirectoryCount($crawler));
$this->assertSelectorExists('[data-directory=a-folder-with-a-very-long-name-level-1]');
$this->assertSelectorExists('[data-directory=sub]');
// List of medias
$this->assertSame(3, $this->getMediaCount($crawler));
$this->assertSelectorTextContains('tr.item:last-child', 'set_null.pdf');
}
public function testFilteringDirectories(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore?criteria[search][value]=sub');
$this->assertResponseIsSuccessful();
// List of directories
$this->assertSame(3, $this->getDirectoryCount($crawler));
$this->assertSelectorExists('[data-directory="sub"]');
$this->assertSelectorExists('[data-directory="sub/folder"]');
$this->assertSelectorExists('[data-directory="sub/folder/deep"]');
// List of medias
$this->assertSame(2, $this->getMediaCount($crawler));
$this->assertSelectorTextContains('tr.item:last-child', 'sub/folder/deep/test.txt');
}
public function testFilteringDirectoriesInChooseMediaModal(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/choose?search=sub');
$this->assertResponseIsSuccessful();
// List of directories
$this->assertSame(3, $this->getDirectoryCount($crawler));
// List of medias
$this->assertSame(2, $this->getMediaCount($crawler));
}
public function testFilteringMedias(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore?criteria[search][value]=test.txt');
$this->assertResponseIsSuccessful();
// List of directories
$this->assertSame(0, $this->getDirectoryCount($crawler));
// List of medias
$this->assertSame(2, $this->getMediaCount($crawler));
$this->assertSelectorTextContains('tr.item:first-child', 'a-folder-with-a-very-long-name-level-10/test.txt');
$this->assertSelectorTextContains('tr.item:last-child', 'sub/folder/deep/test.txt');
}
public function testFilteringMediasInTheChooseMediaModal(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/choose?search=test.txt');
$this->assertResponseIsSuccessful();
// List of directories
$this->assertSame(0, $this->getDirectoryCount($crawler));
// List of medias
$this->assertSame(2, $this->getMediaCount($crawler));
$this->assertSelectorTextContains('.gallery-grid-item:first-child', 'test.txt');
$this->assertSelectorTextContains('.gallery-grid-item:last-child', 'test.txt');
}
public function testSortingMediasByNameWithAscendingOrder(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore?sorting[path]=asc');
$this->assertResponseIsSuccessful();
// List of medias
$this->assertSame(3, $this->getMediaCount($crawler));
$this->assertSelectorTextContains('tr.item:last-child', 'set_null.pdf');
}
public function testSortingMediasByNameWithDescendingOrder(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore?sorting[path]=desc');
$this->assertResponseIsSuccessful();
// List of medias
$this->assertSame(3, $this->getMediaCount($crawler));
$this->assertSelectorTextContains('tr.item:last-child', 'default.pdf');
}
public function testSortingMediasByFileSizeWithAscendingOrder(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore?sorting[fileSize]=asc');
$this->assertResponseIsSuccessful();
// List of medias
$this->assertSame(3, $this->getMediaCount($crawler));
$this->assertSelectorTextContains('tr.item:last-child', 'restrict.pdf');
}
public function testSortingMediasByFileSizeWithDescendingOrder(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore?sorting[fileSize]=desc');
$this->assertResponseIsSuccessful();
// List of medias
$this->assertSame(3, $this->getMediaCount($crawler));
$this->assertSelectorTextContains('tr.item:last-child', 'default.pdf');
}
public function testSortingDirectoriesByNameWithAscendingOrder(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore?sorting[path]=asc');
$this->assertResponseIsSuccessful();
// List of directories
$this->assertSame(3, $this->getDirectoryCount($crawler));
$this->assertSelectorTextContains('tr.item:first-child', 'a-folder-with-a-very-long-name-level-1');
}
public function testSortingDirectoriesByNameWithDescendingOrder(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore?sorting[path]=desc');
$this->assertResponseIsSuccessful();
// List of directories
$this->assertSame(3, $this->getDirectoryCount($crawler));
$this->assertSelectorTextContains('tr.item:first-child', 'sub');
}
public function testMediaDetails(): void
{
$this->client->request(Request::METHOD_GET, '/sylius-admin/media/show/restrict.pdf');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('title', 'restrict.pdf');
// Breadcrumbs
$this->assertSelectorTextContains('ol.breadcrumb li.breadcrumb-item:first-child', 'Dashboard');
$this->assertSelectorTextContains('ol.breadcrumb li.breadcrumb-item.active', 'restrict.pdf');
// URL
$this->assertSelectorExists('[data-test-media-url]');
$this->assertSelectorTextContains('[data-test-media-url]', '/media/original/restrict.pdf');
// File type
$this->assertSelectorExists('[data-test-media-file-type]');
$this->assertSelectorTextContains('[data-test-media-file-type]', 'PDF');
}
public function testDeleteMedia(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore');
$this->assertResponseIsSuccessful();
$previousMediaCount = $this->getMediaCount($crawler);
$deleteButton = $this->client->getCrawler()->filter('tr.item:last-child [data-test-confirm-button]');
$this->client->submit($deleteButton->form());
$this->assertResponseRedirects();
$crawler = $this->client->request('GET', '/sylius-admin/media/explore');
// Test flash message
$this->assertSelectorExists('[data-test-sylius-flash-message]');
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'set_null.pdf has been successfully deleted.');
// One media has been removed
$this->assertSame($previousMediaCount - 1, $this->getMediaCount($crawler));
}
public function testChooseMedia(): void
{
$this->client->request(Request::METHOD_GET, '/sylius-admin/pages/new');
$this->assertResponseIsSuccessful();
// buttons for the media choice
$this->assertSelectorExists('a.joli-media-choice-edit');
$this->assertSelectorTextContains('a.joli-media-choice-edit', 'Choose a file');
$this->assertSelectorExists('button.joli-media-choice-delete');
$this->assertSelectorTextContains('button.joli-media-choice-delete', 'Remove');
}
public function testDeleteDirectoryNotInUse(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore');
$this->assertResponseIsSuccessful();
$previousDirectoryCount = $this->getDirectoryCount($crawler);
$deleteButton = $this->client->getCrawler()->filter('[data-directory=not_used] [data-test-confirm-button]');
$this->client->submit($deleteButton->form());
$this->assertResponseRedirects();
$crawler = $this->client->request('GET', '/sylius-admin/media/explore');
// Test flash message
$this->assertSelectorExists('[data-test-sylius-flash-message]');
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'not_used has been successfully deleted.');
// One directory has been removed
$this->assertSame($previousDirectoryCount - 1, $this->getDirectoryCount($crawler));
}
public function testDeleteDirectoryInUse(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore');
$this->assertResponseIsSuccessful();
$previousDirectoryCount = $this->getDirectoryCount($crawler);
$deleteButton = $this->client->getCrawler()->filter('[data-directory=sub] [data-test-confirm-button]');
$this->client->submit($deleteButton->form());
$this->assertResponseRedirects();
$crawler = $this->client->request('GET', '/sylius-admin/media/explore');
// Test flash message
$this->assertSelectorExists('[data-test-sylius-flash-message]');
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'The media "sub/folder/circle-pattern.png" is used in the "mediaRestrict" field of the "JoliCode\MediaBundle\Tests\Application\Entity\Page" entity. It cannot be deleted.');
// No directory should have been created
$this->assertSame($previousDirectoryCount, $this->getDirectoryCount($crawler));
}
public function testRenameMedia(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/show/default.pdf');
$this->assertResponseIsSuccessful();
$form = $this->getRenameMediaForm($crawler);
$phpValues = $form->getPhpValues();
$phpValues['newPath'] = 'new_name.pdf';
$this->client->request($form->getMethod(), $form->getUri(), $phpValues);
$this->assertResponseRedirects('/sylius-admin/media/show/new_name.pdf');
$this->client->request(Request::METHOD_GET, '/sylius-admin/media/show/new_name.pdf');
$this->assertResponseIsSuccessful();
// Test flash message
$this->assertSelectorExists('[data-test-sylius-flash-message]');
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'The file default.pdf was successfully renamed to new_name.pdf.');
}
public function testRenameDirectory(): void
{
// Use existing directory from fixtures
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore');
$this->assertResponseIsSuccessful();
$form = $this->getDirectoryRenameForm($crawler, 'a-folder-with-a-very-long-name-level-1');
$phpValues = $form->getPhpValues();
$phpValues['newPath'] = 'renamed_directory';
$this->client->request($form->getMethod(), $form->getUri(), $phpValues);
$this->assertResponseRedirects();
// Navigate to the renamed directory to verify
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore/renamed_directory');
$this->assertResponseIsSuccessful();
// Verify we're in the renamed directory
$this->assertSelectorTextContains('ol.breadcrumb li.breadcrumb-item.active', 'renamed_directory');
// Test flash message
$this->assertSelectorExists('[data-test-sylius-flash-message]');
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'The directory "a-folder-with-a-very-long-name-level-1" was successfully renamed to "renamed_directory"');
}
public function testRenameDirectoryFailsWhenTargetExists(): void
{
// 'sub' directory already exists in fixtures
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore');
$this->assertResponseIsSuccessful();
// Create a directory to rename
$form = $this->getCreateDirectoryForm($crawler);
$phpValues = $form->getPhpValues();
$phpValues['name'] = 'dir_to_rename';
$this->client->request($form->getMethod(), $form->getUri(), $phpValues);
$this->assertResponseRedirects();
// Try to rename to 'sub' which already exists (should fail)
$crawler = $this->client->followRedirect();
$form = $this->getDirectoryRenameForm($crawler, 'dir_to_rename');
$phpValues = $form->getPhpValues();
$phpValues['newPath'] = 'sub';
$this->client->request($form->getMethod(), $form->getUri(), $phpValues);
$this->assertResponseRedirects();
// Verify we're still on the explore page and error flash is shown
$crawler = $this->client->followRedirect();
$this->assertResponseIsSuccessful();
$this->assertSelectorExists('[data-test-sylius-flash-message]');
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'Error');
}
public function testUploadMediaOnRootDirectory(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore');
$this->assertResponseIsSuccessful();
$form = $this->getUploadForm($crawler);
$tmpFile = $this->createTemporaryFile();
$this->copyFixtureFileContentInTemporaryFile($tmpFile, 'circle-pattern.png');
$phpValues = $form->getPhpValues();
$this->client->request($form->getMethod(), $form->getUri(), $phpValues, [
'upload' => [
'file' => new UploadedFile(
$tmpFile,
'circle-pattern.png',
'image/png',
null,
true,
),
],
]);
$this->assertResponseFormatSame('json');
$this->assertResponseIsSuccessful();
$responseContent = $this->client->getResponse()->getContent();
$this->assertIsString($responseContent);
$response = json_decode($responseContent, true);
$this->assertArrayHasKey('files', $response);
$this->assertCount(1, $response['files']);
$this->assertArrayHasKey('name', $response['files'][0]);
$this->assertArrayHasKey('url', $response['files'][0]);
$this->assertArrayHasKey('size', $response['files'][0]);
$this->assertArrayHasKey('type', $response['files'][0]);
$this->assertArrayHasKey('thumbnailUrl', $response['files'][0]);
$this->assertSame('circle-pattern.png', $response['files'][0]['name']);
$this->assertSame('/media/original/circle-pattern.png', $response['files'][0]['url']);
$this->assertSame(62563, $response['files'][0]['size']);
$this->assertSame('image/png', $response['files'][0]['type']);
$this->assertSame('/media/cache/joli-media-sylius-admin/circle-pattern.png', $response['files'][0]['thumbnailUrl']);
}
public function testUploadMediaOnSubDirectory(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore/sub');
$this->assertResponseIsSuccessful();
$form = $this->getUploadForm($crawler);
$tmpFile = $this->createTemporaryFile();
$this->copyFixtureFileContentInTemporaryFile($tmpFile, 'circle-pattern.png');
$phpValues = $form->getPhpValues();
$this->client->request($form->getMethod(), $form->getUri(), $phpValues, [
'upload' => [
'file' => new UploadedFile(
$tmpFile,
'circle-pattern.png',
'image/png',
null,
true,
),
],
]);
$this->assertResponseFormatSame('json');
$this->assertResponseIsSuccessful();
$responseContent = $this->client->getResponse()->getContent();
$this->assertIsString($responseContent);
$response = json_decode($responseContent, true);
$this->assertArrayHasKey('files', $response);
$this->assertCount(1, $response['files']);
$this->assertArrayHasKey('name', $response['files'][0]);
$this->assertArrayHasKey('url', $response['files'][0]);
$this->assertArrayHasKey('size', $response['files'][0]);
$this->assertArrayHasKey('type', $response['files'][0]);
$this->assertArrayHasKey('thumbnailUrl', $response['files'][0]);
$this->assertSame('circle-pattern.png', $response['files'][0]['name']);
$this->assertSame('/media/original/sub/circle-pattern.png', $response['files'][0]['url']);
$this->assertSame(62563, $response['files'][0]['size']);
$this->assertSame('image/png', $response['files'][0]['type']);
$this->assertSame('/media/cache/joli-media-sylius-admin/sub/circle-pattern.png', $response['files'][0]['thumbnailUrl']);
}
public function testMoveMediaFromRootToSubdirectory(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/show/default.pdf');
$this->assertResponseIsSuccessful();
$form = $this->getMoveMediaForm($crawler);
$phpValues = $form->getPhpValues();
$phpValues['to'] = 'sub';
$this->client->request($form->getMethod(), $form->getUri(), $phpValues);
$this->assertResponseRedirects();
// Media should have been moved in subdirectory
$this->client->request(Request::METHOD_GET, '/sylius-admin/media/show/sub/default.pdf');
$this->assertResponseIsSuccessful();
// Test flash message
$this->assertSelectorExists('[data-test-sylius-flash-message]');
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'The file default.pdf was successfully moved to sub/default.pdf.');
}
public function testCreateNewDirectoryInRoot(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore');
$previousDirectoryCount = $this->getDirectoryCount($crawler);
$this->assertResponseIsSuccessful();
$form = $this->getCreateDirectoryForm($crawler);
$phpValues = $form->getPhpValues();
$phpValues['name'] = 'New directory';
$this->client->request($form->getMethod(), $form->getUri(), $phpValues);
$this->assertResponseRedirects();
$crawler = $this->client->followRedirect();
// A new directory should appear
$this->assertSame($previousDirectoryCount + 1, $this->getDirectoryCount($crawler));
// Test flash message
$this->assertSelectorExists('[data-test-sylius-flash-message]');
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'Directory "New directory" created successfully');
}
public function testCreateDirectoryFailsWhenEmptyName(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore');
$this->assertResponseIsSuccessful();
$form = $this->getCreateDirectoryForm($crawler);
$phpValues = $form->getPhpValues();
$phpValues['name'] = '';
$this->client->request($form->getMethod(), $form->getUri(), $phpValues);
$this->assertResponseRedirects();
$crawler = $this->client->followRedirect();
// Verify error flash message
$this->assertSelectorExists('[data-test-sylius-flash-message]');
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'Directory name is required');
}
public function testMoveDirectoryFromSubdirectoryToRoot(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/sylius-admin/media/explore/sub/folder');
$this->assertResponseIsSuccessful();
$form = $this->getMoveDirectoryForm($crawler);
$phpValues = $form->getPhpValues();
$phpValues['to'] = '';
$this->client->request($form->getMethod(), $form->getUri(), $phpValues);
$this->assertResponseRedirects('/sylius-admin/media/explore/folder');
// I should be redirected to the new directory path
$this->client->followRedirect();
$this->assertResponseIsSuccessful();
// Test flash message
$this->assertSelectorExists('[data-test-sylius-flash-message]');
$this->assertSelectorTextContains('[data-test-sylius-flash-message]', 'The directory "sub/folder" was successfully moved to "folder".');
}
protected static function getKernelClass(): string
{
return Kernel::class;
}
private function getUploadForm(Crawler $crawler): Form
{
$this->assertSelectorExists('form[name="upload"]');
return $crawler->filter('form[name="upload"]')->form();
}
private function getMoveMediaForm(Crawler $crawler): Form
{
$this->assertSelectorExists('form[id="move-form"]');
return $crawler->filter('form[id="move-form"]')->form();
}
private function getRenameMediaForm(Crawler $crawler): Form
{
$this->assertSelectorExists('form[name="media-rename-form"]');
return $crawler->filter('form[name="media-rename-form"]')->form();
}
private function getDirectoryRenameForm(Crawler $crawler, string $directoryName): Form
{
// Find the row with the directory
$directoryRow = $crawler->filter(\sprintf('[data-directory="%s"]', $directoryName));
$this->assertCount(1, $directoryRow, \sprintf('Directory row not found for "%s"', $directoryName));
// Get the form from that row
$form = $directoryRow->filter('.directory-rename-form');
$this->assertCount(1, $form, \sprintf('Directory rename form not found for "%s"', $directoryName));
return $form->form();
}
private function getCreateDirectoryForm(Crawler $crawler): Form
{
$this->assertSelectorExists('form[data-component="directory-create-form"]');
return $crawler->filter('form[data-component="directory-create-form"]')->form();
}
private function getMoveDirectoryForm(Crawler $crawler): Form
{
$this->assertSelectorExists('form[id="move-form"]');
return $crawler->filter('form[id="move-form"]')->form();
}
private function createTemporaryFile(): string
{
return tempnam(sys_get_temp_dir(), 'upload-test');
}
private function copyFixtureFileContentInTemporaryFile(string $tmpFile, string $filename): void
{
copy(\dirname(__DIR__, 4) . '/fixtures/' . $filename, $tmpFile);
}
private function getDirectoryCount(Crawler $crawler): int
{
return $crawler->filter('[data-test-directory-row]')->count();
}
private function getMediaCount(Crawler $crawler): int
{
return $crawler->filter('[data-test-row]')->count();
}
}