These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace OpenOrchestra\FunctionalTests\ModelBundle\Repository; |
||
4 | |||
5 | use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractKernelTestCase; |
||
6 | use OpenOrchestra\Pagination\Configuration\FinderConfiguration; |
||
7 | use OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration; |
||
8 | use OpenOrchestra\ModelInterface\Repository\ContentRepositoryInterface; |
||
9 | use OpenOrchestra\ModelInterface\Repository\RepositoryTrait\KeywordableTraitInterface; |
||
10 | use OpenOrchestra\ModelInterface\ContentEvents; |
||
11 | use Phake; |
||
12 | use OpenOrchestra\ModelBundle\Document\ContentType; |
||
13 | use OpenOrchestra\ModelBundle\Document\Content; |
||
14 | |||
15 | /** |
||
16 | * Class ContentRepositoryTest |
||
17 | * |
||
18 | * @group integrationTest |
||
19 | */ |
||
20 | class ContentRepositoryTest extends AbstractKernelTestCase |
||
21 | { |
||
22 | /** |
||
23 | * @var ContentRepositoryInterface |
||
24 | */ |
||
25 | protected $repository; |
||
26 | protected $keywordRepository; |
||
27 | protected $userRepository; |
||
28 | protected $statusRepository; |
||
29 | protected $contentTypeRepository; |
||
30 | |||
31 | protected $currentsiteManager; |
||
32 | |||
33 | /** |
||
34 | * Set up test |
||
35 | */ |
||
36 | protected function setUp() |
||
37 | { |
||
38 | parent::setUp(); |
||
39 | static::bootKernel(); |
||
40 | $this->keywordRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.keyword'); |
||
41 | $this->userRepository = static::$kernel->getContainer()->get('open_orchestra_user.repository.user'); |
||
42 | $this->currentsiteManager = Phake::mock('OpenOrchestra\BaseBundle\Context\CurrentSiteIdInterface'); |
||
43 | Phake::when($this->currentsiteManager)->getCurrentSiteId()->thenReturn('2'); |
||
44 | Phake::when($this->currentsiteManager)->getCurrentSiteDefaultLanguage()->thenReturn('fr'); |
||
45 | |||
46 | $this->repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.content'); |
||
47 | $this->statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status'); |
||
48 | $this->contentTypeRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.content_type'); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param string $name |
||
53 | * @param boolean $exists |
||
54 | * |
||
55 | * @dataProvider provideTestUniquenessInContext |
||
56 | */ |
||
57 | public function testTestUniquenessInContext($name, $exists) |
||
58 | { |
||
59 | $test = $this->repository->testUniquenessInContext($name); |
||
60 | |||
61 | $this->assertEquals($exists, $test); |
||
62 | |||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return array |
||
67 | */ |
||
68 | public function provideTestUniquenessInContext() |
||
69 | { |
||
70 | return array( |
||
71 | array('welcome', true), |
||
72 | array('fakeContentId', false), |
||
73 | ); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param string $contentId |
||
78 | * |
||
79 | * @dataProvider provideFindOneByContentId |
||
80 | */ |
||
81 | public function testFindOneByContentId($contentId) |
||
82 | { |
||
83 | $content = $this->repository->findOneByContentId($contentId); |
||
84 | $this->assertSameContent(null, null, null, $contentId, $content); |
||
85 | $this->assertEquals($contentId, $content->getContentId()); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @return array |
||
90 | */ |
||
91 | public function provideFindOneByContentId() |
||
92 | { |
||
93 | return array( |
||
94 | array('notre_vision'), |
||
95 | array('bien_vivre_en_france'), |
||
96 | ); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param $contentId |
||
101 | * @param $version |
||
102 | * @param string|null $language |
||
103 | * |
||
104 | * @dataProvider providefindLastPublishedVersion |
||
105 | */ |
||
106 | public function testFindLastPublishedVersion($contentId, $version, $language) |
||
107 | { |
||
108 | $content = $this->repository->findLastPublishedVersion($contentId, $language); |
||
109 | $this->assertSameContent($language, $version, null, $contentId, $content); |
||
110 | $this->assertEquals($contentId, $content->getContentId()); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @param $contentId |
||
115 | * @param $version |
||
116 | * @param string|null $language |
||
117 | * |
||
118 | * @dataProvider providefindLastPublishedVersion |
||
119 | */ |
||
120 | public function testFindOneCurrentlyPublished($contentId, $version, $language) |
||
121 | { |
||
122 | $content = $this->repository->findOneCurrentlyPublished($contentId, $language, '2'); |
||
123 | $this->assertSameContent($language, $version, null, $contentId, $content); |
||
124 | $this->assertEquals($contentId, $content->getContentId()); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @return array |
||
129 | */ |
||
130 | View Code Duplication | public function providefindLastPublishedVersion() |
|
131 | { |
||
132 | return array( |
||
133 | array('notre_vision', 1, 'fr'), |
||
134 | array('bien_vivre_en_france', 1, 'fr'), |
||
135 | ); |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @param string $contentType |
||
140 | * @param string $choiceType |
||
141 | * @param string|null $keywords |
||
142 | * @param int $count |
||
143 | * |
||
144 | * @dataProvider provideContentTypeKeywordAndCount |
||
145 | */ |
||
146 | public function testFindByContentTypeAndCondition($contentType = '', $choiceType, $keywords = null, $count) |
||
147 | { |
||
148 | $keywords = $this->replaceKeywordLabelById($keywords); |
||
149 | |||
150 | $language = $this->currentsiteManager->getCurrentSiteDefaultLanguage(); |
||
151 | $elements = $this->repository->findByContentTypeAndCondition($language, $contentType, $choiceType, $keywords); |
||
152 | |||
153 | $this->assertCount($count, $elements); |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @return array |
||
158 | */ |
||
159 | public function provideContentTypeKeywordAndCount() |
||
160 | { |
||
161 | return array( |
||
162 | array('car', ContentRepositoryInterface::CHOICE_AND, 'lorem', 3), |
||
163 | array('car',ContentRepositoryInterface::CHOICE_AND, 'sit', 1), |
||
164 | array('car', ContentRepositoryInterface::CHOICE_AND, 'dolor', 0), |
||
165 | array('car', ContentRepositoryInterface::CHOICE_AND, 'sit AND lorem', 1), |
||
166 | array('news', ContentRepositoryInterface::CHOICE_AND, 'lorem', 1), |
||
167 | array('news', ContentRepositoryInterface::CHOICE_AND, 'sit', 2), |
||
168 | array('news', ContentRepositoryInterface::CHOICE_AND, 'dolor', 0), |
||
169 | array('news', ContentRepositoryInterface::CHOICE_AND, 'lorem AND sit', 1), |
||
170 | array('news', ContentRepositoryInterface::CHOICE_AND, '', 4), |
||
171 | array('car', ContentRepositoryInterface::CHOICE_AND, '', 3), |
||
172 | array('', ContentRepositoryInterface::CHOICE_AND, '', 9), |
||
173 | array('', ContentRepositoryInterface::CHOICE_AND, '', 9), |
||
174 | array('', ContentRepositoryInterface::CHOICE_AND, 'lorem', 5), |
||
175 | array('', ContentRepositoryInterface::CHOICE_AND, 'sit', 4), |
||
176 | array('', ContentRepositoryInterface::CHOICE_AND, 'dolor', 0), |
||
177 | array('', ContentRepositoryInterface::CHOICE_AND, 'lorem AND sit', 3), |
||
178 | array('car', ContentRepositoryInterface::CHOICE_OR, 'lorem', 5), |
||
179 | array('car', ContentRepositoryInterface::CHOICE_OR, 'sit', 6), |
||
180 | array('car', ContentRepositoryInterface::CHOICE_OR, 'dolor', 3), |
||
181 | array('car', ContentRepositoryInterface::CHOICE_OR, 'lorem AND sit', 5), |
||
182 | array('news', ContentRepositoryInterface::CHOICE_OR, 'lorem', 8), |
||
183 | array('news', ContentRepositoryInterface::CHOICE_OR, 'sit', 6), |
||
184 | array('news', ContentRepositoryInterface::CHOICE_OR, 'dolor', 4), |
||
185 | array('news', ContentRepositoryInterface::CHOICE_OR, 'lorem AND sit', 6), |
||
186 | array('news', ContentRepositoryInterface::CHOICE_OR, '', 4), |
||
187 | array('car', ContentRepositoryInterface::CHOICE_OR, '', 3), |
||
188 | array('', ContentRepositoryInterface::CHOICE_OR, '', 9), |
||
189 | array('', ContentRepositoryInterface::CHOICE_OR, 'lorem', 5), |
||
190 | array('', ContentRepositoryInterface::CHOICE_OR, 'sit', 4), |
||
191 | array('', ContentRepositoryInterface::CHOICE_OR, 'dolor', 0), |
||
192 | array('', ContentRepositoryInterface::CHOICE_OR, 'lorem AND sit', 3), |
||
193 | array('', ContentRepositoryInterface::CHOICE_OR, '', 9), |
||
194 | ); |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * @param string $contentId |
||
199 | * @param string $language |
||
200 | * |
||
201 | * @dataProvider provideFindOneByContentIdAndLanguage |
||
202 | */ |
||
203 | public function testFindOneByLanguage($contentId, $language) |
||
204 | { |
||
205 | $content = $this->repository->findOneByLanguage($contentId, $language); |
||
206 | |||
207 | $this->assertSameContent($language, null, null, $contentId, $content); |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * @return array |
||
212 | */ |
||
213 | public function provideFindOneByContentIdAndLanguage() |
||
214 | { |
||
215 | return array( |
||
216 | array('notre_vision', 'fr'), |
||
217 | array('bien_vivre_en_france', 'fr'), |
||
218 | ); |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * @param string $contentId |
||
223 | * @param string $language |
||
224 | * |
||
225 | * @dataProvider provideFindByContentIdAndLanguage |
||
226 | */ |
||
227 | public function testFindByLanguage($contentId, $language) |
||
228 | { |
||
229 | $contents = $this->repository->findByLanguage($contentId, $language); |
||
230 | |||
231 | foreach ($contents as $content) { |
||
232 | $this->assertSameContent($language, null, null, $contentId, $content); |
||
233 | } |
||
234 | |||
235 | } |
||
236 | |||
237 | /** |
||
238 | * @return array |
||
239 | */ |
||
240 | public function provideFindByContentIdAndLanguage() |
||
241 | { |
||
242 | return array( |
||
243 | array('notre_vision', 'fr'), |
||
244 | array('bien_vivre_en_france', 'fr'), |
||
245 | ); |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * @param string $contentId |
||
250 | * @param string $language |
||
251 | * @param int $version |
||
252 | * |
||
253 | * @dataProvider provideFindOneByContentIdAndLanguageAndVersion |
||
254 | */ |
||
255 | public function testFindOneByLanguageAndVersion($contentId, $language, $version) |
||
256 | { |
||
257 | $content = $this->repository->findOneByLanguageAndVersion($contentId, $language, $version); |
||
258 | |||
259 | $this->assertSameContent($language, $version, null, $contentId, $content); |
||
260 | |||
261 | } |
||
262 | |||
263 | /** |
||
264 | * @return array |
||
265 | */ |
||
266 | View Code Duplication | public function provideFindOneByContentIdAndLanguageAndVersion() |
|
267 | { |
||
268 | return array( |
||
269 | array('notre_vision', 'fr', 1), |
||
270 | array('bien_vivre_en_france', 'fr', 1), |
||
271 | ); |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * @param string $contentType |
||
276 | * @param array $descriptionEntity |
||
277 | * @param array $search |
||
278 | * @param string $siteId |
||
279 | * @param int $skip |
||
280 | * @param int $limit |
||
281 | * @param integer $count |
||
282 | * |
||
283 | * @dataProvider provideContentTypeAndPaginateAndSearchAndsiteId |
||
284 | */ |
||
285 | public function testFindPaginatedLastVersionByContentTypeAndsite($contentType, $descriptionEntity, $search, $order, $siteId, $skip, $limit, $count, $name = null) |
||
286 | { |
||
287 | $this->markTestSkipped('To unskip when group list is refacto'); |
||
288 | $configuration = PaginateFinderConfiguration::generateFromVariable($descriptionEntity, $search); |
||
289 | $configuration->setPaginateConfiguration($order, $skip, $limit); |
||
290 | $contents = $this->repository->findPaginatedLastVersionByContentTypeAndsite($contentType, $configuration, $siteId); |
||
291 | |||
292 | if(!is_null($name)) { |
||
293 | $this->assertEquals($name, $contents[0]->getName()); |
||
294 | } |
||
295 | $this->assertCount($count, $contents); |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * @return array |
||
300 | */ |
||
301 | public function provideContentTypeAndPaginateAndSearchAndsiteId() |
||
302 | { |
||
303 | $descriptionEntity = $this->getDescriptionColumnEntity(); |
||
304 | |||
305 | return array( |
||
306 | 1 => array('car', $descriptionEntity, null, array("name" => "name", "dir" => "asc"), null, 0 ,5 , 3, '206 3 portes en'), |
||
307 | 2 => array('car', $descriptionEntity, null, array("name" => "name", "dir" => "desc"), null, 0 ,5 , 3, 'R5 3 portes en'), |
||
308 | 3 => array('car', $descriptionEntity, null, array("name" => "attributes.car_name.string_value", "dir" => "asc"), null, 0 ,5 , 3, '206 3 portes en'), |
||
309 | 4 => array('car', $descriptionEntity, null, array("name" => "attributes.car_name.string_value", "dir" => "desc"), null, 0 ,5 , 3, 'R5 3 portes en'), |
||
310 | 5 => array('car', $descriptionEntity, null, null, null, 0 ,1 , 1), |
||
311 | 6 => array('car', $descriptionEntity, $this->generateColumnsProvider(array('name' => '206')), null, null, 0 ,2 , 1), |
||
312 | 7 => array('car', $descriptionEntity, $this->generateColumnsProvider(array('version' => '2')), null, null, 0 ,2 , 2), |
||
313 | 8 => array('news', $descriptionEntity, null, null, null, 0 , 100, 4), |
||
314 | 9 => array('news', $descriptionEntity, null, null, null, 50 , 100, 0), |
||
315 | 10 => array('news', $descriptionEntity, $this->generateColumnsProvider(array('name' => 'news')), null, null, 0 , null, 0), |
||
316 | 11 => array('car', $descriptionEntity, null, null, '2', 0 ,5 , 3), |
||
317 | 12 => array('car', $descriptionEntity, $this->generateColumnsProvider(array('status_label' => 'publish')), null, null, null ,null , 3), |
||
318 | 13 => array('car', $descriptionEntity, $this->generateColumnsProvider(array('status_label' => 'Publi')), null, null, null ,null , 3), |
||
319 | 14 => array('car', $descriptionEntity, $this->generateColumnsProvider(array('status_label' => 'draft')), null, null, null ,null , 0), |
||
320 | 15 => array('car', $descriptionEntity, $this->generateColumnsProvider(array('status_label' => 'brouillon')), null, null, null ,null , 0), |
||
321 | |||
322 | ); |
||
323 | } |
||
324 | |||
325 | /** |
||
326 | * @param string $contentType |
||
327 | * @param string $siteId |
||
328 | * @param integer $count |
||
329 | * |
||
330 | * @dataProvider provideCountByContentTypeAndSiteInLastVersion |
||
331 | */ |
||
332 | public function testCountByContentTypeAndSiteInLastVersion($contentType, $siteId, $count) |
||
333 | { |
||
334 | $contents = $this->repository->countByContentTypeAndSiteInLastVersion($contentType, $siteId); |
||
335 | $this->assertEquals($count, $contents); |
||
336 | } |
||
337 | |||
338 | /** |
||
339 | * @return array |
||
340 | */ |
||
341 | public function provideCountByContentTypeAndSiteInLastVersion() |
||
342 | { |
||
343 | return array( |
||
344 | array('car', '1', 2), |
||
345 | array('car', '2', 3), |
||
346 | array('customer', '1', 1), |
||
347 | array('customer', '2', 1), |
||
348 | array('news', '1', 3), |
||
349 | array('news', '2', 4), |
||
350 | ); |
||
351 | } |
||
352 | |||
353 | /** |
||
354 | * @param string $contentType |
||
355 | * @param array $descriptionEntity |
||
356 | * @param string $search |
||
357 | * @param string $siteId |
||
358 | * @param int $count |
||
359 | * |
||
360 | * @dataProvider provideColumnsAndSearchAndCount |
||
361 | */ |
||
362 | public function testCountByContentTypeInLastVersionWithSearchFilter( |
||
363 | $contentType, |
||
364 | $descriptionEntity, |
||
365 | $search, |
||
366 | $siteId, |
||
367 | $count |
||
368 | ) { |
||
369 | $this->markTestSkipped('To unskip when group list is refacto'); |
||
370 | $configuration = FinderConfiguration::generateFromVariable($descriptionEntity, $search); |
||
371 | $contents = $this->repository->countByContentTypeInLastVersionWithFilter($contentType, $configuration, $siteId); |
||
372 | $this->assertEquals($count, $contents); |
||
373 | } |
||
374 | /** |
||
375 | * @return array |
||
376 | */ |
||
377 | public function provideColumnsAndSearchAndCount() |
||
378 | { |
||
379 | $descriptionEntity = $this->getDescriptionColumnEntity(); |
||
380 | return array( |
||
381 | array('car', $descriptionEntity, $this->generateColumnsProvider(array('name' => '206')), '1', 1), |
||
382 | array('car', $descriptionEntity, $this->generateColumnsProvider(array('name' => '206')), '2', 1), |
||
383 | array('car', $descriptionEntity, $this->generateColumnsProvider(array('name' => 'DS 3')), '1', 0), |
||
384 | array('car', $descriptionEntity, $this->generateColumnsProvider(array('name' => 'DS 3')), '2', 1), |
||
385 | array('car', $descriptionEntity, $this->generateColumnsProvider(null, 'portes'), '1', 2), |
||
386 | array('car', $descriptionEntity, $this->generateColumnsProvider(null, 'portes'), '2', 2), |
||
387 | array('news', $descriptionEntity, $this->generateColumnsProvider(null, 'news'), '1', 0), |
||
388 | array('news', $descriptionEntity, $this->generateColumnsProvider(null, 'news'), '2', 0), |
||
389 | array('news', $descriptionEntity, $this->generateColumnsProvider(null, 'lorem'), '1', 1), |
||
390 | array('news', $descriptionEntity, $this->generateColumnsProvider(null, 'lorem'), '2', 1), |
||
391 | ); |
||
392 | } |
||
393 | |||
394 | /** |
||
395 | * @param string $user |
||
396 | * @param string $siteId |
||
397 | * @param array $eventTypes |
||
398 | * @param boolean|null $published |
||
399 | * @param int $limit |
||
400 | * @param array|null $sort |
||
401 | * @param int $count |
||
402 | * |
||
403 | * @dataProvider provideFindByHistoryAndSiteId |
||
404 | */ |
||
405 | View Code Duplication | public function testFindByHistoryAndSiteId($user, $siteId, array $eventTypes, $published, $limit, $sort, $count) |
|
406 | { |
||
407 | $user = $this->userRepository->findOneByUsername($user); |
||
408 | |||
409 | $contents = $this->repository->findByHistoryAndSiteId($user->getId(), $siteId, $eventTypes, $published, $limit, $sort); |
||
410 | $this->assertCount($count, $contents); |
||
411 | } |
||
412 | |||
413 | /** |
||
414 | * @return array |
||
415 | */ |
||
416 | public function provideFindByHistoryAndSiteId() |
||
417 | { |
||
418 | return array( |
||
419 | 1 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION), null, 10, array('updatedAt' => -1), 0), |
||
420 | 2 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION), false, 10, null, 0), |
||
421 | 3 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION), true, 10, null, 0), |
||
422 | 4 => array('p-admin', '2', array(ContentEvents::CONTENT_UPDATE), true, 10, null, 0), |
||
423 | 5 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION, ContentEvents::CONTENT_UPDATE), true, 10, null, 0), |
||
424 | ); |
||
425 | } |
||
426 | |||
427 | /** |
||
428 | * test updateStatusByContentType |
||
429 | */ |
||
430 | public function testUpdateStatusByContentType() |
||
431 | { |
||
432 | $contentTypeId = 'test'; |
||
433 | |||
434 | $outOfWorkflow = $this->statusRepository->findOneByOutOfWorkflow(); |
||
435 | |||
436 | $dm = $this->contentTypeRepository->getDocumentManager(); |
||
437 | |||
438 | $contentType = new ContentType(); |
||
439 | $contentType->setContentTypeId($contentTypeId); |
||
440 | $dm->persist($contentType); |
||
441 | $dm->flush(); |
||
442 | |||
443 | $content = new Content(); |
||
444 | $content->setContentType($contentTypeId); |
||
445 | $dm->persist($content); |
||
446 | $dm->flush(); |
||
447 | |||
448 | $this->assertEquals('draft', $content->getStatus()->getName()); |
||
449 | |||
450 | $this->repository->updateStatusByContentType($outOfWorkflow, $contentTypeId); |
||
451 | $dm->clear(); |
||
452 | |||
453 | $updatedContent = $this->repository->findOneBy(array('_id' => $content->getId())); |
||
454 | $this->assertEquals('outOfWorkflow', $updatedContent->getStatus()->getName()); |
||
455 | |||
456 | $contentType = $this->contentTypeRepository->findOneBy(array('contentTypeId' => $contentTypeId)); |
||
457 | |||
458 | $dm->remove($updatedContent); |
||
459 | $dm->remove($contentType); |
||
460 | $dm->flush(); |
||
461 | } |
||
462 | |||
463 | /** |
||
464 | * Generate columns of content with search value |
||
465 | * |
||
466 | * @param array|null $searchColumns |
||
467 | * @param string $globalSearch |
||
468 | * |
||
469 | * @return array |
||
470 | */ |
||
471 | View Code Duplication | protected function generateColumnsProvider($searchColumns = null, $globalSearch = '') |
|
472 | { |
||
473 | $search = array(); |
||
474 | if (null !== $searchColumns) { |
||
475 | $columns = array(); |
||
476 | foreach ($searchColumns as $name => $value) { |
||
477 | $columns[$name] = $value; |
||
478 | } |
||
479 | $search['columns'] = $columns; |
||
480 | } |
||
481 | |||
482 | if (!empty($globalSearch)) { |
||
483 | $search['global'] = $globalSearch; |
||
484 | } |
||
485 | |||
486 | return $search; |
||
487 | } |
||
488 | |||
489 | /** |
||
490 | * Generate relation between columns names and entities attributes |
||
491 | * |
||
492 | * @return array |
||
493 | */ |
||
494 | protected function getDescriptionColumnEntity() |
||
495 | { |
||
496 | return array ( |
||
497 | 'name' => |
||
498 | array ( |
||
499 | 'key' => 'name', |
||
500 | 'field' => 'name', |
||
501 | 'type' => 'string', |
||
502 | ), |
||
503 | 'language' => |
||
504 | array ( |
||
505 | 'key' => 'language', |
||
506 | 'field' => 'language', |
||
507 | 'type' => 'string', |
||
508 | ), |
||
509 | 'status_label' => |
||
510 | array ( |
||
511 | 'key' => 'status_label', |
||
512 | 'field' => 'status', |
||
513 | 'type' => 'multiLanguages', |
||
514 | ), |
||
515 | 'version' => |
||
516 | array ( |
||
517 | 'key' => 'version', |
||
518 | 'field' => 'version', |
||
519 | 'type' => 'integer', |
||
520 | ), |
||
521 | 'linked_to_site' => |
||
522 | array ( |
||
523 | 'key' => 'linked_to_site', |
||
524 | 'field' => 'linkedTosite', |
||
525 | 'type' => 'boolean', |
||
526 | ), |
||
527 | 'created_by' => |
||
528 | array ( |
||
529 | 'key' => 'created_by', |
||
530 | 'field' => 'createdBy', |
||
531 | 'type' => 'string', |
||
532 | ), |
||
533 | 'updated_by' => |
||
534 | array ( |
||
535 | 'key' => 'updated_by', |
||
536 | 'field' => 'updatedBy', |
||
537 | 'type' => 'string', |
||
538 | ), |
||
539 | 'created_at' => |
||
540 | array ( |
||
541 | 'key' => 'created_at', |
||
542 | 'field' => 'createdAt', |
||
543 | 'type' => 'date', |
||
544 | ), |
||
545 | 'updated_at' => |
||
546 | array ( |
||
547 | 'key' => 'updated_at', |
||
548 | 'field' => 'updatedAt', |
||
549 | 'type' => 'date', |
||
550 | ), |
||
551 | 'deleted' => |
||
552 | array ( |
||
553 | 'key' => 'deleted', |
||
554 | 'field' => 'deleted', |
||
555 | 'type' => 'boolean', |
||
556 | ), |
||
557 | 'attributes.car_name.string_value' => |
||
558 | array( |
||
559 | 'key' => 'attributes.car_name.string_value', |
||
560 | 'field' => 'attributes.car_name.stringValue', |
||
561 | 'type' => 'string', |
||
562 | 'value' => NULL, |
||
563 | ), |
||
564 | 'attributes.description.string_value' => |
||
565 | array( |
||
566 | 'key' => 'attributes.description.string_value', |
||
567 | 'field' => 'attributes.description.stringValue', |
||
568 | 'type' => 'string', |
||
569 | 'value' => NULL, |
||
570 | ), |
||
571 | ); |
||
572 | } |
||
573 | |||
574 | /** |
||
575 | * @param string $language |
||
576 | * @param int $version |
||
577 | * @param string $siteId |
||
578 | * @param \OpenOrchestra\ModelInterface\Model\ContentInterface $content |
||
579 | * @param string $contentId |
||
580 | */ |
||
581 | protected function assertSameContent($language, $version, $siteId, $contentId, $content) |
||
582 | { |
||
583 | $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\ContentInterface', $content); |
||
584 | $this->assertSame($contentId, $content->getContentId()); |
||
585 | if (!is_null($language)) { |
||
586 | $this->assertSame($language, $content->getLanguage()); |
||
587 | } |
||
588 | if (!is_null($version)) { |
||
589 | $this->assertSame($version, $content->getVersion()); |
||
590 | } |
||
591 | if (!is_null($siteId)) { |
||
592 | $this->assertSame($siteId, $content->getsiteId()); |
||
593 | } |
||
594 | $this->assertSame(false, $content->isDeleted()); |
||
595 | } |
||
596 | |||
597 | /** |
||
598 | * Test has statused element |
||
599 | */ |
||
600 | View Code Duplication | public function testHasStatusedElement() |
|
0 ignored issues
–
show
|
|||
601 | { |
||
602 | $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status'); |
||
603 | $status = $statusRepository->findOneByInitial(); |
||
604 | |||
605 | $this->assertFalse($this->repository->hasStatusedElement($status)); |
||
606 | } |
||
607 | |||
608 | /** |
||
609 | * @param string $condition |
||
610 | * |
||
611 | * @return array |
||
612 | */ |
||
613 | View Code Duplication | protected function replaceKeywordLabelById($condition) |
|
614 | { |
||
615 | $conditionWithoutOperator = preg_replace(explode('|', KeywordableTraitInterface::OPERATOR_SPLIT), ' ', $condition); |
||
616 | $conditionArray = explode(' ', $conditionWithoutOperator); |
||
617 | |||
618 | foreach ($conditionArray as $keyword) { |
||
619 | if ($keyword != '') { |
||
620 | $keywordDocument = $this->keywordRepository->findOneByLabel($keyword); |
||
621 | if (!is_null($keywordDocument)) { |
||
622 | $condition = str_replace($keyword, $keywordDocument->getId(), $condition); |
||
623 | } else { |
||
624 | return ''; |
||
625 | } |
||
626 | } |
||
627 | } |
||
628 | |||
629 | return $condition; |
||
630 | } |
||
631 | } |
||
632 |
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.