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
|
|
|
* ArticleTest |
10
|
|
|
* |
11
|
|
|
* @since 4.1.0 |
12
|
|
|
* |
13
|
|
|
* @package Redaxscript |
14
|
|
|
* @category Tests |
15
|
|
|
* @author Henry Ruhs |
16
|
|
|
* |
17
|
|
|
* @covers Redaxscript\Admin\Controller\Article |
18
|
|
|
* @covers Redaxscript\Admin\Controller\ControllerAbstract |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
class ArticleTest 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(); |
33
|
|
|
$installer = $this->installerFactory(); |
34
|
|
|
$installer->init(); |
35
|
|
|
$installer->rawCreate(); |
36
|
|
|
$installer->insertSettings($optionArray); |
37
|
|
|
Db::forTablePrefix('articles') |
38
|
|
|
->create() |
39
|
|
|
->set( |
40
|
|
|
[ |
41
|
|
|
'title' => 'Article One', |
42
|
|
|
'alias' => 'article-one' |
43
|
|
|
]) |
44
|
|
|
->save(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* tearDown |
49
|
|
|
* |
50
|
|
|
* @since 4.1.0 |
51
|
|
|
*/ |
52
|
|
|
|
53
|
|
|
public function tearDown() : void |
54
|
|
|
{ |
55
|
|
|
$this->dropDatabase(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* testCreate |
60
|
|
|
* |
61
|
|
|
* @since 4.1.0 |
62
|
|
|
* |
63
|
|
|
* @param array $registryArray |
64
|
|
|
* @param array $postArray |
65
|
|
|
* @param string $expect |
66
|
|
|
* |
67
|
|
|
* @dataProvider providerAutoloader |
68
|
|
|
*/ |
69
|
|
|
|
70
|
|
|
public function testCreate(array $registryArray = [], array $postArray = [], string $expect = null) : void |
71
|
|
|
{ |
72
|
|
|
/* setup */ |
73
|
|
|
|
74
|
|
|
$this->_registry->init($registryArray); |
75
|
|
|
$this->_request->set('post', $postArray); |
76
|
|
|
$articleController = new Admin\Controller\Article($this->_registry, $this->_request, $this->_language, $this->_config); |
77
|
|
|
|
78
|
|
|
/* actual */ |
79
|
|
|
|
80
|
|
|
$actual = $articleController->process('create'); |
81
|
|
|
|
82
|
|
|
/* compare */ |
83
|
|
|
|
84
|
|
|
$this->assertEquals($expect, $actual); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* testUpdate |
89
|
|
|
* |
90
|
|
|
* @since 4.1.0 |
91
|
|
|
* |
92
|
|
|
* @param array $registryArray |
93
|
|
|
* @param array $postArray |
94
|
|
|
* @param string $expect |
95
|
|
|
* |
96
|
|
|
* @dataProvider providerAutoloader |
97
|
|
|
*/ |
98
|
|
|
|
99
|
|
|
public function testUpdate(array $registryArray = [], array $postArray = [], string $expect = null) : void |
100
|
|
|
{ |
101
|
|
|
/* setup */ |
102
|
|
|
|
103
|
|
|
$this->_registry->init($registryArray); |
104
|
|
|
$this->_request->set('post', $postArray); |
105
|
|
|
$articleController = new Admin\Controller\Article($this->_registry, $this->_request, $this->_language, $this->_config); |
106
|
|
|
|
107
|
|
|
/* actual */ |
108
|
|
|
|
109
|
|
|
$actual = $articleController->process('update'); |
110
|
|
|
|
111
|
|
|
/* compare */ |
112
|
|
|
|
113
|
|
|
$this->assertEquals($expect, $actual); |
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
|
|
|
$articleController = new Admin\Controller\Article($this->_registry, $this->_request, $this->_language, $this->_config); |
135
|
|
|
|
136
|
|
|
/* actual */ |
137
|
|
|
|
138
|
|
|
$actual = $articleController->process('invalid'); |
139
|
|
|
|
140
|
|
|
/* compare */ |
141
|
|
|
|
142
|
|
|
$this->assertEquals($expect, $actual); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|