예제 #1
0
 public function addCaptcha()
 {
     $captcha = new CaptchaWidget();
     $captcha->setPrivkey($this->options['captchaConfig']['private-key']);
     $captcha->setPubkey($this->options['captchaConfig']['public-key']);
     if ($this->options['showCaptcha']) {
         $this->add(['type' => 'Zend\\Form\\Element\\Captcha', 'name' => 'captcha', 'options' => ['label' => $this->translate('Please verify you are human'), 'captcha' => $captcha]]);
     }
 }
예제 #2
0
 public function testUsesReCaptchaHelper()
 {
     $captcha = new ReCaptcha();
     $this->assertEquals('captcha/recaptcha', $captcha->getHelperName());
 }
예제 #3
0
 /** @group ZF-10991 */
 public function testRenderWillUseElementNameWhenRenderingNoScriptFields()
 {
     $captcha = new Captcha\ReCaptcha();
     $pubKey = 'pubKey';
     $privKey = 'privKey';
     $captcha->setPubkey($pubKey)->setPrivkey($privKey);
     $element = new \Zend\Form\Element\Captcha('captcha', array('captcha' => $captcha, 'belongsTo' => 'contact'));
     $view = new \Zend\View\PhpRenderer();
     $html = $captcha->render($view, $element);
     $this->assertContains('contact[recaptcha_challenge_field]', $html);
     $this->assertContains('contact[recaptcha_response_field]', $html);
 }
예제 #4
0
 public function testPassingElementWithReCaptchaRendersCorrectly()
 {
     if (!constant('TESTS_ZEND_FORM_RECAPTCHA_SUPPORT')) {
         $this->markTestSkipped('Enable TESTS_ZEND_FORM_RECAPTCHA_SUPPORT to test PDF render');
     }
     $captcha = new Captcha\ReCaptcha(array('sessionClass' => 'ZendTest\\Captcha\\TestAsset\\SessionContainer'));
     $service = $captcha->getService();
     $service->setPublicKey($this->publicKey);
     $service->setPrivateKey($this->privateKey);
     $element = $this->getElement();
     $element->setCaptcha($captcha);
     $markup = $this->helper->render($element);
     $this->assertContains('foo-challenge', $markup);
     $this->assertContains('foo-response', $markup);
     $this->assertContains('foo[recaptcha_challenge_field]', $markup);
     $this->assertContains('foo[recaptcha_response_field]', $markup);
     $this->assertContains('zendBindEvent', $markup);
     $this->assertContains($service->getHtml('foo'), $markup);
 }
예제 #5
0
 public function testAllowsSettingThemeOptionOnServiceObject()
 {
     $captcha = new Captcha\ReCaptcha;
     $captcha->setOption('theme', 'black');
     $this->assertEquals('black', $captcha->getService()->getOption('theme'));
 }
예제 #6
0
 public function testPassingElementWithReCaptchaRendersCorrectly()
 {
     $captcha = new Captcha\ReCaptcha(array('sessionClass' => 'ZendTest\\Captcha\\TestAsset\\SessionContainer'));
     $service = $captcha->getService();
     $service->setPublicKey($this->publicKey);
     $service->setPrivateKey($this->privateKey);
     $element = $this->getElement();
     $element->setCaptcha($captcha);
     $markup = $this->helper->render($element);
     $this->assertContains('foo-challenge', $markup);
     $this->assertContains('foo-response', $markup);
     $this->assertContains('foo[recaptcha_challenge_field]', $markup);
     $this->assertContains('foo[recaptcha_response_field]', $markup);
     $this->assertContains('zendBindEvent', $markup);
     $this->assertContains($service->getHtml('foo'), $markup);
 }
예제 #7
0
 /**
  * Configuration options that are needed to render a specific captcha.
  *
  * For example this captcha needs to expose its public key.
  *
  * @return array
  */
 public function options()
 {
     return ['host' => ReCaptchaService::API_SERVER, 'public_key' => $this->reCaptcha->getPubkey()];
 }
 function it_should_get_the_configured_public_key(ReCaptcha $captcha)
 {
     $this->options();
     $captcha->getPubkey()->shouldHaveBeenCalled();
 }