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

RecoverTest::testProcessFailure()   B

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
 * RecoverTest
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 RecoverTest 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
	 * setUpBeforeClass
63
	 *
64
	 * @since 3.0.0
65
	 */
66
67
	public static function setUpBeforeClass()
68
	{
69
		Db::setSetting('captcha', 1);
70
	}
71
72
	/**
73
	 * tearDownAfterClass
74
	 *
75
	 * @since 3.0.0
76
	 */
77
78
	public static function tearDownAfterClass()
79
	{
80
		Db::setSetting('captcha', 0);
81
	}
82
83
	/**
84
	 * providerProcess
85
	 *
86
	 * @since 3.0.0
87
	 *
88
	 * @return array
89
	 */
90
91
	public function providerProcess()
92
	{
93
		return $this->getProvider('tests/provider/Controller/recover_process.json');
94
	}
95
96
	/**
97
	 * providerProcessFailure
98
	 *
99
	 * @since 3.0.0
100
	 *
101
	 * @return array
102
	 */
103
104
	public function providerProcessFailure()
105
	{
106
		return $this->getProvider('tests/provider/Controller/recover_process_failure.json');
107
	}
108
109
	/**
110
	 * testProcess
111
	 *
112
	 * @since 3.0.0
113
	 *
114
	 * @param array $postArray
115
	 * @param array $hashArray
116
	 * @param string $expect
117
	 *
118
	 * @dataProvider providerProcess
119
	 */
120
121
	public function testProcess($postArray = [], $hashArray = [], $expect = null)
122
	{
123
		/* setup */
124
125
		$this->_request->set('post', $postArray);
126
		$this->_request->setPost('solution', function_exists('password_verify') ? $hashArray[0] : $hashArray[1]);
127
		$recoverController = new Controller\Recover($this->_registry, $this->_language, $this->_request);
128
129
		/* actual */
130
131
		$actual = $recoverController->process();
132
133
		/* compare */
134
135
		$this->assertEquals($expect, $actual);
136
	}
137
138
	/**
139
	 * testProcessFailure
140
	 *
141
	 * @since 3.0.0
142
	 *
143
	 * @param array $postArray
144
	 * @param array $hashArray
145
	 * @param string $method
146
	 * @param string $expect
147
	 *
148
	 * @dataProvider providerProcessFailure
149
	 */
150
151
	public function testProcessFailure($postArray = [], $hashArray = [], $method = null, $expect = null)
152
	{
153
		/* setup */
154
155
		$this->_request->set('post', $postArray);
156
		$this->_request->setPost('solution', function_exists('password_verify') ? $hashArray[0] : $hashArray[1]);
157
		$stub = $this
158
			->getMockBuilder('Redaxscript\Controller\Recover')
159
			->setConstructorArgs(
160
			[
161
				$this->_registry,
162
				$this->_language,
163
				$this->_request
164
			])
165
			->setMethods(
166
			[
167
				$method
168
			])
169
			->getMock();
170
171
		/* override */
172
173
		$stub
174
			->expects($this->any())
175
			->method($method)
176
			->will($this->returnValue(false));
177
178
		/* actual */
179
180
		$actual = $stub->process();
181
182
		/* compare */
183
184
		$this->assertEquals($expect, $actual);
185
	}
186
}
187