1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Tests\Model; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Db; |
5
|
|
|
use Redaxscript\Model; |
6
|
|
|
use Redaxscript\Tests\TestCaseAbstract; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* ArticleTest |
10
|
|
|
* |
11
|
|
|
* @since 4.0.0 |
12
|
|
|
* |
13
|
|
|
* @package Redaxscript |
14
|
|
|
* @category Tests |
15
|
|
|
* @author Henry Ruhs |
16
|
|
|
* |
17
|
|
|
* @covers Redaxscript\Model\Article |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
class ArticleTest 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 = $this->getOptionArray(); |
32
|
|
|
$installer = $this->installerFactory(); |
33
|
|
|
$installer->init(); |
34
|
|
|
$installer->rawCreate(); |
35
|
|
|
$installer->insertSettings($optionArray); |
36
|
|
|
$categoryOne = Db::forTablePrefix('categories')->create(); |
37
|
|
|
$categoryOne |
38
|
|
|
->set( |
39
|
|
|
[ |
40
|
|
|
'title' => 'Category One', |
41
|
|
|
'alias' => 'category-one' |
42
|
|
|
]) |
43
|
|
|
->save(); |
44
|
|
|
$categoryTwo = Db::forTablePrefix('categories')->create(); |
45
|
|
|
$categoryTwo |
46
|
|
|
->set( |
47
|
|
|
[ |
48
|
|
|
'title' => 'Category Two', |
49
|
|
|
'alias' => 'category-two', |
50
|
|
|
'language' => 'en', |
51
|
|
|
'parent' => $categoryOne->id |
52
|
|
|
]) |
53
|
|
|
->save(); |
54
|
|
|
$categoryTwoSister = Db::forTablePrefix('categories')->create(); |
55
|
|
|
$categoryTwoSister |
56
|
|
|
->set( |
57
|
|
|
[ |
58
|
|
|
'title' => 'Category Two Sister', |
59
|
|
|
'alias' => 'category-two-sister', |
60
|
|
|
'language' => 'de', |
61
|
|
|
'sibling' => $categoryTwo->id |
62
|
|
|
]) |
63
|
|
|
->save(); |
64
|
|
|
Db::forTablePrefix('articles') |
65
|
|
|
->create() |
66
|
|
|
->set( |
67
|
|
|
[ |
68
|
|
|
'title' => 'Article One', |
69
|
|
|
'alias' => 'article-one', |
70
|
|
|
'category' => $categoryOne->id |
71
|
|
|
]) |
72
|
|
|
->save(); |
73
|
|
|
Db::forTablePrefix('articles') |
74
|
|
|
->create() |
75
|
|
|
->set( |
76
|
|
|
[ |
77
|
|
|
'title' => 'Article Two', |
78
|
|
|
'alias' => 'article-two', |
79
|
|
|
'category' => $categoryTwo->id |
80
|
|
|
]) |
81
|
|
|
->save(); |
82
|
|
|
$articleThree = Db::forTablePrefix('articles')->create(); |
83
|
|
|
$articleThree |
84
|
|
|
->set( |
85
|
|
|
[ |
86
|
|
|
'title' => 'Article Three', |
87
|
|
|
'alias' => 'article-three', |
88
|
|
|
'language' => 'en', |
89
|
|
|
'category' => $categoryTwo->id |
90
|
|
|
]) |
91
|
|
|
->save(); |
92
|
|
|
Db::forTablePrefix('articles') |
93
|
|
|
->create() |
94
|
|
|
->set( |
95
|
|
|
[ |
96
|
|
|
'title' => 'Article Three Sister', |
97
|
|
|
'alias' => 'article-three-sister', |
98
|
|
|
'language' => 'de', |
99
|
|
|
'sibling' => $articleThree->id, |
100
|
|
|
'category' => $categoryTwoSister->id |
101
|
|
|
]) |
102
|
|
|
->save(); |
103
|
|
|
Db::forTablePrefix('articles') |
104
|
|
|
->create() |
105
|
|
|
->set( |
106
|
|
|
[ |
107
|
|
|
'title' => 'Article Four', |
108
|
|
|
'alias' => 'article-four' |
109
|
|
|
]) |
110
|
|
|
->save(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* tearDown |
115
|
|
|
* |
116
|
|
|
* @since 4.0.0 |
117
|
|
|
*/ |
118
|
|
|
|
119
|
|
|
public function tearDown() : void |
120
|
|
|
{ |
121
|
|
|
$this->dropDatabase(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* testGetByAlias |
126
|
|
|
* |
127
|
|
|
* @since 4.0.0 |
128
|
|
|
* |
129
|
|
|
* @param string $articleAlias |
130
|
|
|
* @param int $expect |
131
|
|
|
* |
132
|
|
|
* @dataProvider providerAutoloader |
133
|
|
|
*/ |
134
|
|
|
|
135
|
|
|
public function testGetByAlias(string $articleAlias = null, int $expect = null) : void |
136
|
|
|
{ |
137
|
|
|
/* setup */ |
138
|
|
|
|
139
|
|
|
$articleModel = new Model\Article(); |
140
|
|
|
|
141
|
|
|
/* actual */ |
142
|
|
|
|
143
|
|
|
$actual = $articleModel->getByAlias($articleAlias)?->id; |
|
|
|
|
144
|
|
|
|
145
|
|
|
/* compare */ |
146
|
|
|
|
147
|
|
|
$this->assertEquals($expect, $actual); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* |
152
|
|
|
* testCountByCategoryAndLanguage |
153
|
|
|
* |
154
|
|
|
* @since 4.0.0 |
155
|
|
|
* |
156
|
|
|
* @param int $categoryId |
157
|
|
|
* @param string $language |
158
|
|
|
* @param int $expect |
159
|
|
|
* |
160
|
|
|
* @dataProvider providerAutoloader |
161
|
|
|
*/ |
162
|
|
|
|
163
|
|
|
public function testCountByCategoryAndLanguage(int $categoryId = null, string $language = null, int $expect = null) : void |
164
|
|
|
{ |
165
|
|
|
/* setup */ |
166
|
|
|
|
167
|
|
|
$articleModel = new Model\Article(); |
168
|
|
|
|
169
|
|
|
/* actual */ |
170
|
|
|
|
171
|
|
|
$actual = $articleModel->countByCategoryAndLanguage($categoryId, $language); |
172
|
|
|
|
173
|
|
|
/* compare */ |
174
|
|
|
|
175
|
|
|
$this->assertEquals($expect, $actual); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* testGetSiblingByCategoryAndLanguageAndOrderAndStep |
180
|
|
|
* |
181
|
|
|
* @since 4.0.0 |
182
|
|
|
* |
183
|
|
|
* @param int $categoryId |
184
|
|
|
* @param string $language |
185
|
|
|
* @param string $orderColumn |
186
|
|
|
* @param int $limitStep |
187
|
|
|
* @param array $expectArray |
188
|
|
|
* |
189
|
|
|
* @dataProvider providerAutoloader |
190
|
|
|
*/ |
191
|
|
|
|
192
|
|
|
public function testGetSiblingByCategoryAndLanguageAndOrderAndStep(int $categoryId = null, string $language = null, string $orderColumn = null, int $limitStep = null, array $expectArray = []) : void |
193
|
|
|
{ |
194
|
|
|
/* setup */ |
195
|
|
|
|
196
|
|
|
$articleModel = new Model\Article(); |
197
|
|
|
$setting = $this->settingFactory(); |
198
|
|
|
$setting->set('limit', 1); |
199
|
|
|
|
200
|
|
|
/* actual */ |
201
|
|
|
|
202
|
|
|
$actualArray = []; |
203
|
|
|
$actualObject = $articleModel->getSiblingByCategoryAndLanguageAndOrderAndStep($categoryId, $language, $orderColumn, $limitStep); |
204
|
|
|
|
205
|
|
|
/* process articles */ |
206
|
|
|
|
207
|
|
|
foreach ($actualObject as $value) |
208
|
|
|
{ |
209
|
|
|
$actualArray[] = $value->alias ?? null; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/* compare */ |
213
|
|
|
|
214
|
|
|
$this->assertEquals($expectArray, $actualArray); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* testGetRouteById |
219
|
|
|
* |
220
|
|
|
* @since 4.0.0 |
221
|
|
|
* |
222
|
|
|
* @param int $articleId |
223
|
|
|
* @param string $expect |
224
|
|
|
* |
225
|
|
|
* @dataProvider providerAutoloader |
226
|
|
|
*/ |
227
|
|
|
|
228
|
|
|
public function testGetRouteById(int $articleId = null, string $expect = null) : void |
229
|
|
|
{ |
230
|
|
|
/* setup */ |
231
|
|
|
|
232
|
|
|
$articleModel = new Model\Article(); |
233
|
|
|
|
234
|
|
|
/* actual */ |
235
|
|
|
|
236
|
|
|
$actual = $articleModel->getRouteById($articleId); |
237
|
|
|
|
238
|
|
|
/* compare */ |
239
|
|
|
|
240
|
|
|
$this->assertEquals($expect, $actual); |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|