Completed
Push — master ( 56d35f...106d3c )
by itkg-nanne
03:09
created

ContentRepositoryTest   F

Complexity

Total Complexity 47

Size/Duplication

Total Lines 706
Duplicated Lines 9.35 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 47
c 2
b 0
f 0
lcom 1
cbo 10
dl 66
loc 706
rs 2.7826

36 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 1
A testTestUniquenessInContext() 0 7 1
A provideTestUniquenessInContext() 0 7 1
A testFindOneByContentId() 0 6 1
A provideFindOneByContentId() 0 7 1
A testFindPublishedVersion() 0 6 1
A testFindOnePublished() 0 6 1
A provideFindPublishedVersion() 7 7 1
A testFindNotDeletedSortByUpdatedAt() 0 5 1
A testCountNotDeletedByLanguage() 0 5 1
A provideFindNotDeletedSortByUpdatedAt() 7 7 1
A testFindByContentTypeAndCondition() 0 9 1
B provideContentTypeKeywordAndCount() 0 37 1
A testFindOneByLanguage() 0 6 1
A provideFindOneByContentIdAndLanguage() 0 7 1
A testFindByLanguage() 0 9 2
A provideFindByContentIdAndLanguage() 0 7 1
A testFindOneByLanguageAndVersion() 0 7 1
A provideFindOneByContentIdAndLanguageAndVersion() 7 7 1
B testFindForPaginateFilterByContentTypeSiteAndLanguage() 0 34 2
A provideContentTypeAndPaginateAndSearchAndsiteId() 0 15 1
A testCountFilterByContentTypeSiteAndLanguage() 0 5 1
A provideCountByContentTypeAndSiteInLastVersion() 0 11 1
A testFindByHistoryAndSiteId() 7 7 1
A provideFindByHistoryAndSiteId() 0 10 1
B testUpdateStatusByContentType() 0 32 1
A testRemoveVersion() 13 13 1
A generateColumnsProvider() 0 17 4
B getDescriptionColumnEntity() 0 79 1
A assertSameContent() 0 15 4
A testHasStatusedElement() 7 7 1
A findAllPublishedByContentId() 0 6 1
A testFindElementToAutoPublish() 0 7 1
A testFindElementToAutoUnpublish() 0 7 1
B testFindLastVersion() 0 27 1
A replaceKeywordLabelById() 18 18 4

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ContentRepositoryTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ContentRepositoryTest, and based on these observations, apply Extract Interface, too.

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 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);
0 ignored issues
show
Bug introduced by
The method findByLanguage() does not exist on OpenOrchestra\ModelInter...tentRepositoryInterface. Did you maybe mean findOneByLanguage()?

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...
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()
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...
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);
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...
350
        $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...
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)
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...
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
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...
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()
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...
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()
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...
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)
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...
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