@@ -72,7 +72,9 @@ protected function setUp()
72
72
'setAttributeSetFilter '
73
73
]
74
74
);
75
- $ attribute = $ this ->createPartialMock (\Magento \Eav \Model \Entity \Attribute::class, [
75
+ $ attribute = $ this ->createPartialMock (
76
+ \Magento \Eav \Model \Entity \Attribute::class,
77
+ [
76
78
'getAttributeCode ' ,
77
79
'getId ' ,
78
80
'getIsVisible ' ,
@@ -85,7 +87,8 @@ protected function setUp()
85
87
'getDefaultValue ' ,
86
88
'usesSource ' ,
87
89
'getFrontendInput ' ,
88
- ]);
90
+ ]
91
+ );
89
92
$ attribute ->expects ($ this ->any ())->method ('getIsVisible ' )->willReturn (true );
90
93
$ attribute ->expects ($ this ->any ())->method ('getIsGlobal ' )->willReturn (true );
91
94
$ attribute ->expects ($ this ->any ())->method ('getIsRequired ' )->willReturn (true );
@@ -107,6 +110,7 @@ protected function setUp()
107
110
];
108
111
$ attribute1 = clone $ attribute ;
109
112
$ attribute2 = clone $ attribute ;
113
+ $ attribute3 = clone $ attribute ;
110
114
111
115
$ attribute1 ->expects ($ this ->any ())->method ('getId ' )->willReturn ('1 ' );
112
116
$ attribute1 ->expects ($ this ->any ())->method ('getAttributeCode ' )->willReturn ('attr_code ' );
@@ -118,6 +122,11 @@ protected function setUp()
118
122
$ attribute2 ->expects ($ this ->any ())->method ('getFrontendInput ' )->willReturn ('boolean ' );
119
123
$ attribute2 ->expects ($ this ->any ())->method ('isStatic ' )->willReturn (false );
120
124
125
+ $ attribute3 ->expects ($ this ->any ())->method ('getId ' )->willReturn ('3 ' );
126
+ $ attribute3 ->expects ($ this ->any ())->method ('getAttributeCode ' )->willReturn ('text_attribute ' );
127
+ $ attribute3 ->expects ($ this ->any ())->method ('getFrontendInput ' )->willReturn ('text ' );
128
+ $ attribute3 ->expects ($ this ->any ())->method ('isStatic ' )->willReturn (false );
129
+
121
130
$ this ->entityModel ->expects ($ this ->any ())->method ('getEntityTypeId ' )->willReturn (3 );
122
131
$ this ->entityModel ->expects ($ this ->any ())->method ('getAttributeOptions ' )->willReturnOnConsecutiveCalls (
123
132
['option1 ' , 'option2 ' ],
@@ -126,7 +135,9 @@ protected function setUp()
126
135
$ attrSetColFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ attrSetCollection );
127
136
$ attrSetCollection ->expects ($ this ->any ())->method ('setEntityTypeFilter ' )->willReturn ([$ attributeSet ]);
128
137
$ attrColFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ attrCollection );
129
- $ attrCollection ->expects ($ this ->any ())->method ('setAttributeSetFilter ' )->willReturn ([$ attribute1 , $ attribute2 ]);
138
+ $ attrCollection ->expects ($ this ->any ())
139
+ ->method ('setAttributeSetFilter ' )
140
+ ->willReturn ([$ attribute1 , $ attribute2 , $ attribute3 ]);
130
141
$ attributeSet ->expects ($ this ->any ())->method ('getId ' )->willReturn (1 );
131
142
$ attributeSet ->expects ($ this ->any ())->method ('getAttributeSetName ' )->willReturn ('attribute_set_name ' );
132
143
@@ -157,23 +168,29 @@ protected function setUp()
157
168
],
158
169
]
159
170
)
160
- ->willReturn ([$ attribute1 , $ attribute2 ]);
171
+ ->willReturn ([$ attribute1 , $ attribute2, $ attribute3 ]);
161
172
162
- $ this ->connection = $ this ->createPartialMock (\Magento \Framework \DB \Adapter \Pdo \Mysql::class, [
173
+ $ this ->connection = $ this ->createPartialMock (
174
+ \Magento \Framework \DB \Adapter \Pdo \Mysql::class,
175
+ [
163
176
'select ' ,
164
177
'fetchAll ' ,
165
178
'fetchPairs ' ,
166
179
'joinLeft ' ,
167
180
'insertOnDuplicate ' ,
168
181
'delete ' ,
169
182
'quoteInto '
170
- ]);
171
- $ this ->select = $ this ->createPartialMock (\Magento \Framework \DB \Select::class, [
183
+ ]
184
+ );
185
+ $ this ->select = $ this ->createPartialMock (
186
+ \Magento \Framework \DB \Select::class,
187
+ [
172
188
'from ' ,
173
189
'where ' ,
174
190
'joinLeft ' ,
175
191
'getConnection ' ,
176
- ]);
192
+ ]
193
+ );
177
194
$ this ->select ->expects ($ this ->any ())->method ('from ' )->will ($ this ->returnSelf ());
178
195
$ this ->select ->expects ($ this ->any ())->method ('where ' )->will ($ this ->returnSelf ());
179
196
$ this ->select ->expects ($ this ->any ())->method ('joinLeft ' )->will ($ this ->returnSelf ());
@@ -189,10 +206,13 @@ protected function setUp()
189
206
->method ('fetchAll ' )
190
207
->will ($ this ->returnValue ($ entityAttributes ));
191
208
192
- $ this ->resource = $ this ->createPartialMock (\Magento \Framework \App \ResourceConnection::class, [
209
+ $ this ->resource = $ this ->createPartialMock (
210
+ \Magento \Framework \App \ResourceConnection::class,
211
+ [
193
212
'getConnection ' ,
194
213
'getTableName ' ,
195
- ]);
214
+ ]
215
+ );
196
216
$ this ->resource ->expects ($ this ->any ())->method ('getConnection ' )->will (
197
217
$ this ->returnValue ($ this ->connection )
198
218
);
@@ -257,9 +277,13 @@ public function testIsRowValidSuccess()
257
277
$ rowNum = 1 ;
258
278
$ this ->entityModel ->expects ($ this ->any ())->method ('getRowScope ' )->willReturn (null );
259
279
$ this ->entityModel ->expects ($ this ->never ())->method ('addRowError ' );
260
- $ this ->setPropertyValue ($ this ->simpleType , '_attributes ' , [
261
- $ rowData [\Magento \CatalogImportExport \Model \Import \Product::COL_ATTR_SET ] => [],
262
- ]);
280
+ $ this ->setPropertyValue (
281
+ $ this ->simpleType ,
282
+ '_attributes ' ,
283
+ [
284
+ $ rowData [\Magento \CatalogImportExport \Model \Import \Product::COL_ATTR_SET ] => [],
285
+ ]
286
+ );
263
287
$ this ->assertTrue ($ this ->simpleType ->isRowValid ($ rowData , $ rowNum ));
264
288
}
265
289
@@ -278,13 +302,17 @@ public function testIsRowValidError()
278
302
'attr_code '
279
303
)
280
304
->willReturnSelf ();
281
- $ this ->setPropertyValue ($ this ->simpleType , '_attributes ' , [
282
- $ rowData [\Magento \CatalogImportExport \Model \Import \Product::COL_ATTR_SET ] => [
283
- 'attr_code ' => [
284
- 'is_required ' => true ,
305
+ $ this ->setPropertyValue (
306
+ $ this ->simpleType ,
307
+ '_attributes ' ,
308
+ [
309
+ $ rowData [\Magento \CatalogImportExport \Model \Import \Product::COL_ATTR_SET ] => [
310
+ 'attr_code ' => [
311
+ 'is_required ' => true ,
312
+ ],
285
313
],
286
- ],
287
- ] );
314
+ ]
315
+ );
288
316
289
317
$ this ->assertFalse ($ this ->simpleType ->isRowValid ($ rowData , $ rowNum ));
290
318
}
@@ -364,9 +392,14 @@ public function testPrepareAttributesWithDefaultValueForSave()
364
392
{
365
393
$ rowData = [
366
394
'_attribute_set ' => 'attributeSetName ' ,
367
- 'boolean_attribute ' => 'Yes '
395
+ 'boolean_attribute ' => 'Yes ' ,
396
+ ];
397
+
398
+ $ expected = [
399
+ 'boolean_attribute ' => 1 ,
400
+ 'text_attribute ' => 'default_value '
368
401
];
369
402
$ result = $ this ->simpleType ->prepareAttributesWithDefaultValueForSave ($ rowData );
370
- $ this ->assertEquals ([ ' boolean_attribute ' => 1 ] , $ result );
403
+ $ this ->assertEquals ($ expected , $ result );
371
404
}
372
405
}
0 commit comments