コード例 #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
ファイル: ReCaptchaTest.php プロジェクト: rafalwrzeszcz/zf2
 /** @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
ファイル: FormCaptchaTest.php プロジェクト: haoyanfei/zf2
 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
ファイル: ReCaptchaTest.php プロジェクト: niallmccrudden/zf2
 public function testAllowsSettingThemeOptionOnServiceObject()
 {
     $captcha = new Captcha\ReCaptcha;
     $captcha->setOption('theme', 'black');
     $this->assertEquals('black', $captcha->getService()->getOption('theme'));
 }
コード例 #6
0
ファイル: FormCaptchaTest.php プロジェクト: navassouza/zf2
 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()];
 }
コード例 #8
0
 function it_should_get_the_configured_public_key(ReCaptcha $captcha)
 {
     $this->options();
     $captcha->getPubkey()->shouldHaveBeenCalled();
 }