Note that there are some explanatory texts on larger screens.

plurals
  1. POMocking away captcha field when testing zend Form
    primarykey
    data
    text
    <p>I want to test my form which I have created with Zend_Form. Now the problem is that I have a captcha field within my form. And I was told by one of the Zend Framework Guru's that I should mock away the validation of the captcha field a mock object. </p> <p>I have read this <a href="http://www.phpunit.de/manual/3.0/en/mock-objects.html" rel="nofollow">http://www.phpunit.de/manual/3.0/en/mock-objects.html</a> on the PHPUnit manual. But I really don't understand how I can mock away a validator.</p> <p>Does anyone have experience with this? Can anyone help me out?</p> <p>Thanks</p> <hr> <p>More information:</p> <p>I want my test not to break because it can't test the captcha field. So I need to find out some way the post will not be stopped because of the captcha field. </p> <pre><code>public function testCanSubmitContactForm(){ $mock = $this-&gt;getMock('Zend_Form_Element_Captcha', array(), '', false); $mock-&gt;expects($this-&gt;once()-&gt;method("isValid")-&gt;will($this-&gt;resturnValue(true))); $this-&gt;request-&gt;setMethod('post') -&gt;setPost(array( 'email' =&gt; 'someemail@adres.com', 'comment' =&gt; 'Testing the bladiebla contact form' 'captcha' =&gt; ''//no idea )); $this-&gt;dispach('/contact'); } </code></pre> <p>Here is how my Zend_Form generated form looks like:</p> <pre><code> &lt;form id="contact-form" enctype="application/x-www-form-urlencoded" method="post" action="/index/contact"&gt;&lt;dl class="zend_form"&gt; &lt;dt id="email-label"&gt;&lt;label for="email" class="required"&gt;Uw E-mailadres&lt;/label&gt;&lt;/dt&gt; &lt;dd id="email-element"&gt; &lt;input type="text" name="email" id="email" value="" /&gt;&lt;/dd&gt; &lt;dt id="comment-label"&gt;&lt;label for="comment" class="required"&gt;Stel hieronder uw vraag of geef je commentaar op&lt;/label&gt;&lt;/dt&gt; &lt;dd id="comment-element"&gt; &lt;textarea name="comment" id="comment" cols="71" rows="24"&gt;&lt;/textarea&gt;&lt;/dd&gt; &lt;dt id="captcha-input-label"&gt;&lt;label for="captcha-input" class="required"&gt;SPAM Beveiliging&lt;/label&gt;&lt;/dt&gt; &lt;dd id="captcha-element"&gt; &lt;pre&gt; _ _ __ __ ______ ______ ______ ___ | \ / || \ \\/ // /_ _// /_ _// /_____// / _ \\ | \/ || \ ` // `-| |,- -| ||- `____ ` | / \ || | . . || | || | || _| ||_ /___// | \_/ || |_|\/|_|| |_|| |_|| /_____// `__ ` \___// `-` `-` `-`' `-`' `-----` /_// `---` `-` &lt;/pre&gt; &lt;input type="hidden" name="captcha[id]" value="a4957b2dbfea79d8bd654428f6eb0a2c" id="captcha-id" /&gt; &lt;input type="text" name="captcha[input]" id="captcha-input" value="" /&gt; &lt;p class="description"&gt;Voer de 6 letters in die hierboven getoond worden. Deze vraag wordt gebruikt om te testen of u een menselijke bezoeker bent teneinde spam-inzendingen te vermijden.&lt;/p&gt;&lt;/dd&gt; &lt;dt id="submit-label"&gt;&amp;#160;&lt;/dt&gt;&lt;dd id="submit-element"&gt; &lt;input type="submit" name="submit" id="submit" value="Nu Versturen" /&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload