Completed
Push — master ( 1da492...320203 )
by Henry
07:00
created

tests/unit/Admin/Controller/CategoryTest.php (3 issues)

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\Admin\Controller;
3
4
use Redaxscript\Admin;
5
use Redaxscript\Db;
6
use Redaxscript\Tests\TestCaseAbstract;
7
8
/**
9
 * CategoryTest
10
 *
11
 * @since 4.1.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 *
17
 * @covers Redaxscript\Admin\Controller\Category
18
 * @covers Redaxscript\Admin\Controller\ControllerAbstract
19
 */
20
21
class CategoryTest extends TestCaseAbstract
22
{
23
	/**
24
	 * setUp
25
	 *
26
	 * @since 4.1.0
27
	 */
28
29
	public function setUp() : void
30
	{
31
		parent::setUp();
32
		$optionArray = $this->getOptionArray();
0 ignored issues
show
The method getOptionArray() does not seem to exist on object<Redaxscript\Tests...ontroller\CategoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
		$installer = $this->installerFactory();
0 ignored issues
show
The method installerFactory() does not seem to exist on object<Redaxscript\Tests...ontroller\CategoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
		$installer->init();
35
		$installer->rawCreate();
36
		$installer->insertSettings($optionArray);
37
		Db::forTablePrefix('categories')
38
			->create()
39
			->set(
40
			[
41
				'title' => 'Category One',
42
				'alias' => 'category-one'
43
			])
44
			->save();}
45
46
	/**
47
	 * tearDown
48
	 *
49
	 * @since 4.1.0
50
	 */
51
52
	public function tearDown() : void
53
	{
54
		$this->dropDatabase();
0 ignored issues
show
The method dropDatabase() does not seem to exist on object<Redaxscript\Tests...ontroller\CategoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
	}
56
57
	/**
58
	 * testCreate
59
	 *
60
	 * @since 4.1.0
61
	 *
62
	 * @param array $registryArray
63
	 * @param array $postArray
64
	 * @param string $expect
65
	 *
66
	 * @dataProvider providerAutoloader
67
	 */
68
69
	public function testCreate(array $registryArray = [], array $postArray = [], string $expect = null) : void
70
	{
71
		/* setup */
72
73
		$this->_registry->init($registryArray);
74
		$this->_request->set('post', $postArray);
75
		$categoryController = new Admin\Controller\Category($this->_registry, $this->_request, $this->_language, $this->_config);
76
77
		/* actual */
78
79
		$actual = $categoryController->process('create');
80
81
		/* compare */
82
83
		$this->assertEquals($expect, $actual);
84
	}
85
86
	/**
87
	 * testUpdate
88
	 *
89
	 * @since 4.1.0
90
	 *
91
	 * @param array $registryArray
92
	 * @param array $postArray
93
	 * @param string $expect
94
	 *
95
	 * @dataProvider providerAutoloader
96
	 */
97
98
	public function testUpdate(array $registryArray = [], array $postArray = [], string $expect = null) : void
99
	{
100
		/* setup */
101
102
		$this->_registry->init($registryArray);
103
		$this->_request->set('post', $postArray);
104
		$categoryController = new Admin\Controller\Category($this->_registry, $this->_request, $this->_language, $this->_config);
105
106
		/* actual */
107
108
		$actual = $categoryController->process('update');
109
110
		/* compare */
111
112
		$this->assertEquals($expect, $actual);
113
	}
114
115
116
	/**
117
	 * testInvalid
118
	 *
119
	 * @since 4.1.0
120
	 *
121
	 * @param array $registryArray
122
	 * @param array $postArray
123
	 * @param string $expect
124
	 *
125
	 * @dataProvider providerAutoloader
126
	 */
127
128
	public function testInvalid(array $registryArray = [], array $postArray = [], string $expect = null) : void
129
	{
130
		/* setup */
131
132
		$this->_registry->init($registryArray);
133
		$this->_request->set('post', $postArray);
134
		$categoryController = new Admin\Controller\Category($this->_registry, $this->_request, $this->_language, $this->_config);
135
136
		/* actual */
137
138
		$actual = $categoryController->process('invalid');
139
140
		/* compare */
141
142
		$this->assertEquals($expect, $actual);
143
	}
144
}
145