Hello,
I am struggeling already a few days to unit test a form which has in it zend
Captcha.
I was told to mock away the validator of zend_Captcha but i have no idea
how.
This is my test function:
public function testCanSubmitContactForm(){
$mock = $this->getMock('Zend_Form_Element_Captcha', array(), '',
false);
$mock->expects($this->once()->method("isValid")->will($this->resturnValue(true)));
$this->request->setMethod('post')
->setPost(array(
'email' => '[email protected]',
'comment' => 'This is a comment'
));
$this->dispach('/contact');
$this->assertQueryContentContains('div.contentBody', 'Uw bericht is
succesvol verzonden.');
}
and this is my generated form.
<form id="contact-form" enctype="application/x-www-form-urlencoded"
method="post" action="/index/contact"><dl class="zend_form">
<dt id="email-label"><label for="email" class="required">Uw
E-mailadres</label></dt>
<dd id="email-element">
<input type="text" name="email" id="email" value="" /></dd>
<dt id="comment-label"><label for="comment" class="required">Stel
hieronder uw vraag of geef je commentaar op</label></dt>
<dd id="comment-element">
<textarea name="comment" id="comment" cols="71"
rows="24"></textarea></dd>
<dt id="captcha-input-label"><label for="captcha-input"
class="required">SPAM Beveiliging</label></dt>
<dd id="captcha-element">
<pre> _ _ __ __ ______ ______ ______ ___
| \ / || \ \\/ // /_ _// /_ _// /_____// / _ \\
| \/ || \ ` // `-| |,- -| ||- `____ ` | / \ ||
| . . || | || | || _| ||_ /___// | \_/ ||
|_|\/|_|| |_|| |_|| /_____// `__ ` \___//
`-` `-` `-`' `-`' `-----` /_// `---`
`-`
</pre>
<input type="hidden" name="captcha[id]"
value="a4957b2dbfea79d8bd654428f6eb0a2c" id="captcha-id" />
<input type="text" name="captcha[input]" id="captcha-input" value="" />
<p class="description">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.</p></dd>
<dt id="submit-label"> </dt><dd id="submit-element">
<input type="submit" name="submit" id="submit" value="Nu Versturen"
/></dd></dl></form>
The testcode above doesn't work an generates errors:
K:\stage5\tests>phpunit --verbose
PHPUnit 3.5.10 by Sebastian Bergmann.
.....E.
Time: 7 seconds, Memory: 18.75Mb
There was 1 error:
1) IndexControllerTest::testCanSubmitContactForm
Argument 3 passed to PHPUnit_Framework_TestCase::getMock() must be an array,
str
ing given, called in
K:\stage5\tests\application\controllers\IndexControllerTest
.php on line 92 and defined
K:\stage5\tests\application\controllers\IndexControllerTest.php:92
FAILURES!
Tests: 7, Assertions: 20, Errors: 1.
Generating code coverage report, this may take a moment.
Any idea's on how to test a form which has zend_captcha?
Tnx
J. Sanders