|
23 | 23 | use Ibexa\Core\IO\Values\BinaryFile; |
24 | 24 | use Ibexa\Core\IO\Values\BinaryFileCreateStruct; |
25 | 25 | use Ibexa\Tests\Integration\Core\BaseCoreFieldTypeIntegrationTestCase; |
| 26 | +use PHPUnit\Framework\MockObject\MockObject; |
26 | 27 |
|
27 | 28 | final class ImageStorageTest extends BaseCoreFieldTypeIntegrationTestCase |
28 | 29 | { |
29 | | - /** @var \Ibexa\Core\FieldType\Image\ImageStorage\Gateway */ |
30 | | - private $gateway; |
| 30 | + private DoctrineStorage $gateway; |
31 | 31 |
|
32 | | - /** @var \Ibexa\Core\IO\UrlRedecoratorInterface|\PHPUnit\Framework\MockObject\MockObject */ |
33 | | - private $redecorator; |
| 32 | + private UrlRedecoratorInterface & MockObject $redecorator; |
34 | 33 |
|
35 | | - /** @var \Ibexa\Core\FieldType\Image\PathGenerator|\PHPUnit\Framework\MockObject\MockObject */ |
36 | | - private $pathGenerator; |
| 34 | + private PathGenerator & MockObject $pathGenerator; |
37 | 35 |
|
38 | | - /** @var \Ibexa\Core\FieldType\Image\AliasCleanerInterface|\PHPUnit\Framework\MockObject\MockObject */ |
39 | | - private $aliasCleaner; |
| 36 | + private AliasCleanerInterface & MockObject $aliasCleaner; |
40 | 37 |
|
41 | | - /** @var \Ibexa\Core\IO\FilePathNormalizerInterface|\PHPUnit\Framework\MockObject\MockObject */ |
42 | | - private $filePathNormalizer; |
| 38 | + private FilePathNormalizerInterface & MockObject $filePathNormalizer; |
43 | 39 |
|
44 | | - /** @var \Ibexa\Core\IO\IOServiceInterface|\PHPUnit\Framework\MockObject\MockObject */ |
45 | | - private $ioService; |
| 40 | + private IOServiceInterface & MockObject $ioService; |
46 | 41 |
|
47 | | - /** @var \Ibexa\Core\FieldType\Image\ImageStorage */ |
48 | | - private $storage; |
| 42 | + private ImageStorage $storage; |
49 | 43 |
|
50 | | - /** @var \Ibexa\Core\FieldType\Validator\FileExtensionBlackListValidator&\PHPUnit\Framework\MockObject\MockObject */ |
51 | | - private $fileExtensionBlackListValidator; |
| 44 | + private FileExtensionBlackListValidator & MockObject $fileExtensionBlackListValidator; |
52 | 45 |
|
53 | 46 | protected function setUp(): void |
54 | 47 | { |
@@ -159,6 +152,71 @@ public function testStoreFieldDataDuringUpdateWithDifferentImage(VersionInfo $ve |
159 | 152 | self::assertSame(1, $this->gateway->countImageReferences($binaryFile->uri)); |
160 | 153 | } |
161 | 154 |
|
| 155 | + /** |
| 156 | + * @dataProvider providerOfFieldData |
| 157 | + */ |
| 158 | + public function testStoreFieldDataWithSameImageOnAutosave(VersionInfo $versionInfo, Field $field): void |
| 159 | + { |
| 160 | + $targetPath = '1/8/6/232-eng-GB/' . $field->value->externalData['fileName']; |
| 161 | + |
| 162 | + $binaryFile = new BinaryFile([ |
| 163 | + 'id' => $targetPath, |
| 164 | + 'uri' => $targetPath, |
| 165 | + ]); |
| 166 | + |
| 167 | + $this->filePathNormalizer |
| 168 | + ->expects(self::exactly(2)) |
| 169 | + ->method('normalizePath') |
| 170 | + ->willReturn($targetPath); |
| 171 | + |
| 172 | + $this->ioService |
| 173 | + ->expects(self::exactly(2)) |
| 174 | + ->method('newBinaryCreateStructFromLocalFile') |
| 175 | + ->with($field->value->externalData['inputUri']) |
| 176 | + ->willReturn(new BinaryFileCreateStruct()); |
| 177 | + |
| 178 | + $this->ioService |
| 179 | + ->expects(self::exactly(2)) |
| 180 | + ->method('createBinaryFile') |
| 181 | + ->willReturn($binaryFile); |
| 182 | + |
| 183 | + $this->ioService |
| 184 | + ->expects(self::exactly(2)) |
| 185 | + ->method('getMimeType') |
| 186 | + ->with($binaryFile->id) |
| 187 | + ->willReturn('image/jpeg'); |
| 188 | + |
| 189 | + $this->redecorator |
| 190 | + ->method('redecorateFromSource') |
| 191 | + ->with($binaryFile->uri) |
| 192 | + ->willReturn($binaryFile->uri); |
| 193 | + |
| 194 | + // First save |
| 195 | + $this->storage->storeFieldData($versionInfo, $field); |
| 196 | + |
| 197 | + // Simulate autosave with same image — rebuild externalData |
| 198 | + $field->value = new FieldValue([ |
| 199 | + 'externalData' => [ |
| 200 | + 'id' => null, |
| 201 | + 'path' => $field->value->data['path'] ?? __DIR__ . '/image.jpg', |
| 202 | + 'inputUri' => __DIR__ . '/image.jpg', |
| 203 | + 'fileName' => 'image.jpg', |
| 204 | + 'fileSize' => '12345', |
| 205 | + 'mimeType' => 'image/jpeg', |
| 206 | + 'width' => null, |
| 207 | + 'height' => null, |
| 208 | + 'alternativeText' => null, |
| 209 | + 'imageId' => null, |
| 210 | + 'uri' => null, |
| 211 | + 'additionalData' => [], |
| 212 | + ], |
| 213 | + ]); |
| 214 | + |
| 215 | + $this->storage->storeFieldData($versionInfo, $field); |
| 216 | + |
| 217 | + self::assertSame(1, $this->gateway->countImageReferences($binaryFile->uri)); |
| 218 | + } |
| 219 | + |
162 | 220 | private function runCommonStoreFieldDataMocks(Field $field): BinaryFile |
163 | 221 | { |
164 | 222 | $this->filePathNormalizer |
|
0 commit comments