This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
ReCaptchaTest.php
141 lines (124 loc) · 4.49 KB
/
ReCaptchaTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Captcha
*/
namespace ZendTest\Captcha;
use Zend\Captcha\ReCaptcha;
use ZendService\ReCaptcha\ReCaptcha as ReCaptchaService;
/**
* @category Zend
* @package Zend_Captcha
* @subpackage UnitTests
* @group Zend_Captcha
*/
class ReCaptchaTest extends \PHPUnit_Framework_TestCase
{
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @return void
*/
public function setUp()
{
if (!constant('TESTS_ZEND_CAPTCHA_RECAPTCHA_SUPPORT')) {
$this->markTestSkipped('Enable TESTS_ZEND_CAPTCHA_RECAPTCHA_SUPPORT to test PDF render');
}
if (isset($this->word)) {
unset($this->word);
}
$this->captcha = new ReCaptcha(array(
'sessionClass' => 'ZendTest\Captcha\TestAsset\SessionContainer'
));
}
public function testConstructorShouldSetOptions()
{
$options = array(
'privKey' => 'privateKey',
'pubKey' => 'publicKey',
'ssl' => true,
'xhtml' => true,
);
$captcha = new ReCaptcha($options);
$test = $captcha->getOptions();
$compare = array('privKey' => $options['privKey'], 'pubKey' => $options['pubKey']);
$this->assertEquals($compare, $test);
$service = $captcha->getService();
$test = $service->getParams();
$compare = array('ssl' => $options['ssl'], 'xhtml' => $options['xhtml']);
foreach ($compare as $key => $value) {
$this->assertTrue(array_key_exists($key, $test));
$this->assertSame($value, $test[$key]);
}
}
public function testShouldAllowSpecifyingServiceObject()
{
$captcha = new ReCaptcha();
$try = new ReCaptchaService();
$this->assertNotSame($captcha->getService(), $try);
$captcha->setService($try);
$this->assertSame($captcha->getService(), $try);
}
public function testSetAndGetPublicAndPrivateKeys()
{
$captcha = new ReCaptcha();
$pubKey = 'pubKey';
$privKey = 'privKey';
$captcha->setPubkey($pubKey)
->setPrivkey($privKey);
$this->assertSame($pubKey, $captcha->getPubkey());
$this->assertSame($privKey, $captcha->getPrivkey());
$this->assertSame($pubKey, $captcha->getService()->getPublicKey());
$this->assertSame($privKey, $captcha->getService()->getPrivateKey());
}
public function testSetAndGetRecaptchaServicePublicAndPrivateKeysFromOptions()
{
$publicKey = 'publicKey';
$privateKey = 'privateKey';
$options = array(
'public_key' => $publicKey,
'private_key' => $privateKey
);
$captcha = new ReCaptcha($options);
$this->assertSame($publicKey, $captcha->getService()->getPublicKey());
$this->assertSame($privateKey, $captcha->getService()->getPrivateKey());
}
/** @group ZF-7654 */
public function testConstructorShouldAllowSettingLangOptionOnServiceObject()
{
$options = array('lang'=>'fr');
$captcha = new ReCaptcha($options);
$this->assertEquals('fr', $captcha->getService()->getOption('lang'));
}
/** @group ZF-7654 */
public function testConstructorShouldAllowSettingThemeOptionOnServiceObject()
{
$options = array('theme'=>'black');
$captcha = new ReCaptcha($options);
$this->assertEquals('black', $captcha->getService()->getOption('theme'));
}
/** @group ZF-7654 */
public function testAllowsSettingLangOptionOnServiceObject()
{
$captcha = new ReCaptcha;
$captcha->setOption('lang', 'fr');
$this->assertEquals('fr', $captcha->getService()->getOption('lang'));
}
/** @group ZF-7654 */
public function testAllowsSettingThemeOptionOnServiceObject()
{
$captcha = new ReCaptcha;
$captcha->setOption('theme', 'black');
$this->assertEquals('black', $captcha->getService()->getOption('theme'));
}
public function testUsesReCaptchaHelper()
{
$captcha = new ReCaptcha;
$this->assertEquals('captcha/recaptcha', $captcha->getHelperName());
}
}