|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\MagentoBundle\Tests\Functional\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase; |
|
6
|
|
|
|
|
7
|
|
|
use OroCRM\Bundle\ContactBundle\Entity\ContactAddress; |
|
8
|
|
|
use OroCRM\Bundle\MagentoBundle\Entity\Address; |
|
9
|
|
|
use OroCRM\Bundle\MagentoBundle\Entity\Customer; |
|
10
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Transport\MagentoTransportInterface; |
|
11
|
|
|
use OroCRM\Bundle\MagentoBundle\Tests\Functional\Fixture\ResyncMagentoCustomerAddresses\LoadMagentoChannel; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @dbIsolationPerTest |
|
15
|
|
|
*/ |
|
16
|
|
|
class ReSyncCustomersAddressCommandTest extends WebTestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var MagentoTransportInterface|\PHPUnit_Framework_MockObject_MockObject */ |
|
19
|
|
|
protected $transport; |
|
20
|
|
|
|
|
21
|
|
|
public function setUp() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->initClient(); |
|
24
|
|
|
$this->loadFixtures([LoadMagentoChannel::class]); |
|
25
|
|
|
|
|
26
|
|
|
$this->transport = $this |
|
27
|
|
|
->getMockBuilder('OroCRM\Bundle\MagentoBundle\Provider\Transport\MagentoTransportInterface') |
|
28
|
|
|
->getMock(); |
|
29
|
|
|
$this->getContainer()->set('orocrm_magento.transport.soap_transport', $this->transport); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @dataProvider provider |
|
34
|
|
|
* |
|
35
|
|
|
* @param $magentoCustomerAddresses |
|
36
|
|
|
* @param $customerIdentificator |
|
37
|
|
|
* @param $expectCountExistingAddress |
|
38
|
|
|
* @param $expectCountExistingContactAddress |
|
39
|
|
|
* @param $isPrimary |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testCommand( |
|
42
|
|
|
$magentoCustomerAddresses, |
|
43
|
|
|
$customerIdentificator, |
|
44
|
|
|
$expectCountExistingAddress, |
|
45
|
|
|
$expectCountExistingContactAddress, |
|
46
|
|
|
$isPrimary |
|
47
|
|
|
) { |
|
48
|
|
|
$entityManager = $this->getContainer()->get('doctrine'); |
|
49
|
|
|
$customer = $this->getReference($customerIdentificator); |
|
50
|
|
|
// init transport |
|
51
|
|
|
$this->transport->expects(self::any())->method('getCustomerAddresses') |
|
|
|
|
|
|
52
|
|
|
->willReturn($magentoCustomerAddresses); |
|
53
|
|
|
|
|
54
|
|
|
// loading existing addresses |
|
55
|
|
|
$addressRepository = $entityManager->getRepository('OroCRM\Bundle\MagentoBundle\Entity\Address'); |
|
56
|
|
|
$addresses = $addressRepository->findBy(['owner'=> $customer]); |
|
57
|
|
|
|
|
58
|
|
|
$contactAddressRepository = $entityManager->getRepository('OroCRM\Bundle\ContactBundle\Entity\ContactAddress'); |
|
59
|
|
|
$contactAddress = $contactAddressRepository->findBy(['owner'=>$customer->getContact()]); |
|
60
|
|
|
|
|
61
|
|
|
// Check count |
|
62
|
|
|
self::assertEquals($expectCountExistingContactAddress, count($contactAddress)); |
|
63
|
|
|
self::assertEquals($expectCountExistingAddress, count($addresses)); |
|
64
|
|
|
|
|
65
|
|
|
$integrationId = $this->getReference('integration')->getId(); |
|
66
|
|
|
|
|
67
|
|
|
$this->runCommand('oro:magento:re-sync-customer-address', [ |
|
68
|
|
|
'--integration-id=' . $integrationId, |
|
69
|
|
|
'--id='.$customer->getID(), |
|
70
|
|
|
'--batch-size=2' |
|
71
|
|
|
]); |
|
72
|
|
|
|
|
73
|
|
|
$addresses = $addressRepository->findBy(['owner'=> $customer]); |
|
74
|
|
|
self::assertEquals(1, count($addresses)); |
|
75
|
|
|
|
|
76
|
|
|
$address = current($addresses); |
|
77
|
|
|
$expectedData = reset($magentoCustomerAddresses); |
|
78
|
|
|
$expectedData['owner_id'] = $customer->getID(); |
|
79
|
|
|
$expectedData['integrationId'] = $integrationId; |
|
80
|
|
|
$expectedData['isPrimary'] = $isPrimary; |
|
81
|
|
|
|
|
82
|
|
|
$this->assertCustomerAddress($expectedData, current($addresses), $customer); |
|
83
|
|
|
$this->assertContactAddress($expectedData, $address->getContactAddress(), $customer); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param $expectedData |
|
88
|
|
|
* @param Address $address |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function assertCustomerAddress($expectedData, Address $address, Customer $customer) |
|
91
|
|
|
{ |
|
92
|
|
|
self::assertEquals($expectedData['firstname'], $address->getFirstName()); |
|
93
|
|
|
self::assertEquals($expectedData['lastname'], $address->getLastName()); |
|
94
|
|
|
self::assertEquals($expectedData['country_id'], $address->getCountry()->getIso2Code()); |
|
95
|
|
|
self::assertEquals($expectedData['company'], $address->getOrganization()); |
|
96
|
|
|
self::assertEquals($expectedData['city'], $address->getCity()); |
|
97
|
|
|
self::assertEquals($expectedData['postcode'], $address->getPostalCode()); |
|
98
|
|
|
self::assertEquals($expectedData['street'], $address->getStreet()); |
|
99
|
|
|
self::assertEquals($expectedData['telephone'], $address->getPhone()); |
|
100
|
|
|
self::assertEquals($expectedData['region'], $address->getRegionName()); |
|
101
|
|
|
self::assertEquals($expectedData['owner_id'], $address->getOwner()->getId()); |
|
102
|
|
|
self::assertEquals($expectedData['integrationId'], $address->getChannel()->getId()); |
|
103
|
|
|
self::assertEquals($expectedData['region'], $address->getRegionText()); |
|
104
|
|
|
self::assertEquals($expectedData['isPrimary'], $address->isPrimary()); |
|
105
|
|
|
self::assertEquals($customer->getId(), $address->getOwner()->getId()); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param $expectedData |
|
110
|
|
|
* @param ContactAddress $contactAddress |
|
111
|
|
|
* @param Customer $customer |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function assertContactAddress($expectedData, ContactAddress $contactAddress, Customer $customer) |
|
114
|
|
|
{ |
|
115
|
|
|
self::assertEquals($expectedData['firstname'], $contactAddress->getFirstName()); |
|
116
|
|
|
self::assertEquals($expectedData['lastname'], $contactAddress->getLastName()); |
|
117
|
|
|
self::assertEquals($expectedData['country_id'], $contactAddress->getCountry()->getIso2Code()); |
|
118
|
|
|
self::assertEquals($expectedData['company'], $contactAddress->getOrganization()); |
|
119
|
|
|
self::assertEquals($expectedData['city'], $contactAddress->getCity()); |
|
120
|
|
|
self::assertEquals($expectedData['postcode'], $contactAddress->getPostalCode()); |
|
121
|
|
|
self::assertEquals($expectedData['street'], $contactAddress->getStreet()); |
|
122
|
|
|
self::assertEquals($expectedData['region'], $contactAddress->getRegionName()); |
|
123
|
|
|
self::assertEquals($expectedData['isPrimary'], $contactAddress->isPrimary()); |
|
124
|
|
|
self::assertEquals($customer->getContact()->getId(), $contactAddress->getOwner()->getId()); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return array |
|
129
|
|
|
*/ |
|
130
|
|
|
public function provider() |
|
131
|
|
|
{ |
|
132
|
|
|
return [ |
|
133
|
|
|
'testCommandWithoutAddressAndWithoutContactAddress' => [ |
|
134
|
|
|
'$magentoCustomerAddresses' => $this->getMagentoCustomerAddresses(), |
|
135
|
|
|
'customer_without_address_and_contactAddress' => 'customer_without_address_and_contactAddress', |
|
136
|
|
|
'$expectCountExistingAddress' => 0, |
|
137
|
|
|
'$expectCountExistingContactAddress' => 0, |
|
138
|
|
|
'$isPrimary' => true // there is primary true because new address will be created |
|
139
|
|
|
], |
|
140
|
|
|
'testCommandWithAddressAndWithoutContactAddress' => [ |
|
141
|
|
|
'$magentoCustomerAddresses' => $this->getMagentoCustomerAddressesUpdated(), |
|
142
|
|
|
'customer_without_contactAddress' =>'customer_without_contactAddress', |
|
143
|
|
|
'$expectCountExistingAddress' => 1, |
|
144
|
|
|
'$expectCountExistingContactAddress' => 0, |
|
145
|
|
|
'$isPrimary' => true // there is primary true because existing address is primary |
|
146
|
|
|
], |
|
147
|
|
|
'testCommandWithAddressAndWithContactAddress' => [ |
|
148
|
|
|
'$magentoCustomerAddresses' => $this->getMagentoCustomerAddressesUpdated(), |
|
149
|
|
|
'customer_with_address_and_contactAddress' => 'customer_with_address_and_contactAddress', |
|
150
|
|
|
'$expectCountExistingAddress' => 1, |
|
151
|
|
|
'$expectCountExistingContactAddress' => 1, |
|
152
|
|
|
'$isPrimary' => true // there is primary true because existing address is primary |
|
153
|
|
|
] |
|
154
|
|
|
]; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return array |
|
159
|
|
|
*/ |
|
160
|
|
View Code Duplication |
protected function getMagentoCustomerAddressesUpdated() |
|
|
|
|
|
|
161
|
|
|
{ |
|
162
|
|
|
return [ |
|
163
|
|
|
[ |
|
164
|
|
|
'customer_address_id' => 1, |
|
165
|
|
|
'created_at' => (new \DateTime())->format('Y-m-d H:i'), |
|
166
|
|
|
'updated_at' => (new \DateTime())->format('Y-m-d H:i'), |
|
167
|
|
|
'city' => 'LA1', |
|
168
|
|
|
'company' => 'Oro1', |
|
169
|
|
|
'country_id' => 'US', |
|
170
|
|
|
'firstname' => 'John1', |
|
171
|
|
|
'lastname' => 'Smith1', |
|
172
|
|
|
'postcode' => '900461', |
|
173
|
|
|
'region' => 'California1', |
|
174
|
|
|
'region_id' => 13, |
|
175
|
|
|
'street' => 'Melrose Ave.1', |
|
176
|
|
|
'telephone' => '0011', |
|
177
|
|
|
'is_default_billing' => true, |
|
178
|
|
|
'is_default_shipping' => true, |
|
179
|
|
|
'attributes' => [ |
|
180
|
|
|
[ |
|
181
|
|
|
'key' => 'parent_id', |
|
182
|
|
|
'value' => '194' |
|
183
|
|
|
], |
|
184
|
|
|
[ |
|
185
|
|
|
'key' => 'entity_type_id', |
|
186
|
|
|
'value' => '2' |
|
187
|
|
|
], |
|
188
|
|
|
[ |
|
189
|
|
|
'key' => 'attribute_set_id', |
|
190
|
|
|
'value' => '0' |
|
191
|
|
|
], |
|
192
|
|
|
[ |
|
193
|
|
|
'key' => 'is_active', |
|
194
|
|
|
'value' => '1' |
|
195
|
|
|
], |
|
196
|
|
|
[ |
|
197
|
|
|
'key' => 'customer_id', |
|
198
|
|
|
'value' => '194' |
|
199
|
|
|
] |
|
200
|
|
|
] |
|
201
|
|
|
] |
|
202
|
|
|
]; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @return array |
|
207
|
|
|
*/ |
|
208
|
|
View Code Duplication |
protected function getMagentoCustomerAddresses() |
|
|
|
|
|
|
209
|
|
|
{ |
|
210
|
|
|
return [ |
|
211
|
|
|
[ |
|
212
|
|
|
'customer_address_id' => 1, |
|
213
|
|
|
'created_at' => (new \DateTime())->format('Y-m-d H:i'), |
|
214
|
|
|
'updated_at' => (new \DateTime())->format('Y-m-d H:i'), |
|
215
|
|
|
'city' => 'LA', |
|
216
|
|
|
'company' => 'Oro', |
|
217
|
|
|
'country_id' => 'US', |
|
218
|
|
|
'firstname' => 'John', |
|
219
|
|
|
'lastname' => 'Smith', |
|
220
|
|
|
'postcode' => '90046', |
|
221
|
|
|
'region' => 'California', |
|
222
|
|
|
'region_id' => 12, |
|
223
|
|
|
'street' => 'Melrose Ave.', |
|
224
|
|
|
'telephone' => '001', |
|
225
|
|
|
'is_default_billing' => true, |
|
226
|
|
|
'is_default_shipping' => true, |
|
227
|
|
|
'attributes' => [ |
|
228
|
|
|
[ |
|
229
|
|
|
'key'=>'parent_id', |
|
230
|
|
|
'value'=>'194' |
|
231
|
|
|
], |
|
232
|
|
|
[ |
|
233
|
|
|
'key'=>'entity_type_id', |
|
234
|
|
|
'value'=>'2' |
|
235
|
|
|
], |
|
236
|
|
|
[ |
|
237
|
|
|
'key'=>'attribute_set_id', |
|
238
|
|
|
'value'=>'0' |
|
239
|
|
|
], |
|
240
|
|
|
[ |
|
241
|
|
|
'key'=>'is_active', |
|
242
|
|
|
'value'=>'1' |
|
243
|
|
|
], |
|
244
|
|
|
[ |
|
245
|
|
|
'key'=>'customer_id', |
|
246
|
|
|
'value'=>'194' |
|
247
|
|
|
] |
|
248
|
|
|
] |
|
249
|
|
|
] |
|
250
|
|
|
]; |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: