1010namespace ZendTest \Captcha ;
1111
1212use Zend \Captcha \ReCaptcha ;
13+ use Zend \Http \Client as HttpClient ;
14+ use Zend \Http \Client \Adapter \Socket ;
1315use ZendService \ReCaptcha \ReCaptcha as ReCaptchaService ;
1416
1517/**
@@ -26,16 +28,8 @@ class ReCaptchaTest extends \PHPUnit_Framework_TestCase
2628public function setUp ()
2729 {
2830if (!getenv ('TESTS_ZEND_CAPTCHA_RECAPTCHA_SUPPORT ' )) {
29- $ this ->markTestSkipped ('Enable TESTS_ZEND_CAPTCHA_RECAPTCHA_SUPPORT to testPDF render ' );
31+ $ this ->markTestSkipped ('Enable TESTS_ZEND_CAPTCHA_RECAPTCHA_SUPPORT to testRecaptcha ' );
3032 }
31-
32- if (isset ($ this ->word )) {
33- unset($ this ->word );
34- }
35-
36- $ this ->captcha =new ReCaptcha ([
37- 'sessionClass ' =>'ZendTest\Captcha\TestAsset\SessionContainer '
38- ]);
3933 }
4034
4135public function testConstructorShouldSetOptions ()
@@ -163,4 +157,52 @@ public function testUsesReCaptchaHelper()
163157$ captcha =new ReCaptcha ;
164158$ this ->assertEquals ('captcha/recaptcha ' ,$ captcha ->getHelperName ());
165159 }
160+
161+ public function testValidationForDifferentElementName ()
162+ {
163+ $ captcha =new ReCaptcha ([
164+ 'site_key ' =>getenv ('TESTS_ZEND_SERVICE_RECAPTCHA_SITE_KEY ' ),
165+ 'secret_key ' =>getenv ('TESTS_ZEND_SERVICE_RECAPTCHA_SECRET_KEY ' ),
166+ ]);
167+ $ service =$ captcha ->getService ();
168+ $ service ->setIp ('127.0.0.1 ' );
169+ $ service ->setHttpClient ($ this ->getHttpClient ());
170+
171+ $ response =getenv ('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE ' );
172+ $ value ='g-recaptcha-response ' ;
173+ $ context = ['g-recaptcha-response ' =>getenv ('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE ' )];
174+
175+ $ this ->assertTrue ($ captcha ->isValid ($ value ,$ context ));
176+ }
177+
178+ public function testValidationForResponseElementName ()
179+ {
180+ $ captcha =new ReCaptcha ([
181+ 'site_key ' =>getenv ('TESTS_ZEND_SERVICE_RECAPTCHA_SITE_KEY ' ),
182+ 'secret_key ' =>getenv ('TESTS_ZEND_SERVICE_RECAPTCHA_SECRET_KEY ' ),
183+ ]);
184+ $ service =$ captcha ->getService ();
185+ $ service ->setIp ('127.0.0.1 ' );
186+ $ service ->setHttpClient ($ this ->getHttpClient ());
187+
188+ $ response =getenv ('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE ' );
189+ $ value =getenv ('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE ' );
190+ $ context = ['g-recaptcha-response ' =>getenv ('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE ' )];
191+
192+ $ this ->assertTrue ($ captcha ->isValid ($ value ,$ context ));
193+ }
194+
195+ /**
196+ * @return HttpClient
197+ */
198+ private function getHttpClient ()
199+ {
200+ $ socket =new Socket ();
201+ $ socket ->setOptions ([
202+ 'ssltransport ' =>'tls ' ,
203+ ]);
204+ return new HttpClient (null , [
205+ 'adapter ' =>$ socket ,
206+ ]);
207+ }
166208}