【发布时间】:2023-04-06 17:40:01
【问题描述】:
我使用 Zend/Form 创建了登录表单,它包含输入元素以及 CSRF 元素。
<!-- sample login.phtml code snippet -->
<form method="post" action="/xyz">
<?php
echo $this->formelement($form->get('email'));
echo $this->formelement($form->get('password'));
echo $this->formelement($form->get('csrf'));
echo $this->formelement($form->get('submit'));
?>
</form>
由于针对 CSRF 元素的验证,以下测试用例失败。
public function testLogin()
{
//code goes here
$params = array('email' => 'example@test.com', 'password' => 'example@test.com');
$this->dispatch($url, $method, $params);
//if the given username and password is correct the login page redirected to default home page
$this->assertResponseStatusCode(302);
}
在上面的测试用例中,我设置了电子邮件和密码值,但我不知道如何设置 CSRF 元素。如何测试实现 CSRF 元素的表单?
【问题讨论】:
标签: zend-framework zend-framework2 phpunit