@@ -123,6 +123,78 @@ public function testSaveOptionSystemAttribute()
123123 $ resourceModel ->save ($ model );
124124 }
125125
126+ /**
127+ * Verify select option with multiple choice save one default value
128+ *
129+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
130+ */
131+ public function testSaveSelectDefaultOptionAttribute ()
132+ {
133+ list ($ connectionMock , $ resourceModel ) = $ this ->_prepareResourceModel ();
134+
135+ $ originalData = [
136+ 'entity_type_id ' => 4 ,
137+ 'attribute_code ' => 'custom_layout ' ,
138+ 'backend_model ' => null ,
139+ 'backend_type ' => 'varchar ' ,
140+ 'frontend_input ' => 'select ' ,
141+ 'frontend_label ' => 'Test Dropdown ' ,
142+ 'frontend_class ' => null ,
143+ 'source_model ' => Layout::class,
144+ 'is_required ' => 0 ,
145+ 'is_user_defined ' => 1 ,
146+ 'is_unique ' => 0 ,
147+ 'default_value ' => "option_3 " ,
148+ ];
149+
150+ $ attributeData = [
151+ 'id ' => '999 ' ,
152+ 'attribute_id ' => '123 ' ,
153+ 'entity_type_id ' => 4 ,
154+ 'attribute_code ' => 'custom_layout ' ,
155+ 'backend_model ' => null ,
156+ 'backend_type ' => 'varchar ' ,
157+ 'frontend_input ' => 'select ' ,
158+ 'frontend_label ' => 'Test Dropdown ' ,
159+ 'frontend_class ' => null ,
160+ 'source_model ' => Layout::class,
161+ 'is_required ' => 0 ,
162+ 'is_user_defined ' => 1 ,
163+ 'is_unique ' => 0 ,
164+ 'default_value ' => "option_3 " ,
165+ 'default ' => ['option_1 ' ],
166+ 'sort_order ' => 1 ,
167+ ];
168+
169+ $ objectManagerHelper = new ObjectManager ($ this );
170+ /** @var AbstractModel $model */
171+ $ arguments = $ objectManagerHelper ->getConstructArguments (AbstractModel::class);
172+ $ arguments ['data ' ] = $ attributeData ;
173+ $ arguments ['context ' ] = $ this ->contextMock ;
174+ $ model = $ this ->getMockBuilder (AbstractModel::class)
175+ ->onlyMethods (['save ' ])
176+ ->setConstructorArgs ($ arguments )
177+ ->getMock ();
178+ // $model->expects($this->any())->method('hasDataChanges')->willReturn(true);
179+ $ model ->setOption (
180+ [
181+ 'delete ' =>
182+ [
183+ 'option_1 ' => ['choice_1 ' , 'Frontend choice_1 ' ],
184+ 'option_2 ' => ['choice_2 ' , 'Frontend choice_2 ' ],
185+ 'option_3 ' => ['choice_3 ' , 'Frontend choice_3 ' ]
186+ ]
187+ ]
188+ );
189+
190+ $ connectionMock ->expects ($ this ->any ())
191+ ->method ('update ' )
192+ ->with ('eav_attribute ' , $ this ->logicalOr ($ originalData , ['default_value ' => "option_1 " ]));
193+ // $connectionMock->expects($this->any())->method('getTransactionLevel')->willReturn(1);
194+
195+ $ resourceModel ->save ($ model );
196+ }
197+
126198 /**
127199 * @covers \Magento\Eav\Model\ResourceModel\Entity\Attribute::_saveOption
128200 */
0 commit comments