6
6
*/
7
7
namespace Magento \CatalogImportExport \Test \Unit \Model \Import \Product \Type ;
8
8
9
+ use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
9
10
use Magento \Catalog \Model \ResourceModel \Product \Attribute \CollectionFactory as AttributeCollectionFactory ;
10
11
use Magento \CatalogImportExport \Model \Import \Product ;
11
12
use Magento \CatalogImportExport \Model \Import \Product \RowValidatorInterface ;
12
13
use Magento \CatalogImportExport \Model \Import \Product \Type \AbstractType as AbstractType ;
13
14
use Magento \CatalogImportExport \Model \Import \Product \Type \Simple ;
14
- use Magento \Eav \Model \Entity \Attribute ;
15
15
use Magento \Eav \Model \Entity \Attribute \Set ;
16
16
use Magento \Eav \Model \ResourceModel \Entity \Attribute \Set \Collection ;
17
17
use Magento \Eav \Model \ResourceModel \Entity \Attribute \Set \CollectionFactory as AttributeSetCollectionFactory ;
@@ -87,7 +87,7 @@ protected function setUp(): void
87
87
]
88
88
);
89
89
$ attribute = $ this ->getMockBuilder (Attribute::class)
90
- ->addMethods (['getIsVisible ' , ' getIsGlobal ' , ' getFrontendLabel ' , ' getApplyTo ' ])
90
+ ->addMethods (['getFrontendLabel ' ])
91
91
->onlyMethods (
92
92
[
93
93
'getAttributeCode ' ,
@@ -97,7 +97,10 @@ protected function setUp(): void
97
97
'isStatic ' ,
98
98
'getDefaultValue ' ,
99
99
'usesSource ' ,
100
- 'getFrontendInput '
100
+ 'getFrontendInput ' ,
101
+ 'getIsVisible ' ,
102
+ 'getApplyTo ' ,
103
+ 'getIsGlobal ' ,
101
104
]
102
105
)
103
106
->disableOriginalConstructor ()
@@ -118,21 +121,23 @@ protected function setUp(): void
118
121
->willReturn ('default_value ' );
119
122
$ attribute ->method ('usesSource ' )
120
123
->willReturn (true );
121
-
122
124
$ entityAttributes = [
123
125
[
124
- 'attribute_id ' => 'attribute_id ' ,
126
+ 'attribute_id ' => '1 ' ,
125
127
'attribute_set_name ' => 'attributeSetName ' ,
126
128
],
127
129
[
128
- 'attribute_id ' => 'boolean_attribute ' ,
130
+ 'attribute_id ' => '2 ' ,
129
131
'attribute_set_name ' => 'attributeSetName '
130
- ]
132
+ ],
133
+ [
134
+ 'attribute_id ' => '3 ' ,
135
+ 'attribute_set_name ' => 'attributeSetName '
136
+ ],
131
137
];
132
138
$ attribute1 = clone $ attribute ;
133
139
$ attribute2 = clone $ attribute ;
134
140
$ attribute3 = clone $ attribute ;
135
-
136
141
$ attribute1 ->method ('getId ' )
137
142
->willReturn ('1 ' );
138
143
$ attribute1 ->method ('getAttributeCode ' )
@@ -141,7 +146,6 @@ protected function setUp(): void
141
146
->willReturn ('multiselect ' );
142
147
$ attribute1 ->method ('isStatic ' )
143
148
->willReturn (true );
144
-
145
149
$ attribute2 ->method ('getId ' )
146
150
->willReturn ('2 ' );
147
151
$ attribute2 ->method ('getAttributeCode ' )
@@ -150,7 +154,6 @@ protected function setUp(): void
150
154
->willReturn ('boolean ' );
151
155
$ attribute2 ->method ('isStatic ' )
152
156
->willReturn (false );
153
-
154
157
$ attribute3 ->method ('getId ' )
155
158
->willReturn ('3 ' );
156
159
$ attribute3 ->method ('getAttributeCode ' )
@@ -159,7 +162,6 @@ protected function setUp(): void
159
162
->willReturn ('text ' );
160
163
$ attribute3 ->method ('isStatic ' )
161
164
->willReturn (false );
162
-
163
165
$ this ->entityModel ->method ('getEntityTypeId ' )
164
166
->willReturn (3 );
165
167
$ this ->entityModel ->method ('getAttributeOptions ' )
@@ -179,32 +181,34 @@ protected function setUp(): void
179
181
->willReturn (1 );
180
182
$ attributeSet ->method ('getAttributeSetName ' )
181
183
->willReturn ('attribute_set_name ' );
182
-
183
184
$ attrCollection ->method ('addFieldToFilter ' )
184
- ->with (
185
- ['main_table.attribute_id ' , 'main_table.attribute_code ' ],
185
+ ->withConsecutive (
186
186
[
187
+ ['main_table.attribute_id ' ],
187
188
[
188
- 'in ' => [
189
- 'attribute_id ' ,
190
- 'boolean_attribute ' ,
189
+ [
190
+ 'in ' => ['1 ' , '2 ' , '3 ' ],
191
191
],
192
- ],
192
+ ]
193
+ ],
194
+ [
195
+ ['main_table.attribute_code ' ],
193
196
[
194
- 'in ' => [
195
- 'related_tgtr_position_behavior ' ,
196
- 'related_tgtr_position_limit ' ,
197
- 'upsell_tgtr_position_behavior ' ,
198
- 'upsell_tgtr_position_limit ' ,
199
- 'thumbnail_label ' ,
200
- 'small_image_label ' ,
201
- 'image_label ' ,
197
+ [
198
+ 'in ' => [
199
+ 'related_tgtr_position_behavior ' ,
200
+ 'related_tgtr_position_limit ' ,
201
+ 'upsell_tgtr_position_behavior ' ,
202
+ 'upsell_tgtr_position_limit ' ,
203
+ 'thumbnail_label ' ,
204
+ 'small_image_label ' ,
205
+ 'image_label ' ,
206
+ ],
202
207
],
203
- ],
204
- ]
208
+ ]
209
+ ],
205
210
)
206
- ->willReturn ([$ attribute1 , $ attribute2 , $ attribute3 ]);
207
-
211
+ ->willReturnOnConsecutiveCalls ([$ attribute1 , $ attribute2 , $ attribute3 ], []);
208
212
$ this ->connection = $ this ->getMockBuilder (Mysql::class)
209
213
->addMethods (['joinLeft ' ])
210
214
->onlyMethods (['select ' , 'fetchAll ' , 'fetchPairs ' , 'insertOnDuplicate ' , 'delete ' , 'quoteInto ' ])
@@ -240,7 +244,6 @@ protected function setUp(): void
240
244
->willReturn ('' );
241
245
$ this ->connection ->method ('fetchAll ' )
242
246
->willReturn ($ entityAttributes );
243
-
244
247
$ this ->resource = $ this ->createPartialMock (
245
248
ResourceConnection::class,
246
249
[
@@ -252,7 +255,6 @@ protected function setUp(): void
252
255
->willReturn ($ this ->connection );
253
256
$ this ->resource ->method ('getTableName ' )
254
257
->willReturn ('tableName ' );
255
-
256
258
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
257
259
$ this ->simpleType = $ this ->objectManagerHelper ->getObject (
258
260
Simple::class,
@@ -263,12 +265,24 @@ protected function setUp(): void
263
265
'resource ' => $ this ->resource ,
264
266
]
265
267
);
266
-
267
268
$ this ->abstractType = $ this ->getMockBuilder (AbstractType::class)
268
269
->disableOriginalConstructor ()
269
270
->getMockForAbstractClass ();
270
271
}
271
272
273
+ /**
274
+ * Because AbstractType has static member variables, we must clean them in between tests.
275
+ * Luckily they are publicly accessible.
276
+ *
277
+ * @return void
278
+ */
279
+ protected function tearDown (): void
280
+ {
281
+ AbstractType::$ commonAttributesCache = [];
282
+ AbstractType::$ invAttributesCache = [];
283
+ AbstractType::$ attributeCodeToId = [];
284
+ }
285
+
272
286
/**
273
287
* @dataProvider addAttributeOptionDataProvider
274
288
*/
@@ -428,7 +442,6 @@ public function testPrepareAttributesWithDefaultValueForSave()
428
442
'_attribute_set ' => 'attributeSetName ' ,
429
443
'boolean_attribute ' => 'Yes ' ,
430
444
];
431
-
432
445
$ expected = [
433
446
'boolean_attribute ' => 1 ,
434
447
'text_attribute ' => 'default_value '
0 commit comments