7
7
8
8
namespace Magento \Catalog \Test \Unit \Controller \Adminhtml \Product \Attribute ;
9
9
10
+ use Magento \Backend \Model \Session ;
10
11
use Magento \Backend \Model \View \Result \Redirect as ResultRedirect ;
11
12
use Magento \Catalog \Api \Data \ProductAttributeInterface ;
12
13
use Magento \Catalog \Controller \Adminhtml \Product \Attribute \Save ;
13
14
use Magento \Catalog \Helper \Product as ProductHelper ;
15
+ use Magento \Catalog \Model \Product \Attribute \Frontend \Inputtype \Presentation ;
14
16
use Magento \Catalog \Model \Product \AttributeSet \Build ;
15
17
use Magento \Catalog \Model \Product \AttributeSet \BuildFactory ;
16
18
use Magento \Catalog \Model \ResourceModel \Eav \AttributeFactory ;
31
33
32
34
/**
33
35
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
36
+ * @SuppressWarnings(PHPMD.TooManyFields)
34
37
*/
35
38
class SaveTest extends AttributeTest
36
39
{
37
40
/**
38
41
* @var BuildFactory|MockObject
39
42
*/
40
- protected $ buildFactoryMock ;
43
+ private $ buildFactoryMock ;
41
44
42
45
/**
43
46
* @var FilterManager|MockObject
44
47
*/
45
- protected $ filterManagerMock ;
48
+ private $ filterManagerMock ;
46
49
47
50
/**
48
51
* @var ProductHelper|MockObject
49
52
*/
50
- protected $ productHelperMock ;
53
+ private $ productHelperMock ;
51
54
52
55
/**
53
56
* @var AttributeFactory|MockObject
54
57
*/
55
- protected $ attributeFactoryMock ;
58
+ private $ attributeFactoryMock ;
56
59
57
60
/**
58
61
* @var ValidatorFactory|MockObject
59
62
*/
60
- protected $ validatorFactoryMock ;
63
+ private $ validatorFactoryMock ;
61
64
62
65
/**
63
66
* @var CollectionFactory|MockObject
64
67
*/
65
- protected $ groupCollectionFactoryMock ;
68
+ private $ groupCollectionFactoryMock ;
66
69
67
70
/**
68
71
* @var LayoutFactory|MockObject
69
72
*/
70
- protected $ layoutFactoryMock ;
73
+ private $ layoutFactoryMock ;
71
74
72
75
/**
73
76
* @var ResultRedirect|MockObject
74
77
*/
75
- protected $ redirectMock ;
78
+ private $ redirectMock ;
76
79
77
80
/**
78
- * @var AttributeSet |MockObject
81
+ * @var AttributeSetInterface |MockObject
79
82
*/
80
- protected $ attributeSetMock ;
83
+ private $ attributeSetMock ;
81
84
82
85
/**
83
86
* @var Build|MockObject
84
87
*/
85
- protected $ builderMock ;
88
+ private $ builderMock ;
86
89
87
90
/**
88
91
* @var InputTypeValidator|MockObject
89
92
*/
90
- protected $ inputTypeValidatorMock ;
93
+ private $ inputTypeValidatorMock ;
91
94
92
95
/**
93
96
* @var FormData|MockObject
@@ -104,19 +107,34 @@ class SaveTest extends AttributeTest
104
107
*/
105
108
private $ attributeCodeValidatorMock ;
106
109
110
+ /**
111
+ * @var Presentation|MockObject
112
+ */
113
+ private $ presentationMock ;
114
+
115
+ /**
116
+ * @var Session|MockObject
117
+ */
118
+
119
+ private $ sessionMock ;
120
+
107
121
protected function setUp (): void
108
122
{
109
123
parent ::setUp ();
124
+ $ this ->filterManagerMock = $ this ->createMock (FilterManager::class);
125
+ $ this ->productHelperMock = $ this ->createMock (ProductHelper::class);
126
+ $ this ->attributeSetMock = $ this ->createMock (AttributeSetInterface::class);
127
+ $ this ->builderMock = $ this ->createMock (Build::class);
128
+ $ this ->inputTypeValidatorMock = $ this ->createMock (InputTypeValidator::class);
129
+ $ this ->formDataSerializerMock = $ this ->createMock (FormData::class);
130
+ $ this ->attributeCodeValidatorMock = $ this ->createMock (AttributeCodeValidator::class);
131
+ $ this ->presentationMock = $ this ->createMock (Presentation::class);
132
+ $ this ->sessionMock = $ this ->createMock (Session::class);
133
+ $ this ->layoutFactoryMock = $ this ->createMock (LayoutFactory::class);
110
134
$ this ->buildFactoryMock = $ this ->getMockBuilder (BuildFactory::class)
111
135
->setMethods (['create ' ])
112
136
->disableOriginalConstructor ()
113
137
->getMock ();
114
- $ this ->filterManagerMock = $ this ->getMockBuilder (FilterManager::class)
115
- ->disableOriginalConstructor ()
116
- ->getMock ();
117
- $ this ->productHelperMock = $ this ->getMockBuilder (ProductHelper::class)
118
- ->disableOriginalConstructor ()
119
- ->getMock ();
120
138
$ this ->attributeFactoryMock = $ this ->getMockBuilder (AttributeFactory::class)
121
139
->setMethods (['create ' ])
122
140
->disableOriginalConstructor ()
@@ -129,32 +147,23 @@ protected function setUp(): void
129
147
->setMethods (['create ' ])
130
148
->disableOriginalConstructor ()
131
149
->getMock ();
132
- $ this ->layoutFactoryMock = $ this ->getMockBuilder (LayoutFactory::class)
133
- ->disableOriginalConstructor ()
134
- ->getMock ();
135
150
$ this ->redirectMock = $ this ->getMockBuilder (ResultRedirect::class)
136
151
->setMethods (['setData ' , 'setPath ' ])
137
152
->disableOriginalConstructor ()
138
153
->getMock ();
139
- $ this ->attributeSetMock = $ this ->getMockBuilder (AttributeSetInterface::class)
140
- ->disableOriginalConstructor ()
141
- ->getMockForAbstractClass ();
142
- $ this ->builderMock = $ this ->getMockBuilder (Build::class)
143
- ->disableOriginalConstructor ()
144
- ->getMock ();
145
- $ this ->inputTypeValidatorMock = $ this ->getMockBuilder (InputTypeValidator::class)
146
- ->disableOriginalConstructor ()
147
- ->getMock ();
148
- $ this ->formDataSerializerMock = $ this ->getMockBuilder (FormData::class)
149
- ->disableOriginalConstructor ()
150
- ->getMock ();
151
- $ this ->attributeCodeValidatorMock = $ this ->getMockBuilder (AttributeCodeValidator::class)
152
- ->disableOriginalConstructor ()
153
- ->getMock ();
154
154
$ this ->productAttributeMock = $ this ->getMockBuilder (ProductAttributeInterface::class)
155
- ->setMethods (['getId ' , 'get ' ])
156
- ->getMockForAbstractClass ();
157
-
155
+ ->setMethods (
156
+ [
157
+ 'getId ' ,
158
+ 'get ' ,
159
+ 'getBackendTypeByInput ' ,
160
+ 'getDefaultValueByInput ' ,
161
+ 'getBackendType ' ,
162
+ 'getFrontendClass ' ,
163
+ 'addData ' ,
164
+ 'save '
165
+ ]
166
+ )->getMockForAbstractClass ();
158
167
$ this ->buildFactoryMock ->expects ($ this ->any ())
159
168
->method ('create ' )
160
169
->willReturn ($ this ->builderMock );
@@ -167,7 +176,7 @@ protected function setUp(): void
167
176
}
168
177
169
178
/**
170
- * { @inheritdoc}
179
+ * @inheritdoc
171
180
*/
172
181
protected function getModel ()
173
182
{
@@ -184,7 +193,9 @@ protected function getModel()
184
193
'groupCollectionFactory ' => $ this ->groupCollectionFactoryMock ,
185
194
'layoutFactory ' => $ this ->layoutFactoryMock ,
186
195
'formDataSerializer ' => $ this ->formDataSerializerMock ,
187
- 'attributeCodeValidator ' => $ this ->attributeCodeValidatorMock
196
+ 'attributeCodeValidator ' => $ this ->attributeCodeValidatorMock ,
197
+ 'presentation ' => $ this ->presentationMock ,
198
+ '_session ' => $ this ->sessionMock
188
199
]);
189
200
}
190
201
@@ -214,6 +225,67 @@ public function testExecuteWithEmptyData()
214
225
$ this ->assertInstanceOf (ResultRedirect::class, $ this ->getModel ()->execute ());
215
226
}
216
227
228
+ public function testExecuteSaveFrontendClass ()
229
+ {
230
+ $ data = [
231
+ 'frontend_input ' => 'test_frontend_input ' ,
232
+ ];
233
+
234
+ $ this ->requestMock ->expects ($ this ->any ())
235
+ ->method ('getParam ' )
236
+ ->willReturnMap ([
237
+ ['isAjax ' , null , null ],
238
+ ['serialized_options ' , '[] ' , '' ],
239
+ ['set ' , null , 1 ],
240
+ ['attribute_code ' , null , 'test_attribute_code ' ],
241
+ ]);
242
+ $ this ->formDataSerializerMock
243
+ ->expects ($ this ->once ())
244
+ ->method ('unserialize ' )
245
+ ->with ('' )
246
+ ->willReturn ([]);
247
+ $ this ->requestMock ->expects ($ this ->once ())
248
+ ->method ('getPostValue ' )
249
+ ->willReturn ($ data );
250
+ $ this ->inputTypeValidatorMock ->expects ($ this ->any ())
251
+ ->method ('isValid ' )
252
+ ->with ($ data ['frontend_input ' ])
253
+ ->willReturn (true );
254
+ $ this ->presentationMock ->expects ($ this ->once ())
255
+ ->method ('convertPresentationDataToInputType ' )
256
+ ->willReturn ($ data );
257
+ $ this ->productHelperMock ->expects ($ this ->once ())
258
+ ->method ('getAttributeSourceModelByInputType ' )
259
+ ->with ($ data ['frontend_input ' ])
260
+ ->willReturn (null );
261
+ $ this ->productHelperMock ->expects ($ this ->once ())
262
+ ->method ('getAttributeBackendModelByInputType ' )
263
+ ->with ($ data ['frontend_input ' ])
264
+ ->willReturn (null );
265
+ $ this ->productAttributeMock ->expects ($ this ->once ())
266
+ ->method ('getBackendTypeByInput ' )
267
+ ->with ($ data ['frontend_input ' ])
268
+ ->willReturnSelf ('test_backend_type ' );
269
+ $ this ->productAttributeMock ->expects ($ this ->once ())
270
+ ->method ('getDefaultValueByInput ' )
271
+ ->with ($ data ['frontend_input ' ])
272
+ ->willReturn (null );
273
+ $ this ->productAttributeMock ->expects ($ this ->once ())
274
+ ->method ('getBackendType ' )
275
+ ->willReturn ('static ' );
276
+ $ this ->productAttributeMock ->expects ($ this ->once ())
277
+ ->method ('getFrontendClass ' )
278
+ ->willReturn ('static ' );
279
+ $ this ->resultFactoryMock ->expects ($ this ->any ())
280
+ ->method ('create ' )
281
+ ->willReturn ($ this ->redirectMock );
282
+ $ this ->redirectMock ->expects ($ this ->any ())
283
+ ->method ('setPath ' )
284
+ ->willReturnSelf ();
285
+
286
+ $ this ->assertInstanceOf (ResultRedirect::class, $ this ->getModel ()->execute ());
287
+ }
288
+
217
289
public function testExecute ()
218
290
{
219
291
$ data = [
0 commit comments