1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpenOrchestra\FunctionalTests\ModelBundle\Repository; |
4
|
|
|
|
5
|
|
|
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractKernelTestCase; |
6
|
|
|
use OpenOrchestra\ModelInterface\Model\NodeInterface; |
7
|
|
|
use OpenOrchestra\ModelBundle\Repository\NodeRepository; |
8
|
|
|
use Phake; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class NodeRepositoryTest |
12
|
|
|
* |
13
|
|
|
* @group integrationTest |
14
|
|
|
*/ |
15
|
|
|
class NodeRepositoryTest extends AbstractKernelTestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var NodeRepository |
19
|
|
|
*/ |
20
|
|
|
protected $repository; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Set up test |
24
|
|
|
*/ |
25
|
|
|
protected function setUp() |
26
|
|
|
{ |
27
|
|
|
parent::setUp(); |
28
|
|
|
|
29
|
|
|
static::bootKernel(); |
30
|
|
|
$this->repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.node'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $language |
35
|
|
|
* @param int $version |
36
|
|
|
* @param string $siteId |
37
|
|
|
* |
38
|
|
|
* @dataProvider provideLanguageLastVersionAndSiteId |
39
|
|
|
*/ |
40
|
|
|
public function testFindOneCurrentlyPublished($language, $version, $siteId) |
41
|
|
|
{ |
42
|
|
|
$node = $this->repository->findOneCurrentlyPublished(NodeInterface::ROOT_NODE_ID, $language, $siteId); |
43
|
|
|
|
44
|
|
|
$this->assertSameNode($language, $version, $siteId, $node); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
|
View Code Duplication |
public function provideLanguageLastVersionAndSiteId() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
return array( |
53
|
|
|
array('en', 1, '2'), |
54
|
|
|
array('fr', 1, '2'), |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param $language |
60
|
|
|
* @param $version |
61
|
|
|
* @param $siteId |
62
|
|
|
* |
63
|
|
|
* @dataProvider provideLanguageLastVersionAndSiteId |
64
|
|
|
*/ |
65
|
|
|
public function testFindOneByNodeIdAndLanguageAndVersionAndSiteIdWithPublishedDataSet($language, $version, $siteId) |
66
|
|
|
{ |
67
|
|
|
$node = $this->repository->findVersion(NodeInterface::ROOT_NODE_ID, $language, $siteId, $version); |
68
|
|
|
|
69
|
|
|
$this->assertSameNode($language, $version, $siteId, $node); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string $language |
74
|
|
|
* @param int $version |
75
|
|
|
* @param string $siteId |
76
|
|
|
* @param int $versionExpected |
77
|
|
|
* |
78
|
|
|
* @dataProvider provideLanguageLastVersionAndSiteIdNotPublished |
79
|
|
|
*/ |
80
|
|
|
public function testFindOneByNodeIdAndLanguageAndVersionAndSiteIdWithNotPublishedDataSet($language, $version = null, $siteId, $versionExpected) |
81
|
|
|
{ |
82
|
|
|
$node = $this->repository->findVersion(NodeInterface::ROOT_NODE_ID, $language, $siteId, $version); |
83
|
|
|
|
84
|
|
|
$this->assertSameNode($language, $versionExpected, $siteId, $node); |
85
|
|
|
$this->assertSame('draft', $node->getStatus()->getName()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
View Code Duplication |
public function provideLanguageLastVersionAndSiteIdNotPublished() |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
return array( |
94
|
|
|
array('fr', 2, '2', 2), |
95
|
|
|
array('fr', null, '2', 2), |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string $language |
101
|
|
|
* @param int $version |
102
|
|
|
* @param string $siteId |
103
|
|
|
* @param int $versionExpected |
104
|
|
|
* |
105
|
|
|
* @dataProvider provideLanguageLastVersionAndSiteIdNotPublished |
106
|
|
|
*/ |
107
|
|
|
public function testFindInLastVersion($language, $version = null, $siteId, $versionExpected) |
|
|
|
|
108
|
|
|
{ |
109
|
|
|
$node = $this->repository->findInLastVersion(NodeInterface::ROOT_NODE_ID, $language, $siteId); |
110
|
|
|
|
111
|
|
|
$this->assertSameNode($language, $versionExpected, $siteId, $node); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param int $countVersions |
116
|
|
|
* @param string $language |
117
|
|
|
* @param string $siteId |
118
|
|
|
* |
119
|
|
|
* @dataProvider provideLanguageAndVersionListAndSiteId |
120
|
|
|
*/ |
121
|
|
|
public function testFindByNodeAndLanguageAndSite($countVersions, $language, $siteId) |
122
|
|
|
{ |
123
|
|
|
$nodes = $this->repository->findByNodeAndLanguageAndSite(NodeInterface::ROOT_NODE_ID, $language, $siteId); |
124
|
|
|
|
125
|
|
|
$this->assertCount($countVersions, $nodes); |
126
|
|
|
foreach ($nodes as $node) { |
127
|
|
|
$this->assertSameNode($language, $node->getVersion(), $siteId, $node); |
128
|
|
|
} |
129
|
|
|
if (count($nodes) > 1) { |
130
|
|
|
for ($i = 1; $i < count($nodes); $i++) { |
|
|
|
|
131
|
|
|
$this->assertGreaterThan($nodes[$i]->getVersion(), $nodes[$i-1]->getVersion()); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return array |
138
|
|
|
*/ |
139
|
|
View Code Duplication |
public function provideLanguageAndVersionListAndSiteId() |
|
|
|
|
140
|
|
|
{ |
141
|
|
|
return array( |
142
|
|
|
array(1, 'en', '2'), |
143
|
|
|
array(2, 'fr', '2'), |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param string $nodeId |
149
|
|
|
* @param string $siteId |
150
|
|
|
* @param int $count |
151
|
|
|
* |
152
|
|
|
* @dataProvider provideNodeSiteAndCount |
153
|
|
|
*/ |
154
|
|
|
public function testFindByNodeAndSite($nodeId, $siteId, $count) |
155
|
|
|
{ |
156
|
|
|
$this->assertCount($count, $this->repository->findByNodeAndSite($nodeId, $siteId)); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return array |
161
|
|
|
*/ |
162
|
|
|
public function provideNodeSiteAndCount() |
163
|
|
|
{ |
164
|
|
|
return array( |
165
|
|
|
array(NodeInterface::ROOT_NODE_ID, '2', 3), |
166
|
|
|
array(NodeInterface::TRANSVERSE_NODE_ID, '2', 3), |
167
|
|
|
array('fixture_page_what_is_orchestra', '2', 0), |
168
|
|
|
); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param string $parentId |
173
|
|
|
* @param string $siteId |
174
|
|
|
* @param int $count |
175
|
|
|
* |
176
|
|
|
* @dataProvider provideParentIdSiteIdAndCount |
177
|
|
|
*/ |
178
|
|
|
public function testFindByParent($parentId, $siteId, $count) |
179
|
|
|
{ |
180
|
|
|
$nodes = $this->repository->findByParent($parentId, $siteId); |
181
|
|
|
|
182
|
|
|
$this->assertGreaterThanOrEqual($count, count($nodes)); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return array |
187
|
|
|
*/ |
188
|
|
|
public function provideParentIdSiteIdAndCount() |
189
|
|
|
{ |
190
|
|
|
return array( |
191
|
|
|
array(NodeInterface::ROOT_NODE_ID, '2', 5), |
192
|
|
|
array('fixture_page_community', '2', 0), |
193
|
|
|
array(NodeInterface::TRANSVERSE_NODE_ID, '2', 0), |
194
|
|
|
array('fixture_page_what_is_orchestra', '2', 0), |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param string $path |
200
|
|
|
* @param string $siteId |
201
|
|
|
* @param int $count |
202
|
|
|
* |
203
|
|
|
* @dataProvider providePathSiteIdAndCount |
204
|
|
|
*/ |
205
|
|
|
public function testFindByIncludedPathAndSiteId($path, $siteId, $count) |
206
|
|
|
{ |
207
|
|
|
$nodes = $this->repository->findByIncludedPathAndSiteId($path, $siteId); |
208
|
|
|
|
209
|
|
|
$this->assertGreaterThanOrEqual($count, count($nodes)); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return array |
214
|
|
|
*/ |
215
|
|
|
public function providePathSiteIdAndCount() |
216
|
|
|
{ |
217
|
|
|
return array( |
218
|
|
|
array('root', '2', 5), |
219
|
|
|
array('root/fixture_page_community', '2', 0), |
220
|
|
|
array('transverse', '2', 0), |
221
|
|
|
); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param string $siteId |
226
|
|
|
* @param int $version |
227
|
|
|
* |
228
|
|
|
* @dataProvider provideSiteIdAndLastVersion |
229
|
|
|
*/ |
230
|
|
|
public function testFindLastVersionByType($siteId, $version) |
231
|
|
|
{ |
232
|
|
|
$nodes = $this->repository->findLastVersionByType($siteId); |
233
|
|
|
|
234
|
|
|
$this->assertSameNode('fr', $version, $siteId, $nodes[NodeInterface::ROOT_NODE_ID]); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @return array |
239
|
|
|
*/ |
240
|
|
|
public function provideSiteIdAndLastVersion() |
241
|
|
|
{ |
242
|
|
|
return array( |
243
|
|
|
array('2', 2), |
244
|
|
|
); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param string $language |
249
|
|
|
* @param int $version |
250
|
|
|
* @param string $siteId |
251
|
|
|
* @param NodeInterface $node |
252
|
|
|
* @param string $nodeId |
253
|
|
|
*/ |
254
|
|
|
protected function assertSameNode($language, $version, $siteId, $node, $nodeId = NodeInterface::ROOT_NODE_ID) |
255
|
|
|
{ |
256
|
|
|
$this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\NodeInterface', $node); |
257
|
|
|
$this->assertSame($nodeId, $node->getNodeId()); |
258
|
|
|
$this->assertSame($language, $node->getLanguage()); |
259
|
|
|
$this->assertSame($version, $node->getVersion()); |
260
|
|
|
$this->assertSame($siteId, $node->getSiteId()); |
261
|
|
|
$this->assertSame(false, $node->isDeleted()); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @param string $siteId |
266
|
|
|
* @param int $nodeNumber |
267
|
|
|
* @param int $version |
268
|
|
|
* @param string $language |
269
|
|
|
* @param string|null $nodeId |
270
|
|
|
* |
271
|
|
|
* @dataProvider provideForGetFooter() |
272
|
|
|
*/ |
273
|
|
View Code Duplication |
public function testGetFooterTree($siteId, $nodeNumber, $version, $language = 'fr', $nodeId = null) |
|
|
|
|
274
|
|
|
{ |
275
|
|
|
$nodes = $this->repository->getFooterTree($language, $siteId); |
276
|
|
|
$this->assertCount($nodeNumber, $nodes); |
277
|
|
|
if ($nodeId) { |
|
|
|
|
278
|
|
|
$this->assertSameNode($language, $version, $siteId, $nodes[$nodeId], $nodeId); |
279
|
|
|
$this->assertSame('published', $nodes[$nodeId]->getStatus()->getName()); |
280
|
|
|
} |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @return array |
285
|
|
|
*/ |
286
|
|
|
public function provideForGetFooter() |
287
|
|
|
{ |
288
|
|
|
return array( |
289
|
|
|
array('2', 1, 1, 'fr', 'fixture_page_legal_mentions'), |
290
|
|
|
array('2', 1, 1, 'en'), |
291
|
|
|
array('2', 1, 1), |
292
|
|
|
); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @param string $siteId |
297
|
|
|
* @param int $nodeNumber |
298
|
|
|
* @param int $version |
299
|
|
|
* @param string $language |
300
|
|
|
* |
301
|
|
|
* @dataProvider provideForGetMenu() |
302
|
|
|
*/ |
303
|
|
|
public function testGetMenuTree($siteId, $nodeNumber, $version, $language = 'fr') |
304
|
|
|
{ |
305
|
|
|
$nodes = $this->repository->getMenuTree($language, $siteId); |
306
|
|
|
|
307
|
|
|
$this->assertCount($nodeNumber, $nodes); |
308
|
|
|
$this->assertSameNode($language, $version, $siteId, $nodes[NodeInterface::ROOT_NODE_ID]); |
309
|
|
|
$this->assertSame('published', $nodes[NodeInterface::ROOT_NODE_ID]->getStatus()->getName()); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @return array |
314
|
|
|
*/ |
315
|
|
View Code Duplication |
public function provideForGetMenu() |
|
|
|
|
316
|
|
|
{ |
317
|
|
|
return array( |
318
|
|
|
array('2', 4, 1, 'fr'), |
319
|
|
|
array('2', 4, 1, 'en'), |
320
|
|
|
); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @param string $nodeId |
325
|
|
|
* @param int $nbLevel |
326
|
|
|
* @param int $nodeNumber |
327
|
|
|
* @param int $version |
328
|
|
|
* @param string $siteId |
329
|
|
|
* @param string $local |
330
|
|
|
* |
331
|
|
|
* @dataProvider provideForGetSubMenu |
332
|
|
|
*/ |
333
|
|
View Code Duplication |
public function testGetSubMenu($nodeId, $nbLevel, $nodeNumber, $version, $siteId, $local) |
|
|
|
|
334
|
|
|
{ |
335
|
|
|
$nodes = $this->repository->getSubMenu($nodeId, $nbLevel, $local, $siteId); |
336
|
|
|
|
337
|
|
|
$this->assertCount($nodeNumber, $nodes); |
338
|
|
|
if ($nodeNumber > 0) { |
339
|
|
|
$this->assertSameNode($local, $version, $siteId, $nodes[0], $nodeId); |
340
|
|
|
$this->assertSame('published', $nodes[0]->getStatus()->getName()); |
341
|
|
|
} |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @return array |
346
|
|
|
*/ |
347
|
|
|
public function provideForGetSubMenu() |
348
|
|
|
{ |
349
|
|
|
return array( |
350
|
|
|
array(NodeInterface::ROOT_NODE_ID, 1, 7, 1, '2', 'fr'), |
351
|
|
|
array(NodeInterface::ROOT_NODE_ID, 2, 7, 1, '2', 'fr'), |
352
|
|
|
array(NodeInterface::ROOT_NODE_ID, 0, 7, 1, '2', 'fr'), |
353
|
|
|
array(NodeInterface::ROOT_NODE_ID, 0, 7, 1, '2', 'en'), |
354
|
|
|
array('fixture_page_community', 1, 1, 1, '2', 'fr'), |
355
|
|
|
array('fixture_page_community', 1, 1, 1, '2', 'en'), |
356
|
|
|
array('page_unexistant', 1, 0, 1, '2', 'fr'), |
357
|
|
|
); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* @param string $language |
362
|
|
|
* @param string $siteId |
363
|
|
|
* @param int $count |
364
|
|
|
* |
365
|
|
|
* @dataProvider provideLanguageSiteIdAndCount |
366
|
|
|
*/ |
367
|
|
|
public function testFindCurrentlyPublishedVersion($language, $siteId, $count) |
368
|
|
|
{ |
369
|
|
|
$nodes = $this->repository->findCurrentlyPublishedVersion($language, $siteId); |
370
|
|
|
|
371
|
|
|
$this->assertCount($count, $nodes); |
372
|
|
|
foreach ($nodes as $node) { |
373
|
|
|
$this->assertSame($language, $node->getLanguage()); |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @return array |
379
|
|
|
*/ |
380
|
|
View Code Duplication |
public function provideLanguageSiteIdAndCount() |
|
|
|
|
381
|
|
|
{ |
382
|
|
|
return array( |
383
|
|
|
array('en', '2', 5), |
384
|
|
|
array('fr', '2', 5), |
385
|
|
|
); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* @param string $author |
390
|
|
|
* @param string $siteId |
391
|
|
|
* @param boolean|null $published |
392
|
|
|
* @param int $limit |
393
|
|
|
* @param array|null $sort |
394
|
|
|
* @param int $count |
395
|
|
|
* |
396
|
|
|
* @dataProvider provideFindByAuthorAndSiteId |
397
|
|
|
*/ |
398
|
|
|
public function testFindByAuthorAndSiteId($author, $siteId, $published, $limit, $sort, $count) |
399
|
|
|
{ |
400
|
|
|
$this->assertCount( |
401
|
|
|
$count, |
402
|
|
|
$this->repository->findByAuthorAndSiteId($author, $siteId, $published, $limit, $sort) |
403
|
|
|
); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* @return array |
408
|
|
|
*/ |
409
|
|
|
public function provideFindByAuthorAndSiteId() |
410
|
|
|
{ |
411
|
|
|
return array( |
412
|
|
|
array('fake_admin', '2', null, 10, array('updatedAt' => -1), 3), |
413
|
|
|
array('fake_admin', '2', false, 10, null, 1), |
414
|
|
|
array('fake_admin', '2', true, 10, null, 2), |
415
|
|
|
array('fake_admin', '2', true, 2, null, 2), |
416
|
|
|
array('fake_contributor', '2', false, 10, null, 0), |
417
|
|
|
array('fake_contributor', '2', null, 10, null, 0), |
418
|
|
|
array('fake_admin', '3', true, 10, null, 1), |
419
|
|
|
); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* @param string $nodeId |
424
|
|
|
* @param string $language |
425
|
|
|
* @param int $count |
426
|
|
|
* |
427
|
|
|
* @dataProvider provideFindPublishedSortedVersionData |
428
|
|
|
*/ |
429
|
|
|
public function testFindPublishedSortedByVersion($nodeId, $language, $count) |
430
|
|
|
{ |
431
|
|
|
$this->assertCount($count, $this->repository->findPublishedSortedByVersion($nodeId, $language, '2')); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* @return array |
436
|
|
|
*/ |
437
|
|
|
public function provideFindPublishedSortedVersionData() |
438
|
|
|
{ |
439
|
|
|
return array( |
440
|
|
|
array(NodeInterface::ROOT_NODE_ID, 'fr', 1), |
441
|
|
|
array(NodeInterface::ROOT_NODE_ID, 'en', 1), |
442
|
|
|
array('fixture_page_contact', 'en', 1), |
443
|
|
|
); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* @param string $language |
448
|
|
|
* |
449
|
|
|
* @dataProvider provideLanguage |
450
|
|
|
*/ |
451
|
|
|
public function testFindSubTreeByPath($language) |
452
|
|
|
{ |
453
|
|
|
$nodes = $this->repository->findSubTreeByPath('root', '2', $language); |
454
|
|
|
|
455
|
|
|
$this->assertCount(6, $nodes); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* @return array |
460
|
|
|
*/ |
461
|
|
|
public function provideLanguage() |
462
|
|
|
{ |
463
|
|
|
return array( |
464
|
|
|
array('en'), |
465
|
|
|
array('fr'), |
466
|
|
|
); |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* @param string $parentId |
471
|
|
|
* @param string $routePattern |
472
|
|
|
* @param string $nodeId |
473
|
|
|
* |
474
|
|
|
* @dataProvider provideParentRouteAndNodeId |
475
|
|
|
*/ |
476
|
|
|
public function testFindByParentAndRoutePattern($parentId, $routePattern, $nodeId) |
477
|
|
|
{ |
478
|
|
|
$this->assertEmpty($this->repository->findByParentAndRoutePattern($parentId, $routePattern, $nodeId, '2')); |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* @return array |
483
|
|
|
*/ |
484
|
|
|
public function provideParentRouteAndNodeId() |
485
|
|
|
{ |
486
|
|
|
return array( |
487
|
|
|
array(NodeInterface::ROOT_NODE_ID, 'page-contact', 'fixture_page_contact'), |
488
|
|
|
array(NodeInterface::ROOT_NODE_ID, 'mentions-legales', 'fixture_page_legal_mentions'), |
489
|
|
|
); |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* @param string $parentId |
494
|
|
|
* @param int $order |
495
|
|
|
* @param string $nodeId |
496
|
|
|
* @param bool $expectedValue |
497
|
|
|
* @param string $siteId |
498
|
|
|
* |
499
|
|
|
* @dataProvider provideParentAndOrder |
500
|
|
|
*/ |
501
|
|
|
public function testHasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $expectedValue, $siteId = '2') |
502
|
|
|
{ |
503
|
|
|
$this->assertSame($expectedValue, $this->repository->hasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $siteId)); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* @return array |
508
|
|
|
*/ |
509
|
|
|
public function provideParentAndOrder() |
510
|
|
|
{ |
511
|
|
|
return array( |
512
|
|
|
array(NodeInterface::ROOT_NODE_ID, 10, 'fixture_page_contact', true), |
513
|
|
|
array(NodeInterface::ROOT_NODE_ID, 0, 'fixture_page_contact', false), |
514
|
|
|
array('fixture_page_legal_mentions', 0, 'fakeID', false), |
515
|
|
|
array(NodeInterface::ROOT_NODE_ID, 0, 'fakeID', false, '3'), |
516
|
|
|
array(NodeInterface::TRANSVERSE_NODE_ID, 1, '-', false,), |
517
|
|
|
); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* @param string $type |
522
|
|
|
* @param int $count |
523
|
|
|
* |
524
|
|
|
* @dataProvider provideNodeTypeAndCount |
525
|
|
|
*/ |
526
|
|
|
public function testFindAllNodesOfTypeInLastPublishedVersionForSite($type, $count) |
527
|
|
|
{ |
528
|
|
|
$this->assertCount($count, $this->repository->findAllNodesOfTypeInLastPublishedVersionForSite($type, '2')); |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* @return array |
533
|
|
|
*/ |
534
|
|
|
public function provideNodeTypeAndCount() |
535
|
|
|
{ |
536
|
|
|
return array( |
537
|
|
|
array(NodeInterface::TYPE_DEFAULT, 14), |
538
|
|
|
array(NodeInterface::TYPE_ERROR, 6), |
539
|
|
|
array(NodeInterface::TYPE_TRANSVERSE, 0), |
540
|
|
|
); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
/** |
544
|
|
|
* Test has statused element |
545
|
|
|
*/ |
546
|
|
View Code Duplication |
public function testHasStatusedElement() |
|
|
|
|
547
|
|
|
{ |
548
|
|
|
$statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status'); |
549
|
|
|
$status = $statusRepository->findOneByInitial(); |
550
|
|
|
|
551
|
|
|
$this->assertTrue($this->repository->hasStatusedElement($status)); |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* Test find by site and defaultTheme |
556
|
|
|
*/ |
557
|
|
|
public function testFindBySiteIdAndDefaultTheme() |
558
|
|
|
{ |
559
|
|
|
$this->assertCount(0, $this->repository->findBySiteIdAndDefaultTheme('2', false)); |
560
|
|
|
$this->assertGreaterThanOrEqual(16, $this->repository->findBySiteIdAndDefaultTheme('2', true)); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* @param string $nodeId |
565
|
|
|
* @param string $language |
566
|
|
|
* |
567
|
|
|
* @dataProvider provideNodeIdAndLanguageForPublishedFlag |
568
|
|
|
*/ |
569
|
|
|
public function testfindAllCurrentlyPublishedByElementId($nodeId, $language) |
570
|
|
|
{ |
571
|
|
|
$node = Phake::mock(NodeInterface::CLASS); |
572
|
|
|
Phake::when($node)->getNodeId()->thenReturn($nodeId); |
573
|
|
|
Phake::when($node)->getLanguage()->thenReturn($language); |
574
|
|
|
Phake::when($node)->getSiteId()->thenReturn('2'); |
575
|
|
|
|
576
|
|
|
$this->assertCount(1, $this->repository->findAllCurrentlyPublishedByElementId($node)); |
|
|
|
|
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
/** |
580
|
|
|
* @return array |
581
|
|
|
*/ |
582
|
|
|
public function provideNodeIdAndLanguageForPublishedFlag() |
583
|
|
|
{ |
584
|
|
|
return array( |
585
|
|
|
'root in fr' => array(NodeInterface::ROOT_NODE_ID, 'fr'), |
586
|
|
|
'root in en' => array(NodeInterface::ROOT_NODE_ID, 'en'), |
587
|
|
|
'community in fr' => array('fixture_page_community', 'fr'), |
588
|
|
|
'community in en' => array('fixture_page_community', 'en'), |
589
|
|
|
); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* @param string $siteId |
594
|
|
|
* @param integer $expectedCount |
595
|
|
|
* |
596
|
|
|
* @dataProvider provideFindLastVersionByTypeCurrentlyPublished |
597
|
|
|
*/ |
598
|
|
|
public function testFindLastVersionByTypeCurrentlyPublished($siteId, $expectedCount) |
599
|
|
|
{ |
600
|
|
|
$this->assertCount($expectedCount, $this->repository->findLastVersionByTypeCurrentlyPublished($siteId)); |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* @return array |
605
|
|
|
*/ |
606
|
|
|
public function provideFindLastVersionByTypeCurrentlyPublished() |
607
|
|
|
{ |
608
|
|
|
return array( |
609
|
|
|
array("1", 0), |
610
|
|
|
array("2", 14), |
611
|
|
|
); |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
/** |
615
|
|
|
* @param string $path |
616
|
|
|
* @param string $siteId |
617
|
|
|
* @param integer $expectedCount |
618
|
|
|
* |
619
|
|
|
* @dataProvider provideFindByPathCurrentlyPublished |
620
|
|
|
*/ |
621
|
|
|
public function testFindByPathCurrentlyPublished($path, $siteId, $expectedCount) |
622
|
|
|
{ |
623
|
|
|
$this->assertCount($expectedCount, $this->repository->findByPathCurrentlyPublished($path, $siteId)); |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* @return array |
628
|
|
|
*/ |
629
|
|
View Code Duplication |
public function provideFindByPathCurrentlyPublished() |
|
|
|
|
630
|
|
|
{ |
631
|
|
|
return array( |
632
|
|
|
array("root", "2", 7), |
633
|
|
|
array("transverse", "2", 0), |
634
|
|
|
); |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
/** |
638
|
|
|
* @param string $path |
639
|
|
|
* @param string $siteId |
640
|
|
|
* @param string $language |
641
|
|
|
* @param integer $expectedCount |
642
|
|
|
* |
643
|
|
|
* @dataProvider provideFindByPathCurrentlyPublishedAndLanguage |
644
|
|
|
*/ |
645
|
|
|
public function testFindByPathCurrentlyPublishedAndLanguage($path, $siteId, $language, $expectedCount) |
646
|
|
|
{ |
647
|
|
|
$this->assertCount($expectedCount, $this->repository->findByPathCurrentlyPublishedAndLanguage($path, $siteId, $language)); |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
/** |
651
|
|
|
* @return array |
652
|
|
|
*/ |
653
|
|
View Code Duplication |
public function provideFindByPathCurrentlyPublishedAndLanguage() |
|
|
|
|
654
|
|
|
{ |
655
|
|
|
return array( |
656
|
|
|
array("root", "2", "en", 7), |
657
|
|
|
array("transverse", "2", "en", 0), |
658
|
|
|
); |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
/** |
662
|
|
|
* @param string $path |
663
|
|
|
* @param string $siteId |
664
|
|
|
* @param string $language |
665
|
|
|
* @param integer $expectedCount |
666
|
|
|
* |
667
|
|
|
* @dataProvider provideFindByIncludedPathSiteIdAndLanguage |
668
|
|
|
*/ |
669
|
|
|
public function testFindByIncludedPathSiteIdAndLanguage($path, $siteId, $language, $expectedCount) |
670
|
|
|
{ |
671
|
|
|
$this->assertCount($expectedCount, $this->repository->findByIncludedPathSiteIdAndLanguage($path, $siteId, $language)); |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
/** |
675
|
|
|
* @return array |
676
|
|
|
*/ |
677
|
|
View Code Duplication |
public function provideFindByIncludedPathSiteIdAndLanguage() |
|
|
|
|
678
|
|
|
{ |
679
|
|
|
return array( |
680
|
|
|
array("root", "2", "en", 7), |
681
|
|
|
array("transverse", "2", "en", 1), |
682
|
|
|
); |
683
|
|
|
} |
684
|
|
|
} |
685
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.