Completed
Push — update_vendor ( 4e04e9...325785 )
by amaury
03:22
created

ContentRepositoryTest   C

Complexity

Total Complexity 44

Size/Duplication

Total Lines 629
Duplicated Lines 10.02 %

Coupling/Cohesion

Components 2
Dependencies 8

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 44
c 2
b 0
f 0
lcom 2
cbo 8
dl 63
loc 629
rs 6.1351

33 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 1
A testTestUniquenessInContext() 0 7 1
A provideTestUniquenessInContext() 0 7 1
A testFindOneByContentId() 0 6 1
A provideFindOneByContentId() 0 7 1
A testFindLastPublishedVersion() 0 6 1
A testFindOneCurrentlyPublished() 0 6 1
A providefindLastPublishedVersion() 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
A testFindPaginatedLastVersionByContentTypeAndsite() 0 11 2
A provideContentTypeAndPaginateAndSearchAndsiteId() 0 23 1
A testCountByContentTypeInLastVersion() 0 6 1
A provideContentTypeCount() 0 8 1
A testCountByContentTypeAndSiteInLastVersion() 0 5 1
A provideCountByContentTypeAndSiteInLastVersion() 0 11 1
A testCountByContentTypeInLastVersionWithSearchFilter() 0 11 1
A provideColumnsAndSearchAndCount() 0 16 1
A testFindByAuthorAndsiteId() 0 5 1
A provideFindByAuthorAndsiteId() 0 13 1
A testFindByHistoryAndSiteId() 7 7 1
A provideFindByHistoryAndSiteId() 0 10 1
A generateColumnsProvider() 17 17 4
B getDescriptionColumnEntity() 0 79 1
A assertSameContent() 0 15 4
A testHasStatusedElement() 7 7 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\FinderConfiguration;
7
use OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration;
8
use OpenOrchestra\ModelInterface\Repository\ContentRepositoryInterface;
9
use OpenOrchestra\ModelInterface\Repository\RepositoryTrait\KeywordableTraitInterface;
10
use OpenOrchestra\ModelInterface\ContentEvents;
11
use Phake;
12
13
/**
14
 * Class ContentRepositoryTest
15
 *
16
 * @group integrationTest
17
 */
18
class ContentRepositoryTest extends AbstractKernelTestCase
19
{
20
    /**
21
     * @var ContentRepositoryInterface
22
     */
23
    protected $repository;
24
    protected $keywordRepository;
25
    protected $userRepository;
26
27
    protected $currentsiteManager;
28
29
    /**
30
     * Set up test
31
     */
32
    protected function setUp()
33
    {
34
        parent::setUp();
35
        static::bootKernel();
36
        $this->keywordRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.keyword');
37
        $this->userRepository = static::$kernel->getContainer()->get('open_orchestra_user.repository.user');
38
        $this->currentsiteManager = Phake::mock('OpenOrchestra\BaseBundle\Context\CurrentSiteIdInterface');
39
        Phake::when($this->currentsiteManager)->getCurrentSiteId()->thenReturn('2');
40
        Phake::when($this->currentsiteManager)->getCurrentSiteDefaultLanguage()->thenReturn('fr');
41
42
        $this->repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.content');
43
    }
44
45
    /**
46
     * @param string  $name
47
     * @param boolean $exists
48
     *
49
     * @dataProvider provideTestUniquenessInContext
50
     */
51
    public function testTestUniquenessInContext($name, $exists)
52
    {
53
        $test = $this->repository->testUniquenessInContext($name);
54
55
        $this->assertEquals($exists, $test);
56
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public function provideTestUniquenessInContext()
63
    {
64
        return array(
65
            array('welcome', true),
66
            array('fakeContentId', false),
67
        );
68
    }
69
70
    /**
71
     * @param string $contentId
72
     *
73
     * @dataProvider provideFindOneByContentId
74
     */
75
    public function testFindOneByContentId($contentId)
76
    {
77
        $content = $this->repository->findOneByContentId($contentId);
78
        $this->assertSameContent(null, null, null, $contentId, $content);
79
        $this->assertEquals($contentId, $content->getContentId());
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function provideFindOneByContentId()
86
    {
87
        return array(
88
            array('notre_vision'),
89
            array('bien_vivre_en_france'),
90
        );
91
    }
92
93
    /**
94
     * @param $contentId
95
     * @param $version
96
     * @param string|null $language
97
     *
98
     * @dataProvider providefindLastPublishedVersion
99
     */
100
    public function testFindLastPublishedVersion($contentId, $version, $language)
101
    {
102
        $content = $this->repository->findLastPublishedVersion($contentId, $language);
103
        $this->assertSameContent($language, $version, null, $contentId, $content);
104
        $this->assertEquals($contentId, $content->getContentId());
105
    }
106
107
    /**
108
     * @param $contentId
109
     * @param $version
110
     * @param string|null $language
111
     *
112
     * @dataProvider providefindLastPublishedVersion
113
     */
114
    public function testFindOneCurrentlyPublished($contentId, $version, $language)
115
    {
116
        $content = $this->repository->findOneCurrentlyPublished($contentId, $language, '2');
117
        $this->assertSameContent($language, $version, null, $contentId, $content);
118
        $this->assertEquals($contentId, $content->getContentId());
119
    }
120
121
    /**
122
     * @return array
123
     */
124 View Code Duplication
    public function providefindLastPublishedVersion()
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...
125
    {
126
        return array(
127
            array('notre_vision', 1, 'fr'),
128
            array('bien_vivre_en_france', 1, 'fr'),
129
        );
130
    }
131
132
    /**
133
     * @param string      $contentType
134
     * @param string      $choiceType
135
     * @param string|null $keywords
136
     * @param int         $count
137
     *
138
     * @dataProvider provideContentTypeKeywordAndCount
139
     */
140
    public function testFindByContentTypeAndCondition($contentType = '', $choiceType, $keywords = null, $count)
141
    {
142
        $keywords = $this->replaceKeywordLabelById($keywords);
143
144
        $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...
145
        $elements = $this->repository->findByContentTypeAndCondition($language, $contentType, $choiceType, $keywords);
146
147
        $this->assertCount($count, $elements);
148
    }
149
150
    /**
151
     * @return array
152
     */
153
    public function provideContentTypeKeywordAndCount()
154
    {
155
        return array(
156
            array('car', ContentRepositoryInterface::CHOICE_AND, 'lorem', 3),
157
            array('car',ContentRepositoryInterface::CHOICE_AND, 'sit', 1),
158
            array('car', ContentRepositoryInterface::CHOICE_AND, 'dolor', 0),
159
            array('car', ContentRepositoryInterface::CHOICE_AND, 'sit AND lorem', 1),
160
            array('news', ContentRepositoryInterface::CHOICE_AND, 'lorem', 1),
161
            array('news', ContentRepositoryInterface::CHOICE_AND, 'sit', 2),
162
            array('news', ContentRepositoryInterface::CHOICE_AND, 'dolor', 0),
163
            array('news', ContentRepositoryInterface::CHOICE_AND, 'lorem AND sit', 1),
164
            array('news', ContentRepositoryInterface::CHOICE_AND, '', 4),
165
            array('car', ContentRepositoryInterface::CHOICE_AND, '', 3),
166
            array('', ContentRepositoryInterface::CHOICE_AND, '', 9),
167
            array('', ContentRepositoryInterface::CHOICE_AND, '', 9),
168
            array('', ContentRepositoryInterface::CHOICE_AND, 'lorem', 5),
169
            array('', ContentRepositoryInterface::CHOICE_AND, 'sit', 4),
170
            array('', ContentRepositoryInterface::CHOICE_AND, 'dolor', 0),
171
            array('', ContentRepositoryInterface::CHOICE_AND, 'lorem AND sit', 3),
172
            array('car', ContentRepositoryInterface::CHOICE_OR, 'lorem', 5),
173
            array('car', ContentRepositoryInterface::CHOICE_OR, 'sit', 6),
174
            array('car', ContentRepositoryInterface::CHOICE_OR, 'dolor', 3),
175
            array('car', ContentRepositoryInterface::CHOICE_OR, 'lorem AND sit', 5),
176
            array('news', ContentRepositoryInterface::CHOICE_OR, 'lorem', 8),
177
            array('news', ContentRepositoryInterface::CHOICE_OR, 'sit', 6),
178
            array('news', ContentRepositoryInterface::CHOICE_OR, 'dolor', 4),
179
            array('news', ContentRepositoryInterface::CHOICE_OR, 'lorem AND sit', 6),
180
            array('news', ContentRepositoryInterface::CHOICE_OR, '', 4),
181
            array('car', ContentRepositoryInterface::CHOICE_OR, '', 3),
182
            array('', ContentRepositoryInterface::CHOICE_OR, '', 9),
183
            array('', ContentRepositoryInterface::CHOICE_OR, 'lorem', 5),
184
            array('', ContentRepositoryInterface::CHOICE_OR, 'sit', 4),
185
            array('', ContentRepositoryInterface::CHOICE_OR, 'dolor', 0),
186
            array('', ContentRepositoryInterface::CHOICE_OR, 'lorem AND sit', 3),
187
            array('', ContentRepositoryInterface::CHOICE_OR, '', 9),
188
        );
189
    }
190
191
    /**
192
     * @param string $contentId
193
     * @param string $language
194
     *
195
     * @dataProvider provideFindOneByContentIdAndLanguage
196
     */
197
    public function testFindOneByLanguage($contentId, $language)
198
    {
199
        $content = $this->repository->findOneByLanguage($contentId, $language);
200
201
        $this->assertSameContent($language, null, null, $contentId, $content);
202
    }
203
204
    /**
205
     * @return array
206
     */
207
    public function provideFindOneByContentIdAndLanguage()
208
    {
209
        return array(
210
            array('notre_vision', 'fr'),
211
            array('bien_vivre_en_france', 'fr'),
212
        );
213
    }
214
215
    /**
216
     * @param string $contentId
217
     * @param string $language
218
     *
219
     * @dataProvider provideFindByContentIdAndLanguage
220
     */
221
    public function testFindByLanguage($contentId, $language)
222
    {
223
        $contents = $this->repository->findByLanguage($contentId, $language);
224
225
        foreach ($contents as $content) {
226
            $this->assertSameContent($language, null, null, $contentId, $content);
227
        }
228
229
    }
230
231
    /**
232
     * @return array
233
     */
234
    public function provideFindByContentIdAndLanguage()
235
    {
236
        return array(
237
            array('notre_vision', 'fr'),
238
            array('bien_vivre_en_france', 'fr'),
239
        );
240
    }
241
242
    /**
243
     * @param string $contentId
244
     * @param string $language
245
     * @param int    $version
246
     *
247
     * @dataProvider provideFindOneByContentIdAndLanguageAndVersion
248
     */
249
    public function testFindOneByLanguageAndVersion($contentId, $language, $version)
250
    {
251
        $content = $this->repository->findOneByLanguageAndVersion($contentId, $language, $version);
252
253
        $this->assertSameContent($language, $version, null, $contentId, $content);
254
255
    }
256
257
    /**
258
     * @return array
259
     */
260 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...
261
    {
262
        return array(
263
            array('notre_vision', 'fr', 1),
264
            array('bien_vivre_en_france', 'fr', 1),
265
        );
266
    }
267
268
    /**
269
     * @param string   $contentType
270
     * @param array    $descriptionEntity
271
     * @param array    $search
272
     * @param string   $siteId
273
     * @param int      $skip
274
     * @param int      $limit
275
     * @param integer  $count
276
     *
277
     * @dataProvider provideContentTypeAndPaginateAndSearchAndsiteId
278
     */
279
    public function testFindPaginatedLastVersionByContentTypeAndsite($contentType, $descriptionEntity, $search, $order, $siteId, $skip, $limit, $count, $name = null)
280
    {
281
        $configuration = PaginateFinderConfiguration::generateFromVariable($descriptionEntity, $search);
282
        $configuration->setPaginateConfiguration($order, $skip, $limit);
283
        $contents = $this->repository->findPaginatedLastVersionByContentTypeAndsite($contentType, $configuration, $siteId);
0 ignored issues
show
Documentation introduced by
$configuration is of type object<OpenOrchestra\Pag...on\FinderConfiguration>, but the function expects a null|object<OpenOrchestr...ateFinderConfiguration>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
284
285
        if(!is_null($name)) {
286
            $this->assertEquals($name, $contents[0]->getName());
287
        }
288
        $this->assertCount($count, $contents);
289
    }
290
291
    /**
292
     * @return array
293
     */
294
    public function provideContentTypeAndPaginateAndSearchAndsiteId()
295
    {
296
        $descriptionEntity = $this->getDescriptionColumnEntity();
297
298
        return array(
299
            array('car', $descriptionEntity, null, array("name" => "name", "dir" => "asc"), null, 0 ,5 , 3, '206 3 portes fr'),
300
            array('car', $descriptionEntity, null, array("name" => "name", "dir" => "desc"), null, 0 ,5 , 3, 'R5 3 portes en'),
301
            array('car', $descriptionEntity, null, array("name" => "attributes.car_name.string_value", "dir" => "asc"), null, 0 ,5 , 3, '206 3 portes fr'),
302
            array('car', $descriptionEntity, null, array("name" => "attributes.car_name.string_value", "dir" => "desc"), null, 0 ,5 , 3, 'R5 3 portes en'),
303
            array('car', $descriptionEntity, null, null, null, 0 ,1 , 1),
304
            array('car', $descriptionEntity, $this->generateColumnsProvider(array('name' => '206')), null, null, 0 ,2 , 1),
305
            array('car', $descriptionEntity, $this->generateColumnsProvider(array('version' => '2')), null, null, 0 ,2 , 2),
306
            array('news', $descriptionEntity, null, null, null, 0 , 100, 4),
307
            array('news', $descriptionEntity, null, null, null, 50 , 100, 0),
308
            array('news', $descriptionEntity, $this->generateColumnsProvider(array('name' => 'news')), null, null, 0 , null, 0),
309
            array('car', $descriptionEntity, null, null, '2', 0 ,5 , 3),
310
            array('car', $descriptionEntity, $this->generateColumnsProvider(array('status_label' => 'publish')), null, null, null ,null , 3),
311
            array('car', $descriptionEntity, $this->generateColumnsProvider(array('status_label' => 'Publi')), null, null, null ,null , 3),
312
            array('car', $descriptionEntity, $this->generateColumnsProvider(array('status_label' => 'draft')), null, null, null ,null , 0),
313
            array('car', $descriptionEntity, $this->generateColumnsProvider(array('status_label' => 'brouillon')), null, null, null ,null , 0),
314
315
        );
316
    }
317
318
    /**
319
     * @param string  $contentType
320
     * @param integer $count
321
     *
322
     * @dataProvider provideContentTypeCount
323
     * @deprecated will be removed in 2.0, use countByContentTypeAndSiteInLastVersion
324
     */
325
    public function testCountByContentTypeInLastVersion($contentType, $count)
326
    {
327
        @trigger_error('The '.__METHOD__.' method is deprecated since version 1.1.3 and will be removed in 2.0. Use the '.__CLASS__.'::countByContentTypeAndSiteInLastVersion method instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
328
        $contents = $this->repository->countByContentTypeInLastVersion($contentType);
0 ignored issues
show
Deprecated Code introduced by
The method OpenOrchestra\ModelInter...tentTypeInLastVersion() has been deprecated with message: will be removed in 2.0, use countByContentTypeAndSiteInLastVersion

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
329
        $this->assertEquals($count, $contents);
330
    }
331
332
    /**
333
     * @return array
334
     */
335
    public function provideContentTypeCount()
336
    {
337
        return array(
338
            array('car', 3),
339
            array('customer', 2),
340
            array('news', 4),
341
        );
342
    }
343
344
    /**
345
     * @param string  $contentType
346
     * @param string  $siteId
347
     * @param integer $count
348
     *
349
     * @dataProvider provideCountByContentTypeAndSiteInLastVersion
350
     */
351
    public function testCountByContentTypeAndSiteInLastVersion($contentType, $siteId, $count)
352
    {
353
        $contents = $this->repository->countByContentTypeAndSiteInLastVersion($contentType, $siteId);
354
        $this->assertEquals($count, $contents);
355
    }
356
357
    /**
358
     * @return array
359
     */
360
    public function provideCountByContentTypeAndSiteInLastVersion()
361
    {
362
        return array(
363
            array('car', '1', 2),
364
            array('car', '2', 3),
365
            array('customer', '1', 1),
366
            array('customer', '2', 1),
367
            array('news', '1', 3),
368
            array('news', '2', 4),
369
        );
370
    }
371
372
    /**
373
     * @param string  $contentType
374
     * @param array   $descriptionEntity
375
     * @param string  $search
376
     * @param string  $siteId
377
     * @param int     $count
378
     *
379
     * @dataProvider provideColumnsAndSearchAndCount
380
     */
381
    public function testCountByContentTypeInLastVersionWithSearchFilter(
382
        $contentType,
383
        $descriptionEntity,
384
        $search,
385
        $siteId,
386
        $count
387
    ) {
388
        $configuration = FinderConfiguration::generateFromVariable($descriptionEntity, $search);
0 ignored issues
show
Documentation introduced by
$search is of type string, but the function expects a null|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
389
        $contents = $this->repository->countByContentTypeInLastVersionWithFilter($contentType, $configuration, $siteId);
390
        $this->assertEquals($count, $contents);
391
    }
392
    /**
393
     * @return array
394
     */
395
    public function provideColumnsAndSearchAndCount()
396
    {
397
        $descriptionEntity = $this->getDescriptionColumnEntity();
398
        return array(
399
            array('car', $descriptionEntity, $this->generateColumnsProvider(array('name' => '206')), '1', 1),
400
            array('car', $descriptionEntity, $this->generateColumnsProvider(array('name' => '206')), '2', 1),
401
            array('car', $descriptionEntity, $this->generateColumnsProvider(array('name' => 'DS 3')), '1', 0),
402
            array('car', $descriptionEntity, $this->generateColumnsProvider(array('name' => 'DS 3')), '2', 1),
403
            array('car', $descriptionEntity, $this->generateColumnsProvider(null, 'portes'), '1', 2),
404
            array('car', $descriptionEntity, $this->generateColumnsProvider(null, 'portes'), '2', 2),
405
            array('news', $descriptionEntity, $this->generateColumnsProvider(null, 'news'), '1', 0),
406
            array('news', $descriptionEntity, $this->generateColumnsProvider(null, 'news'), '2', 0),
407
            array('news', $descriptionEntity, $this->generateColumnsProvider(null, 'lorem'), '1', 1),
408
            array('news', $descriptionEntity, $this->generateColumnsProvider(null, 'lorem'), '2', 1),
409
        );
410
    }
411
412
    /**
413
     * @param string       $author
414
     * @param string       $siteId
415
     * @param boolean|null $published
416
     * @param int          $limit
417
     * @param array|null   $sort
418
     * @param int          $count
419
     *
420
     * @dataProvider provideFindByAuthorAndsiteId
421
     */
422
    public function testFindByAuthorAndsiteId($author, $siteId, $published, $limit, $sort, $count)
423
    {
424
        $contents = $this->repository->findByAuthorAndsiteId($author, $siteId, $published, $limit, $sort);
0 ignored issues
show
Deprecated Code introduced by
The method OpenOrchestra\ModelInter...findByAuthorAndSiteId() has been deprecated with message: will be removed in 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
425
        $this->assertCount($count, $contents);
426
    }
427
428
    /**
429
     * @return array
430
     */
431
    public function provideFindByAuthorAndsiteId()
432
    {
433
        return array(
434
            array('admin', '2', null, 10, array('updatedAt' => -1), 8),
435
            array('admin', '2', false, 10, null, 0),
436
            array('admin', '2', true, 10, null, 8),
437
            array('fakeContributor', '2', false, 10, null, 0),
438
            array('fakeContributor', '2', null, 10, null, 0),
439
            array('admin', '3', true, 10, null, 7),
440
            array('admin', 'not-an-id', true, 10, null, 6),
441
            array('admin', 'not-an-id', true, 3, null, 3),
442
        );
443
    }
444
445
    /**
446
     * @param string       $user
447
     * @param string       $siteId
448
     * @param array        $eventTypes
449
     * @param boolean|null $published
450
     * @param int          $limit
451
     * @param array|null   $sort
452
     * @param int          $count
453
     *
454
     * @dataProvider provideFindByHistoryAndSiteId
455
     */
456 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...
457
    {
458
        $user = $this->userRepository->findOneByUsername($user);
459
460
        $contents = $this->repository->findByHistoryAndSiteId($user->getId(), $siteId, $eventTypes, $published, $limit, $sort);
461
        $this->assertCount($count, $contents);
462
    }
463
464
    /**
465
     * @return array
466
     */
467
    public function provideFindByHistoryAndSiteId()
468
    {
469
        return array(
470
            array('admin', '2', array(ContentEvents::CONTENT_CREATION), null, 10, array('updatedAt' => -1), 2),
471
            array('admin', '2', array(ContentEvents::CONTENT_CREATION), false, 10, null, 0),
472
            array('admin', '2', array(ContentEvents::CONTENT_CREATION), true, 10, null, 2),
473
            array('admin', '2', array(ContentEvents::CONTENT_UPDATE), true, 10, null, 1),
474
            array('admin', '2', array(ContentEvents::CONTENT_CREATION, ContentEvents::CONTENT_UPDATE), true, 10, null, 3),
475
        );
476
    }
477
478
    /**
479
     * Generate columns of content with search value
480
     *
481
     * @param array|null $searchColumns
482
     * @param string     $globalSearch
483
     *
484
     * @return array
485
     */
486 View Code Duplication
    protected function generateColumnsProvider($searchColumns = null, $globalSearch = '')
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...
487
    {
488
        $search = array();
489
        if (null !== $searchColumns) {
490
            $columns = array();
491
            foreach ($searchColumns as $name => $value) {
492
                $columns[$name] = $value;
493
            }
494
            $search['columns'] = $columns;
495
        }
496
497
        if (!empty($globalSearch)) {
498
            $search['global'] = $globalSearch;
499
        }
500
501
        return $search;
502
    }
503
504
    /**
505
     * Generate relation between columns names and entities attributes
506
     *
507
     * @return array
508
     */
509
    protected function getDescriptionColumnEntity()
510
    {
511
        return array (
512
            'name' =>
513
            array (
514
                'key' => 'name',
515
                'field' => 'name',
516
                'type' => 'string',
517
            ),
518
            'language' =>
519
            array (
520
                'key' => 'language',
521
                'field' => 'language',
522
                'type' => 'string',
523
            ),
524
            'status_label' =>
525
            array (
526
                'key' => 'status_label',
527
                'field' => 'status',
528
                'type' => 'multiLanguages',
529
            ),
530
            'version' =>
531
            array (
532
                'key' => 'version',
533
                'field' => 'version',
534
                'type' => 'integer',
535
            ),
536
            'linked_to_site' =>
537
            array (
538
                'key' => 'linked_to_site',
539
                'field' => 'linkedTosite',
540
                'type' => 'boolean',
541
            ),
542
            'created_by' =>
543
            array (
544
                'key' => 'created_by',
545
                'field' => 'createdBy',
546
                'type' => 'string',
547
            ),
548
            'updated_by' =>
549
            array (
550
                'key' => 'updated_by',
551
                'field' => 'updatedBy',
552
                'type' => 'string',
553
            ),
554
            'created_at' =>
555
            array (
556
                'key' => 'created_at',
557
                'field' => 'createdAt',
558
                'type' => 'date',
559
            ),
560
            'updated_at' =>
561
            array (
562
                'key' => 'updated_at',
563
                'field' => 'updatedAt',
564
                'type' => 'date',
565
            ),
566
            'deleted' =>
567
            array (
568
                'key' => 'deleted',
569
                'field' => 'deleted',
570
                'type' => 'boolean',
571
            ),
572
            'attributes.car_name.string_value' =>
573
            array(
574
                'key' => 'attributes.car_name.string_value',
575
                'field' => 'attributes.car_name.stringValue',
576
                'type' => 'string',
577
                'value' => NULL,
578
            ),
579
            'attributes.description.string_value' =>
580
            array(
581
                'key' => 'attributes.description.string_value',
582
                'field' => 'attributes.description.stringValue',
583
                'type' => 'string',
584
                'value' => NULL,
585
            ),
586
        );
587
    }
588
589
    /**
590
     * @param string                                               $language
591
     * @param int                                                  $version
592
     * @param string                                               $siteId
593
     * @param \OpenOrchestra\ModelInterface\Model\ContentInterface $content
594
     * @param string                                               $contentId
595
     */
596
    protected function assertSameContent($language, $version, $siteId, $contentId, $content)
597
    {
598
        $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\ContentInterface', $content);
599
        $this->assertSame($contentId, $content->getContentId());
600
        if (!is_null($language)) {
601
            $this->assertSame($language, $content->getLanguage());
602
        }
603
        if (!is_null($version)) {
604
            $this->assertSame($version, $content->getVersion());
605
        }
606
        if (!is_null($siteId)) {
607
            $this->assertSame($siteId, $content->getsiteId());
608
        }
609
        $this->assertSame(false, $content->isDeleted());
610
    }
611
612
    /**
613
     * Test has statused element
614
     */
615 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...
616
    {
617
        $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
618
        $status = $statusRepository->findOneByInitial();
619
620
        $this->assertFalse($this->repository->hasStatusedElement($status));
621
    }
622
623
    /**
624
     * @param string $condition
625
     *
626
     * @return array
627
     */
628 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...
629
    {
630
        $conditionWithoutOperator = preg_replace(explode('|', KeywordableTraitInterface::OPERATOR_SPLIT), ' ', $condition);
631
        $conditionArray = explode(' ', $conditionWithoutOperator);
632
633
        foreach ($conditionArray as $keyword) {
634
            if ($keyword != '') {
635
                $keywordDocument = $this->keywordRepository->findOneByLabel($keyword);
636
                if (!is_null($keywordDocument)) {
637
                    $condition = str_replace($keyword, $keywordDocument->getId(), $condition);
638
                } else {
639
                    return '';
640
                }
641
            }
642
        }
643
644
        return $condition;
645
    }
646
}
647