symfony 中的文件上传功能测试,无需调用 click()
我似乎无法通过 sfTestFunctional 的 post() 方法对文件上传执行功能测试。我处理 HTTP post 的操作能够获取除文件上传字段之外的所有参数。
查看Symfony 1.4的源代码,我认为 sfBrowserBase 仅通过 click() 方法(具体来说, doClickElement())处理文件上传。这是通过功能测试“上传”文件的唯一方法吗?
顺便说一句,我问这个问题是因为我没有任何代表要提交的数据的 HTML 表单,它是 REST API 的一部分。如果功能测试必须“click()”,那么我只需使用所需的 html 表单元素创建虚拟 html 页面。
I can't seem to perform functional test on file uploads through the sfTestFunctional's post() method. My action handling the HTTP post is able to get all parameters except the file upload field.
Looking at Symfony 1.4's source codes, i think the sfBrowserBase only handle file upload through the click() method (specifically, the doClickElement()) . Is that the only way to 'upload' a file through functional test?
BTW, i'm asking this as i do not have any HTML form that represents the data to submit, its part of a REST API. If the functional test must 'click()', then i just have to create dummy html page with the needed html form elements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现了这个: http://www .devcomments.com/Uploads-on-function-test-for-REST-services-to189066.htm#filtered
但我必须对其进行一些修改才能使其与 Symfony 1.4 一起使用。作为形式问题,我引入了一个新类“Browser”,它扩展了“sfBrowser”和“TestFunctional”,它扩展了“sfTestFunctional”。
Browser::uploadFile():
我为内容类型添加了 $type 参数,否则测试会失败('无效的 mime-type')
TestFunctional::uploadFile()
您必须注意命名:
I found this: http://www.devcomments.com/Uploads-on-functional-test-for-REST-services-to189066.htm#filtered
But I had to modify it a little bit in order to get it to work with Symfony 1.4. As a matter of form I introduced a new class 'Browser', which extends 'sfBrowser' and 'TestFunctional', which extends 'sfTestFunctional'.
Browser::uploadFile():
I added a $type parameter for the content-type, otherwise the test fails ('invalid mime-type')
TestFunctional::uploadFile()
You have to take care about naming:
问题是功能测试认为 mime_type 是“”(即空白)。因此,对我来说,一种更简单的方法是在 app.yml 中定义有效的文件类型:
然后在表单中,
如果需要文件字段,则其他解决方案(sfBrowser 和 sfTestFunctional 上的额外方法)对我不起作用。
The problem is that the functional test thinks the mime_type is '' (i.e., blank). So for me an easier way was to define the valid file types in app.yml:
Then in the Form,
The other solution (extra methods on the sfBrowser and sfTestFunctional) won't work for me if the file field is required.