Completed
Branch master (48c558)
by
unknown
05:41
created

RegisterTest::testProcessFailure()   B

↳ Parent: RegisterTest

Complexity

Conditions 2
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 35
Code Lines 18

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 18
nc 1
nop 4
1
<?php
2
namespace Redaxscript\Tests\Controller;
3
4
use Redaxscript\Controller;
5
use Redaxscript\Db;
6
use Redaxscript\Language;
7
use Redaxscript\Registry;
8
use Redaxscript\Request;
9
use Redaxscript\Tests\TestCaseAbstract;
10
11
/**
12
 * RegisterTest
13
 *
14
 * @since 3.0.0
15
 *
16
 * @package Redaxscript
17
 * @category Tests
18
 * @author Henry Ruhs
19
 * @author Balázs Szilágyi
20
 */
21
22
class RegisterTest extends TestCaseAbstract
23
{
24
	/**
25
	 * instance of the registry class
26
	 *
27
	 * @var object
28
	 */
29
30
	protected $_registry;
31
32
	/**
33
	 * instance of the language class
34
	 *
35
	 * @var object
36
	 */
37
38
	protected $_language;
39
40
	/**
41
	 * instance of the request class
42
	 *
43
	 * @var object
44
	 */
45
46
	protected $_request;
47
48
	/**
49
	 * setUp
50
	 *
51
	 * @since 3.0.0
52
	 */
53
54
	public function setUp()
55
	{
56
		$this->_registry = Registry::getInstance();
57
		$this->_language = Language::getInstance();
58
		$this->_request = Request::getInstance();
59
	}
60
61
	/**
62
	 * tearDown
63
	 *
64
	 * @since 3.0.0
65
	 */
66
67
	public function tearDown()
68
	{
69
		Db::forTablePrefix('users')->where('user', 'new')->deleteMany();
70
	}
71
72
	/**
73
	 * setUpBeforeClass
74
	 *
75
	 * @since 3.0.0
76
	 */
77
78
	public static function setUpBeforeClass()
79
	{
80
		Db::setSetting('captcha', 1);
81
		Db::setSetting('notification', 1);
82
	}
83
84
	/**
85
	 * tearDownAfterClass
86
	 *
87
	 * @since 3.0.0
88
	 */
89
90
	public static function tearDownAfterClass()
91
	{
92
		Db::setSetting('captcha', 0);
93
		Db::setSetting('notification', 0);
94
	}
95
96
	/**
97
	 * providerProcess
98
	 *
99
	 * @since 3.0.0
100
	 *
101
	 * @return array
102
	 */
103
104
	public function providerProcess()
105
	{
106
		return $this->getProvider('tests/provider/Controller/register_process.json');
107
	}
108
109
	/**
110
	 * providerProcessFailure
111
	 *
112
	 * @since 3.0.0
113
	 *
114
	 * @return array
115
	 */
116
117
	public function providerProcessFailure()
118
	{
119
		return $this->getProvider('tests/provider/Controller/register_process_failure.json');
120
	}
121
122
	/**
123
	 * testProcess
124
	 *
125
	 * @since 3.0.0
126
	 *
127
	 * @param array $postArray
128
	 * @param array $hashArray
129
	 * @param string $expect
130
	 *
131
	 * @dataProvider providerProcess
132
	 */
133
134
	public function testProcess($postArray = [], $hashArray = [], $expect = null)
135
	{
136
		/* setup */
137
138
		$this->_request->set('post', $postArray);
139
		$this->_request->setPost('solution', function_exists('password_verify') ? $hashArray[0] : $hashArray[1]);
140
		$registerController = new Controller\Register($this->_registry, $this->_language, $this->_request);
141
142
		/* actual */
143
144
		$actual = $registerController->process();
145
146
		/* compare */
147
148
		$this->assertEquals($expect, $actual);
149
	}
150
151
	/**
152
	 * testProcessFailure
153
	 *
154
	 * @since 3.0.0
155
	 *
156
	 * @param array $postArray
157
	 * @param array $hashArray
158
	 * @param string $method
159
	 * @param string $expect
160
	 *
161
	 * @dataProvider providerProcessFailure
162
	 */
163
164
	public function testProcessFailure($postArray = [], $hashArray = [], $method = null, $expect = null)
165
	{
166
		/* setup */
167
168
		$this->_request->set('post', $postArray);
169
		$this->_request->setPost('solution', function_exists('password_verify') ? $hashArray[0] : $hashArray[1]);
170
		$stub = $this
171
			->getMockBuilder('Redaxscript\Controller\Register')
172
			->setConstructorArgs(
173
			[
174
				$this->_registry,
175
				$this->_language,
176
				$this->_request
177
			])
178
			->setMethods(
179
			[
180
				$method
181
			])
182
			->getMock();
183
184
		/* override */
185
186
		$stub
187
			->expects($this->any())
188
			->method($method)
189
			->will($this->returnValue(false));
190
191
		/* actual */
192
193
		$actual = $stub->process();
194
195
		/* compare */
196
197
		$this->assertEquals($expect, $actual);
198
	}
199
}
200