Completed
Push — master ( 0ea243...da58d4 )
by Henry
10:25 queued 33s
created

tests/unit/Controller/RecoverTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Tests\Controller;
3
4
use Redaxscript\Controller;
5
use Redaxscript\Tests\TestCaseAbstract;
6
7
/**
8
 * RecoverTest
9
 *
10
 * @since 3.0.0
11
 *
12
 * @package Redaxscript
13
 * @category Tests
14
 * @author Henry Ruhs
15
 * @author Balázs Szilágyi
16
 *
17
 * @covers Redaxscript\Controller\ControllerAbstract
18
 * @covers Redaxscript\Controller\Recover
19
 */
20
21
class RecoverTest extends TestCaseAbstract
22
{
23
	/**
24
	 * setUp
25
	 *
26
	 * @since 3.1.0
27
	 */
28
29
	public function setUp() : void
30
	{
31
		parent::setUp();
32
		$optionArray =
33
		[
34
			'adminName' => 'Test',
35
			'adminUser' => 'test',
36
			'adminPassword' => 'test',
37
			'adminEmail' => '[email protected]'
38
		];
39
		$installer = $this->installerFactory();
40
		$installer->init();
41
		$installer->rawCreate();
42
		$installer->insertSettings($optionArray);
43
		$installer->insertUsers($optionArray);
44
		$setting = $this->settingFactory();
45
		$setting->set('captcha', 1);
46
	}
47
48
	/**
49
	 * tearDown
50
	 *
51
	 * @since 3.1.0
52
	 */
53
54
	public function tearDown() : void
55
	{
56
		$this->dropDatabase();
57
	}
58
59
	/**
60
	 * testProcess
61
	 *
62
	 * @since 3.0.0
63
	 *
64
	 * @param array $postArray
65
	 * @param string $method
66
	 * @param string $expect
67
	 *
68
	 * @dataProvider providerAutoloader
69
	 */
70
71
	public function testProcess(array $postArray = [], string $method = null, string $expect = null) : void
72
	{
73
		/* setup */
74
75
		$this->_request->set('post', $postArray);
76
		if ($method)
0 ignored issues
show
Bug Best Practice introduced by
The expression $method of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
77
		{
78
			$recoverController = $this
79
				->getMockBuilder('Redaxscript\Controller\Recover')
80
				->setConstructorArgs(
81
				[
82
					$this->_registry,
83
					$this->_request,
84
					$this->_language,
85
					$this->_config
86
				])
87
				->setMethods(
88
				[
89
					$method
90
				])
91
				->getMock();
92
93
			/* override */
94
95
			$recoverController
96
				->expects($this->any())
97
				->method($method)
98
				->will($this->returnValue(false));
99
		}
100
		else
101
		{
102
			$recoverController = new Controller\Recover($this->_registry, $this->_request, $this->_language, $this->_config);
103
		}
104
105
		/* actual */
106
107
		$actual = $recoverController->process();
108
109
		/* compare */
110
111
		$this->assertEquals($expect, $actual);
112
	}
113
}
114