1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2012 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \Eav \Test \Unit \Model \ResourceModel \Entity ;
9
9
10
10
use Magento \Catalog \Model \Product \Attribute \Source \Status ;
11
+ use Magento \Catalog \Model \Product \Attribute \Source \Layout ;
11
12
use Magento \Eav \Model \Config ;
12
13
use Magento \Eav \Model \Entity \Attribute \Source \Table ;
13
14
use Magento \Eav \Model \ResourceModel \Entity \Attribute ;
@@ -99,15 +100,13 @@ public function testSaveOptionSystemAttribute()
99
100
)->method (
100
101
'fetchRow '
101
102
)->willReturnMap (
102
-
103
+ [
103
104
[
104
- [
105
- 'SELECT `eav_attribute`.* FROM `eav_attribute` ' .
106
- 'WHERE (attribute_code="status") AND (entity_type_id="4") ' ,
107
- $ attributeData ,
108
- ],
109
- ]
110
-
105
+ 'SELECT `eav_attribute`.* FROM `eav_attribute` ' .
106
+ 'WHERE (attribute_code="status") AND (entity_type_id="4") ' ,
107
+ $ attributeData ,
108
+ ],
109
+ ]
111
110
);
112
111
$ connectionMock ->expects (
113
112
$ this ->once ()
@@ -123,6 +122,76 @@ public function testSaveOptionSystemAttribute()
123
122
$ resourceModel ->save ($ model );
124
123
}
125
124
125
+ /**
126
+ * Verify select option with multiple choice save one default value
127
+ *
128
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
129
+ */
130
+ public function testSaveSelectDefaultOptionAttribute ()
131
+ {
132
+ list ($ connectionMock , $ resourceModel ) = $ this ->_prepareResourceModel ();
133
+
134
+ $ originalData = [
135
+ 'entity_type_id ' => 4 ,
136
+ 'attribute_code ' => 'custom_layout ' ,
137
+ 'backend_model ' => null ,
138
+ 'backend_type ' => 'varchar ' ,
139
+ 'frontend_input ' => 'select ' ,
140
+ 'frontend_label ' => 'Test Dropdown ' ,
141
+ 'frontend_class ' => null ,
142
+ 'source_model ' => Layout::class,
143
+ 'is_required ' => 0 ,
144
+ 'is_user_defined ' => 1 ,
145
+ 'is_unique ' => 0 ,
146
+ 'default_value ' => "option_3 " ,
147
+ ];
148
+
149
+ $ attributeData = [
150
+ 'id ' => '999 ' ,
151
+ 'attribute_id ' => '123 ' ,
152
+ 'entity_type_id ' => 4 ,
153
+ 'attribute_code ' => 'custom_layout ' ,
154
+ 'backend_model ' => null ,
155
+ 'backend_type ' => 'varchar ' ,
156
+ 'frontend_input ' => 'select ' ,
157
+ 'frontend_label ' => 'Test Dropdown ' ,
158
+ 'frontend_class ' => null ,
159
+ 'source_model ' => Layout::class,
160
+ 'is_required ' => 0 ,
161
+ 'is_user_defined ' => 1 ,
162
+ 'is_unique ' => 0 ,
163
+ 'default_value ' => "option_3 " ,
164
+ 'default ' => ['option_1 ' ],
165
+ 'sort_order ' => 1 ,
166
+ ];
167
+
168
+ $ objectManagerHelper = new ObjectManager ($ this );
169
+ /** @var AbstractModel $model */
170
+ $ arguments = $ objectManagerHelper ->getConstructArguments (AbstractModel::class);
171
+ $ arguments ['data ' ] = $ attributeData ;
172
+ $ arguments ['context ' ] = $ this ->contextMock ;
173
+ $ model = $ this ->getMockBuilder (AbstractModel::class)
174
+ ->onlyMethods (['save ' ])
175
+ ->setConstructorArgs ($ arguments )
176
+ ->getMock ();
177
+ $ model ->setOption (
178
+ [
179
+ 'delete ' =>
180
+ [
181
+ 'option_1 ' => ['choice_1 ' , 'Frontend choice_1 ' ],
182
+ 'option_2 ' => ['choice_2 ' , 'Frontend choice_2 ' ],
183
+ 'option_3 ' => ['choice_3 ' , 'Frontend choice_3 ' ]
184
+ ]
185
+ ]
186
+ );
187
+
188
+ $ connectionMock ->expects ($ this ->any ())
189
+ ->method ('update ' )
190
+ ->with ('eav_attribute ' , $ this ->logicalOr ($ originalData , ['default_value ' => "option_1 " ]));
191
+
192
+ $ resourceModel ->save ($ model );
193
+ }
194
+
126
195
/**
127
196
* @covers \Magento\Eav\Model\ResourceModel\Entity\Attribute::_saveOption
128
197
*/
@@ -171,24 +240,22 @@ public function testSaveOptionNewUserDefinedAttribute()
171
240
)->method (
172
241
'update '
173
242
)->willReturnMap (
174
-
175
- [[ 'eav_attribute ' , ['default_value ' => '' ], ['attribute_id = ? ' => 123 ], 1 ] ]
176
-
243
+ [
244
+ ['eav_attribute ' , ['default_value ' => '' ], ['attribute_id = ? ' => 123 ], 1 ]
245
+ ]
177
246
);
178
247
$ connectionMock ->expects (
179
248
$ this ->once ()
180
249
)->method (
181
250
'fetchRow '
182
251
)->willReturnMap (
183
-
252
+ [
184
253
[
185
- [
186
- 'SELECT `eav_attribute`.* FROM `eav_attribute` ' .
187
- 'WHERE (attribute_code="a_dropdown") AND (entity_type_id="4") ' ,
188
- false ,
189
- ],
190
- ]
191
-
254
+ 'SELECT `eav_attribute`.* FROM `eav_attribute` ' .
255
+ 'WHERE (attribute_code="a_dropdown") AND (entity_type_id="4") ' ,
256
+ false ,
257
+ ],
258
+ ]
192
259
);
193
260
$ connectionMock ->expects (
194
261
$ this ->once ()
@@ -202,22 +269,20 @@ public function testSaveOptionNewUserDefinedAttribute()
202
269
)->method (
203
270
'insert '
204
271
)->willReturnMap (
205
-
272
+ [
273
+ ['eav_attribute ' , $ attributeData , 1 ],
274
+ ['eav_attribute_option ' , ['attribute_id ' => 123 , 'sort_order ' => 0 ], 1 ],
206
275
[
207
- ['eav_attribute ' , $ attributeData , 1 ],
208
- ['eav_attribute_option ' , ['attribute_id ' => 123 , 'sort_order ' => 0 ], 1 ],
209
- [
210
- 'eav_attribute_option_value ' ,
211
- ['option_id ' => 123 , 'store_id ' => 0 , 'value ' => 'Backend Label ' ],
212
- 1
213
- ],
214
- [
215
- 'eav_attribute_option_value ' ,
216
- ['option_id ' => 123 , 'store_id ' => 1 , 'value ' => 'Frontend Label ' ],
217
- 1
218
- ],
219
- ]
220
-
276
+ 'eav_attribute_option_value ' ,
277
+ ['option_id ' => 123 , 'store_id ' => 0 , 'value ' => 'Backend Label ' ],
278
+ 1
279
+ ],
280
+ [
281
+ 'eav_attribute_option_value ' ,
282
+ ['option_id ' => 123 , 'store_id ' => 1 , 'value ' => 'Frontend Label ' ],
283
+ 1
284
+ ],
285
+ ]
221
286
);
222
287
$ connectionMock ->expects ($ this ->any ())->method ('getTransactionLevel ' )->willReturn (1 );
223
288
0 commit comments