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

tests/unit/Controller/RegisterTest.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
 * RegisterTest
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\Register
19
 */
20
21
class RegisterTest 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
		$setting->set('notification', 1);
47
	}
48
49
	/**
50
	 * tearDown
51
	 *
52
	 * @since 3.1.0
53
	 */
54
55
	public function tearDown() : void
56
	{
57
		$this->dropDatabase();
58
	}
59
60
	/**
61
	 * testProcess
62
	 *
63
	 * @since 3.0.0
64
	 *
65
	 * @param array $postArray
66
	 * @param string $method
67
	 * @param string $expect
68
	 *
69
	 * @dataProvider providerAutoloader
70
	 */
71
72
	public function testProcess(array $postArray = [], string $method = null, string $expect = null) : void
73
	{
74
		/* setup */
75
76
		$this->_request->set('post', $postArray);
77
		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...
78
		{
79
			$registerController = $this
80
				->getMockBuilder('Redaxscript\Controller\Register')
81
				->setConstructorArgs(
82
				[
83
					$this->_registry,
84
					$this->_request,
85
					$this->_language,
86
					$this->_config
87
				])
88
				->setMethods(
89
				[
90
					$method
91
				])
92
				->getMock();
93
94
			/* override */
95
96
			$registerController
97
				->expects($this->any())
98
				->method($method)
99
				->will($this->returnValue(false));
100
		}
101
		else
102
		{
103
			$registerController = new Controller\Register($this->_registry, $this->_request, $this->_language, $this->_config);
104
		}
105
106
		/* actual */
107
108
		$actual = $registerController->process();
109
110
		/* compare */
111
112
		$this->assertEquals($expect, $actual);
113
	}
114
}
115