-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathRegisterTest.php
More file actions
115 lines (96 loc) · 3.96 KB
/
RegisterTest.php
File metadata and controls
115 lines (96 loc) · 3.96 KB
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
<?php
namespace ZfcUserTest\Form;
use ZfcUser\Form\Register as Form;
class RegisterTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerTestConstruct
*/
public function testConstruct($useCaptcha = false)
{
$options = $this->getMock('ZfcUser\Options\RegistrationOptionsInterface');
$options->expects($this->once())
->method('getEnableUsername')
->will($this->returnValue(false));
$options->expects($this->once())
->method('getEnableDisplayName')
->will($this->returnValue(false));
$options->expects($this->any())
->method('getUseRegistrationFormCaptcha')
->will($this->returnValue($useCaptcha));
if ($useCaptcha && class_exists('\Zend\Captcha\AbstractAdapter')) {
$captcha = $this->getMockForAbstractClass('\Zend\Captcha\AbstractAdapter');
$options->expects($this->once())
->method('getFormCaptchaOptions')
->will($this->returnValue($captcha));
}
$form = new Form(null, $options);
$elements = $form->getElements();
$this->assertArrayNotHasKey('userId', $elements);
$this->assertArrayNotHasKey('username', $elements);
$this->assertArrayNotHasKey('display_name', $elements);
$this->assertArrayHasKey('email', $elements);
$this->assertArrayHasKey('password', $elements);
$this->assertArrayHasKey('passwordVerify', $elements);
$this->assertArrayHasKey('security', $elements);
}
public function providerTestConstruct()
{
return array(
array(true),
array(false)
);
}
public function testSetGetRegistrationOptions()
{
$options = $this->getMock('ZfcUser\Options\RegistrationOptionsInterface');
$options->expects($this->once())
->method('getEnableUsername')
->will($this->returnValue(false));
$options->expects($this->once())
->method('getEnableDisplayName')
->will($this->returnValue(false));
$options->expects($this->any())
->method('getUseRegistrationFormCaptcha')
->will($this->returnValue(false));
$form = new Form(null, $options);
$this->assertSame($options, $form->getRegistrationOptions());
$optionsNew = $this->getMock('ZfcUser\Options\RegistrationOptionsInterface');
$form->setRegistrationOptions($optionsNew);
$this->assertSame($optionsNew, $form->getRegistrationOptions());
}
public function testSetCaptchaElement()
{
$options = $this->getMock('ZfcUser\Options\RegistrationOptionsInterface');
$options->expects($this->once())
->method('getEnableUsername')
->will($this->returnValue(false));
$options->expects($this->once())
->method('getEnableDisplayName')
->will($this->returnValue(false));
$options->expects($this->any())
->method('getUseRegistrationFormCaptcha')
->will($this->returnValue(false));
$captcha = $this->getMock('\Zend\Form\Element\Captcha');
$form = new Form(null, $options);
$form->setCaptchaElement($captcha);
$reflection = $this->helperMakePropertyAccessable($form, 'captchaElement');
$this->assertSame($captcha, $reflection->getValue($form));
}
/**
*
* @param mixed $objectOrClass
* @param string $property
* @param mixed $value = null
* @return \ReflectionProperty
*/
public function helperMakePropertyAccessable($objectOrClass, $property, $value = null)
{
$reflectionProperty = new \ReflectionProperty($objectOrClass, $property);
$reflectionProperty->setAccessible(true);
if ($value !== null) {
$reflectionProperty->setValue($objectOrClass, $value);
}
return $reflectionProperty;
}
}