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\MediaAdminBundle\EventSubscriber; |
||
4 | |||
5 | use OpenOrchestra\FunctionalTests\Utils\AbstractAuthenticatedTest; |
||
6 | use OpenOrchestra\Media\Model\MediaInterface; |
||
7 | use OpenOrchestra\MediaModelBundle\Document\Media; |
||
8 | use OpenOrchestra\ModelBundle\Document\Block; |
||
9 | use OpenOrchestra\ModelBundle\Document\Node; |
||
10 | use Symfony\Component\EventDispatcher\EventDispatcher; |
||
11 | use OpenOrchestra\ModelInterface\Event\BlockEvent; |
||
12 | use OpenOrchestra\ModelInterface\BlockEvents; |
||
13 | |||
14 | /** |
||
15 | * Class UpdateMediaReferenceSubscriberTest |
||
16 | * |
||
17 | * @group media |
||
18 | */ |
||
19 | class UpdateMediaReferenceSubscriberTest extends AbstractAuthenticatedTest |
||
20 | { |
||
21 | const ATTRIBUTE_ID_SUFFIX = "Id"; |
||
22 | const METHOD_SUFFIX = "BlockConfiguration"; |
||
23 | |||
24 | /** |
||
25 | * @var Node node |
||
26 | */ |
||
27 | protected $node; |
||
28 | |||
29 | /** |
||
30 | * @var array medias |
||
31 | */ |
||
32 | protected $medias; |
||
33 | |||
34 | /** |
||
35 | * @var EventDispatcher eventDispatcher |
||
36 | */ |
||
37 | protected $eventDispatcher; |
||
38 | |||
39 | /** |
||
40 | * Set up the test |
||
41 | */ |
||
42 | public function setUp() |
||
43 | { |
||
44 | parent::setUp(); |
||
45 | |||
46 | $mediaRepository = static::$kernel->getContainer()->get('open_orchestra_media.repository.media'); |
||
47 | $this->medias = array( |
||
48 | $mediaRepository->findOneByName("Image 03"), |
||
49 | $mediaRepository->findOneByName("Image 04") |
||
50 | ); |
||
51 | $this->eventDispatcher = static::$kernel->getContainer()->get('event_dispatcher'); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param array $blockType |
||
56 | * @param int $mediaIndex |
||
57 | * |
||
58 | * @dataProvider provideMediaBlocks |
||
59 | */ |
||
60 | public function testAddMediaBlocks(array $blockType, $mediaIndex) |
||
61 | { |
||
62 | /** @var Media $media */ |
||
63 | $media = $this->medias[$mediaIndex]; |
||
64 | $this->checkMediaReference($media, array()); |
||
65 | |||
66 | $block = $this->generateBlock($blockType['component']); |
||
67 | $attributes = $block->getAttributes(); |
||
68 | $attributes['pictures'] = array(array('id' => $media->getId(), 'format' => '')); |
||
69 | $attributes['id'] = $blockType["component"] . self::ATTRIBUTE_ID_SUFFIX; |
||
70 | $method = $blockType["component"] . self::METHOD_SUFFIX; |
||
71 | $attributes = $this->$method($attributes); |
||
72 | $block->setAttributes($attributes); |
||
73 | |||
74 | $event = new BlockEvent($block); |
||
75 | |||
76 | $this->eventDispatcher->dispatch(BlockEvents::POST_BLOCK_UPDATE, $event); |
||
77 | |||
78 | $expectedReference = array('block' => array($block->getId() => $block->getId())); |
||
79 | $this->checkMediaReference($media, $expectedReference); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @return array |
||
84 | */ |
||
85 | public function provideMediaBlocks() |
||
86 | { |
||
87 | return array( |
||
88 | array(array("component" => "gallery"), 0), |
||
89 | array(array("component" => "slideshow"), 1), |
||
90 | ); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param MediaInterface $media |
||
95 | * @param array $expectedReference |
||
96 | */ |
||
97 | protected function checkMediaReference($media, $expectedReference) |
||
98 | { |
||
99 | $references = $media->getUseReferences(); |
||
100 | $this->assertEquals($references, $expectedReference); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @param array $attributes |
||
105 | * |
||
106 | * @return array |
||
107 | */ |
||
108 | protected function slideshowBlockConfiguration($attributes) |
||
109 | { |
||
110 | $attributes['height'] = 200; |
||
111 | $attributes['width'] = 250; |
||
112 | |||
113 | return $attributes; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @param array $attributes |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | protected function galleryBlockConfiguration($attributes) |
||
122 | { |
||
123 | $attributes['imageFormat'] = MediaInterface::MEDIA_ORIGINAL; |
||
124 | $attributes['thumbnailFormat'] = MediaInterface::MEDIA_ORIGINAL; |
||
125 | $attributes['width'] = ''; |
||
126 | |||
127 | return $attributes; |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @param string $blockType |
||
132 | * @param string $id |
||
0 ignored issues
–
show
|
|||
133 | * |
||
134 | * @return Block |
||
135 | */ |
||
136 | protected function generateBlock($blockType) |
||
137 | { |
||
138 | $block = new Block(); |
||
139 | $block->setComponent($blockType); |
||
140 | |||
141 | static::$kernel->getContainer()->get('object_manager')->persist($block); |
||
142 | static::$kernel->getContainer()->get('object_manager')->flush(); |
||
143 | |||
144 | return $block; |
||
145 | } |
||
146 | } |
||
147 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.