如何对包含CSRF表单元素的Zend_Form进行单元测试? [英] How do you Unit Test a Zend_Form that includes the CSRF form element?
问题描述
我在Zend_Form中使用CSRF隐藏的哈希元素,并尝试对登录进行单元测试,但是不知道如何编写单元测试以包含该元素.在文档中查找并阅读了我所能找到的尽可能多的教程.我什至都将它们全部美味了,但是没有人提及.
I'm using the CSRF hidden hash element with Zend_Form and trying to Unit Test the login but don't know how to write a Unit Test to include that element. Looked in the docs and read as many tutorials as I could find. I even delicioused them all, but no one mentions this.
推荐答案
正确的哈希存储在会话中,并且Hash表单元素具有Zend_Session_Namespace实例,其中包含哈希的名称空间.
The correct hash is stored in the session, and the Hash form element has a Zend_Session_Namespace instance which contains the namespace for the hash.
要对元素进行单元测试,请将元素中的Zend_Session_Namespace实例(使用setSession)替换为您自己创建的实例,该实例包含正确的哈希(哈希存储在键哈希"中)
To unit test the element, you would replace the Zend_Session_Namespace instance in the element (with setSession) with one you create yourself which contains the correct hash (the hash is stored in key "hash")
有关其他示例,您可能会查看Zend_Form_Element_Hash类的Zend Framework单元测试.我认为他们也必须处理这个问题.
For further examples you could probably look at the Zend Framework unit tests for the Zend_Form_Element_Hash class. I would assume they have had to deal with this as well.
这篇关于如何对包含CSRF表单元素的Zend_Form进行单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!