Skip to content

Commit 775ec3a

Browse files
committed
Product image builder - Override attributes when builder used multiple times
Extract test data with and without attributes to separate methods
1 parent f721b69 commit 775ec3a

File tree

1 file changed

+69
-151
lines changed

1 file changed

+69
-151
lines changed

app/code/Magento/Catalog/Test/Unit/Block/Product/ImageBuilderTest.php

Lines changed: 69 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -197,58 +197,61 @@ public function testCreateMultipleCalls($data)
197197
/**
198198
* @return array
199199
*/
200-
public function createDataProvider()
200+
public function createDataProvider(): array
201+
{
202+
return [
203+
$this->getTestDataWithoutAttributes(),
204+
$this->getTestDataWithAttributes(),
205+
];
206+
}
207+
208+
/**
209+
* @return array
210+
*/
211+
public function createMultipleCallsDataProvider(): array
201212
{
202213
return [
203214
[
204-
'data' => [
205-
'frame' => 0,
206-
'url' => 'test_url_1',
207-
'width' => 100,
208-
'height' => 100,
209-
'label' => 'test_label',
210-
'custom_attributes' => [],
211-
'imagesize' => [100, 100],
212-
],
213-
'expected' => [
214-
'data' => [
215-
'template' => 'Magento_Catalog::product/image_with_borders.phtml',
216-
'image_url' => 'test_url_1',
217-
'width' => 100,
218-
'height' => 100,
219-
'label' => 'test_label',
220-
'ratio' => 1,
221-
'custom_attributes' => '',
222-
'resized_image_width' => 100,
223-
'resized_image_height' => 100,
224-
],
215+
[
216+
'without_attributes' => $this->getTestDataWithoutAttributes(),
217+
'with_attributes' => $this->getTestDataWithAttributes(),
225218
],
226219
],
227220
[
221+
[
222+
'with_attributes' => $this->getTestDataWithAttributes(),
223+
'without_attributes' => $this->getTestDataWithoutAttributes(),
224+
],
225+
],
226+
];
227+
}
228+
229+
/**
230+
* @return array
231+
*/
232+
private function getTestDataWithoutAttributes(): array
233+
{
234+
return [
235+
'data' => [
236+
'frame' => 0,
237+
'url' => 'test_url_1',
238+
'width' => 100,
239+
'height' => 100,
240+
'label' => 'test_label',
241+
'custom_attributes' => [],
242+
'imagesize' => [100, 100],
243+
],
244+
'expected' => [
228245
'data' => [
229-
'frame' => 1,
230-
'url' => 'test_url_2',
246+
'template' => 'Magento_Catalog::product/image_with_borders.phtml',
247+
'image_url' => 'test_url_1',
231248
'width' => 100,
232-
'height' => 50,
233-
'label' => 'test_label_2',
234-
'custom_attributes' => [
235-
'name_1' => 'value_1',
236-
'name_2' => 'value_2',
237-
],
238-
'imagesize' => [120, 70],
239-
],
240-
'expected' => [
241-
'data' => [
242-
'template' => 'Magento_Catalog::product/image.phtml',
243-
'image_url' => 'test_url_2',
244-
'width' => 100,
245-
'height' => 50,
246-
'label' => 'test_label_2',
247-
'ratio' => 0.5,
248-
'custom_attributes' => 'name_1="value_1" name_2="value_2"',
249-
'resized_image_width' => 120,
250-
'resized_image_height' => 70,
251-
],
249+
'height' => 100,
250+
'label' => 'test_label',
251+
'ratio' => 1,
252+
'custom_attributes' => '',
253+
'resized_image_width' => 100,
254+
'resized_image_height' => 100,
252255
],
253256
],
254257
];
@@ -257,117 +260,32 @@ public function createDataProvider()
257260
/**
258261
* @return array
259262
*/
260-
public function createMultipleCallsDataProvider()
263+
private function getTestDataWithAttributes(): array
261264
{
262265
return [
263-
[
264-
[
265-
'without_attributes' => [
266-
'data' => [
267-
'frame' => 0,
268-
'url' => 'test_url_1',
269-
'width' => 100,
270-
'height' => 100,
271-
'label' => 'test_label',
272-
'custom_attributes' => [],
273-
'imagesize' => [100, 100],
274-
],
275-
'expected' => [
276-
'data' => [
277-
'template' => 'Magento_Catalog::product/image_with_borders.phtml',
278-
'image_url' => 'test_url_1',
279-
'width' => 100,
280-
'height' => 100,
281-
'label' => 'test_label',
282-
'ratio' => 1,
283-
'custom_attributes' => '',
284-
'resized_image_width' => 100,
285-
'resized_image_height' => 100,
286-
],
287-
],
288-
],
289-
'with_attributes' => [
290-
'data' => [
291-
'frame' => 1,
292-
'url' => 'test_url_2',
293-
'width' => 100,
294-
'height' => 50,
295-
'label' => 'test_label_2',
296-
'custom_attributes' => [
297-
'name_1' => 'value_1',
298-
'name_2' => 'value_2',
299-
],
300-
'imagesize' => [120, 70],
301-
],
302-
'expected' => [
303-
'data' => [
304-
'template' => 'Magento_Catalog::product/image.phtml',
305-
'image_url' => 'test_url_2',
306-
'width' => 100,
307-
'height' => 50,
308-
'label' => 'test_label_2',
309-
'ratio' => 0.5,
310-
'custom_attributes' => 'name_1="value_1" name_2="value_2"',
311-
'resized_image_width' => 120,
312-
'resized_image_height' => 70,
313-
],
314-
],
315-
],
266+
'data' => [
267+
'frame' => 1,
268+
'url' => 'test_url_2',
269+
'width' => 100,
270+
'height' => 50,
271+
'label' => 'test_label_2',
272+
'custom_attributes' => [
273+
'name_1' => 'value_1',
274+
'name_2' => 'value_2',
316275
],
276+
'imagesize' => [120, 70],
317277
],
318-
[
319-
[
320-
'with_attributes' => [
321-
'data' => [
322-
'frame' => 1,
323-
'url' => 'test_url_2',
324-
'width' => 100,
325-
'height' => 50,
326-
'label' => 'test_label_2',
327-
'custom_attributes' => [
328-
'name_1' => 'value_1',
329-
'name_2' => 'value_2',
330-
],
331-
'imagesize' => [120, 70],
332-
],
333-
'expected' => [
334-
'data' => [
335-
'template' => 'Magento_Catalog::product/image.phtml',
336-
'image_url' => 'test_url_2',
337-
'width' => 100,
338-
'height' => 50,
339-
'label' => 'test_label_2',
340-
'ratio' => 0.5,
341-
'custom_attributes' => 'name_1="value_1" name_2="value_2"',
342-
'resized_image_width' => 120,
343-
'resized_image_height' => 70,
344-
],
345-
],
346-
],
347-
'without_attributes' => [
348-
'data' => [
349-
'frame' => 0,
350-
'url' => 'test_url_1',
351-
'width' => 100,
352-
'height' => 100,
353-
'label' => 'test_label',
354-
'custom_attributes' => [],
355-
'imagesize' => [100, 100],
356-
],
357-
'expected' => [
358-
'data' => [
359-
'template' => 'Magento_Catalog::product/image_with_borders.phtml',
360-
'image_url' => 'test_url_1',
361-
'width' => 100,
362-
'height' => 100,
363-
'label' => 'test_label',
364-
'ratio' => 1,
365-
'custom_attributes' => '',
366-
'resized_image_width' => 100,
367-
'resized_image_height' => 100,
368-
],
369-
],
370-
],
278+
'expected' => [
279+
'data' => [
280+
'template' => 'Magento_Catalog::product/image.phtml',
281+
'image_url' => 'test_url_2',
282+
'width' => 100,
283+
'height' => 50,
284+
'label' => 'test_label_2',
285+
'ratio' => 0.5,
286+
'custom_attributes' => 'name_1="value_1" name_2="value_2"',
287+
'resized_image_width' => 120,
288+
'resized_image_height' => 70,
371289
],
372290
],
373291
];

0 commit comments

Comments
 (0)