@@ -54,9 +54,6 @@ 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
-
60
57
public function setUp ()
61
58
{
62
59
$ this ->attribute = $ this ->getMock ('\Magento\Catalog\Model\ResourceModel\Eav\Attribute ' , [], [], '' , false );
@@ -90,12 +87,6 @@ public function setUp()
90
87
'swatchHelper ' => $ this ->swatchHelper ,
91
88
]
92
89
);
93
- $ this ->source = $ this ->getMockForAbstractClass (
94
- 'Magento\Eav\Model\Entity\Attribute\Source\AbstractSource ' ,
95
- [],
96
- '' ,
97
- false
98
- );
99
90
100
91
101
92
$ this ->optionIds = [
@@ -108,16 +99,23 @@ public function setUp()
108
99
109
100
public function testBeforeSaveVisualSwatch ()
110
101
{
111
- $ this ->attribute ->expects ($ this ->exactly (4 ))->method ('getData ' )->withConsecutive (
102
+ $ option = [
103
+ 'value ' => [
104
+ 0 => 'option value ' ,
105
+ ]
106
+ ];
107
+ $ this ->attribute ->expects ($ this ->exactly (6 ))->method ('getData ' )->withConsecutive (
112
108
['defaultvisual ' ],
113
109
['optionvisual ' ],
114
110
['swatchvisual ' ],
115
- [Swatch::SWATCH_INPUT_TYPE_KEY ]
111
+ ['optionvisual ' ],
112
+ ['option/delete/0 ' ]
116
113
)->will ($ this ->onConsecutiveCalls (
117
114
self ::ATTRIBUTE_DEFAULT_VALUE ,
118
115
self ::ATTRIBUTE_OPTION_VALUE ,
119
116
self ::ATTRIBUTE_SWATCH_VALUE ,
120
- Swatch::SWATCH_INPUT_TYPE_VISUAL
117
+ $ option ,
118
+ false
121
119
));
122
120
123
121
$ this ->attribute ->expects ($ this ->exactly (3 ))->method ('setData ' )
@@ -127,22 +125,9 @@ public function testBeforeSaveVisualSwatch()
127
125
['swatch ' , self ::ATTRIBUTE_SWATCH_VALUE ]
128
126
);
129
127
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
-
143
128
$ this ->swatchHelper ->expects ($ this ->once ())->method ('assembleAdditionalDataEavAttribute ' )
144
129
->with ($ this ->attribute );
145
- $ this ->swatchHelper ->expects ($ this ->once ())->method ('isVisualSwatch ' )
130
+ $ this ->swatchHelper ->expects ($ this ->atLeastOnce ())->method ('isVisualSwatch ' )
146
131
->with ($ this ->attribute )
147
132
->willReturn (true );
148
133
$ this ->swatchHelper ->expects ($ this ->once ())->method ('isSwatchAttribute ' )
@@ -155,17 +140,24 @@ public function testBeforeSaveVisualSwatch()
155
140
156
141
public function testBeforeSaveTextSwatch ()
157
142
{
158
- $ this ->attribute ->expects ($ this ->exactly (4 ))->method ('getData ' )->withConsecutive (
143
+ $ option = [
144
+ 'value ' => [
145
+ 0 => 'option value ' ,
146
+ ]
147
+ ];
148
+ $ this ->attribute ->expects ($ this ->exactly (6 ))->method ('getData ' )->withConsecutive (
159
149
['defaulttext ' ],
160
150
['optiontext ' ],
161
151
['swatchtext ' ],
162
- [Swatch::SWATCH_INPUT_TYPE_KEY ]
152
+ ['optiontext ' ],
153
+ ['option/delete/0 ' ]
163
154
)->will (
164
155
$ this ->onConsecutiveCalls (
165
156
self ::ATTRIBUTE_DEFAULT_VALUE ,
166
157
self ::ATTRIBUTE_OPTION_VALUE ,
167
158
self ::ATTRIBUTE_SWATCH_VALUE ,
168
- Swatch::SWATCH_INPUT_TYPE_TEXT
159
+ $ option ,
160
+ false
169
161
)
170
162
);
171
163
@@ -176,25 +168,12 @@ public function testBeforeSaveTextSwatch()
176
168
['swatch ' , self ::ATTRIBUTE_SWATCH_VALUE ]
177
169
);
178
170
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
-
192
171
$ this ->swatchHelper ->expects ($ this ->once ())->method ('assembleAdditionalDataEavAttribute ' )
193
172
->with ($ this ->attribute );
194
- $ this ->swatchHelper ->expects ($ this ->once ())->method ('isVisualSwatch ' )
173
+ $ this ->swatchHelper ->expects ($ this ->atLeastOnce ())->method ('isVisualSwatch ' )
195
174
->with ($ this ->attribute )
196
175
->willReturn (false );
197
- $ this ->swatchHelper ->expects ($ this ->once ())->method ('isTextSwatch ' )
176
+ $ this ->swatchHelper ->expects ($ this ->atLeastOnce ())->method ('isTextSwatch ' )
198
177
->with ($ this ->attribute )
199
178
->willReturn (true );
200
179
$ this ->swatchHelper ->expects ($ this ->once ())->method ('isSwatchAttribute ' )
@@ -210,21 +189,83 @@ public function testBeforeSaveTextSwatch()
210
189
*/
211
190
public function testBeforeSaveWithFailedValidation ()
212
191
{
213
- $ this ->swatchHelper ->expects ($ this ->once ())->method ('isSwatchAttribute ' )
192
+ $ optionText = [
193
+ 'value ' => [
194
+ 0 => '' ,
195
+ ]
196
+ ];
197
+ $ this ->swatchHelper ->expects ($ this ->once ())
198
+ ->method ('isSwatchAttribute ' )
214
199
->with ($ this ->attribute )
215
200
->willReturn (true );
216
201
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 ([]);
202
+ $ this ->swatchHelper ->expects ($ this ->atLeastOnce ())
203
+ ->method ('isVisualSwatch ' )
204
+ ->willReturn (true );
205
+ $ this ->attribute ->expects ($ this ->exactly (5 ))
206
+ ->method ('getData ' )
207
+ ->withConsecutive (
208
+ ['defaultvisual ' ],
209
+ ['optionvisual ' ],
210
+ ['swatchvisual ' ],
211
+ ['optionvisual ' ],
212
+ ['option/delete/0 ' ]
213
+ )
214
+ ->will (
215
+ $ this ->onConsecutiveCalls (
216
+ self ::ATTRIBUTE_DEFAULT_VALUE ,
217
+ self ::ATTRIBUTE_OPTION_VALUE ,
218
+ self ::ATTRIBUTE_SWATCH_VALUE ,
219
+ $ optionText ,
220
+ false
221
+ )
222
+ );
224
223
225
224
$ this ->eavAttribute ->beforeSave ($ this ->attribute );
226
225
}
227
226
227
+ /**
228
+ * @covers \Magento\Swatches\Model\Plugin\EavAttribute::beforeSave()
229
+ */
230
+ public function testBeforeSaveWithDeletedOption ()
231
+ {
232
+ $ optionText = [
233
+ 'value ' => [
234
+ 0 => '' ,
235
+ ]
236
+ ];
237
+
238
+ $ this ->swatchHelper ->expects ($ this ->once ())
239
+ ->method ('isSwatchAttribute ' )
240
+ ->with ($ this ->attribute )
241
+ ->willReturn (true );
242
+
243
+ $ this ->swatchHelper ->expects ($ this ->atLeastOnce ())
244
+ ->method ('isVisualSwatch ' )
245
+ ->willReturn (true );
246
+ $ this ->attribute ->expects ($ this ->exactly (6 ))
247
+ ->method ('getData ' )
248
+ ->withConsecutive (
249
+ ['defaultvisual ' ],
250
+ ['optionvisual ' ],
251
+ ['swatchvisual ' ],
252
+ ['optionvisual ' ],
253
+ ['option/delete/0 ' ],
254
+ ['swatch_input_type ' ]
255
+ )
256
+ ->will (
257
+ $ this ->onConsecutiveCalls (
258
+ self ::ATTRIBUTE_DEFAULT_VALUE ,
259
+ self ::ATTRIBUTE_OPTION_VALUE ,
260
+ self ::ATTRIBUTE_SWATCH_VALUE ,
261
+ $ optionText ,
262
+ true ,
263
+ false
264
+ )
265
+ );
266
+ $ this ->eavAttribute ->beforeSave ($ this ->attribute );
267
+ }
268
+
228
269
public function testBeforeSaveNotSwatch ()
229
270
{
230
271
$ additionalData = [
0 commit comments