public function testValidateNoAnswerGiven()
 {
     $tc = new HTML_QuickForm2_Element_Captcha_TextCAPTCHA(null, null, array('captchaType' => 'Word', 'phrase' => '123'));
     $tc->setSession(new HTML_QuickForm2_Element_Captcha_Session_Mock());
     $vcm = new ReflectionMethod(get_class($tc), 'validate');
     $vcm->setAccessible(true);
     $this->assertFalse($vcm->invoke($tc));
 }
示例#2
0
 /**
  * Generates the captcha question and answer and prepares the
  * session data.
  *
  * @return boolean TRUE when the captcha has been created newly, FALSE
  *                 if it already existed.
  */
 protected function generateCaptcha()
 {
     if (!parent::generateCaptcha()) {
         if (is_file($this->imageDir . $this->getSession()->question)) {
             return false;
         }
         // Create a new captcha if file no longer exists
         $this->getSession()->clear();
         $this->getSession()->solved = false;
         $this->loadAdapter();
     }
     $session = $this->getSession();
     $captchaFile = $session->getSessionId() . $this->imageSuffix;
     // Save image to file
     file_put_contents($this->imageDir . $captchaFile, $this->adapter->getCAPTCHA());
     list($width, $height) = getimagesize($this->imageDir . $captchaFile);
     $session->question = $captchaFile;
     $session->imageHeight = $height;
     $session->imageWidth = $width;
     $this->garbageCollection();
     return true;
 }
 public function test__toStringFrozen()
 {
     $tc = new HTML_QuickForm2_Element_Captcha_TextCAPTCHA(null, null, array('captchaType' => 'Word', 'phrase' => '123'));
     $tc->setSession(new HTML_QuickForm2_Element_Captcha_Session_Mock());
     $tc->toggleFrozen(true);
     $html = (string) $tc;
     $this->assertContains('one two three', $html);
 }