1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Tests\Model; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Db; |
5
|
|
|
use Redaxscript\Model; |
6
|
|
|
use Redaxscript\Tests\TestCaseAbstract; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* ContentAbstractTest |
10
|
|
|
* |
11
|
|
|
* @since 4.0.0 |
12
|
|
|
* |
13
|
|
|
* @package Redaxscript |
14
|
|
|
* @category Tests |
15
|
|
|
* @author Henry Ruhs |
16
|
|
|
* |
17
|
|
|
* @covers Redaxscript\Model\ContentAbstract |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
class ContentAbstractTest extends TestCaseAbstract |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* setUp |
24
|
|
|
* |
25
|
|
|
* @since 4.0.0 |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
public function setUp() : void |
29
|
|
|
{ |
30
|
|
|
parent::setUp(); |
31
|
|
|
$optionArray = |
32
|
|
|
[ |
33
|
|
|
'adminName' => 'Test', |
34
|
|
|
'adminUser' => 'test', |
35
|
|
|
'adminPassword' => 'test', |
36
|
|
|
'adminEmail' => '[email protected]' |
37
|
|
|
]; |
38
|
|
|
$installer = $this->installerFactory(); |
39
|
|
|
$installer->init(); |
40
|
|
|
$installer->rawCreate(); |
41
|
|
|
$installer->insertSettings($optionArray); |
42
|
|
|
$articleOne = Db::forTablePrefix('articles')->create(); |
43
|
|
|
$articleOne |
44
|
|
|
->set( |
45
|
|
|
[ |
46
|
|
|
'title' => 'Article One', |
47
|
|
|
'alias' => 'article-one', |
48
|
|
|
'language' => 'en', |
49
|
|
|
'rank' => 1 |
50
|
|
|
]) |
51
|
|
|
->save(); |
52
|
|
|
Db::forTablePrefix('articles') |
53
|
|
|
->create() |
54
|
|
|
->set( |
55
|
|
|
[ |
56
|
|
|
'title' => 'Article One Sister', |
57
|
|
|
'alias' => 'article-one-sister', |
58
|
|
|
'language' => 'de', |
59
|
|
|
'sibling' => $articleOne->id, |
60
|
|
|
'rank' => 2 |
61
|
|
|
]) |
62
|
|
|
->save(); |
63
|
|
|
Db::forTablePrefix('articles') |
64
|
|
|
->create() |
65
|
|
|
->set( |
66
|
|
|
[ |
67
|
|
|
'title' => 'Article One Brother', |
68
|
|
|
'alias' => 'article-one-brother', |
69
|
|
|
'language' => 'fr', |
70
|
|
|
'sibling' => $articleOne->id, |
71
|
|
|
'rank' => 2 |
72
|
|
|
]) |
73
|
|
|
->save(); |
74
|
|
|
$articleThree = Db::forTablePrefix('articles')->create(); |
75
|
|
|
$articleThree |
76
|
|
|
->set( |
77
|
|
|
[ |
78
|
|
|
'title' => 'Article Two', |
79
|
|
|
'alias' => 'article-two', |
80
|
|
|
'language' => 'en', |
81
|
|
|
'rank' => 3 |
82
|
|
|
]) |
83
|
|
|
->save(); |
84
|
|
|
Db::forTablePrefix('articles') |
85
|
|
|
->create() |
86
|
|
|
->set( |
87
|
|
|
[ |
88
|
|
|
'title' => 'Article Two Sister', |
89
|
|
|
'alias' => 'article-two-sister', |
90
|
|
|
'language' => 'de', |
91
|
|
|
'sibling' => $articleThree->id, |
92
|
|
|
'rank' => 4 |
93
|
|
|
]) |
94
|
|
|
->save(); |
95
|
|
|
Db::forTablePrefix('articles') |
96
|
|
|
->create() |
97
|
|
|
->set( |
98
|
|
|
[ |
99
|
|
|
'title' => 'Article Three', |
100
|
|
|
'alias' => 'article-three', |
101
|
|
|
'date' => 1456786800, |
102
|
|
|
'rank' => 5, |
103
|
|
|
'status' => 2 |
104
|
|
|
]) |
105
|
|
|
->save(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* tearDown |
110
|
|
|
* |
111
|
|
|
* @since 4.0.0 |
112
|
|
|
*/ |
113
|
|
|
|
114
|
|
|
public function tearDown() : void |
115
|
|
|
{ |
116
|
|
|
$this->dropDatabase(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* testGetAllByOrder |
121
|
|
|
* |
122
|
|
|
* @since 4.0.0 |
123
|
|
|
* |
124
|
|
|
* @param string $orderColumn |
125
|
|
|
* @param array $expectArray |
126
|
|
|
* |
127
|
|
|
* @dataProvider providerAutoloader |
128
|
|
|
*/ |
129
|
|
|
|
130
|
|
|
public function testGetAllByOrder(string $orderColumn = null, array $expectArray = []) : void |
131
|
|
|
{ |
132
|
|
|
/* setup */ |
133
|
|
|
|
134
|
|
|
$articleModel = new Model\Article(); |
135
|
|
|
|
136
|
|
|
/* actual */ |
137
|
|
|
|
138
|
|
|
$actualArray = []; |
139
|
|
|
$actualObject = $articleModel->getAllByOrder($orderColumn); |
140
|
|
|
|
141
|
|
|
/* process articles */ |
142
|
|
|
|
143
|
|
|
foreach ($actualObject as $value) |
|
|
|
|
144
|
|
|
{ |
145
|
|
|
$actualArray[] = $value->alias; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/* compare */ |
149
|
|
|
|
150
|
|
|
$this->assertEquals($expectArray, $actualArray); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* testGetByLanguageAndOrder |
155
|
|
|
* |
156
|
|
|
* @since 4.0.0 |
157
|
|
|
* |
158
|
|
|
* @param string $language |
159
|
|
|
* @param string $orderColumn |
160
|
|
|
* @param array $expectArray |
161
|
|
|
* |
162
|
|
|
* @dataProvider providerAutoloader |
163
|
|
|
*/ |
164
|
|
|
|
165
|
|
|
public function testGetByLanguageAndOrder(string $language = null, string $orderColumn = null, array $expectArray = []) : void |
166
|
|
|
{ |
167
|
|
|
/* setup */ |
168
|
|
|
|
169
|
|
|
$articleModel = new Model\Article(); |
170
|
|
|
|
171
|
|
|
/* actual */ |
172
|
|
|
|
173
|
|
|
$actualArray = []; |
174
|
|
|
$actualObject = $articleModel->getByLanguageAndOrder($language, $orderColumn); |
175
|
|
|
|
176
|
|
|
/* process articles */ |
177
|
|
|
|
178
|
|
|
foreach ($actualObject as $value) |
|
|
|
|
179
|
|
|
{ |
180
|
|
|
$actualArray[] = $value->alias; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/* compare */ |
184
|
|
|
|
185
|
|
|
$this->assertEquals($expectArray, $actualArray); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* testGetByLanguageAndOrder |
190
|
|
|
* |
191
|
|
|
* @since 4.0.0 |
192
|
|
|
* |
193
|
|
|
* @param int $contentId |
194
|
|
|
* @param string $language |
195
|
|
|
* @param string $orderColumn |
196
|
|
|
* @param array $expectArray |
197
|
|
|
* |
198
|
|
|
* @dataProvider providerAutoloader |
199
|
|
|
*/ |
200
|
|
|
|
201
|
|
|
public function testGetSiblingByIdAndLanguageAndOrder(int $contentId = null, string $language = null, string $orderColumn = null, array $expectArray = []) : void |
202
|
|
|
{ |
203
|
|
|
/* setup */ |
204
|
|
|
|
205
|
|
|
$articleModel = new Model\Article(); |
206
|
|
|
|
207
|
|
|
/* actual */ |
208
|
|
|
|
209
|
|
|
$actualArray = []; |
210
|
|
|
$actualObject = $articleModel->getSiblingByIdAndLanguageAndOrder($contentId, $language, $orderColumn); |
211
|
|
|
|
212
|
|
|
/* process articles */ |
213
|
|
|
|
214
|
|
|
foreach ($actualObject as $value) |
|
|
|
|
215
|
|
|
{ |
216
|
|
|
$actualArray[] = $value->alias; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/* compare */ |
220
|
|
|
|
221
|
|
|
$this->assertEquals($expectArray, $actualArray); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* testGetSiblingArrayById |
226
|
|
|
* |
227
|
|
|
* @since 4.0.0 |
228
|
|
|
* |
229
|
|
|
* @param int $contentId |
230
|
|
|
* @param array $expectArray |
231
|
|
|
* |
232
|
|
|
* @dataProvider providerAutoloader |
233
|
|
|
*/ |
234
|
|
|
|
235
|
|
|
public function testGetSiblingArrayById(int $contentId = null, array $expectArray = []) : void |
236
|
|
|
{ |
237
|
|
|
/* setup */ |
238
|
|
|
|
239
|
|
|
$articleModel = new Model\Article(); |
240
|
|
|
|
241
|
|
|
/* actual */ |
242
|
|
|
|
243
|
|
|
$actualArray = $articleModel->getSiblingArrayById($contentId); |
244
|
|
|
|
245
|
|
|
/* compare */ |
246
|
|
|
|
247
|
|
|
$this->assertEquals($expectArray, $actualArray); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* testPublishByDate |
252
|
|
|
* |
253
|
|
|
* @since 4.0.0 |
254
|
|
|
* |
255
|
|
|
* @param int $date |
256
|
|
|
* @param bool $expect |
257
|
|
|
* |
258
|
|
|
* @dataProvider providerAutoloader |
259
|
|
|
*/ |
260
|
|
|
|
261
|
|
|
public function testPublishByDate(int $date = null, bool $expect = null) : void |
262
|
|
|
{ |
263
|
|
|
/* setup */ |
264
|
|
|
|
265
|
|
|
$articleModel = new Model\Article(); |
266
|
|
|
|
267
|
|
|
/* actual */ |
268
|
|
|
|
269
|
|
|
$actual = $articleModel->publishByDate($date); |
270
|
|
|
|
271
|
|
|
/* compare */ |
272
|
|
|
|
273
|
|
|
$this->assertEquals($expect, $actual); |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.