@@ -40,7 +40,12 @@ class GalleryTest extends \PHPUnit_Framework_TestCase
40
40
/**
41
41
* @var \Magento\Catalog\Model\Product\Gallery\ImagesConfigFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
42
42
*/
43
- protected $ imagesConfigMock ;
43
+ protected $ imagesConfigFactoryMock ;
44
+
45
+ /**
46
+ * @var \Magento\Framework\Data\Collection|\PHPUnit_Framework_MockObject_MockObject
47
+ */
48
+ protected $ galleryImagesConfigMock ;
44
49
45
50
protected function setUp ()
46
51
{
@@ -54,15 +59,13 @@ protected function setUp()
54
59
->disableOriginalConstructor ()
55
60
->getMock ();
56
61
57
- $ this ->imagesConfigMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product\Gallery\ImagesConfigFactoryInterface ' )
58
- ->disableOriginalConstructor ()
59
- ->getMock ();
62
+ $ this ->imagesConfigFactoryMock = $ this ->getImagesConfigFactory ();
60
63
61
64
$ this ->model = new \Magento \Catalog \Block \Product \View \Gallery (
62
65
$ this ->context ,
63
66
$ this ->arrayUtils ,
64
67
$ this ->jsonEncoderMock ,
65
- $ this ->imagesConfigMock
68
+ $ this ->imagesConfigFactoryMock
66
69
);
67
70
}
68
71
@@ -117,6 +120,10 @@ public function testGetGalleryImages()
117
120
->with ('product ' )
118
121
->willReturn ($ productMock );
119
122
123
+ $ this ->galleryImagesConfigMock ->expects ($ this ->exactly (1 ))
124
+ ->method ('getItems ' )
125
+ ->willReturn ($ this ->getGalleryImagesConfigItems ());
126
+
120
127
$ this ->imageHelper ->expects ($ this ->exactly (3 ))
121
128
->method ('init ' )
122
129
->willReturnMap ([
@@ -164,4 +171,56 @@ private function getImagesCollection()
164
171
165
172
return $ collectionMock ;
166
173
}
174
+
175
+ /**
176
+ * getImagesConfigFactory
177
+ *
178
+ * @return \Magento\Catalog\Model\Product\Gallery\ImagesConfigFactoryInterface
179
+ */
180
+ private function getImagesConfigFactory ()
181
+ {
182
+ $ this ->galleryImagesConfigMock = $ this ->getMockBuilder ('\Magento\Framework\Data\Collection ' )
183
+ ->disableOriginalConstructor ()
184
+ ->getMock ();
185
+
186
+ $ this ->galleryImagesConfigMock ->expects ($ this ->any ())
187
+ ->method ('getIterator ' )
188
+ ->willReturn (new \ArrayIterator ($ this ->getGalleryImagesConfigItems ()));
189
+
190
+ $ galleryImagesConfigFactoryMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product\Gallery\ImagesConfigFactoryInterface ' )
191
+ ->disableOriginalConstructor ()
192
+ ->getMock ();
193
+
194
+ $ galleryImagesConfigFactoryMock ->expects ($ this ->any ())
195
+ ->method ('create ' )
196
+ ->willReturn ($ this ->galleryImagesConfigMock );
197
+
198
+ return $ galleryImagesConfigFactoryMock ;
199
+ }
200
+
201
+ /**
202
+ * getGalleryImagesConfigItems
203
+ *
204
+ * @return array
205
+ */
206
+ private function getGalleryImagesConfigItems ()
207
+ {
208
+ return [
209
+ new \Magento \Framework \DataObject ([
210
+ 'image_id ' => 'product_page_image_small ' ,
211
+ 'data_object_key ' => 'small_image_url ' ,
212
+ 'json_object_key ' => 'thumb '
213
+ ]),
214
+ new \Magento \Framework \DataObject ([
215
+ 'image_id ' => 'product_page_image_medium ' ,
216
+ 'data_object_key ' => 'medium_image_url ' ,
217
+ 'json_object_key ' => 'img '
218
+ ]),
219
+ new \Magento \Framework \DataObject ([
220
+ 'image_id ' => 'product_page_image_large ' ,
221
+ 'data_object_key ' => 'large_image_url ' ,
222
+ 'json_object_key ' => 'full '
223
+ ])
224
+ ];
225
+ }
167
226
}
0 commit comments