我正在使用拉拉维尔5.6
and Dusk
对于这个具体的测试。
我正在尝试在我的拖放区中断言文件上传。但我的 Dropzone 是以我没有的方式创建的file
输入元素。所以我不能使用attach()
method.
所以我尝试了以下方法
$file = new \Symfony\Component\HttpFoundation\File\UploadedFile(base_path() . '/tests/samples/Cylinder.stl', 'Cylinder.stl');
$response = $this->actingAs( $this->user )
->from( 'my-url' )
->post( route('attachments.store' ) , [
'file' => $file
]);
但是错误包包含这个错误
"errors" => Illuminate\Support\ViewErrorBag {#1194
#bags: array:1 [
"default" => Illuminate\Support\MessageBag {#1189
#messages: array:1 [
"file" => array:1 [
0 => "The file failed to upload."
]
]
#format: ":message"
}
]
}
当然,当我手动执行此操作时,这是有效的。
Dropzonejs 添加一个带有特定 ' 的输入字段dz 隐藏输入' 班级。
您可以在 html 页面的底部找到它,可能就在</body>
tag:
<input type="file" multiple="multiple" class="dz-hidden-input">
因此,您可以告诉 Dusk 通过 Attach 方法匹配该确切的选择器:
$browser->attach('input.dz-hidden-input', storage_path('app/public/testing/test-file.jpg'));
如果您有显示文件名和“删除文件”按钮的拖放区预览,则可以链接一些像这样的断言以确保也可以删除该文件:
$browser->attach('input.dz-hidden-input', storage_path('app/public/testing/test-file.jpg'))
->assertSee('test-file.jpg')
->assertSeeLink('Remove file')
->clickLink('Remove file')
->assertDontSee('test-file.jpg');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)