May 6, 2016
0
Level 6
Integrated - Attach multiple files
I'm working on a form, where you have the option to upload multiple files. This is how it look like in the view file:
<form action="{{ route('admin.media.store') }}" enctype="multipart/form-data" accept-charset="UTF-8" method="post">
{{ csrf_field() }}
<input type="file" name="files[]" id="upload-files" multiple="multiple" />
<button type="submit" class="btn btn-primary" id="btn-media-upload">Upload files</button>
</form>
Please note that the file input field's name is files[].
It' working well in the browser, but I don't know how to write the test for this form with Integrated.
If I try this way:
$this->visit('/admin/media')
->attach($filePath, 'files[]')
->press('Upload files');
I get the following error while running the test:
PHPUnit 4.8.24 by Sebastian Bergmann and contributors.
E
Time: 5.44 seconds, Memory: 38.50Mb
There was 1 error:
1) AdminManageMediaTest::an_admin_should_be_able_to_upload_an_image_file_to_the_storage
InvalidArgumentException: Unreachable field ""
/Users/jpapp/Code/Personal/vendor/symfony/dom-crawler/FormFieldRegistry.php:89
/Users/jpapp/Code/Personal/vendor/symfony/dom-crawler/FormFieldRegistry.php:126
/Users/jpapp/Code/Personal/vendor/symfony/dom-crawler/Form.php:77
/Users/jpapp/Code/Personal/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:576
/Users/jpapp/Code/Personal/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:556
/Users/jpapp/Code/Personal/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:543
/Users/jpapp/Code/Personal/tests/features/AdminManageMediaTest.php:46
If I try to use the id of the file input:
$this->visit('/admin/media')
->attach($filePath, '#upload-files')
->press('Upload files');
I get the following error:
PHPUnit 4.8.24 by Sebastian Bergmann and contributors.
E
Time: 1.61 seconds, Memory: 38.50Mb
There was 1 error:
1) AdminManageMediaTest::an_admin_should_be_able_to_upload_an_image_file_to_the_storage
InvalidArgumentException: Unreachable field "upload-files"
/Users/jpapp/Code/Personal/vendor/symfony/dom-crawler/FormFieldRegistry.php:89
/Users/jpapp/Code/Personal/vendor/symfony/dom-crawler/FormFieldRegistry.php:126
/Users/jpapp/Code/Personal/vendor/symfony/dom-crawler/Form.php:77
/Users/jpapp/Code/Personal/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:576
/Users/jpapp/Code/Personal/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:556
/Users/jpapp/Code/Personal/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:543
/Users/jpapp/Code/Personal/tests/features/AdminManageMediaTest.php:46
Any idea how to test the multiple file upload fields?
Please or to participate in this conversation.