sonata-project /
SonataMediaBundle
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 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /* |
||
| 6 | * This file is part of the Sonata Project package. |
||
| 7 | * |
||
| 8 | * (c) Thomas Rabaix <[email protected]> |
||
| 9 | * |
||
| 10 | * For the full copyright and license information, please view the LICENSE |
||
| 11 | * file that was distributed with this source code. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Sonata\MediaBundle\Tests\Provider; |
||
| 15 | |||
| 16 | use Gaufrette\Adapter; |
||
| 17 | use Gaufrette\Filesystem; |
||
| 18 | use Sonata\AdminBundle\Form\FormMapper; |
||
| 19 | use Sonata\MediaBundle\CDN\CDNInterface; |
||
| 20 | use Sonata\MediaBundle\CDN\Server; |
||
| 21 | use Sonata\MediaBundle\Generator\IdGenerator; |
||
| 22 | use Sonata\MediaBundle\Model\MediaInterface; |
||
| 23 | use Sonata\MediaBundle\Provider\BaseProvider; |
||
| 24 | use Sonata\MediaBundle\Provider\MediaProviderInterface; |
||
| 25 | use Sonata\MediaBundle\Tests\Entity\Media; |
||
| 26 | use Sonata\MediaBundle\Thumbnail\ThumbnailInterface; |
||
| 27 | use Symfony\Component\Form\FormBuilder; |
||
| 28 | |||
| 29 | class BaseProviderTest extends AbstractProviderTest |
||
| 30 | { |
||
| 31 | public function getProvider(): MediaProviderInterface |
||
| 32 | { |
||
| 33 | $adapter = $this->createMock(Adapter::class); |
||
| 34 | |||
| 35 | $filesystem = $this->getMockBuilder(Filesystem::class) |
||
| 36 | ->onlyMethods(['get']) |
||
| 37 | ->setConstructorArgs([$adapter]) |
||
| 38 | ->getMock(); |
||
| 39 | |||
| 40 | $cdn = new Server('/uploads/media'); |
||
| 41 | |||
| 42 | $generator = new IdGenerator(); |
||
| 43 | |||
| 44 | $thumbnail = $this->createMock(ThumbnailInterface::class); |
||
| 45 | |||
| 46 | $provider = new TestProvider('test', $filesystem, $cdn, $generator, $thumbnail); |
||
| 47 | $this->assertInstanceOf(BaseProvider::class, $provider); |
||
| 48 | |||
| 49 | return $provider; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function testBaseProvider(): void |
||
| 53 | { |
||
| 54 | $provider = $this->getProvider(); |
||
| 55 | $provider->setTemplates([ |
||
| 56 | 'edit' => 'edit.twig', |
||
| 57 | ]); |
||
| 58 | |||
| 59 | $this->assertIsArray($provider->getTemplates()); |
||
| 60 | $this->assertSame('edit.twig', $provider->getTemplate('edit')); |
||
| 61 | |||
| 62 | $this->assertInstanceOf(CDNInterface::class, $provider->getCdn()); |
||
|
0 ignored issues
–
show
|
|||
| 63 | |||
| 64 | $provider->addFormat('small', []); |
||
| 65 | |||
| 66 | $this->assertIsArray($provider->getFormat('small')); |
||
| 67 | |||
| 68 | $media = new Media(); |
||
| 69 | $media->setContext('test'); |
||
| 70 | |||
| 71 | $this->assertSame('admin', $provider->getFormatName($media, 'admin')); |
||
| 72 | $this->assertSame('reference', $provider->getFormatName($media, 'reference')); |
||
| 73 | $this->assertSame('test_small', $provider->getFormatName($media, 'small')); |
||
| 74 | $this->assertSame('test_small', $provider->getFormatName($media, 'test_small')); |
||
| 75 | } |
||
| 76 | |||
| 77 | public function testGetCdnPath(): void |
||
| 78 | { |
||
| 79 | $provider = $this->getProvider(); |
||
| 80 | $this->assertSame('/uploads/media/my_file.txt', $provider->getCdnPath('my_file.txt', false)); |
||
| 81 | } |
||
| 82 | |||
| 83 | public function testMetadata(): void |
||
| 84 | { |
||
| 85 | $provider = $this->getProvider(); |
||
| 86 | |||
| 87 | $this->assertSame('test', $provider->getProviderMetadata()->getTitle()); |
||
| 88 | $this->assertSame('test.description', $provider->getProviderMetadata()->getDescription()); |
||
| 89 | $this->assertNotNull($provider->getProviderMetadata()->getImage()); |
||
| 90 | $this->assertSame('fa fa-file', $provider->getProviderMetadata()->getOption('class')); |
||
| 91 | $this->assertSame('SonataMediaBundle', $provider->getProviderMetadata()->getDomain()); |
||
| 92 | } |
||
| 93 | |||
| 94 | public function testPostRemove(): void |
||
| 95 | { |
||
| 96 | $reflect = new \ReflectionClass(BaseProvider::class); |
||
| 97 | $prop = $reflect->getProperty('clones'); |
||
| 98 | $prop->setAccessible(true); |
||
| 99 | |||
| 100 | $provider = $this->getProvider(); |
||
| 101 | $media = new Media(); |
||
| 102 | $media->setId(1399); |
||
| 103 | $media->setProviderReference('1f981a048e7d8b671415d17e9633abc0059df394.png'); |
||
| 104 | $hash = spl_object_hash($media); |
||
| 105 | |||
| 106 | $provider->preRemove($media); |
||
| 107 | |||
| 108 | $this->assertArrayHasKey($hash, $prop->getValue($provider)); |
||
| 109 | |||
| 110 | $media->setId(null); // Emulate an object detached from the EntityManager. |
||
| 111 | $provider->postRemove($media); |
||
| 112 | |||
| 113 | $this->assertArrayNotHasKey($hash, $prop->getValue($provider)); |
||
| 114 | $this->assertSame('/0001/02/1f981a048e7d8b671415d17e9633abc0059df394.png', $provider->prevReferenceImage); |
||
|
0 ignored issues
–
show
Accessing
prevReferenceImage on the interface Sonata\MediaBundle\Provider\MediaProviderInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
| 115 | |||
| 116 | $prop->setAccessible(false); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | class TestProvider extends BaseProvider |
||
| 121 | { |
||
| 122 | /** |
||
| 123 | * @var string |
||
| 124 | */ |
||
| 125 | public $prevReferenceImage; |
||
| 126 | |||
| 127 | public function getHelperProperties(MediaInterface $media, $format, $options = []): void |
||
| 128 | { |
||
| 129 | // TODO: Implement getHelperProperties() method. |
||
| 130 | } |
||
| 131 | |||
| 132 | public function postPersist(MediaInterface $media): void |
||
| 133 | { |
||
| 134 | // TODO: Implement postPersist() method. |
||
| 135 | } |
||
| 136 | |||
| 137 | public function buildEditForm(FormMapper $form): void |
||
| 138 | { |
||
| 139 | $form->add('foo'); |
||
| 140 | } |
||
| 141 | |||
| 142 | public function buildCreateForm(FormMapper $form): void |
||
| 143 | { |
||
| 144 | $form->add('foo'); |
||
| 145 | } |
||
| 146 | |||
| 147 | public function postUpdate(MediaInterface $media): void |
||
| 148 | { |
||
| 149 | // TODO: Implement postUpdate() method. |
||
| 150 | } |
||
| 151 | |||
| 152 | public function getAbsolutePath(MediaInterface $media): void |
||
|
0 ignored issues
–
show
|
|||
| 153 | { |
||
| 154 | // TODO: Implement getAbsolutePath() method. |
||
| 155 | } |
||
| 156 | |||
| 157 | public function getReferenceImage(MediaInterface $media): string |
||
| 158 | { |
||
| 159 | // A copy of the code from \Sonata\MediaBundle\Provider\FileProvider::getReferenceImage() |
||
| 160 | $this->prevReferenceImage = sprintf( |
||
| 161 | '%s/%s', |
||
| 162 | $this->generatePath($media), |
||
| 163 | $media->getProviderReference() |
||
| 164 | ); |
||
| 165 | |||
| 166 | return $this->prevReferenceImage; |
||
| 167 | } |
||
| 168 | |||
| 169 | public function generatePrivateUrl(MediaInterface $media, $format): void |
||
| 170 | { |
||
| 171 | // TODO: Implement generatePrivateUrl() method. |
||
| 172 | } |
||
| 173 | |||
| 174 | public function generatePublicUrl(MediaInterface $media, $format): void |
||
| 175 | { |
||
| 176 | // TODO: Implement generatePublicUrl() method. |
||
| 177 | } |
||
| 178 | |||
| 179 | public function getReferenceFile(MediaInterface $media): void |
||
| 180 | { |
||
| 181 | // TODO: Implement getReferenceFile() method. |
||
| 182 | } |
||
| 183 | |||
| 184 | public function preUpdate(MediaInterface $media): void |
||
| 185 | { |
||
| 186 | // TODO: Implement preUpdate() method. |
||
| 187 | } |
||
| 188 | |||
| 189 | public function prePersist(MediaInterface $media): void |
||
| 190 | { |
||
| 191 | // TODO: Implement prePersist() method. |
||
| 192 | } |
||
| 193 | |||
| 194 | public function getDownloadResponse(MediaInterface $media, $format, $mode, array $headers = []): void |
||
| 195 | { |
||
| 196 | // TODO: Implement getDownloadResponse() method. |
||
| 197 | } |
||
| 198 | |||
| 199 | public function buildMediaType(FormBuilder $formBuilder): void |
||
| 200 | { |
||
| 201 | $formBuilder->add('foo'); |
||
| 202 | } |
||
| 203 | |||
| 204 | public function updateMetadata(MediaInterface $media, $force = false): void |
||
| 205 | { |
||
| 206 | // TODO: Implement updateMetadata() method. |
||
| 207 | } |
||
| 208 | |||
| 209 | protected function doTransform(MediaInterface $media): void |
||
| 210 | { |
||
| 211 | // TODO: Implement doTransform() method. |
||
| 212 | } |
||
| 213 | } |
||
| 214 |
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.