Ok, in the wonderfull world of PhpUnit tests I wanted to test a user registration process with Captcha enabled. But, what do you put in the Captcha field since it’s an automated test ? Well, reading the session appears to be the simplest way to get this information. Here’s a simple function I wrote, suggested by Matthew Weier O’Phinney, that will allow you simply to get the Captcha word while in your php tests :
- private function testGetCaptcha()
- foreach ($_SESSION as $key=>$value)
- if(ereg(“Zend_Form_Captcha.*”, $key))
- return $value[‘word’];
And here you go… It’s a quick and dirty solution since this will only work if you have a unique Zend_Form_Captcha to test for. Feel free to write a better solution !