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

ResetTest::testProcessFailure()   B

↳ Parent: ResetTest

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\Db;
5
use Redaxscript\Controller;
6
use Redaxscript\Language;
7
use Redaxscript\Registry;
8
use Redaxscript\Request;
9
use Redaxscript\Tests\TestCaseAbstract;
10
11
/**
12
 * ResetTest
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 ResetTest 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')->whereIdIs(1)->findOne()->set('password', 'test')->save();
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
	}
82
83
	/**
84
	 * tearDownAfterClass
85
	 *
86
	 * @since 3.0.0
87
	 */
88
89
	public static function tearDownAfterClass()
90
	{
91
		Db::setSetting('captcha', 0);
92
	}
93
94
	/**
95
	 * providerProcess
96
	 *
97
	 * @since 3.0.0
98
	 *
99
	 * @return array
100
	 */
101
102
	public function providerProcess()
103
	{
104
		return $this->getProvider('tests/provider/Controller/reset_process.json');
105
	}
106
107
	/**
108
	 * providerProcessFailure
109
	 *
110
	 * @since 3.0.0
111
	 *
112
	 * @return array
113
	 */
114
115
	public function providerProcessFailure()
116
	{
117
		return $this->getProvider('tests/provider/Controller/reset_process_failure.json');
118
	}
119
120
	/**
121
	 * testProcess
122
	 *
123
	 * @since 3.0.0
124
	 *
125
	 * @param array $postArray
126
	 * @param array $hashArray
127
	 * @param string $expect
128
	 *
129
	 * @dataProvider providerProcess
130
	 */
131
132
	public function testProcess($postArray = [], $hashArray = [], $expect = null)
133
	{
134
		/* setup */
135
136
		$this->_request->set('post', $postArray);
137
		$this->_request->setPost('solution', function_exists('password_verify') ? $hashArray[0] : $hashArray[1]);
138
		$resetController = new Controller\Reset($this->_registry, $this->_language, $this->_request);
139
140
		/* actual */
141
142
		$actual = $resetController->process();
143
144
		/* compare */
145
146
		$this->assertEquals($expect, $actual);
147
	}
148
149
	/**
150
	 * testProcessFailure
151
	 *
152
	 * @since 3.0.0
153
	 *
154
	 * @param array $postArray
155
	 * @param array $hashArray
156
	 * @param string $method
157
	 * @param string $expect
158
	 *
159
	 * @dataProvider providerProcessFailure
160
	 */
161
162
	public function testProcessFailure($postArray = [], $hashArray = [], $method = null, $expect = null)
163
	{
164
		/* setup */
165
166
		$this->_request->set('post', $postArray);
167
		$this->_request->setPost('solution', function_exists('password_verify') ? $hashArray[0] : $hashArray[1]);
168
		$stub = $this
169
			->getMockBuilder('Redaxscript\Controller\Reset')
170
			->setConstructorArgs(
171
			[
172
				$this->_registry,
173
				$this->_language,
174
				$this->_request
175
			])
176
			->setMethods(
177
			[
178
				$method
179
			])
180
			->getMock();
181
182
		/* override */
183
184
		$stub
185
			->expects($this->any())
186
			->method($method)
187
			->will($this->returnValue(false));
188
189
		/* actual */
190
191
		$actual = $stub->process();
192
193
		/* compare */
194
195
		$this->assertEquals($expect, $actual);
196
	}
197
}
198