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\PaginateFinderConfiguration; |
||
7 | use OpenOrchestra\ModelInterface\Repository\ContentRepositoryInterface; |
||
8 | use OpenOrchestra\ModelInterface\Repository\RepositoryTrait\KeywordableTraitInterface; |
||
9 | use OpenOrchestra\ModelInterface\ContentEvents; |
||
10 | use Phake; |
||
11 | use OpenOrchestra\ModelBundle\Document\ContentType; |
||
12 | use OpenOrchestra\ModelBundle\Document\Content; |
||
13 | |||
14 | /** |
||
15 | * Class ContentRepositoryTest |
||
16 | * |
||
17 | * @group integrationTest |
||
18 | */ |
||
19 | class ContentRepositoryTest extends AbstractKernelTestCase |
||
20 | { |
||
21 | /** |
||
22 | * @var ContentRepositoryInterface |
||
23 | */ |
||
24 | protected $repository; |
||
25 | protected $keywordRepository; |
||
26 | protected $userRepository; |
||
27 | protected $statusRepository; |
||
28 | protected $contentTypeRepository; |
||
29 | |||
30 | protected $currentsiteManager; |
||
31 | |||
32 | /** |
||
33 | * Set up test |
||
34 | */ |
||
35 | protected function setUp() |
||
36 | { |
||
37 | parent::setUp(); |
||
38 | static::bootKernel(); |
||
39 | $this->keywordRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.keyword'); |
||
40 | $this->userRepository = static::$kernel->getContainer()->get('open_orchestra_user.repository.user'); |
||
41 | $this->currentsiteManager = Phake::mock('OpenOrchestra\BaseBundle\Context\CurrentSiteIdInterface'); |
||
42 | Phake::when($this->currentsiteManager)->getCurrentSiteId()->thenReturn('2'); |
||
43 | Phake::when($this->currentsiteManager)->getCurrentSiteDefaultLanguage()->thenReturn('fr'); |
||
44 | |||
45 | $this->repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.content'); |
||
46 | $this->statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status'); |
||
47 | $this->contentTypeRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.content_type'); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param string $name |
||
52 | * @param boolean $exists |
||
53 | * |
||
54 | * @dataProvider provideTestUniquenessInContext |
||
55 | */ |
||
56 | public function testTestUniquenessInContext($name, $exists) |
||
57 | { |
||
58 | $test = $this->repository->testUniquenessInContext($name); |
||
59 | |||
60 | $this->assertEquals($exists, $test); |
||
61 | |||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @return array |
||
66 | */ |
||
67 | public function provideTestUniquenessInContext() |
||
68 | { |
||
69 | return array( |
||
70 | array('welcome', true), |
||
71 | array('fakeContentId', false), |
||
72 | ); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param string $contentId |
||
77 | * |
||
78 | * @dataProvider provideFindOneByContentId |
||
79 | */ |
||
80 | public function testFindOneByContentId($contentId) |
||
81 | { |
||
82 | $content = $this->repository->findOneByContentId($contentId); |
||
83 | $this->assertSameContent(null, null, null, $contentId, $content); |
||
84 | $this->assertEquals($contentId, $content->getContentId()); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @return array |
||
89 | */ |
||
90 | public function provideFindOneByContentId() |
||
91 | { |
||
92 | return array( |
||
93 | array('notre_vision'), |
||
94 | array('bien_vivre_en_france'), |
||
95 | ); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @param $contentId |
||
100 | * @param $version |
||
101 | * @param string|null $language |
||
102 | * |
||
103 | * @dataProvider provideFindPublishedVersion |
||
104 | */ |
||
105 | public function testFindPublishedVersion($contentId, $version, $language) |
||
106 | { |
||
107 | $content = $this->repository->findPublishedVersion($contentId, $language); |
||
108 | $this->assertSameContent($language, $version, null, $contentId, $content); |
||
109 | $this->assertEquals($contentId, $content->getContentId()); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @param $contentId |
||
114 | * @param $version |
||
115 | * @param string|null $language |
||
116 | * |
||
117 | * @dataProvider provideFindPublishedVersion |
||
118 | */ |
||
119 | public function testFindOnePublished($contentId, $version, $language) |
||
120 | { |
||
121 | $content = $this->repository->findOnePublished($contentId, $language, '2'); |
||
122 | $this->assertSameContent($language, $version, null, $contentId, $content); |
||
123 | $this->assertEquals($contentId, $content->getContentId()); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * @return array |
||
128 | */ |
||
129 | View Code Duplication | public function provideFindPublishedVersion() |
|
130 | { |
||
131 | return array( |
||
132 | array('notre_vision', '1', 'fr'), |
||
133 | array('bien_vivre_en_france', '1', 'fr'), |
||
134 | ); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @param string $contentId |
||
139 | * @param string $language |
||
140 | * @param int $count |
||
141 | * |
||
142 | * @dataProvider provideFindNotDeletedSortByUpdatedAt |
||
143 | */ |
||
144 | public function testFindNotDeletedSortByUpdatedAt($contentId, $language, $count) |
||
145 | { |
||
146 | $contents = $this->repository->findNotDeletedSortByUpdatedAt($contentId, $language); |
||
147 | $this->assertCount($count, $contents); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @param string $contentId |
||
152 | * @param string $language |
||
153 | * @param int $count |
||
154 | * |
||
155 | * @dataProvider provideFindNotDeletedSortByUpdatedAt |
||
156 | */ |
||
157 | public function testCountNotDeletedByLanguage($contentId, $language, $count) |
||
158 | { |
||
159 | $countContents = $this->repository->countNotDeletedByLanguage($contentId, $language); |
||
160 | $this->assertSame($count, $countContents); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * @return array |
||
165 | */ |
||
166 | View Code Duplication | public function provideFindNotDeletedSortByUpdatedAt() |
|
167 | { |
||
168 | return array( |
||
169 | array('notre_vision', 'fr', 1), |
||
170 | array('bien_vivre_en_france', 'fr', 1), |
||
171 | ); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * @param string $contentType |
||
176 | * @param string $choiceType |
||
177 | * @param string|null $keywords |
||
178 | * @param int $count |
||
179 | * |
||
180 | * @dataProvider provideContentTypeKeywordAndCount |
||
181 | */ |
||
182 | public function testFindByContentTypeAndCondition($contentType = '', $choiceType, $keywords = null, $count) |
||
183 | { |
||
184 | $keywords = $this->replaceKeywordLabelById($keywords); |
||
185 | |||
186 | $language = $this->currentsiteManager->getCurrentSiteDefaultLanguage(); |
||
187 | $elements = $this->repository->findByContentTypeAndCondition($language, $contentType, $choiceType, $keywords); |
||
188 | |||
189 | $this->assertCount($count, $elements); |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * @return array |
||
194 | */ |
||
195 | public function provideContentTypeKeywordAndCount() |
||
196 | { |
||
197 | return array( |
||
198 | array('car', ContentRepositoryInterface::CHOICE_AND, 'lorem', 3), |
||
199 | array('car',ContentRepositoryInterface::CHOICE_AND, 'sit', 1), |
||
200 | array('car', ContentRepositoryInterface::CHOICE_AND, 'dolor', 0), |
||
201 | array('car', ContentRepositoryInterface::CHOICE_AND, 'sit AND lorem', 1), |
||
202 | array('news', ContentRepositoryInterface::CHOICE_AND, 'lorem', 1), |
||
203 | array('news', ContentRepositoryInterface::CHOICE_AND, 'sit', 2), |
||
204 | array('news', ContentRepositoryInterface::CHOICE_AND, 'dolor', 0), |
||
205 | array('news', ContentRepositoryInterface::CHOICE_AND, 'lorem AND sit', 1), |
||
206 | array('news', ContentRepositoryInterface::CHOICE_AND, '', 4), |
||
207 | array('car', ContentRepositoryInterface::CHOICE_AND, '', 3), |
||
208 | array('', ContentRepositoryInterface::CHOICE_AND, '', 9), |
||
209 | array('', ContentRepositoryInterface::CHOICE_AND, '', 9), |
||
210 | array('', ContentRepositoryInterface::CHOICE_AND, 'lorem', 5), |
||
211 | array('', ContentRepositoryInterface::CHOICE_AND, 'sit', 4), |
||
212 | array('', ContentRepositoryInterface::CHOICE_AND, 'dolor', 0), |
||
213 | array('', ContentRepositoryInterface::CHOICE_AND, 'lorem AND sit', 3), |
||
214 | array('car', ContentRepositoryInterface::CHOICE_OR, 'lorem', 5), |
||
215 | array('car', ContentRepositoryInterface::CHOICE_OR, 'sit', 6), |
||
216 | array('car', ContentRepositoryInterface::CHOICE_OR, 'dolor', 3), |
||
217 | array('car', ContentRepositoryInterface::CHOICE_OR, 'lorem AND sit', 5), |
||
218 | array('news', ContentRepositoryInterface::CHOICE_OR, 'lorem', 8), |
||
219 | array('news', ContentRepositoryInterface::CHOICE_OR, 'sit', 6), |
||
220 | array('news', ContentRepositoryInterface::CHOICE_OR, 'dolor', 4), |
||
221 | array('news', ContentRepositoryInterface::CHOICE_OR, 'lorem AND sit', 6), |
||
222 | array('news', ContentRepositoryInterface::CHOICE_OR, '', 4), |
||
223 | array('car', ContentRepositoryInterface::CHOICE_OR, '', 3), |
||
224 | array('', ContentRepositoryInterface::CHOICE_OR, '', 9), |
||
225 | array('', ContentRepositoryInterface::CHOICE_OR, 'lorem', 5), |
||
226 | array('', ContentRepositoryInterface::CHOICE_OR, 'sit', 4), |
||
227 | array('', ContentRepositoryInterface::CHOICE_OR, 'dolor', 0), |
||
228 | array('', ContentRepositoryInterface::CHOICE_OR, 'lorem AND sit', 3), |
||
229 | array('', ContentRepositoryInterface::CHOICE_OR, '', 9), |
||
230 | ); |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * @param string $contentId |
||
235 | * @param string $language |
||
236 | * |
||
237 | * @dataProvider provideFindOneByContentIdAndLanguage |
||
238 | */ |
||
239 | public function testFindOneByLanguage($contentId, $language) |
||
240 | { |
||
241 | $content = $this->repository->findOneByLanguage($contentId, $language); |
||
242 | |||
243 | $this->assertSameContent($language, null, null, $contentId, $content); |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * @return array |
||
248 | */ |
||
249 | public function provideFindOneByContentIdAndLanguage() |
||
250 | { |
||
251 | return array( |
||
252 | array('notre_vision', 'fr'), |
||
253 | array('bien_vivre_en_france', 'fr'), |
||
254 | ); |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * @param string $contentId |
||
259 | * @param string $language |
||
260 | * |
||
261 | * @dataProvider provideFindByContentIdAndLanguage |
||
262 | */ |
||
263 | public function testFindByLanguage($contentId, $language) |
||
264 | { |
||
265 | $contents = $this->repository->findByLanguage($contentId, $language); |
||
266 | |||
267 | foreach ($contents as $content) { |
||
268 | $this->assertSameContent($language, null, null, $contentId, $content); |
||
269 | } |
||
270 | |||
271 | } |
||
272 | |||
273 | /** |
||
274 | * @return array |
||
275 | */ |
||
276 | public function provideFindByContentIdAndLanguage() |
||
277 | { |
||
278 | return array( |
||
279 | array('notre_vision', 'fr'), |
||
280 | array('bien_vivre_en_france', 'fr'), |
||
281 | ); |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * @param string $contentId |
||
286 | * @param string $language |
||
287 | * @param int $version |
||
288 | * |
||
289 | * @dataProvider provideFindOneByContentIdAndLanguageAndVersion |
||
290 | */ |
||
291 | public function testFindOneByLanguageAndVersion($contentId, $language, $version) |
||
292 | { |
||
293 | $content = $this->repository->findOneByLanguageAndVersion($contentId, $language, $version); |
||
294 | |||
295 | $this->assertSameContent($language, $version, null, $contentId, $content); |
||
296 | |||
297 | } |
||
298 | |||
299 | /** |
||
300 | * @return array |
||
301 | */ |
||
302 | View Code Duplication | public function provideFindOneByContentIdAndLanguageAndVersion() |
|
303 | { |
||
304 | return array( |
||
305 | array('notre_vision', 'fr', '1'), |
||
306 | array('bien_vivre_en_france', 'fr', '1'), |
||
307 | ); |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * @param string $contentType |
||
312 | * @param array|null $search |
||
313 | * @param array|null $order |
||
314 | * @param string $siteId |
||
315 | * @param int $skip |
||
316 | * @param int $limit |
||
317 | * @param string $language |
||
318 | * @param integer $count |
||
319 | * @param integer $totalCount |
||
320 | * @param string $name |
||
321 | * |
||
322 | * @dataProvider provideContentTypeAndPaginateAndSearchAndsiteId |
||
323 | */ |
||
324 | public function testFindForPaginateFilterByContentTypeSiteAndLanguage($contentType, $search, $order, $siteId, $skip, $limit, $language, $count, $totalCount, $name = null) |
||
325 | { |
||
326 | $mapping = array( |
||
327 | 'name' => 'name', |
||
328 | 'status_label' => 'status.labels.'.$language, |
||
329 | 'linked_to_site' => 'linkedToSite', |
||
330 | 'created_at' => 'createdAt', |
||
331 | 'created_by' => 'createdBy', |
||
332 | 'updated_at' => 'updatedAt', |
||
333 | 'updated_by' => 'updatedBy', |
||
334 | 'fields.car_name.string_value' => 'attributes.car_name.stringValue', |
||
335 | 'fields.description.string_value' => 'attributes.description.stringValue', |
||
336 | 'fields.on_market.string_value' => 'attributes.on_market.stringValue', |
||
337 | 'fields.tinimce_test.string_value' => 'attributes.tinimce_test.stringValue', |
||
338 | ); |
||
339 | |||
340 | $searchTypes = array ( |
||
341 | 'attributes.car_name' => 'text', |
||
342 | 'attributes.description' => 'text', |
||
343 | 'attributes.on_market' => 'date', |
||
344 | 'attributes.tinimce_test' => 'text', |
||
345 | ); |
||
346 | |||
347 | |||
348 | $configuration = PaginateFinderConfiguration::generateFromVariable($order, $skip, $limit, $mapping, $search); |
||
349 | $contents = $this->repository->findForPaginateFilterByContentTypeSiteAndLanguage($configuration, $contentType, $siteId, $language, $searchTypes); |
||
350 | $repositoryCount = $this->repository->countWithFilterAndContentTypeSiteAndLanguage($configuration, $contentType, $siteId, $language, $searchTypes); |
||
351 | |||
352 | if(!is_null($name)) { |
||
353 | $this->assertEquals($name, $contents[0]->getName()); |
||
354 | } |
||
355 | $this->assertCount($count, $contents); |
||
356 | $this->assertEquals($totalCount, $repositoryCount); |
||
357 | } |
||
358 | |||
359 | /** |
||
360 | * @return array |
||
361 | */ |
||
362 | public function provideContentTypeAndPaginateAndSearchAndsiteId() |
||
363 | { |
||
364 | return array( |
||
365 | 1 => array('car', null, array("name" => "name", "dir" => "asc"), '2', 0 ,5 , 'en', 3, 3, '206 3 portes en'), |
||
366 | 2 => array('car', null, array("name" => "name", "dir" => "desc"), '2', 0 ,5 , 'en', 3, 3, 'R5 3 portes en'), |
||
367 | 3 => array('car', null, array("name" => "fields.car_name.string_value", "dir" => "asc"), '2', 0 ,5 , 'en', 3, 3, '206 3 portes en'), |
||
368 | 4 => array('car', null, array("name" => "fields.car_name.string_value", "dir" => "desc"),'2', 0 ,5 , 'en', 3, 3, 'R5 3 portes en'), |
||
369 | 5 => array('car', null, null, null, 0 ,1 , 'en', 1, 2), |
||
370 | 6 => array('car', array('attributes.car_name' => '206'), null, '2', 0 , 2 , 'en', 1, 1), |
||
371 | 7 => array('news', null, null, '2', 0 , 100, 'fr', 4, 4), |
||
372 | 8 => array('news', null, null, '2', 50 , 100, 'en', 0, 0), |
||
373 | 9 => array('news', array('name' => 'news'), null, '2', 0 , null, 'fr', 0, 0), |
||
374 | 10 => array('car', null, null, '2', 0 ,5 , 'en', 3, 3), |
||
375 | ); |
||
376 | } |
||
377 | |||
378 | /** |
||
379 | * @param string $contentType |
||
380 | * @param string $siteId |
||
381 | * @param string $language |
||
382 | * @param integer $count |
||
383 | * |
||
384 | * @dataProvider provideCountByContentTypeAndSiteInLastVersion |
||
385 | */ |
||
386 | public function testCountFilterByContentTypeSiteAndLanguage($contentType, $siteId, $language, $count) |
||
387 | { |
||
388 | $contents = $this->repository->countFilterByContentTypeSiteAndLanguage($contentType, $siteId, $language); |
||
389 | $this->assertEquals($count, $contents); |
||
390 | } |
||
391 | |||
392 | /** |
||
393 | * @return array |
||
394 | */ |
||
395 | public function provideCountByContentTypeAndSiteInLastVersion() |
||
396 | { |
||
397 | return array( |
||
398 | array('car', '1', 'en', 2), |
||
399 | array('car', '2', 'en', 3), |
||
400 | array('customer', '1', 'en', 1), |
||
401 | array('customer', '2', 'en', 1), |
||
402 | array('news', '1', 'en', 0), |
||
403 | array('news', '2', 'fr', 4), |
||
404 | ); |
||
405 | } |
||
406 | |||
407 | /** |
||
408 | * @param string $user |
||
409 | * @param string $siteId |
||
410 | * @param array $eventTypes |
||
411 | * @param boolean|null $published |
||
412 | * @param int $limit |
||
413 | * @param array|null $sort |
||
414 | * @param int $count |
||
415 | * |
||
416 | * @dataProvider provideFindByHistoryAndSiteId |
||
417 | */ |
||
418 | View Code Duplication | public function testFindByHistoryAndSiteId($user, $siteId, array $eventTypes, $published, $limit, $sort, $count) |
|
419 | { |
||
420 | $user = $this->userRepository->findOneByUsername($user); |
||
421 | |||
422 | $contents = $this->repository->findByHistoryAndSiteId($user->getId(), $siteId, $eventTypes, $published, $limit, $sort); |
||
423 | $this->assertCount($count, $contents); |
||
424 | } |
||
425 | |||
426 | /** |
||
427 | * @return array |
||
428 | */ |
||
429 | public function provideFindByHistoryAndSiteId() |
||
430 | { |
||
431 | return array( |
||
432 | 1 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION), null, 10, array('updatedAt' => -1), 0), |
||
433 | 2 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION), false, 10, null, 0), |
||
434 | 3 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION), true, 10, null, 0), |
||
435 | 4 => array('p-admin', '2', array(ContentEvents::CONTENT_UPDATE), true, 10, null, 0), |
||
436 | 5 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION, ContentEvents::CONTENT_UPDATE), true, 10, null, 0), |
||
437 | ); |
||
438 | } |
||
439 | |||
440 | /** |
||
441 | * test updateStatusByContentType |
||
442 | */ |
||
443 | public function testUpdateStatusByContentType() |
||
444 | { |
||
445 | $contentTypeId = 'test'; |
||
446 | |||
447 | $outOfWorkflow = $this->statusRepository->findOneByOutOfWorkflow(); |
||
448 | |||
449 | $dm = $this->contentTypeRepository->getDocumentManager(); |
||
450 | |||
451 | $contentType = new ContentType(); |
||
452 | $contentType->setContentTypeId($contentTypeId); |
||
453 | $dm->persist($contentType); |
||
454 | $dm->flush(); |
||
455 | |||
456 | $content = new Content(); |
||
457 | $content->setContentType($contentTypeId); |
||
458 | $dm->persist($content); |
||
459 | $dm->flush(); |
||
460 | |||
461 | $this->assertEquals('draft', $content->getStatus()->getName()); |
||
462 | |||
463 | $this->repository->updateStatusByContentType($outOfWorkflow, $contentTypeId); |
||
464 | $dm->clear(); |
||
465 | |||
466 | $updatedContent = $this->repository->findOneBy(array('_id' => $content->getId())); |
||
0 ignored issues
–
show
|
|||
467 | $this->assertEquals('outOfWorkflow', $updatedContent->getStatus()->getName()); |
||
468 | |||
469 | $contentType = $this->contentTypeRepository->findOneBy(array('contentTypeId' => $contentTypeId)); |
||
470 | |||
471 | $dm->remove($updatedContent); |
||
472 | $dm->remove($contentType); |
||
473 | $dm->flush(); |
||
474 | } |
||
475 | |||
476 | /** |
||
477 | * Test remove content version |
||
478 | */ |
||
479 | View Code Duplication | public function testRemoveVersion() |
|
480 | { |
||
481 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
482 | $content = $this->repository->findOneByLanguageAndVersion('bien_vivre_en_france', 'fr', "1"); |
||
483 | $storageIds = array($content->geTId()); |
||
484 | $dm->detach($content); |
||
485 | |||
486 | $this->repository->removeContentVersion($storageIds); |
||
487 | $this->assertNull($this->repository->findOneByLanguageAndVersion('bien_vivre_en_france', 'fr', "1")); |
||
488 | |||
489 | $dm->persist($content); |
||
490 | $dm->flush(); |
||
491 | } |
||
492 | |||
493 | /** |
||
494 | * Generate columns of content with search value |
||
495 | * |
||
496 | * @param array|null $searchColumns |
||
497 | * @param string $globalSearch |
||
498 | * |
||
499 | * @return array |
||
500 | */ |
||
501 | protected function generateColumnsProvider($searchColumns = null, $globalSearch = '') |
||
502 | { |
||
503 | $search = array(); |
||
504 | if (null !== $searchColumns) { |
||
505 | $columns = array(); |
||
506 | foreach ($searchColumns as $name => $value) { |
||
507 | $columns[$name] = $value; |
||
508 | } |
||
509 | $search['columns'] = $columns; |
||
510 | } |
||
511 | |||
512 | if (!empty($globalSearch)) { |
||
513 | $search['global'] = $globalSearch; |
||
514 | } |
||
515 | |||
516 | return $search; |
||
517 | } |
||
518 | |||
519 | /** |
||
520 | * Generate relation between columns names and entities attributes |
||
521 | * |
||
522 | * @return array |
||
523 | */ |
||
524 | protected function getDescriptionColumnEntity() |
||
525 | { |
||
526 | return array ( |
||
527 | 'name' => |
||
528 | array ( |
||
529 | 'key' => 'name', |
||
530 | 'field' => 'name', |
||
531 | 'type' => 'string', |
||
532 | ), |
||
533 | 'language' => |
||
534 | array ( |
||
535 | 'key' => 'language', |
||
536 | 'field' => 'language', |
||
537 | 'type' => 'string', |
||
538 | ), |
||
539 | 'status_label' => |
||
540 | array ( |
||
541 | 'key' => 'status_label', |
||
542 | 'field' => 'status', |
||
543 | 'type' => 'multiLanguages', |
||
544 | ), |
||
545 | 'version' => |
||
546 | array ( |
||
547 | 'key' => 'version', |
||
548 | 'field' => 'version', |
||
549 | 'type' => 'integer', |
||
550 | ), |
||
551 | 'linked_to_site' => |
||
552 | array ( |
||
553 | 'key' => 'linked_to_site', |
||
554 | 'field' => 'linkedTosite', |
||
555 | 'type' => 'boolean', |
||
556 | ), |
||
557 | 'created_by' => |
||
558 | array ( |
||
559 | 'key' => 'created_by', |
||
560 | 'field' => 'createdBy', |
||
561 | 'type' => 'string', |
||
562 | ), |
||
563 | 'updated_by' => |
||
564 | array ( |
||
565 | 'key' => 'updated_by', |
||
566 | 'field' => 'updatedBy', |
||
567 | 'type' => 'string', |
||
568 | ), |
||
569 | 'created_at' => |
||
570 | array ( |
||
571 | 'key' => 'created_at', |
||
572 | 'field' => 'createdAt', |
||
573 | 'type' => 'date', |
||
574 | ), |
||
575 | 'updated_at' => |
||
576 | array ( |
||
577 | 'key' => 'updated_at', |
||
578 | 'field' => 'updatedAt', |
||
579 | 'type' => 'date', |
||
580 | ), |
||
581 | 'deleted' => |
||
582 | array ( |
||
583 | 'key' => 'deleted', |
||
584 | 'field' => 'deleted', |
||
585 | 'type' => 'boolean', |
||
586 | ), |
||
587 | 'attributes.car_name.string_value' => |
||
588 | array( |
||
589 | 'key' => 'attributes.car_name.string_value', |
||
590 | 'field' => 'attributes.car_name.stringValue', |
||
591 | 'type' => 'string', |
||
592 | 'value' => NULL, |
||
593 | ), |
||
594 | 'attributes.description.string_value' => |
||
595 | array( |
||
596 | 'key' => 'attributes.description.string_value', |
||
597 | 'field' => 'attributes.description.stringValue', |
||
598 | 'type' => 'string', |
||
599 | 'value' => NULL, |
||
600 | ), |
||
601 | ); |
||
602 | } |
||
603 | |||
604 | /** |
||
605 | * @param string $language |
||
606 | * @param int $version |
||
607 | * @param string $siteId |
||
608 | * @param \OpenOrchestra\ModelInterface\Model\ContentInterface $content |
||
609 | * @param string $contentId |
||
610 | */ |
||
611 | protected function assertSameContent($language, $version, $siteId, $contentId, $content) |
||
612 | { |
||
613 | $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\ContentInterface', $content); |
||
614 | $this->assertSame($contentId, $content->getContentId()); |
||
615 | if (!is_null($language)) { |
||
616 | $this->assertSame($language, $content->getLanguage()); |
||
617 | } |
||
618 | if (!is_null($version)) { |
||
619 | $this->assertSame($version, $content->getVersion()); |
||
620 | } |
||
621 | if (!is_null($siteId)) { |
||
622 | $this->assertSame($siteId, $content->getsiteId()); |
||
623 | } |
||
624 | $this->assertSame(false, $content->isDeleted()); |
||
625 | } |
||
626 | |||
627 | /** |
||
628 | * Test has statused element |
||
629 | */ |
||
630 | View Code Duplication | public function testHasStatusedElement() |
|
631 | { |
||
632 | $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status'); |
||
633 | $status = $statusRepository->findOneByInitial(); |
||
634 | |||
635 | $this->assertTrue($this->repository->hasStatusedElement($status)); |
||
636 | } |
||
637 | |||
638 | /** |
||
639 | * Test findAllPublishedByContentId |
||
640 | */ |
||
641 | public function findAllPublishedByContentId() |
||
642 | { |
||
643 | $contents = $this->repository->findAllPublishedByContentId('bien_vivre_en_france'); |
||
644 | |||
645 | $this->assertEquals(1, count($contents)); |
||
646 | } |
||
647 | |||
648 | /** |
||
649 | * Test findElementToAutoPublish |
||
650 | */ |
||
651 | public function testFindElementToAutoPublish() |
||
652 | { |
||
653 | $fromStatus = $this->statusRepository->findByAutoPublishFrom(); |
||
654 | $contents = $this->repository->findElementToAutoPublish('2', $fromStatus); |
||
655 | |||
656 | $this->assertEquals(0, count($contents)); |
||
657 | } |
||
658 | |||
659 | /** |
||
660 | * Test findElementToAutoUnpublish |
||
661 | */ |
||
662 | public function testFindElementToAutoUnpublish() |
||
663 | { |
||
664 | $publishedStatus = $this->statusRepository->findOneByPublished(); |
||
665 | $contents = $this->repository->findElementToAutoUnpublish('2', $publishedStatus); |
||
666 | |||
667 | $this->assertEquals(0, count($contents)); |
||
668 | } |
||
669 | |||
670 | /** |
||
671 | * Test find last version |
||
672 | */ |
||
673 | public function testFindLastVersion() |
||
674 | { |
||
675 | $documentManager = static::$kernel->getContainer()->get('object_manager'); |
||
676 | $contentId = 'test-find-last-version'; |
||
677 | |||
678 | $firstContent = new Content(); |
||
679 | $firstContent->setCreatedAt(new \DateTime('2017-02-27T15:03:01.012345Z')); |
||
680 | $firstContent->setContentId($contentId); |
||
681 | $firstContent->setContentType('car'); |
||
682 | $documentManager->persist($firstContent); |
||
683 | |||
684 | $lastContent = new Content(); |
||
685 | $lastContent->setCreatedAt(new \DateTime('2017-02-28T15:03:01.012345Z')); |
||
686 | $lastContent->setContentId($contentId); |
||
687 | $lastContent->setContentType('car'); |
||
688 | $documentManager->persist($lastContent); |
||
689 | |||
690 | $documentManager->flush(); |
||
691 | |||
692 | $content = $this->repository->findLastVersion($contentId); |
||
693 | $this->assertEquals((new \DateTime('2017-02-28T15:03:01.012345Z'))->getTimestamp(), $content->getCreatedAt()->getTimestamp()); |
||
694 | |||
695 | $documentManager->remove($firstContent); |
||
696 | $documentManager->remove($lastContent); |
||
697 | |||
698 | $documentManager->flush(); |
||
699 | } |
||
700 | |||
701 | /** |
||
702 | * @param string $condition |
||
703 | * |
||
704 | * @return array |
||
705 | */ |
||
706 | View Code Duplication | protected function replaceKeywordLabelById($condition) |
|
707 | { |
||
708 | $conditionWithoutOperator = preg_replace(explode('|', KeywordableTraitInterface::OPERATOR_SPLIT), ' ', $condition); |
||
709 | $conditionArray = explode(' ', $conditionWithoutOperator); |
||
710 | |||
711 | foreach ($conditionArray as $keyword) { |
||
712 | if ($keyword != '') { |
||
713 | $keywordDocument = $this->keywordRepository->findOneByLabel($keyword); |
||
714 | if (!is_null($keywordDocument)) { |
||
715 | $condition = str_replace($keyword, $keywordDocument->getId(), $condition); |
||
716 | } else { |
||
717 | return ''; |
||
718 | } |
||
719 | } |
||
720 | } |
||
721 | |||
722 | return $condition; |
||
723 | } |
||
724 | } |
||
725 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.