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