@@ -59,11 +59,13 @@ public function testExecuteWithImageDuplicate()
59
59
}
60
60
61
61
/**
62
- * @covers \Magento\Catalog\Model\Product\Gallery\CreateHandler::execute
63
62
* @dataProvider executeDataProvider
64
- * @param array $expectedValues
63
+ * @param $image
64
+ * @param $smallImage
65
+ * @param $swatchImage
66
+ * @param $thumbnail
65
67
*/
66
- public function testExecuteWithImageRoles ($ expectedValues )
68
+ public function testExecuteWithImageRoles ($ image , $ smallImage , $ swatchImage , $ thumbnail )
67
69
{
68
70
/** @var $product \Magento\Catalog\Model\Product */
69
71
$ product = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
@@ -74,55 +76,106 @@ public function testExecuteWithImageRoles($expectedValues)
74
76
'media_gallery ' ,
75
77
['images ' => ['image ' => ['file ' => $ this ->fileName , 'label ' => '' ]]]
76
78
);
77
- foreach ($ expectedValues as $ mediaAttribute => $ value ) {
78
- if ($ value ) {
79
- $ product ->setData ($ mediaAttribute , $ value );
80
- }
81
- }
79
+ $ product ->setData ('image ' , $ image );
80
+ $ product ->setData ('small_image ' , $ smallImage );
81
+ $ product ->setData ('swatch_image ' , $ swatchImage );
82
+ $ product ->setData ('thumbnail ' , $ thumbnail );
82
83
$ this ->createHandler ->execute ($ product );
84
+
85
+ $ resource = $ product ->getResource ();
86
+ $ id = $ product ->getId ();
87
+ $ storeId = $ product ->getStoreId ();
88
+
83
89
$ this ->assertStringStartsWith ('/m/a/magento_image ' , $ product ->getData ('media_gallery/images/image/new_file ' ));
90
+ $ this ->assertEquals (
91
+ $ image ,
92
+ $ resource ->getAttributeRawValue ($ id , $ resource ->getAttribute ('image ' ), $ storeId )
93
+ );
94
+ $ this ->assertEquals (
95
+ $ smallImage ,
96
+ $ resource ->getAttributeRawValue ($ id , $ resource ->getAttribute ('small_image ' ), $ storeId )
97
+ );
98
+ $ this ->assertEquals (
99
+ $ swatchImage ,
100
+ $ resource ->getAttributeRawValue ($ id , $ resource ->getAttribute ('swatch_image ' ), $ storeId )
101
+ );
102
+ $ this ->assertEquals (
103
+ $ thumbnail ,
104
+ $ resource ->getAttributeRawValue ($ id , $ resource ->getAttribute ('thumbnail ' ),$ storeId )
105
+ );
106
+ }
107
+
108
+ /**
109
+ * @dataProvider executeDataProvider
110
+ * @param $image
111
+ * @param $smallImage
112
+ * @param $swatchImage
113
+ * @param $thumbnail
114
+ */
115
+ public function testExecuteWithoutImages ($ image , $ smallImage , $ swatchImage , $ thumbnail )
116
+ {
117
+ /** @var $product \Magento\Catalog\Model\Product */
118
+ $ product = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
119
+ \Magento \Catalog \Model \Product::class
120
+ );
121
+ $ product ->load (1 );
122
+ $ product ->setData (
123
+ 'media_gallery ' ,
124
+ ['images ' => ['image ' => ['file ' => $ this ->fileName , 'label ' => '' ]]]
125
+ );
126
+ $ product ->setData ('image ' , $ image );
127
+ $ product ->setData ('small_image ' , $ smallImage );
128
+ $ product ->setData ('swatch_image ' , $ swatchImage );
129
+ $ product ->setData ('thumbnail ' , $ thumbnail );
130
+ $ this ->createHandler ->execute ($ product );
131
+
132
+ $ product ->unsetData ('image ' );
133
+ $ product ->unsetData ('small_image ' );
134
+ $ product ->unsetData ('swatch_image ' );
135
+ $ product ->unsetData ('thumbnail ' );
136
+ $ this ->createHandler ->execute ($ product );
137
+
84
138
$ resource = $ product ->getResource ();
85
- $ attributeValues = [];
86
- foreach (array_keys ($ expectedValues ) as $ mediaAttribute ) {
87
- $ attributeValues [$ mediaAttribute ] = $ resource ->getAttributeRawValue (
88
- $ product ->getId (),
89
- $ resource ->getAttribute ($ mediaAttribute ),
90
- $ product ->getStoreId ()
91
- );
92
- }
139
+ $ id = $ product ->getId ();
140
+ $ storeId = $ product ->getStoreId ();
141
+
93
142
$ this ->assertStringStartsWith ('/m/a/magento_image ' , $ product ->getData ('media_gallery/images/image/new_file ' ));
94
- $ this ->assertEquals ($ expectedValues , $ attributeValues );
143
+ $ this ->assertEquals (
144
+ $ image ,
145
+ $ resource ->getAttributeRawValue ($ id , $ resource ->getAttribute ('image ' ), $ storeId )
146
+ );
147
+ $ this ->assertEquals (
148
+ $ smallImage ,
149
+ $ resource ->getAttributeRawValue ($ id , $ resource ->getAttribute ('small_image ' ), $ storeId )
150
+ );
151
+ $ this ->assertEquals (
152
+ $ swatchImage ,
153
+ $ resource ->getAttributeRawValue ($ id , $ resource ->getAttribute ('swatch_image ' ), $ storeId )
154
+ );
155
+ $ this ->assertEquals (
156
+ $ thumbnail ,
157
+ $ resource ->getAttributeRawValue ($ id , $ resource ->getAttribute ('thumbnail ' ),$ storeId )
158
+ );
95
159
}
96
160
161
+
97
162
/**
98
163
* @return array
99
164
*/
100
165
public function executeDataProvider ()
101
166
{
102
167
return [
103
168
[
104
- [
105
- 'image ' => $ this ->fileName ,
106
- 'small_image ' => $ this ->fileName ,
107
- 'swatch_image ' => $ this ->fileName ,
108
- 'thumbnail ' => $ this ->fileName
109
- ]
110
- ],
111
- [
112
- [
113
- 'image ' => 'no_selection ' ,
114
- 'small_image ' => 'no_selection ' ,
115
- 'swatch_image ' => 'no_selection ' ,
116
- 'thumbnail ' => 'no_selection '
117
- ]
169
+ 'image ' => $ this ->fileName ,
170
+ 'small_image ' => $ this ->fileName ,
171
+ 'swatch_image ' => $ this ->fileName ,
172
+ 'thumbnail ' => $ this ->fileName
118
173
],
119
174
[
120
- [
121
- 'image ' => null ,
122
- 'small_image ' => null ,
123
- 'swatch_image ' => null ,
124
- 'thumbnail ' => null
125
- ]
175
+ 'image ' => 'no_selection ' ,
176
+ 'small_image ' => 'no_selection ' ,
177
+ 'swatch_image ' => 'no_selection ' ,
178
+ 'thumbnail ' => 'no_selection '
126
179
]
127
180
];
128
181
}
0 commit comments