22 private $productRepository;
27 private $searchCriteriaBuilder;
47 private $mediaDirectory;
57 \
Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
65 $this->readHandler = $readHandler;
82 $this->assertProductMediaGallery(
$product);
83 $this->assertProductMediaAttributes(
$product);
84 $this->assertProductImageExistsInFS(
$product);
98 $extendedProduct = $this->readHandler->execute(
$product);
99 $mediaGalleryImages = $extendedProduct->getMediaGalleryEntries();
101 if (count($mediaGalleryImages) !== 1) {
102 throw new \AssertionError(
'Product supposed to contain one image');
105 $image = reset($mediaGalleryImages);
107 if (
$image->getFile() ===
null) {
108 throw new \AssertionError(
'Image path should not be null');
119 private function assertProductMediaAttributes(\
Magento\Catalog\Model\Product
$product)
122 if (empty($attributeValue)) {
123 throw new \AssertionError(
136 private function assertProductImageExistsInFS(\
Magento\Catalog\Model\Product
$product)
138 $mediaDirectory = $this->getMediaDirectory();
139 $mediaAttributes =
$product->getMediaAttributeValues();
141 if (!$mediaDirectory->isExist($this->mediaConfig->getBaseMediaPath() . $mediaAttributes[
'image'])) {
142 throw new \AssertionError(
'Image file for product supposed to exist');
151 private function getMediaDirectory()
153 if ($this->mediaDirectory ===
null) {
157 return $this->mediaDirectory;
__construct(\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Catalog\Model\Product\Gallery\ReadHandler $readHandler, \Magento\Framework\Filesystem $filesystem, \Magento\Catalog\Model\Product\Media\Config $mediaConfig)