Skip to content

Commit 2db5aa1

Browse files
committed
MAGETWO-54718: [GitHub] Exception thrown where no Product Image file found #5184 #5497 #5871
1 parent 2e03028 commit 2db5aa1

File tree

2 files changed

+11
-57
lines changed
  • app/code/Magento/Catalog

2 files changed

+11
-57
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.php

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ class Content extends \Magento\Backend\Block\Widget
4040
*/
4141
private $imageHelper;
4242

43-
/**
44-
* @var \Magento\Framework\View\Asset\Repository
45-
*/
46-
private $assetRepo;
47-
4843
/**
4944
* @param \Magento\Backend\Block\Template\Context $context
5045
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
@@ -139,20 +134,16 @@ public function getImagesJson()
139134
is_array($value['images']) &&
140135
count($value['images'])
141136
) {
142-
$mediaDir = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
137+
$mediaDir = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
143138
$images = $this->sortImagesByPosition($value['images']);
144139
foreach ($images as &$image) {
145140
$image['url'] = $this->_mediaConfig->getMediaUrl($image['file']);
146141
try {
147142
$fileHandler = $mediaDir->stat($this->_mediaConfig->getMediaPath($image['file']));
148143
$image['size'] = $fileHandler['size'];
149144
} catch (FileSystemException $e) {
150-
$staticDir = $this->_filesystem->getDirectoryRead(DirectoryList::STATIC_VIEW);
151-
$image['url'] = $this->getImageHelper()->getDefaultPlaceholderUrl('thumbnail');
152-
$fileHandler = $staticDir->stat(
153-
$this->getAssetRepo()->createAsset($this->getImageHelper()->getPlaceholder('thumbnail'))->getPath()
154-
);
155-
$image['size'] = $fileHandler['size'];
145+
$image['url'] = $this->getImageHelper()->getDefaultPlaceholderUrl('small_image');
146+
$image['size'] = 0;
156147
$this->_logger->warning($e);
157148
}
158149
}
@@ -261,18 +252,4 @@ private function getImageHelper()
261252
}
262253
return $this->imageHelper;
263254
}
264-
265-
/**
266-
* @return \Magento\Framework\View\Asset\Repository
267-
* @deprecated
268-
*/
269-
private function getAssetRepo()
270-
{
271-
if ($this->assetRepo === null) {
272-
$this->assetRepo = \Magento\Framework\App\ObjectManager::getInstance()
273-
->get('\Magento\Framework\View\Asset\Repository');
274-
}
275-
276-
return $this->assetRepo;
277-
}
278255
}

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Helper/Form/Gallery/ContentTest.php

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ class ContentTest extends \PHPUnit_Framework_TestCase
4646
*/
4747
protected $imageHelper;
4848

49-
/**
50-
* @var \Magento\Framework\View\Asset\Repository|\PHPUnit_Framework_MockObject_MockObject
51-
*/
52-
protected $assetRepo;
53-
5449
/**
5550
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
5651
*/
@@ -171,46 +166,33 @@ public function testGetImagesJsonWithException()
171166
{
172167
$this->imageHelper = $this->getMockBuilder('Magento\Catalog\Helper\Image')
173168
->disableOriginalConstructor()
174-
->setMethods(['getDefaultPlaceholderUrl', 'getPlaceholder'])
175-
->getMock();
176-
177-
$this->assetRepo = $this->getMockBuilder('Magento\Framework\View\Asset\Repository')
178-
->disableOriginalConstructor()
179-
->setMethods(['createAsset', 'getPath'])
169+
->setMethods(['getDefaultPlaceholderUrl'])
180170
->getMock();
181171

182172
$this->objectManager->setBackwardCompatibleProperty(
183173
$this->content,
184174
'imageHelper',
185-
$this->imageHelper
186-
);
187-
188-
$this->objectManager->setBackwardCompatibleProperty(
189-
$this->content,
190-
'assetRepo',
191-
$this->assetRepo
175+
$this->imageHelper
192176
);
193177

194178
$placeholderUrl = 'url_to_the_placeholder/placeholder.jpg';
195179

196-
$sizePlaceholder = ['size' => 399659];
197-
198180
$imagesResult = [
199181
[
200182
'value_id' => '2',
201183
'file' => 'file_2.jpg',
202184
'media_type' => 'image',
203185
'position' => '0',
204186
'url' => 'url_to_the_placeholder/placeholder.jpg',
205-
'size' => 399659
187+
'size' => 0
206188
],
207189
[
208190
'value_id' => '1',
209191
'file' => 'file_1.jpg',
210192
'media_type' => 'image',
211193
'position' => '1',
212194
'url' => 'url_to_the_placeholder/placeholder.jpg',
213-
'size' => 399659
195+
'size' => 0
214196
]
215197
];
216198

@@ -238,20 +220,15 @@ public function testGetImagesJsonWithException()
238220
$this->mediaConfigMock->expects($this->any())->method('getMediaPath');
239221
$this->readMock->expects($this->any())->method('stat')->willReturnOnConsecutiveCalls(
240222
$this->throwException(
241-
new \Magento\Framework\Exception\FileSystemException(new \Magento\Framework\Phrase('test'))
223+
new \Magento\Framework\Exception\FileSystemException(new Phrase('test'))
242224
),
243-
$sizePlaceholder,
244225
$this->throwException(
245-
new \Magento\Framework\Exception\FileSystemException(new \Magento\Framework\Phrase('test'))
246-
),
247-
$sizePlaceholder
226+
new \Magento\Framework\Exception\FileSystemException(new Phrase('test'))
227+
)
248228
);
249229
$this->imageHelper->expects($this->any())->method('getDefaultPlaceholderUrl')->willReturn($placeholderUrl);
250-
$this->imageHelper->expects($this->any())->method('getPlaceholder');
251-
$this->assetRepo->expects($this->any())->method('createAsset')->willReturnSelf();
252-
$this->assetRepo->expects($this->any())->method('getPath');
253230
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
254231

255232
$this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
256-
}
233+
}
257234
}

0 commit comments

Comments
 (0)