@@ -54,6 +54,9 @@ class EavAttributeTest extends \PHPUnit_Framework_TestCase
54
54
/** @var array */
55
55
private $ dependencyArray = [];
56
56
57
+ /** @var \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource|\PHPUnit_Framework_MockObject_MockObject */
58
+ protected $ source ;
59
+
57
60
public function setUp ()
58
61
{
59
62
$ this ->attribute = $ this ->getMock ('\Magento\Catalog\Model\ResourceModel\Eav\Attribute ' , [], [], '' , false );
@@ -87,6 +90,13 @@ public function setUp()
87
90
'swatchHelper ' => $ this ->swatchHelper ,
88
91
]
89
92
);
93
+ $ this ->source = $ this ->getMockForAbstractClass (
94
+ 'Magento\Eav\Model\Entity\Attribute\Source\AbstractSource ' ,
95
+ [],
96
+ '' ,
97
+ false
98
+ );
99
+
90
100
91
101
$ this ->optionIds = [
92
102
'value ' => ['option 89 ' => 'test 1 ' , 'option 114 ' => 'test 2 ' , 'option 170 ' => 'test 3 ' ],
@@ -117,6 +127,19 @@ public function testBeforeSaveVisualSwatch()
117
127
['swatch ' , self ::ATTRIBUTE_SWATCH_VALUE ]
118
128
);
119
129
130
+ $ this ->attribute ->expects ($ this ->once ())
131
+ ->method ('getSource ' )
132
+ ->willReturn ($ this ->source );
133
+ $ this ->source ->expects ($ this ->once ())
134
+ ->method ('getAllOptions ' )
135
+ ->with (false )
136
+ ->willReturn ([
137
+ [
138
+ 'value ' => 'value ' ,
139
+ 'label ' => 'label '
140
+ ]
141
+ ]);
142
+
120
143
$ this ->swatchHelper ->expects ($ this ->once ())->method ('assembleAdditionalDataEavAttribute ' )
121
144
->with ($ this ->attribute );
122
145
$ this ->swatchHelper ->expects ($ this ->once ())->method ('isVisualSwatch ' )
@@ -153,6 +176,19 @@ public function testBeforeSaveTextSwatch()
153
176
['swatch ' , self ::ATTRIBUTE_SWATCH_VALUE ]
154
177
);
155
178
179
+ $ this ->attribute ->expects ($ this ->once ())
180
+ ->method ('getSource ' )
181
+ ->willReturn ($ this ->source );
182
+ $ this ->source ->expects ($ this ->once ())
183
+ ->method ('getAllOptions ' )
184
+ ->with (false )
185
+ ->willReturn ([
186
+ [
187
+ 'value ' => 'value ' ,
188
+ 'label ' => 'label '
189
+ ]
190
+ ]);
191
+
156
192
$ this ->swatchHelper ->expects ($ this ->once ())->method ('assembleAdditionalDataEavAttribute ' )
157
193
->with ($ this ->attribute );
158
194
$ this ->swatchHelper ->expects ($ this ->once ())->method ('isVisualSwatch ' )
@@ -168,6 +204,27 @@ public function testBeforeSaveTextSwatch()
168
204
$ this ->eavAttribute ->beforeSave ($ this ->attribute );
169
205
}
170
206
207
+ /**
208
+ * @expectedException \Magento\Framework\Exception\InputException
209
+ * @expectedExceptionMessage Admin is a required field in the each row
210
+ */
211
+ public function testBeforeSaveWithFailedValidation ()
212
+ {
213
+ $ this ->swatchHelper ->expects ($ this ->once ())->method ('isSwatchAttribute ' )
214
+ ->with ($ this ->attribute )
215
+ ->willReturn (true );
216
+
217
+ $ this ->attribute ->expects ($ this ->once ())
218
+ ->method ('getSource ' )
219
+ ->willReturn ($ this ->source );
220
+ $ this ->source ->expects ($ this ->once ())
221
+ ->method ('getAllOptions ' )
222
+ ->with (false )
223
+ ->willReturn ([]);
224
+
225
+ $ this ->eavAttribute ->beforeSave ($ this ->attribute );
226
+ }
227
+
171
228
public function testBeforeSaveNotSwatch ()
172
229
{
173
230
$ additionalData = [
0 commit comments