Completed
Push — master ( df742a...ae5fc8 )
by amaury
03:07
created

ContentRepositoryTest::testUpdateEmbeddedStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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();
0 ignored issues
show
Bug introduced by
The method getCurrentSiteDefaultLanguage() does not seem to exist on object<Phake_IMock>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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 provideFindByContentIdAndLanguage
238
     */
239
    public function testFindByLanguage($contentId, $language)
240
    {
241
        $contents = $this->repository->findByLanguage($contentId, $language);
0 ignored issues
show
Bug introduced by
The method findByLanguage() does not seem to exist on object<OpenOrchestra\Mod...entRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
242
243
        foreach ($contents as $content) {
244
            $this->assertSameContent($language, null, null, $contentId, $content);
245
        }
246
247
    }
248
249
    /**
250
     * @return array
251
     */
252
    public function provideFindByContentIdAndLanguage()
253
    {
254
        return array(
255
            array('notre_vision', 'fr'),
256
            array('bien_vivre_en_france', 'fr'),
257
        );
258
    }
259
260
    /**
261
     * @param string $contentId
262
     * @param string $language
263
     * @param int    $version
264
     *
265
     * @dataProvider provideFindOneByContentIdAndLanguageAndVersion
266
     */
267
    public function testFindOneByLanguageAndVersion($contentId, $language, $version)
268
    {
269
        $content = $this->repository->findOneByLanguageAndVersion($contentId, $language, $version);
270
271
        $this->assertSameContent($language, $version, null, $contentId, $content);
272
273
    }
274
275
    /**
276
     * @return array
277
     */
278 View Code Duplication
    public function provideFindOneByContentIdAndLanguageAndVersion()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
279
    {
280
        return array(
281
            array('notre_vision', 'fr', '1'),
282
            array('bien_vivre_en_france', 'fr', '1'),
283
        );
284
    }
285
286
    /**
287
     * @param string     $contentType
288
     * @param array|null $search
289
     * @param array|null $order
290
     * @param string     $siteId
291
     * @param int        $skip
292
     * @param int        $limit
293
     * @param string     $language
294
     * @param integer    $count
295
     * @param integer    $totalCount
296
     * @param string     $name
297
     *
298
     * @dataProvider provideContentTypeAndPaginateAndSearchAndsiteId
299
     */
300
    public function testFindForPaginateFilterByContentTypeSiteAndLanguage($contentType, $search, $order, $siteId, $skip, $limit, $language, $count, $totalCount, $name = null)
301
    {
302
        $mapping = array(
303
            'name' => 'name',
304
            'status_label' => 'status.labels.'.$language,
305
            'linked_to_site' => 'linkedToSite',
306
            'created_at' => 'createdAt',
307
            'created_by' => 'createdBy',
308
            'updated_at' => 'updatedAt',
309
            'updated_by' => 'updatedBy',
310
            'fields.car_name.string_value' => 'attributes.car_name.stringValue',
311
            'fields.description.string_value' => 'attributes.description.stringValue',
312
            'fields.on_market.string_value' => 'attributes.on_market.stringValue',
313
            'fields.tinimce_test.string_value' => 'attributes.tinimce_test.stringValue',
314
        );
315
316
        $searchTypes = array (
317
            'attributes.car_name' => 'text',
318
            'attributes.description' => 'text',
319
            'attributes.on_market' => 'date',
320
            'attributes.tinimce_test' => 'text',
321
        );
322
323
324
        $configuration = PaginateFinderConfiguration::generateFromVariable($order, $skip, $limit, $mapping, $search);
325
        $contents = $this->repository->findForPaginateFilterByContentTypeSiteAndLanguage($configuration, $contentType, $siteId, $language, $searchTypes);
0 ignored issues
show
Unused Code introduced by
The call to ContentRepositoryInterfa...ntTypeSiteAndLanguage() has too many arguments starting with $searchTypes.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
326
        $repositoryCount = $this->repository->countWithFilterAndContentTypeSiteAndLanguage($configuration, $contentType, $siteId, $language, $searchTypes);
0 ignored issues
show
Unused Code introduced by
The call to ContentRepositoryInterfa...ntTypeSiteAndLanguage() has too many arguments starting with $searchTypes.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
327
328
        if(!is_null($name)) {
329
            $this->assertEquals($name, $contents[0]->getName());
330
        }
331
        $this->assertCount($count, $contents);
332
        $this->assertEquals($totalCount, $repositoryCount);
333
    }
334
335
    /**
336
     * @return array
337
     */
338
    public function provideContentTypeAndPaginateAndSearchAndsiteId()
339
    {
340
        return array(
341
            1  => array('car', null, array("name" => "name", "dir" => "asc"), '2', 0 ,5 , 'en', 3, 3, '206 3 portes en'),
342
            2  => array('car', null, array("name" => "name", "dir" => "desc"), '2', 0 ,5 , 'en', 3, 3, 'R5 3 portes en'),
343
            3  => array('car', null, array("name" => "fields.car_name.string_value", "dir" => "asc"), '2', 0 ,5 , 'en', 3, 3, '206 3 portes en'),
344
            4  => array('car', null, array("name" => "fields.car_name.string_value", "dir" => "desc"),'2', 0 ,5 , 'en', 3, 3, 'R5 3 portes en'),
345
            5  => array('car', null, null, null, 0 ,1 , 'en', 1, 2),
346
            6  => array('car', array('attributes.car_name' => '206'), null, '2', 0 , 2 , 'en', 1, 1),
347
            7  => array('news', null, null, '2', 0 , 100, 'fr', 4, 4),
348
            8  => array('news', null, null, '2', 50 , 100, 'en', 0, 0),
349
            9 => array('news', array('name' => 'news'), null, '2', 0 , null, 'fr', 0, 0),
350
            10 => array('car', null, null, '2', 0 ,5 , 'en', 3, 3),
351
        );
352
    }
353
354
    /**
355
     * @param string  $contentType
356
     * @param string  $siteId
357
     * @param string  $language
358
     * @param integer $count
359
     *
360
     * @dataProvider provideCountByContentTypeAndSiteInLastVersion
361
     */
362
    public function testCountFilterByContentTypeSiteAndLanguage($contentType, $siteId, $language, $count)
363
    {
364
        $contents = $this->repository->countFilterByContentTypeSiteAndLanguage($contentType, $siteId, $language);
365
        $this->assertEquals($count, $contents);
366
    }
367
368
    /**
369
     * @return array
370
     */
371
    public function provideCountByContentTypeAndSiteInLastVersion()
372
    {
373
        return array(
374
            array('car', '1', 'en', 2),
375
            array('car', '2', 'en', 3),
376
            array('customer', '1', 'en', 1),
377
            array('customer', '2', 'en', 1),
378
            array('news', '1', 'en', 0),
379
            array('news', '2', 'fr', 4),
380
        );
381
    }
382
383
    /**
384
     * @param string       $user
385
     * @param string       $siteId
386
     * @param array        $eventTypes
387
     * @param boolean|null $published
388
     * @param int          $limit
389
     * @param array|null   $sort
390
     * @param int          $count
391
     *
392
     * @dataProvider provideFindByHistoryAndSiteId
393
     */
394 View Code Duplication
    public function testFindByHistoryAndSiteId($user, $siteId, array $eventTypes, $published, $limit, $sort, $count)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
395
    {
396
        $user = $this->userRepository->findOneByUsername($user);
397
398
        $contents = $this->repository->findByHistoryAndSiteId($user->getId(), $siteId, $eventTypes, $published, $limit, $sort);
399
        $this->assertCount($count, $contents);
400
    }
401
402
    /**
403
     * @return array
404
     */
405
    public function provideFindByHistoryAndSiteId()
406
    {
407
        return array(
408
            1 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION), null, 10, array('updatedAt' => -1), 0),
409
            2 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION), false, 10, null, 0),
410
            3 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION), true, 10, null, 0),
411
            4 => array('p-admin', '2', array(ContentEvents::CONTENT_UPDATE), true, 10, null, 0),
412
            5 => array('p-admin', '2', array(ContentEvents::CONTENT_CREATION, ContentEvents::CONTENT_UPDATE), true, 10, null, 0),
413
        );
414
    }
415
416
    /**
417
     * test updateStatusByContentType
418
     */
419
    public function testUpdateStatusByContentType()
420
    {
421
        $contentTypeId = 'test';
422
423
        $outOfWorkflow = $this->statusRepository->findOneByOutOfWorkflow();
424
425
        $dm = $this->contentTypeRepository->getDocumentManager();
426
427
        $contentType = new ContentType();
428
        $contentType->setContentTypeId($contentTypeId);
429
        $dm->persist($contentType);
430
        $dm->flush();
431
432
        $content = new Content();
433
        $content->setContentType($contentTypeId);
434
        $dm->persist($content);
435
        $dm->flush();
436
437
        $this->assertEquals('draft', $content->getStatus()->getName());
438
439
        $this->repository->updateStatusByContentType($outOfWorkflow, $contentTypeId);
440
        $dm->clear();
441
442
        $updatedContent = $this->repository->findOneBy(array('_id' => $content->getId()));
0 ignored issues
show
Bug introduced by
The method findOneBy() does not exist on OpenOrchestra\ModelInter...tentRepositoryInterface. Did you maybe mean findOneByContentId()?

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.

Loading history...
443
        $this->assertEquals('outOfWorkflow', $updatedContent->getStatus()->getName());
444
445
        $contentType = $this->contentTypeRepository->findOneBy(array('contentTypeId' => $contentTypeId));
446
447
        $dm->remove($updatedContent);
448
        $dm->remove($contentType);
449
        $dm->flush();
450
    }
451
452
    /**
453
     * Test remove content version
454
     */
455 View Code Duplication
    public function testRemoveVersion()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
456
    {
457
        $dm = static::$kernel->getContainer()->get('object_manager');
458
        $content = $this->repository->findOneByLanguageAndVersion('bien_vivre_en_france', 'fr', "1");
459
        $storageIds = array($content->geTId());
460
        $dm->detach($content);
461
462
        $this->repository->removeContentVersion($storageIds);
463
        $this->assertNull($this->repository->findOneByLanguageAndVersion('bien_vivre_en_france', 'fr', "1"));
464
465
        $dm->persist($content);
466
        $dm->flush();
467
    }
468
469
    /**
470
     * Generate columns of content with search value
471
     *
472
     * @param array|null $searchColumns
473
     * @param string     $globalSearch
474
     *
475
     * @return array
476
     */
477
    protected function generateColumnsProvider($searchColumns = null, $globalSearch = '')
478
    {
479
        $search = array();
480
        if (null !== $searchColumns) {
481
            $columns = array();
482
            foreach ($searchColumns as $name => $value) {
483
                $columns[$name] = $value;
484
            }
485
            $search['columns'] = $columns;
486
        }
487
488
        if (!empty($globalSearch)) {
489
            $search['global'] = $globalSearch;
490
        }
491
492
        return $search;
493
    }
494
495
    /**
496
     * Generate relation between columns names and entities attributes
497
     *
498
     * @return array
499
     */
500
    protected function getDescriptionColumnEntity()
501
    {
502
        return array (
503
            'name' =>
504
            array (
505
                'key' => 'name',
506
                'field' => 'name',
507
                'type' => 'string',
508
            ),
509
            'language' =>
510
            array (
511
                'key' => 'language',
512
                'field' => 'language',
513
                'type' => 'string',
514
            ),
515
            'status_label' =>
516
            array (
517
                'key' => 'status_label',
518
                'field' => 'status',
519
                'type' => 'multiLanguages',
520
            ),
521
            'version' =>
522
            array (
523
                'key' => 'version',
524
                'field' => 'version',
525
                'type' => 'integer',
526
            ),
527
            'linked_to_site' =>
528
            array (
529
                'key' => 'linked_to_site',
530
                'field' => 'linkedTosite',
531
                'type' => 'boolean',
532
            ),
533
            'created_by' =>
534
            array (
535
                'key' => 'created_by',
536
                'field' => 'createdBy',
537
                'type' => 'string',
538
            ),
539
            'updated_by' =>
540
            array (
541
                'key' => 'updated_by',
542
                'field' => 'updatedBy',
543
                'type' => 'string',
544
            ),
545
            'created_at' =>
546
            array (
547
                'key' => 'created_at',
548
                'field' => 'createdAt',
549
                'type' => 'date',
550
            ),
551
            'updated_at' =>
552
            array (
553
                'key' => 'updated_at',
554
                'field' => 'updatedAt',
555
                'type' => 'date',
556
            ),
557
            'deleted' =>
558
            array (
559
                'key' => 'deleted',
560
                'field' => 'deleted',
561
                'type' => 'boolean',
562
            ),
563
            'attributes.car_name.string_value' =>
564
            array(
565
                'key' => 'attributes.car_name.string_value',
566
                'field' => 'attributes.car_name.stringValue',
567
                'type' => 'string',
568
                'value' => NULL,
569
            ),
570
            'attributes.description.string_value' =>
571
            array(
572
                'key' => 'attributes.description.string_value',
573
                'field' => 'attributes.description.stringValue',
574
                'type' => 'string',
575
                'value' => NULL,
576
            ),
577
        );
578
    }
579
580
    /**
581
     * @param string                                               $language
582
     * @param int                                                  $version
583
     * @param string                                               $siteId
584
     * @param \OpenOrchestra\ModelInterface\Model\ContentInterface $content
585
     * @param string                                               $contentId
586
     */
587
    protected function assertSameContent($language, $version, $siteId, $contentId, $content)
588
    {
589
        $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\ContentInterface', $content);
590
        $this->assertSame($contentId, $content->getContentId());
591
        if (!is_null($language)) {
592
            $this->assertSame($language, $content->getLanguage());
593
        }
594
        if (!is_null($version)) {
595
            $this->assertSame($version, $content->getVersion());
596
        }
597
        if (!is_null($siteId)) {
598
            $this->assertSame($siteId, $content->getsiteId());
599
        }
600
        $this->assertSame(false, $content->isDeleted());
601
    }
602
603
    /**
604
     * Test has statused element
605
     */
606 View Code Duplication
    public function testHasStatusedElement()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
607
    {
608
        $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
609
        $status = $statusRepository->findOneByInitial();
610
611
        $this->assertTrue($this->repository->hasStatusedElement($status));
612
    }
613
614
    /**
615
     * Test findAllPublishedByContentId
616
     */
617
    public function findAllPublishedByContentId()
618
    {
619
        $contents = $this->repository->findAllPublishedByContentId('bien_vivre_en_france');
620
621
        $this->assertEquals(1, count($contents));
622
    }
623
624
    /**
625
     * Test findElementToAutoPublish
626
     */
627
    public function testFindElementToAutoPublish()
628
    {
629
        $fromStatus = $this->statusRepository->findByAutoPublishFrom();
630
        $contents = $this->repository->findElementToAutoPublish('2', $fromStatus);
631
632
        $this->assertEquals(0, count($contents));
633
    }
634
635
    /**
636
     * Test findElementToAutoUnpublish
637
     */
638
    public function testFindElementToAutoUnpublish()
639
    {
640
        $publishedStatus = $this->statusRepository->findOneByPublished();
641
        $contents = $this->repository->findElementToAutoUnpublish('2', $publishedStatus);
642
643
        $this->assertEquals(0, count($contents));
644
    }
645
646
    /**
647
     * Test find last version
648
     */
649
    public function testFindLastVersion()
650
    {
651
        $documentManager = static::$kernel->getContainer()->get('object_manager');
652
        $contentId = 'test-find-last-version';
653
654
        $firstContent = new Content();
655
        $firstContent->setCreatedAt(new \DateTime('2017-02-27T15:03:01.012345Z'));
656
        $firstContent->setContentId($contentId);
657
        $firstContent->setContentType('car');
658
        $documentManager->persist($firstContent);
659
660
        $lastContent = new Content();
661
        $lastContent->setCreatedAt(new \DateTime('2017-02-28T15:03:01.012345Z'));
662
        $lastContent->setContentId($contentId);
663
        $lastContent->setContentType('car');
664
        $documentManager->persist($lastContent);
665
666
        $documentManager->flush();
667
668
        $content = $this->repository->findLastVersion($contentId);
669
        $this->assertEquals((new \DateTime('2017-02-28T15:03:01.012345Z'))->getTimestamp(), $content->getCreatedAt()->getTimestamp());
670
671
        $documentManager->remove($firstContent);
672
        $documentManager->remove($lastContent);
673
674
        $documentManager->flush();
675
    }
676
677
    /**
678
     * Test soft delete content
679
     */
680
    public function testSoftDeleteAndRestoreContent()
681
    {
682
        $contentId = 'bien_vivre_en_france';
683
684
        $this->repository->softDeleteContent($contentId);
685
        $contents = $this->repository->findByContentId($contentId);
686
        foreach ($contents as $content ) {
687
            $this->assertTrue($content->isDeleted());
688
        }
689
        $this->repository->restoreDeletedContent($contentId);
690
691
        $documentManager = static::$kernel->getContainer()->get('object_manager');
692
        $documentManager->clear();
693
        $documentManager->close();
694
695
        $contents = $this->repository->findByContentId($contentId);
696
        foreach ($contents as $content ) {
697
            $this->assertFalse($content->isDeleted());
698
        }
699
    }
700
701
    /**
702
     * @param string $contentId
703
     * @param bool   $has
704
     *
705
     * @dataProvider provideContentIdforHasContentNotOffline
706
     */
707
    public function testHasContentIdWithoutAutoUnpublishToState($contentId, $has)
708
    {
709
        $this->assertSame($has, $this->repository->hasContentIdWithoutAutoUnpublishToState($contentId));
710
    }
711
712
    /**
713
     * @return array
714
     */
715
    public function provideContentIdforHasContentNotOffline()
716
    {
717
        return array(
718
            array('bien_vivre_en_france', true),
719
            array('notre_vision', true)
720
        );
721
    }
722
723
    /**
724
     * @param string $condition
725
     *
726
     * @return array
727
     */
728 View Code Duplication
    protected function replaceKeywordLabelById($condition)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
729
    {
730
        $conditionWithoutOperator = preg_replace(explode('|', KeywordableTraitInterface::OPERATOR_SPLIT), ' ', $condition);
731
        $conditionArray = explode(' ', $conditionWithoutOperator);
732
733
        foreach ($conditionArray as $keyword) {
734
            if ($keyword != '') {
735
                $keywordDocument = $this->keywordRepository->findOneByLabel($keyword);
736
                if (!is_null($keywordDocument)) {
737
                    $condition = str_replace($keyword, $keywordDocument->getId(), $condition);
738
                } else {
739
                    return '';
740
                }
741
            }
742
        }
743
744
        return $condition;
745
    }
746
747
    /**
748
     * Test update embedded status
749
     */
750 View Code Duplication
    public function testUpdateEmbeddedStatus()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
751
    {
752
        $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
753
        $status = $statusRepository->findOneByName('published');
754
        $fakeColor = 'fakeColor';
755
        $saveColor = $status->getDisplayColor();
756
        $status->setDisplayColor($fakeColor);
757
        $this->repository->updateEmbeddedStatus($status);
758
759
        $content = $this->repository->findOnePublished('bien_vivre_en_france', 'fr', '2');
760
        $this->assertEquals($fakeColor, $content->getStatus()->getDisplayColor());
761
762
        $status->setDisplayColor($saveColor);
763
        $this->repository->updateEmbeddedStatus($status);
764
    }
765
}
766