Skip to content

Commit f954258

Browse files
committed
[BC BREAK] Remove captcha
1 parent 85823f4 commit f954258

File tree

8 files changed

+5
-218
lines changed

8 files changed

+5
-218
lines changed

composer.json

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "zf-commons/zfc-user",
3-
"description": "A generic user registration and authentication module for ZF2. Supports Zend\\Db and Doctrine2.",
3+
"description": "A generic user registration and authentication module for ZF2. Supports multiple adapters with built-in support for Zend\\Db.",
44
"type": "library",
55
"license": "BSD-3-Clause",
66
"keywords": [
7-
"zf2"
7+
"zf2",
8+
"authentication"
89
],
910
"homepage": "https://github.com/ZF-Commons/ZfcUser",
1011
"authors": [
@@ -48,11 +49,7 @@
4849
},
4950
"require-dev" : {
5051
"phpunit/phpunit" : ">=3.7,<4",
51-
"squizlabs/php_codesniffer" : "1.4.*",
52-
"zendframework/zend-captcha" : "~2.1"
53-
},
54-
"suggest": {
55-
"zendframework/zend-captcha" : "Zend\\Captcha if you want to use the captcha component"
52+
"squizlabs/php_codesniffer" : "1.4.*"
5653
},
5754
"autoload": {
5855
"psr-0": {

src/ZfcUser/Form/Base.php

-11
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,6 @@ public function __construct()
6161
),
6262
));
6363

64-
if ($this->getRegistrationOptions()->getUseRegistrationFormCaptcha()) {
65-
$this->add(array(
66-
'name' => 'captcha',
67-
'type' => 'Zend\Form\Element\Captcha',
68-
'options' => array(
69-
'label' => 'Please type the following text',
70-
'captcha' => $this->getRegistrationOptions()->getFormCaptchaOptions(),
71-
),
72-
));
73-
}
74-
7564
$submitElement = new Element\Button('submit');
7665
$submitElement
7766
->setLabel('Submit')

src/ZfcUser/Form/Register.php

-11
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
namespace ZfcUser\Form;
44

5-
use Zend\Form\Element\Captcha as Captcha;
65
use ZfcUser\Options\RegistrationOptionsInterface;
76

87
class Register extends Base
98
{
10-
protected $captchaElement= null;
11-
129
/**
1310
* @var RegistrationOptionsInterface
1411
*/
@@ -30,18 +27,10 @@ public function __construct($name, RegistrationOptionsInterface $options)
3027
if (!$this->getRegistrationOptions()->getEnableDisplayName()) {
3128
$this->remove('display_name');
3229
}
33-
if ($this->getRegistrationOptions()->getUseRegistrationFormCaptcha() && $this->captchaElement) {
34-
$this->add($this->captchaElement, array('name'=>'captcha'));
35-
}
3630
$this->get('submit')->setLabel('Register');
3731
$this->getEventManager()->trigger('init', $this);
3832
}
3933

40-
public function setCaptchaElement(Captcha $captchaElement)
41-
{
42-
$this->captchaElement= $captchaElement;
43-
}
44-
4534
/**
4635
* Set Registration Options
4736
*

src/ZfcUser/Options/ModuleOptions.php

-60
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ class ModuleOptions extends AbstractOptions implements UserControllerOptionsInte
9191
*/
9292
protected $enableDisplayName = false;
9393

94-
/**
95-
* @var bool
96-
*/
97-
protected $useRegistrationFormCaptcha = false;
98-
9994
/**
10095
* @var int
10196
*/
@@ -107,17 +102,6 @@ class ModuleOptions extends AbstractOptions implements UserControllerOptionsInte
107102

108103
protected $tableName = 'user';
109104

110-
/**
111-
* @var array
112-
*/
113-
protected $formCaptchaOptions = array(
114-
'class' => 'figlet',
115-
'options' => array(
116-
'wordLen' => 5,
117-
'expiration' => 300,
118-
'timeout' => 300,
119-
),
120-
);
121105

122106
/**
123107
* set login redirect route
@@ -449,28 +433,6 @@ public function getEnableDisplayName()
449433
return $this->enableDisplayName;
450434
}
451435

452-
/**
453-
* set use a captcha in registration form
454-
*
455-
* @param bool $useRegistrationFormCaptcha
456-
* @return ModuleOptions
457-
*/
458-
public function setUseRegistrationFormCaptcha($useRegistrationFormCaptcha)
459-
{
460-
$this->useRegistrationFormCaptcha = $useRegistrationFormCaptcha;
461-
return $this;
462-
}
463-
464-
/**
465-
* get use a captcha in registration form
466-
*
467-
* @return bool
468-
*/
469-
public function getUseRegistrationFormCaptcha()
470-
{
471-
return $this->useRegistrationFormCaptcha;
472-
}
473-
474436
/**
475437
* set user entity class name
476438
*
@@ -534,26 +496,4 @@ public function getTableName()
534496
{
535497
return $this->tableName;
536498
}
537-
538-
/**
539-
* set form CAPTCHA options
540-
*
541-
* @param array $formCaptchaOptions
542-
* @return ModuleOptions
543-
*/
544-
public function setFormCaptchaOptions($formCaptchaOptions)
545-
{
546-
$this->formCaptchaOptions = $formCaptchaOptions;
547-
return $this;
548-
}
549-
550-
/**
551-
* get form CAPTCHA options
552-
*
553-
* @return array
554-
*/
555-
public function getFormCaptchaOptions()
556-
{
557-
return $this->formCaptchaOptions;
558-
}
559499
}

src/ZfcUser/Options/RegistrationOptionsInterface.php

-30
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,6 @@ public function setUserFormTimeout($userFormTimeout);
6262
*/
6363
public function getUserFormTimeout();
6464

65-
/**
66-
* set use a captcha in registration form
67-
*
68-
* @param bool $useRegistrationFormCaptcha
69-
* @return ModuleOptions
70-
*/
71-
public function setUseRegistrationFormCaptcha($useRegistrationFormCaptcha);
72-
73-
/**
74-
* get use a captcha in registration form
75-
*
76-
* @return bool
77-
*/
78-
public function getUseRegistrationFormCaptcha();
79-
8065
/**
8166
* set login after registration
8267
*
@@ -91,19 +76,4 @@ public function setLoginAfterRegistration($loginAfterRegistration);
9176
* @return bool
9277
*/
9378
public function getLoginAfterRegistration();
94-
95-
/**
96-
* set form CAPTCHA options
97-
*
98-
* @param array $formCaptchaOptions
99-
* @return ModuleOptions
100-
*/
101-
public function setFormCaptchaOptions($formCaptchaOptions);
102-
103-
/**
104-
* get form CAPTCHA options
105-
*
106-
* @return array
107-
*/
108-
public function getFormCaptchaOptions();
10979
}

tests/ZfcUserTest/Form/BaseTest.php

+1-26
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,9 @@
66

77
class BaseTest extends \PHPUnit_Framework_TestCase
88
{
9-
/**
10-
* @dataProvider providerTestConstruct
11-
*/
12-
public function testConstruct($useCaptcha = false)
9+
public function testConstruct()
1310
{
1411
$options = $this->getMock('ZfcUser\Options\RegistrationOptionsInterface');
15-
$options->expects($this->once())
16-
->method('getUseRegistrationFormCaptcha')
17-
->will($this->returnValue($useCaptcha));
18-
19-
if ($useCaptcha) {
20-
if (!class_exists('\Zend\Captcha\AbstractAdapter')) {
21-
$this->markTestSkipped('we need zendframework/zend-captcha to cover this');
22-
}
23-
$captcha = $this->getMockForAbstractClass('\Zend\Captcha\AbstractAdapter');
24-
25-
$options->expects($this->once())
26-
->method('getFormCaptchaOptions')
27-
->will($this->returnValue($captcha));
28-
}
2912

3013
$form = new Form($options);
3114

@@ -39,12 +22,4 @@ public function testConstruct($useCaptcha = false)
3922
$this->assertArrayHasKey('submit', $elements);
4023
$this->assertArrayHasKey('userId', $elements);
4124
}
42-
43-
public function providerTestConstruct()
44-
{
45-
return array(
46-
array(true),
47-
array(false)
48-
);
49-
}
5025
}

tests/ZfcUserTest/Form/RegisterTest.php

-23
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,6 @@ public function testSetGetRegistrationOptions()
5151
$this->assertSame($optionsNew, $form->getRegistrationOptions());
5252
}
5353

54-
public function testSetCaptchaElement()
55-
{
56-
$options = $this->getMock('ZfcUser\Options\RegistrationOptionsInterface');
57-
$options->expects($this->once())
58-
->method('getEnableUsername')
59-
->will($this->returnValue(false));
60-
$options->expects($this->once())
61-
->method('getEnableDisplayName')
62-
->will($this->returnValue(false));
63-
$options->expects($this->any())
64-
->method('getUseRegistrationFormCaptcha')
65-
->will($this->returnValue(false));
66-
67-
$captcha = $this->getMock('\Zend\Form\Element\Captcha');
68-
$form = new Form(null, $options);
69-
70-
$form->setCaptchaElement($captcha);
71-
72-
$reflection = $this->helperMakePropertyAccessable($form, 'captchaElement');
73-
$this->assertSame($captcha, $reflection->getValue($form));
74-
}
75-
76-
7754
/**
7855
*
7956
* @param mixed $objectOrClass

tests/ZfcUserTest/Options/ModuleOptionsTest.php

-50
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,6 @@ public function testGetEnableDisplayName()
287287
$this->assertFalse($this->options->getEnableDisplayName());
288288
}
289289

290-
/**
291-
* @covers ZfcUser\Options\ModuleOptions::getUseRegistrationFormCaptcha
292-
* @covers ZfcUser\Options\ModuleOptions::setUseRegistrationFormCaptcha
293-
*/
294-
public function testSetGetUseRegistrationFormCaptcha()
295-
{
296-
$this->options->setUseRegistrationFormCaptcha(true);
297-
$this->assertTrue($this->options->getUseRegistrationFormCaptcha());
298-
}
299-
300-
/**
301-
* @covers ZfcUser\Options\ModuleOptions::getUseRegistrationFormCaptcha
302-
*/
303-
public function testGetUseRegistrationFormCaptcha()
304-
{
305-
$this->assertFalse($this->options->getUseRegistrationFormCaptcha());
306-
}
307-
308290
/**
309291
* @covers ZfcUser\Options\ModuleOptions::getUserEntityClass
310292
* @covers ZfcUser\Options\ModuleOptions::setUserEntityClass
@@ -358,36 +340,4 @@ public function testGetTableName()
358340
{
359341
$this->assertEquals('user', $this->options->getTableName());
360342
}
361-
362-
/**
363-
* @covers ZfcUser\Options\ModuleOptions::getFormCaptchaOptions
364-
* @covers ZfcUser\Options\ModuleOptions::setFormCaptchaOptions
365-
*/
366-
public function testSetGetFormCaptchaOptions()
367-
{
368-
$expected = array(
369-
'class' => 'someClass',
370-
'options' => array(
371-
'anOption' => 3,
372-
),
373-
);
374-
$this->options->setFormCaptchaOptions($expected);
375-
$this->assertEquals($expected, $this->options->getFormCaptchaOptions());
376-
}
377-
378-
/**
379-
* @covers ZfcUser\Options\ModuleOptions::getFormCaptchaOptions
380-
*/
381-
public function testGetFormCaptchaOptions()
382-
{
383-
$expected = array(
384-
'class' => 'figlet',
385-
'options' => array(
386-
'wordLen' => 5,
387-
'expiration' => 300,
388-
'timeout' => 300,
389-
),
390-
);
391-
$this->assertEquals($expected, $this->options->getFormCaptchaOptions());
392-
}
393343
}

0 commit comments

Comments
 (0)