@@ -58,6 +58,11 @@ class CustomerTest extends \PHPUnit_Framework_TestCase
58
58
/** @var \Magento\Customer\Model\ResourceModel\Customer|\PHPUnit_Framework_MockObject_MockObject */
59
59
protected $ resourceMock ;
60
60
61
+ /**
62
+ * @var \Magento\Framework\Reflection\DataObjectProcessor|\PHPUnit_Framework_MockObject_MockObject
63
+ */
64
+ private $ dataObjectProcessor ;
65
+
61
66
protected function setUp ()
62
67
{
63
68
$ this ->_website = $ this ->getMock (\Magento \Store \Model \Website::class, [], [], '' , false );
@@ -102,6 +107,15 @@ protected function setUp()
102
107
false ,
103
108
false
104
109
);
110
+
111
+ $ this ->dataObjectProcessor = $ this ->getMock (
112
+ \Magento \Framework \Reflection \DataObjectProcessor::class,
113
+ ['buildOutputDataArray ' ],
114
+ [],
115
+ '' ,
116
+ false
117
+ );
118
+
105
119
$ this ->resourceMock ->expects ($ this ->any ())
106
120
->method ('getIdFieldName ' )
107
121
->will ($ this ->returnValue ('id ' ));
@@ -119,6 +133,7 @@ protected function setUp()
119
133
'attributeFactory ' => $ this ->attributeFactoryMock ,
120
134
'registry ' => $ this ->registryMock ,
121
135
'resource ' => $ this ->resourceMock ,
136
+ 'dataObjectProcessor ' => $ this ->dataObjectProcessor
122
137
]
123
138
);
124
139
}
@@ -271,4 +286,65 @@ public function dataProviderIsConfirmationRequired()
271
286
[1 , null , 'test2@example.com ' , true ],
272
287
];
273
288
}
289
+
290
+ public function testUpdateData ()
291
+ {
292
+ $ customerDataAttributes = [
293
+ 'attribute ' => 'attribute ' ,
294
+ 'test1 ' => 'test1 ' ,
295
+ 'test33 ' => 'test33 ' ,
296
+ ];
297
+
298
+ $ customer = $ this ->getMock (
299
+ \Magento \Customer \Model \Data \Customer::class,
300
+ [
301
+ 'getCustomAttributes ' ,
302
+ 'getId ' ,
303
+ ],
304
+ [],
305
+ '' ,
306
+ false
307
+ );
308
+
309
+ $ attribute = $ this ->getMock (
310
+ \Magento \Framework \Api \AttributeValue::class,
311
+ [
312
+ 'getAttributeCode ' ,
313
+ 'getValue ' ,
314
+ ],
315
+ [],
316
+ '' ,
317
+ false
318
+ );
319
+
320
+ $ this ->dataObjectProcessor ->expects ($ this ->once ())
321
+ ->method ('buildOutputDataArray ' )
322
+ ->withConsecutive (
323
+ [$ customer , \Magento \Customer \Api \Data \CustomerInterface::class]
324
+ )->willReturn ($ customerDataAttributes );
325
+
326
+ $ attribute ->expects ($ this ->exactly (3 ))
327
+ ->method ('getAttributeCode ' )
328
+ ->willReturn ('test33 ' );
329
+
330
+ $ attribute ->expects ($ this ->exactly (2 ))
331
+ ->method ('getValue ' )
332
+ ->willReturn ('test33 ' );
333
+
334
+ $ customer ->expects ($ this ->once ())
335
+ ->method ('getCustomAttributes ' )
336
+ ->willReturn ([$ attribute ->getAttributeCode () => $ attribute ]);
337
+
338
+ $ this ->_model ->updateData ($ customer );
339
+
340
+ foreach ($ customerDataAttributes as $ key => $ value ) {
341
+ $ expectedResult [strtolower (trim (preg_replace ('/([A-Z]|[0-9]+)/ ' , "_$1 " , $ key ), '_ ' ))] = $ value ;
342
+ }
343
+
344
+ $ expectedResult [$ attribute ->getAttributeCode ()] = $ attribute ->getValue ();
345
+ $ expectedResult ['attribute_set_id ' ] =
346
+ \Magento \Customer \Api \CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER ;
347
+
348
+ $ this ->assertEquals ($ this ->_model ->getData (), $ expectedResult );
349
+ }
274
350
}
0 commit comments