简体   繁体   English

如何使用Zend_Test_PHPUnit声明完整的响应,而不仅仅是断言“ view”部分?

[英]How to assert the full response, not just the“view” part using Zend_Test_PHPUnit?

I want to test that my /login page is working well and rejecting invalid credentials ie not redirecting to the user's dashboard and showing an aller message identified here with the .alert HTML class. 我想测试我的/login页面是否工作正常并且拒绝无效的凭据,即不重定向到用户的仪表板,并显示在此处标识为.alert HTML类的.alert消息。 So I've created a test like this: 所以我创建了一个像这样的测试:

class AuthControllerTest extends Zend_Test_PHPUnit_ControllerTestCase {
    ...
    public function testUserFailingLogin() {

        $this->request->setPost(array(
            'email'  => 'wrong@email.com',
            'password' => 'wrongpassword',
        ));

        $this->request->setMethod('POST');
        $this->dispatch('/login');

        $this->assertQuery('.alert');
    }
}

My problem is that the assertQuery() method is running against the render of login.phtml view file and is not including my Zend_Layout set up (that's where the .alert 's are shown) and thereof, the assertQuery() assertion fails always. 我的问题是, assertQuery()方法是针对login.phtml视图文件的渲染运行的,并且不包括我的Zend_Layout设置(在其中显示.alert的位置),并且assertQuery()声明始终会失败。

Is there any way to get assert*Query*() assertions evaluating the full response ("layout" + "view"), instead of just the "view" part? 有什么方法可以获取评估完整响应(而不只是“视图”部分assert*Query*()声明来评估完整响应(“布局” +“视图”)?

您(I)应该使用未记录的outputBody()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM