6 declare(strict_types=1);
15 use Magento\Catalog\Model\View\Asset\ImageFactory as ViewAssetImageFactory;
23 private $paramsBuilder;
29 private $objectManager;
39 private $viewAssetImageFactory;
43 $this->viewConfig = $this->createMock(View::class);
44 $configInterface = $this->createMock(ConfigInterface::class);
45 $configInterface->method(
'getViewConfig')->willReturn($this->viewConfig);
46 $this->viewAssetImageFactory = $this->createMock(ViewAssetImageFactory::class);
47 $this->paramsBuilder = $this->createMock(ParamsBuilder::class);
48 $this->objectManager = $this->createMock(ObjectManager::class);
49 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
50 $this->model = $objectManager->getObject(
53 'objectManager' => $this->objectManager,
54 'presentationConfig' => $configInterface,
55 'viewAssetImageFactory' => $this->viewAssetImageFactory,
56 'imageParamsBuilder' => $this->paramsBuilder
67 $product = $this->createMock(Product::class);
68 $product->method(
'getName')->willReturn(
$data[
'product'][
'name']);
69 $product->method(
'getData')->willReturnOnConsecutiveCalls(
70 $data[
'product'][
'image_type'],
71 $data[
'product'][
'image_type_label']
73 $imageBlock = $this->createMock(Image::class);
74 $this->viewConfig->method(
'getMediaAttributes')->willReturn(
$data[
'viewImageConfig']);
75 $this->viewConfig->method(
'getVarValue')->willReturn(
$data[
'frame']);
76 $this->viewAssetImageFactory->method(
'create')->willReturn(
77 $viewAssetImage = $this->createMock(ViewAssetImage::class)
79 $this->paramsBuilder->method(
'build')->willReturn(
$data[
'imageParamsBuilder']);
80 $viewAssetImage->method(
'getUrl')->willReturn(
$data[
'url']);
82 $this->objectManager->expects(self::once())
84 ->with(Image::class, $expected)
85 ->willReturn($imageBlock);
86 $actual = $this->model->create(
$product,
'image_id',
$data[
'custom_attributes']);
87 self::assertInstanceOf(Image::class, $actual);
96 $this->getTestDataWithoutAttributes(),
97 $this->getTestDataWithAttributes(),
104 private function getTestDataWithoutAttributes(): array
108 'viewImageConfig' => [
111 'constrain_only' =>
false,
112 'aspect_ratio' =>
false,
114 'transparency' =>
false,
115 'background' =>
'255,255,255',
116 'type' =>
'image_type' 118 'imageParamsBuilder' => [
119 'image_width' => 100,
120 'image_height' => 100,
121 'constrain_only' =>
false,
122 'keep_aspect_ratio' =>
false,
123 'keep_frame' =>
false,
124 'keep_transparency' =>
false,
125 'background' =>
'255,255,255',
126 'image_type' =>
'image_type',
131 'image_type_label' =>
'test_image_label',
132 'name' =>
'test_product_name',
133 'image_type' =>
'test_image_path' 135 'url' =>
'test_url_1',
136 'frame' =>
'test_frame',
137 'custom_attributes' => [],
141 'template' =>
'Magento_Catalog::product/image_with_borders.phtml',
142 'image_url' =>
'test_url_1',
145 'label' =>
'test_image_label',
147 'custom_attributes' =>
'',
157 private function getTestDataWithAttributes(): array
161 'viewImageConfig' => [
164 'constrain_only' =>
false,
165 'aspect_ratio' =>
false,
167 'transparency' =>
false,
168 'background' =>
'255,255,255',
169 'type' =>
'image_type' 171 'imageParamsBuilder' => [
172 'image_width' => 100,
173 'image_height' => 50,
174 'constrain_only' =>
false,
175 'keep_aspect_ratio' =>
false,
176 'keep_frame' =>
true,
177 'keep_transparency' =>
false,
178 'background' =>
'255,255,255',
179 'image_type' =>
'image_type',
184 'image_type_label' =>
null,
185 'name' =>
'test_product_name',
186 'image_type' =>
'test_image_path' 188 'url' =>
'test_url_2',
189 'frame' =>
'test_frame',
190 'custom_attributes' => [
191 'name_1' =>
'value_1',
192 'name_2' =>
'value_2',
197 'template' =>
'Magento_Catalog::product/image_with_borders.phtml',
198 'image_url' =>
'test_url_2',
201 'label' =>
'test_product_name',
203 'custom_attributes' =>
'name_1="value_1" name_2="value_2"',
testCreate($data, $expected)