This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace OpenOrchestra\FunctionalTests\MediaBundle\Repository; |
||
4 | |||
5 | use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractKernelTestCase; |
||
6 | use OpenOrchestra\Media\DisplayMedia\Strategies\VideoStrategy; |
||
7 | use OpenOrchestra\Media\Repository\MediaRepositoryInterface; |
||
8 | use OpenOrchestra\MediaAdmin\FileAlternatives\Strategy\ImageStrategy; |
||
9 | use OpenOrchestra\ModelInterface\Repository\RepositoryTrait\KeywordableTraitInterface; |
||
10 | use OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration; |
||
11 | |||
12 | /** |
||
13 | * Class MediaRepositoryTest |
||
14 | * |
||
15 | * @group integrationTest |
||
16 | */ |
||
17 | class MediaRepositoryTest extends AbstractKernelTestCase |
||
18 | { |
||
19 | /** |
||
20 | * @var MediaRepositoryInterface |
||
21 | */ |
||
22 | protected $repository; |
||
23 | protected $keywordRepository; |
||
24 | |||
25 | /** |
||
26 | * Set up test |
||
27 | */ |
||
28 | View Code Duplication | protected function setUp() |
|
0 ignored issues
–
show
|
|||
29 | { |
||
30 | parent::setUp(); |
||
31 | |||
32 | static::bootKernel(); |
||
33 | $this->keywordRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.keyword'); |
||
34 | $this->repository = static::$kernel->getContainer()->get('open_orchestra_media.repository.media'); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param string $keywords |
||
39 | * @param int $count |
||
40 | * |
||
41 | * @dataProvider provideKeywordAndCount |
||
42 | */ |
||
43 | public function testFindByKeywords($keywords, $count) |
||
44 | { |
||
45 | $keywords = $this->replaceKeywordLabelById($keywords); |
||
46 | $keywords = $this->repository->findByKeywords($keywords); |
||
47 | |||
48 | $this->assertCount($count, $keywords); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return array |
||
53 | */ |
||
54 | public function provideKeywordAndCount() |
||
55 | { |
||
56 | return array( |
||
57 | array('lorem', 5), |
||
58 | array('sit', 0), |
||
59 | array('dolor', 4), |
||
60 | array('lorem OR dolor', 5), |
||
61 | ); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @param string $condition |
||
66 | * |
||
67 | * @return array |
||
68 | */ |
||
69 | View Code Duplication | protected function replaceKeywordLabelById($condition) |
|
0 ignored issues
–
show
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...
|
|||
70 | { |
||
71 | $conditionWithoutOperator = preg_replace(explode('|', KeywordableTraitInterface::OPERATOR_SPLIT), ' ', $condition); |
||
72 | $conditionArray = explode(' ', $conditionWithoutOperator); |
||
73 | |||
74 | foreach ($conditionArray as $keyword) { |
||
75 | if ($keyword != '') { |
||
76 | $keywordDocument = $this->keywordRepository->findOneByLabel($keyword); |
||
77 | if (!is_null($keywordDocument)) { |
||
78 | $condition = str_replace($keyword, $keywordDocument->getId(), $condition); |
||
79 | } else { |
||
80 | return ''; |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | |||
85 | return $condition; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * test findForPaginate |
||
90 | * |
||
91 | * @param string $siteId |
||
92 | * @param PaginateFinderConfiguration $configuration |
||
93 | * @param int $expectedCount |
||
94 | * @param int $expectedFilteredCount |
||
95 | * |
||
96 | * @dataProvider providePaginateConfiguration |
||
97 | */ |
||
98 | public function testFindForPaginate($siteId, PaginateFinderConfiguration $configuration, $expectedCount, $expectedFilteredCount) |
||
0 ignored issues
–
show
|
|||
99 | { |
||
100 | $this->assertCount($expectedCount, $this->repository->findForPaginate($configuration, $siteId)); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * test count |
||
105 | */ |
||
106 | public function testCount() |
||
107 | { |
||
108 | $this->assertSame(6, $this->repository->count('2')); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * test count with Filtertered |
||
113 | */ |
||
114 | public function testCountFiltered() |
||
115 | { |
||
116 | $this->assertSame(1, $this->repository->count('2', 'pdf')); |
||
117 | $this->assertSame(5, $this->repository->count('2', 'image')); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * test countWithFilter |
||
122 | * |
||
123 | * @param string $siteId |
||
124 | * @param PaginateFinderConfiguration $configuration |
||
125 | * @param int $expectedCount |
||
126 | * @param int $expectedFilteredCount |
||
127 | * |
||
128 | * @dataProvider providePaginateConfiguration |
||
129 | */ |
||
130 | public function testCountWithFilter($siteId, PaginateFinderConfiguration $configuration, $expectedCount, $expectedFilteredCount) |
||
0 ignored issues
–
show
|
|||
131 | { |
||
132 | $this->assertSame($expectedFilteredCount, $this->repository->countWithFilter($configuration, $siteId)); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Provide PaginateFinderConfiguration |
||
137 | * |
||
138 | * @return array |
||
139 | */ |
||
140 | public function providePaginateConfiguration() |
||
141 | { |
||
142 | $mapping = array(); |
||
143 | $conf1 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, null); |
||
144 | $conf2 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, array('label' => 'dolor', 'language' => 'en')); |
||
145 | $conf3 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, array('type' => 'pdf')); |
||
146 | |||
147 | return array( |
||
148 | 'No criteria' => array('2', $conf1, 6, 6), |
||
149 | 'Filtering "dolor"' => array('2', $conf2, 4, 4), |
||
150 | 'Filtering pdf' => array('2', $conf3, 1, 1), |
||
151 | ); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Test remove medias |
||
156 | */ |
||
157 | View Code Duplication | public function testRemoveMedias() |
|
0 ignored issues
–
show
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...
|
|||
158 | { |
||
159 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
160 | $image01 = $this->repository->findOneByName('Image 01'); |
||
161 | $image02 = $this->repository->findOneByName('Image 02'); |
||
162 | |||
163 | $mediaIds = array($image01->getId(), $image02->getId()); |
||
164 | |||
165 | $this->repository->removeMedias($mediaIds); |
||
166 | $this->assertNull($this->repository->findOneByName('Image 01')); |
||
167 | $this->assertNull($this->repository->findOneByName('Image 02')); |
||
168 | |||
169 | $dm->persist(clone $image01); |
||
170 | $dm->persist(clone $image02); |
||
171 | $dm->flush(); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * test countByFolderId |
||
176 | */ |
||
177 | public function testCountByFolderId() |
||
178 | { |
||
179 | $folderRepository = static::$kernel->getContainer()->get('open_orchestra_media.repository.media_folder'); |
||
180 | $folder = $folderRepository->findOneBy(array('folderId' => 'files')); |
||
181 | $this->assertEquals(0, $this->repository->countByFolderId($folder->getId())); |
||
182 | |||
183 | $folder = $folderRepository->findOneBy(array('folderId' => 'images')); |
||
184 | $this->assertEquals(4, $this->repository->countByFolderId($folder->getId())); |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * Test is media type of |
||
189 | */ |
||
190 | public function testIsMediaTypeOf() |
||
191 | { |
||
192 | $image = $this->repository->findOneByName('logo Open-Orchestra'); |
||
193 | |||
194 | $this->assertEquals(true, $this->repository->isMediaTypeOf($image->getId(), ImageStrategy::MEDIA_TYPE)); |
||
195 | $this->assertEquals(false, $this->repository->isMediaTypeOf($image->getId(), VideoStrategy::MEDIA_TYPE)); |
||
196 | } |
||
197 | } |
||
198 |
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.