任何人都可以提供一些有关 Zend Framework 中表单单元测试的资源吗?
如何测试 zend 框架中的表单? 我的 zend 项目中有一个登录表单,Login.php 是:
<?php
class DEMO_Form_Login extends Zend_Form {
public function init() {
$this
->setMethod('post')
->addElementPrefixPaths(array(
'decorator' => array('DEMO_Decorator' => '../application/decorators'),
));
$this
->addElement('text', 'username', array(
'label' => _T('USERNAME'),
'required' => true,
'value' => '',
'filters' => array('StringTrim'),
'decorators' => array('ViewHelper')
))
->addElement('password', 'password', array(
'label' => _T('PASSWORD'),
'required' => true,
'value' => '',
'decorators' => array('ViewHelper')
))
->addElement('submit', 'submit', array(
'label' => _T('LOG_INTO'),
'ignore' => true,
'decorators' => array(
array('Submit', array('separator'=>'<br />')))
));
}
}
如何测试它?任何人都可以提供一些有关它的资源吗?
How can I test the forms in zend framework?
I have a login form in my zend project, the Login.php is:
<?php
class DEMO_Form_Login extends Zend_Form {
public function init() {
$this
->setMethod('post')
->addElementPrefixPaths(array(
'decorator' => array('DEMO_Decorator' => '../application/decorators'),
));
$this
->addElement('text', 'username', array(
'label' => _T('USERNAME'),
'required' => true,
'value' => '',
'filters' => array('StringTrim'),
'decorators' => array('ViewHelper')
))
->addElement('password', 'password', array(
'label' => _T('PASSWORD'),
'required' => true,
'value' => '',
'decorators' => array('ViewHelper')
))
->addElement('submit', 'submit', array(
'label' => _T('LOG_INTO'),
'ignore' => true,
'decorators' => array(
array('Submit', array('separator'=>'<br />')))
));
}
}
How can I test it? Can anyone provide some resource about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想不出任何资源,但我可以给你一个例子来说明我将如何做到这一点。
因此,我将创建一个 FormTestCase 类,如下所示:
然后可以按如下方式测试每个表单:
在上面的示例中
My_Form_Demo
是 表单的简化版本。我需要简化它,因为我没有您的自定义装饰器,并且无法运行测试。我用于此示例的设置可以在此处查看(以及所有我的其他测试)。希望这会对您有所帮助。
I cannot think of any resource, but I can give you one example of how I would do it.
So, I would create a FormTestCase class as follows:
Then each form could be tested as follows:
In the above example
My_Form_Demo
is simplified version of your form. I needed to simplify it, because I do not have your custom decorators and I could not run the test. The setup that I used for this example, can be seen here (along with all my other tests).Hope this will help you.