13
13
14
14
use Magento \Customer \Model \Customer ;
15
15
use Magento \Customer \Model \AccountConfirmation ;
16
+ use Magento \Customer \Model \ResourceModel \Address \CollectionFactory as AddressCollectionFactory ;
17
+ use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
16
18
17
19
/**
18
20
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -68,6 +70,21 @@ class CustomerTest extends \PHPUnit\Framework\TestCase
68
70
*/
69
71
private $ accountConfirmation ;
70
72
73
+ /**
74
+ * @var AddressCollectionFactory|\PHPUnit_Framework_MockObject_MockObject
75
+ */
76
+ private $ addressesFactory ;
77
+
78
+ /**
79
+ * @var CustomerInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
80
+ */
81
+ private $ customerDataFactory ;
82
+
83
+ /**
84
+ * @var \Magento\Framework\Api\DataObjectHelper|\PHPUnit_Framework_MockObject_MockObject
85
+ */
86
+ private $ dataObjectHelper ;
87
+
71
88
protected function setUp ()
72
89
{
73
90
$ this ->_website = $ this ->createMock (\Magento \Store \Model \Website::class);
@@ -100,6 +117,19 @@ protected function setUp()
100
117
$ this ->_encryptor = $ this ->createMock (\Magento \Framework \Encryption \EncryptorInterface::class);
101
118
$ helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
102
119
$ this ->accountConfirmation = $ this ->createMock (AccountConfirmation::class);
120
+ $ this ->addressesFactory = $ this ->getMockBuilder (AddressCollectionFactory::class)
121
+ ->disableOriginalConstructor ()
122
+ ->setMethods (['create ' ])
123
+ ->getMock ();
124
+ $ this ->customerDataFactory = $ this ->getMockBuilder (CustomerInterfaceFactory::class)
125
+ ->disableOriginalConstructor ()
126
+ ->setMethods (['create ' ])
127
+ ->getMock ();
128
+ $ this ->dataObjectHelper = $ this ->getMockBuilder (\Magento \Framework \Api \DataObjectHelper::class)
129
+ ->disableOriginalConstructor ()
130
+ ->setMethods (['populateWithArray ' ])
131
+ ->getMock ();
132
+
103
133
$ this ->_model = $ helper ->getObject (
104
134
\Magento \Customer \Model \Customer::class,
105
135
[
@@ -112,7 +142,10 @@ protected function setUp()
112
142
'registry ' => $ this ->registryMock ,
113
143
'resource ' => $ this ->resourceMock ,
114
144
'dataObjectProcessor ' => $ this ->dataObjectProcessor ,
115
- 'accountConfirmation ' => $ this ->accountConfirmation
145
+ 'accountConfirmation ' => $ this ->accountConfirmation ,
146
+ '_addressesFactory ' => $ this ->addressesFactory ,
147
+ 'customerDataFactory ' => $ this ->customerDataFactory ,
148
+ 'dataObjectHelper ' => $ this ->dataObjectHelper
116
149
]
117
150
);
118
151
}
@@ -186,13 +219,13 @@ public function testSendNewAccountEmailWithoutStoreId()
186
219
->will ($ this ->returnValue ($ transportMock ));
187
220
188
221
$ this ->_model ->setData ([
189
- 'website_id ' => 1 ,
190
- 'store_id ' => 1 ,
191
- 'email ' => 'email@example.com ' ,
192
- 'firstname ' => 'FirstName ' ,
193
- 'lastname ' => 'LastName ' ,
194
- 'middlename ' => 'MiddleName ' ,
195
- 'prefix ' => 'Name Prefix ' ,
222
+ 'website_id ' => 1 ,
223
+ 'store_id ' => 1 ,
224
+ 'email ' => 'email@example.com ' ,
225
+ 'firstname ' => 'FirstName ' ,
226
+ 'lastname ' => 'LastName ' ,
227
+ 'middlename ' => 'MiddleName ' ,
228
+ 'prefix ' => 'Name Prefix ' ,
196
229
]);
197
230
$ this ->_model ->sendNewAccountEmail ('registered ' );
198
231
}
@@ -310,4 +343,43 @@ public function testUpdateData()
310
343
311
344
$ this ->assertEquals ($ this ->_model ->getData (), $ expectedResult );
312
345
}
346
+
347
+ /**
348
+ * Test for the \Magento\Customer\Model\Customer::getDataModel() method
349
+ */
350
+ public function testGetDataModel ()
351
+ {
352
+ $ customerId = 1 ;
353
+ $ this ->_model ->setEntityId ($ customerId );
354
+ $ this ->_model ->setId ($ customerId );
355
+ $ addressDataModel = $ this ->getMockForAbstractClass (\Magento \Customer \Api \Data \AddressInterface::class);
356
+ $ address = $ this ->getMockBuilder (\Magento \Customer \Model \Address::class)
357
+ ->disableOriginalConstructor ()
358
+ ->setMethods (['setCustomer ' , 'getDataModel ' ])
359
+ ->getMock ();
360
+ $ address ->expects ($ this ->atLeastOnce ())->method ('getDataModel ' )->willReturn ($ addressDataModel );
361
+ $ addresses = new \ArrayIterator ([$ address , $ address ]);
362
+ $ addressCollection = $ this ->getMockBuilder (\Magento \Customer \Model \ResourceModel \Address \Collection::class)
363
+ ->disableOriginalConstructor ()
364
+ ->setMethods (['setCustomerFilter ' , 'addAttributeToSelect ' , 'getIterator ' , 'getItems ' ])
365
+ ->getMock ();
366
+ $ addressCollection ->expects ($ this ->atLeastOnce ())->method ('setCustomerFilter ' )->willReturnSelf ();
367
+ $ addressCollection ->expects ($ this ->atLeastOnce ())->method ('addAttributeToSelect ' )->willReturnSelf ();
368
+ $ addressCollection ->expects ($ this ->atLeastOnce ())->method ('getIterator ' )
369
+ ->willReturn ($ addresses );
370
+ $ addressCollection ->expects ($ this ->atLeastOnce ())->method ('getItems ' )
371
+ ->willReturn ($ addresses );
372
+ $ this ->addressesFactory ->expects ($ this ->atLeastOnce ())->method ('create ' )->willReturn ($ addressCollection );
373
+ $ customerDataObject = $ this ->getMockForAbstractClass (\Magento \Customer \Api \Data \CustomerInterface::class);
374
+ $ this ->customerDataFactory ->expects ($ this ->atLeastOnce ())->method ('create ' )->willReturn ($ customerDataObject );
375
+ $ this ->dataObjectHelper ->expects ($ this ->atLeastOnce ())->method ('populateWithArray ' )
376
+ ->with ($ customerDataObject , $ this ->_model ->getData (), \Magento \Customer \Api \Data \CustomerInterface::class)
377
+ ->willReturnSelf ();
378
+ $ customerDataObject ->expects ($ this ->atLeastOnce ())->method ('setAddresses ' )
379
+ ->with ([$ addressDataModel , $ addressDataModel ])
380
+ ->willReturnSelf ();
381
+ $ customerDataObject ->expects ($ this ->atLeastOnce ())->method ('setId ' )->with ($ customerId )->willReturnSelf ();
382
+ $ this ->_model ->getDataModel ();
383
+ $ this ->assertEquals ($ customerDataObject , $ this ->_model ->getDataModel ());
384
+ }
313
385
}
0 commit comments