3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \ProductVideo \Test \Unit \Model \Plugin \Catalog \Product \Gallery ;
7
8
8
9
/**
@@ -37,6 +38,9 @@ class CreateHandlerTest extends \PHPUnit\Framework\TestCase
37
38
*/
38
39
protected $ mediaGalleryCreateHandler ;
39
40
41
+ /**
42
+ * {@inheritDoc}
43
+ */
40
44
protected function setUp ()
41
45
{
42
46
$ this ->product = $ this ->createMock (\Magento \Catalog \Model \Product::class);
@@ -62,72 +66,18 @@ protected function setUp()
62
66
);
63
67
}
64
68
65
- public function testAfterExecute ()
69
+ /**
70
+ * @dataProvider provideImageForAfterExecute
71
+ * @param array $image
72
+ * @param array $expectedSave
73
+ * @param int $rowSaved
74
+ */
75
+ public function testAfterExecute ($ image , $ expectedSave , $ rowSaved ): void
66
76
{
67
- $ mediaData = [
68
- 'images ' => [
69
- '72mljfhmasfilp9cuq ' => [
70
- 'position ' => '3 ' ,
71
- 'media_type ' => 'external-video ' ,
72
- 'file ' => '/i/n/index111111.jpg ' ,
73
- 'value_id ' => '4 ' ,
74
- 'label ' => '' ,
75
- 'disabled ' => '0 ' ,
76
- 'removed ' => '' ,
77
- 'video_provider ' => 'youtube ' ,
78
- 'video_url ' => 'https://www.youtube.com/watch?v=ab123456 ' ,
79
- 'video_title ' => 'Some second title ' ,
80
- 'video_description ' => 'Description second ' ,
81
- 'video_metadata ' => 'meta two ' ,
82
- 'role ' => '' ,
83
- ],
84
- 'w596fi79hv1p6wj21u ' => [
85
- 'position ' => '4 ' ,
86
- 'media_type ' => 'image ' ,
87
- 'video_provider ' => '' ,
88
- 'file ' => '/h/d/hd_image.jpg ' ,
89
- 'value_id ' => '7 ' ,
90
- 'label ' => '' ,
91
- 'disabled ' => '0 ' ,
92
- 'removed ' => '' ,
93
- 'video_url ' => '' ,
94
- 'video_title ' => '' ,
95
- 'video_description ' => '' ,
96
- 'video_metadata ' => '' ,
97
- 'role ' => '' ,
98
- ],
99
- 'tcodwd7e0dirifr64j ' => [
100
- 'position ' => '4 ' ,
101
- 'media_type ' => 'external-video ' ,
102
- 'file ' => '/s/a/sample_3.jpg ' ,
103
- 'value_id ' => '5 ' ,
104
- 'label ' => '' ,
105
- 'disabled ' => '0 ' ,
106
- 'removed ' => '' ,
107
- 'video_provider ' => 'youtube ' ,
108
- 'video_url ' => 'https://www.youtube.com/watch?v=ab123456 ' ,
109
- 'video_title ' => 'Some second title ' ,
110
- 'video_description ' => 'Description second ' ,
111
- 'video_metadata ' => 'meta two ' ,
112
- 'role ' => '' ,
113
- 'additional_store_data ' => [
114
- 0 => [
115
- 'store_id ' => '0 ' ,
116
- 'video_provider ' => null ,
117
- 'video_url ' => 'https://www.youtube.com/watch?v=ab123456 ' ,
118
- 'video_title ' => 'New Title ' ,
119
- 'video_description ' => 'New Description ' ,
120
- 'video_metadata ' => 'New metadata ' ,
121
- ],
122
- ]
123
- ],
124
- ],
125
- ];
126
-
127
77
$ this ->product ->expects ($ this ->once ())
128
78
->method ('getData ' )
129
79
->with ('media_gallery ' )
130
- ->willReturn ($ mediaData );
80
+ ->willReturn ([ ' images ' => $ image ] );
131
81
$ this ->product ->expects ($ this ->once ())
132
82
->method ('getStoreId ' )
133
83
->willReturn (0 );
@@ -136,13 +86,150 @@ public function testAfterExecute()
136
86
->method ('getAttribute ' )
137
87
->willReturn ($ this ->attribute );
138
88
139
- $ this ->subject ->afterExecute (
140
- $ this ->mediaGalleryCreateHandler ,
141
- $ this ->product
142
- );
89
+ $ this ->resourceModel ->expects ($ this ->exactly ($ rowSaved ))
90
+ ->method ('saveDataRow ' )
91
+ ->with ('catalog_product_entity_media_gallery_value_video ' , $ expectedSave )
92
+ ->willReturn (1 );
93
+
94
+ $ this ->subject ->afterExecute ($ this ->mediaGalleryCreateHandler , $ this ->product );
95
+ }
96
+
97
+ /**
98
+ * DataProvider for testAfterExecute
99
+ *
100
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
101
+ * @return array
102
+ */
103
+ public function provideImageForAfterExecute (): array
104
+ {
105
+ return [
106
+ 'new_video ' => [
107
+ [
108
+ '72mljfhmasfilp9cuq ' => [
109
+ 'position ' => '3 ' ,
110
+ 'media_type ' => 'external-video ' ,
111
+ 'file ' => '/i/n/index111111.jpg ' ,
112
+ 'value_id ' => '4 ' ,
113
+ 'label ' => '' ,
114
+ 'disabled ' => '0 ' ,
115
+ 'removed ' => '' ,
116
+ 'video_provider ' => 'youtube ' ,
117
+ 'video_url ' => 'https://www.youtube.com/watch?v=ab123456 ' ,
118
+ 'video_title ' => 'Some second title ' ,
119
+ 'video_description ' => 'Description second ' ,
120
+ 'video_metadata ' => 'meta two ' ,
121
+ 'role ' => '' ,
122
+ ],
123
+ ],
124
+ [
125
+ 'value_id ' => '4 ' ,
126
+ 'store_id ' => 0 ,
127
+ 'provider ' => 'youtube ' ,
128
+ 'url ' => 'https://www.youtube.com/watch?v=ab123456 ' ,
129
+ 'title ' => 'Some second title ' ,
130
+ 'description ' => 'Description second ' ,
131
+ 'metadata ' => 'meta two ' ,
132
+ ],
133
+ 2
134
+ ],
135
+ 'image ' => [
136
+ [
137
+ 'w596fi79hv1p6wj21u ' => [
138
+ 'position ' => '4 ' ,
139
+ 'media_type ' => 'image ' ,
140
+ 'video_provider ' => '' ,
141
+ 'file ' => '/h/d/hd_image.jpg ' ,
142
+ 'value_id ' => '7 ' ,
143
+ 'label ' => '' ,
144
+ 'disabled ' => '0 ' ,
145
+ 'removed ' => '' ,
146
+ 'video_url ' => '' ,
147
+ 'video_title ' => '' ,
148
+ 'video_description ' => '' ,
149
+ 'video_metadata ' => '' ,
150
+ 'role ' => '' ,
151
+ ],
152
+ ],
153
+ [],
154
+ 0
155
+ ],
156
+ 'new_video_with_additional_data ' => [
157
+ [
158
+ 'tcodwd7e0dirifr64j ' => [
159
+ 'position ' => '4 ' ,
160
+ 'media_type ' => 'external-video ' ,
161
+ 'file ' => '/s/a/sample_3.jpg ' ,
162
+ 'value_id ' => '5 ' ,
163
+ 'label ' => '' ,
164
+ 'disabled ' => '0 ' ,
165
+ 'removed ' => '' ,
166
+ 'video_provider ' => 'youtube ' ,
167
+ 'video_url ' => 'https://www.youtube.com/watch?v=ab123456 ' ,
168
+ 'video_title ' => 'Some second title ' ,
169
+ 'video_description ' => 'Description second ' ,
170
+ 'video_metadata ' => 'meta two ' ,
171
+ 'role ' => '' ,
172
+ 'additional_store_data ' => [
173
+ 0 => [
174
+ 'store_id ' => 0 ,
175
+ 'video_provider ' => 'youtube ' ,
176
+ 'video_url ' => 'https://www.youtube.com/watch?v=ab123456 ' ,
177
+ 'video_title ' => 'Some second title ' ,
178
+ 'video_description ' => 'Description second ' ,
179
+ 'video_metadata ' => 'meta two ' ,
180
+ ],
181
+ ]
182
+ ],
183
+ ],
184
+ [
185
+ 'value_id ' => '5 ' ,
186
+ 'store_id ' => 0 ,
187
+ 'provider ' => 'youtube ' ,
188
+ 'url ' => 'https://www.youtube.com/watch?v=ab123456 ' ,
189
+ 'title ' => 'Some second title ' ,
190
+ 'description ' => 'Description second ' ,
191
+ 'metadata ' => 'meta two ' ,
192
+ ],
193
+ 3
194
+ ],
195
+ 'not_new_video ' => [
196
+ [
197
+ '72mljfhmasfilp9cuq ' => [
198
+ 'position ' => '3 ' ,
199
+ 'media_type ' => 'external-video ' ,
200
+ 'file ' => '/i/n/index111111.jpg ' ,
201
+ 'value_id ' => '4 ' ,
202
+ 'label ' => '' ,
203
+ 'disabled ' => '0 ' ,
204
+ 'removed ' => '' ,
205
+ 'video_provider ' => 'youtube ' ,
206
+ 'video_url ' => 'https://www.youtube.com/watch?v=ab123456 ' ,
207
+ 'video_url_default ' => 'https://www.youtube.com/watch?v=ab123456 ' ,
208
+ 'video_title ' => 'Some second title ' ,
209
+ 'video_title_default ' => 'Some second title ' ,
210
+ 'video_description ' => 'Description second ' ,
211
+ 'video_metadata ' => 'meta two ' ,
212
+ 'role ' => '' ,
213
+ ],
214
+ ],
215
+ [
216
+ 'value_id ' => '4 ' ,
217
+ 'store_id ' => 0 ,
218
+ 'provider ' => 'youtube ' ,
219
+ 'url ' => 'https://www.youtube.com/watch?v=ab123456 ' ,
220
+ 'title ' => 'Some second title ' ,
221
+ 'description ' => 'Description second ' ,
222
+ 'metadata ' => 'meta two ' ,
223
+ ],
224
+ 1
225
+ ],
226
+ ];
143
227
}
144
228
145
- public function testAfterExecuteEmpty ()
229
+ /**
230
+ * Tests empty media gallery
231
+ */
232
+ public function testAfterExecuteEmpty (): void
146
233
{
147
234
$ this ->product ->expects ($ this ->once ())
148
235
->method ('getData ' )
@@ -162,7 +249,7 @@ public function testAfterExecuteEmpty()
162
249
/**
163
250
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
164
251
*/
165
- public function testBeforeExecute ()
252
+ public function testBeforeExecute (): void
166
253
{
167
254
$ mediaData = [
168
255
'images ' => [
0 commit comments