1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\SalesBundle\Tests\Functional\ImportExport\Strategy; |
4
|
|
|
|
5
|
|
|
use Akeneo\Bundle\BatchBundle\Entity\JobExecution; |
6
|
|
|
use Akeneo\Bundle\BatchBundle\Entity\StepExecution; |
7
|
|
|
|
8
|
|
|
use Oro\Bundle\AddressBundle\Entity\Address; |
9
|
|
|
use Oro\Bundle\AddressBundle\Entity\Country; |
10
|
|
|
use Oro\Bundle\ImportExportBundle\Context\StepExecutionProxyContext; |
11
|
|
|
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase; |
12
|
|
|
|
13
|
|
|
use OroCRM\Bundle\AccountBundle\Entity\Account; |
14
|
|
|
use OroCRM\Bundle\ChannelBundle\Entity\Channel; |
15
|
|
|
use OroCRM\Bundle\SalesBundle\Entity\B2bCustomer; |
16
|
|
|
use OroCRM\Bundle\SalesBundle\ImportExport\Strategy\B2bConfigurableAddOrReplaceStrategy; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @dbIsolationPerTest |
20
|
|
|
*/ |
21
|
|
|
class B2bConfigurableAddOrReplaceStrategyTest extends WebTestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var B2bConfigurableAddOrReplaceStrategy |
25
|
|
|
*/ |
26
|
|
|
protected $strategy; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var StepExecutionProxyContext |
30
|
|
|
*/ |
31
|
|
|
protected $context; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var StepExecution |
35
|
|
|
*/ |
36
|
|
|
protected $stepExecution; |
37
|
|
|
|
38
|
|
|
protected function setUp() |
39
|
|
|
{ |
40
|
|
|
$this->initClient( |
41
|
|
|
['debug' => false], |
42
|
|
|
array_merge($this->generateBasicAuthHeader(), array('HTTP_X-CSRF-Header' => 1)) |
43
|
|
|
); |
44
|
|
|
$this->client->useHashNavigation(true); |
45
|
|
|
|
46
|
|
|
$this->loadFixtures( |
47
|
|
|
[ |
48
|
|
|
'OroCRM\Bundle\SalesBundle\Tests\Functional\Fixture\LoadSalesBundleFixtures' |
49
|
|
|
] |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$container = $this->getContainer(); |
53
|
|
|
|
54
|
|
|
$this->strategy = new B2bConfigurableAddOrReplaceStrategy( |
55
|
|
|
$container->get('event_dispatcher'), |
56
|
|
|
$container->get('oro_importexport.strategy.import.helper'), |
57
|
|
|
$container->get('oro_importexport.field.field_helper'), |
58
|
|
|
$container->get('oro_importexport.field.database_helper'), |
59
|
|
|
$container->get('oro_entity.entity_class_name_provider'), |
60
|
|
|
$container->get('translator'), |
61
|
|
|
$container->get('oro_importexport.strategy.new_entities_helper'), |
62
|
|
|
$container->get('oro_entity.doctrine_helper') |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$this->stepExecution = new StepExecution('step', new JobExecution()); |
66
|
|
|
$this->context = new StepExecutionProxyContext($this->stepExecution); |
67
|
|
|
$this->strategy->setImportExportContext($this->context); |
68
|
|
|
$this->strategy->setEntityName( |
69
|
|
|
$container->getParameter('orocrm_sales.b2bcustomer.entity.class') |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function tearDown() |
74
|
|
|
{ |
75
|
|
|
unset($this->strategy, $this->context, $this->stepExecution); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testUpdateAddress() |
79
|
|
|
{ |
80
|
|
|
$address = new Address(); |
81
|
|
|
$address->setStreet('Test1'); |
82
|
|
|
$address->setCity('test_city'); |
83
|
|
|
$country = new Country('US'); |
84
|
|
|
$address->setCountry($country); |
85
|
|
|
|
86
|
|
|
$account = new Account(); |
87
|
|
|
$account->setName('some account name'); |
88
|
|
|
|
89
|
|
|
$channel = new Channel(); |
90
|
|
|
$channel->setName('b2b Channel'); |
91
|
|
|
|
92
|
|
|
$newB2bCustomer = new B2bCustomer(); |
93
|
|
|
$newB2bCustomer->setName('b2bCustomer name'); |
94
|
|
|
$newB2bCustomer->setShippingAddress($address); |
95
|
|
|
$newB2bCustomer->setBillingAddress($address); |
96
|
|
|
$newB2bCustomer->setAccount($account); |
97
|
|
|
$newB2bCustomer->setDataChannel($channel); |
98
|
|
|
|
99
|
|
|
/** @var B2bCustomer $existedCustomer */ |
100
|
|
|
$existedCustomer = $this->getReference('default_b2bcustomer'); |
101
|
|
|
self::assertEquals('1215 Caldwell Road', $existedCustomer->getShippingAddress()->getStreet()); |
102
|
|
|
$this->strategy->process($newB2bCustomer); |
103
|
|
|
self::assertEquals('Test1', $existedCustomer->getShippingAddress()->getStreet()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function testUpdateCustomerByEmptyAddress() |
107
|
|
|
{ |
108
|
|
|
$account = new Account(); |
109
|
|
|
$account->setName('some account name'); |
110
|
|
|
|
111
|
|
|
$channel = new Channel(); |
112
|
|
|
$channel->setName('b2b Channel'); |
113
|
|
|
|
114
|
|
|
$newB2bCustomer = new B2bCustomer(); |
115
|
|
|
$newB2bCustomer->setName('b2bCustomer name'); |
116
|
|
|
$newB2bCustomer->setAccount($account); |
117
|
|
|
$newB2bCustomer->setDataChannel($channel); |
118
|
|
|
|
119
|
|
|
/** @var B2bCustomer $existedCustomer */ |
120
|
|
|
$existedCustomer = $this->getReference('default_b2bcustomer'); |
121
|
|
|
self::assertEquals('1215 Caldwell Road', $existedCustomer->getShippingAddress()->getStreet()); |
122
|
|
|
$this->strategy->process($newB2bCustomer); |
123
|
|
|
self::assertNull($existedCustomer->getShippingAddress()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function testUpdateRegionText() |
127
|
|
|
{ |
128
|
|
|
$address = new Address(); |
129
|
|
|
$address->setStreet('1215 Caldwell Road'); |
130
|
|
|
$address->setCity('Rochester'); |
131
|
|
|
$address->setPostalCode('14608'); |
132
|
|
|
$country = new Country('US'); |
133
|
|
|
$address->setCountry($country); |
134
|
|
|
$address->setRegionText('test'); |
135
|
|
|
|
136
|
|
|
$account = new Account(); |
137
|
|
|
$account->setName('some account name'); |
138
|
|
|
|
139
|
|
|
$channel = new Channel(); |
140
|
|
|
$channel->setName('b2b Channel'); |
141
|
|
|
|
142
|
|
|
$newB2bCustomer = new B2bCustomer(); |
143
|
|
|
$newB2bCustomer->setName('b2bCustomer name'); |
144
|
|
|
$newB2bCustomer->setAccount($account); |
145
|
|
|
$newB2bCustomer->setDataChannel($channel); |
146
|
|
|
$newB2bCustomer->setBillingAddress($address); |
147
|
|
|
$newB2bCustomer->setShippingAddress($address); |
148
|
|
|
|
149
|
|
|
$this->context->setValue('itemData', [ |
150
|
|
|
'shippingAddress' => ['regionText' => 'test'], |
151
|
|
|
'billingAddress' => ['regionText' => 'test'] |
152
|
|
|
]); |
153
|
|
|
|
154
|
|
|
/** @var B2bCustomer $existedCustomer */ |
155
|
|
|
$existedCustomer = $this->getReference('default_b2bcustomer'); |
156
|
|
|
self::assertEquals('Arizona1', $existedCustomer->getShippingAddress()->getRegionText()); |
157
|
|
|
$this->strategy->process($newB2bCustomer); |
158
|
|
|
self::assertEquals('test', $existedCustomer->getShippingAddress()->getRegionText()); |
159
|
|
|
self::assertEquals('test', $existedCustomer->getBillingAddress()->getRegionText()); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function testConvertRegionTextToRegion() |
163
|
|
|
{ |
164
|
|
|
$country = new Country('US'); |
165
|
|
|
|
166
|
|
|
$address = new Address(); |
167
|
|
|
$address->setStreet('1215 Caldwell Road'); |
168
|
|
|
$address->setCity('Rochester'); |
169
|
|
|
$address->setPostalCode('14608'); |
170
|
|
|
$address->setCountry($country); |
171
|
|
|
$address->setRegionText('Arizona'); |
172
|
|
|
|
173
|
|
|
$account = new Account(); |
174
|
|
|
$account->setName('some account name'); |
175
|
|
|
|
176
|
|
|
$channel = new Channel(); |
177
|
|
|
$channel->setName('b2b Channel'); |
178
|
|
|
|
179
|
|
|
$newB2bCustomer = new B2bCustomer(); |
180
|
|
|
$newB2bCustomer->setName('b2bCustomer name'); |
181
|
|
|
$newB2bCustomer->setAccount($account); |
182
|
|
|
$newB2bCustomer->setDataChannel($channel); |
183
|
|
|
$newB2bCustomer->setBillingAddress($address); |
184
|
|
|
$newB2bCustomer->setShippingAddress($address); |
185
|
|
|
|
186
|
|
|
$this->context->setValue('itemData', [ |
187
|
|
|
'shippingAddress' => ['regionText' => 'Arizona'], |
188
|
|
|
'billingAddress' => ['regionText' => 'Arizona'] |
189
|
|
|
]); |
190
|
|
|
|
191
|
|
|
/** @var B2bCustomer $existedCustomer */ |
192
|
|
|
$existedCustomer = $this->getReference('default_b2bcustomer'); |
193
|
|
|
self::assertEquals('Arizona1', $existedCustomer->getShippingAddress()->getRegionText()); |
194
|
|
|
self::assertNull($existedCustomer->getShippingAddress()->getRegion()); |
195
|
|
|
$this->strategy->process($newB2bCustomer); |
196
|
|
|
self::assertNull($existedCustomer->getShippingAddress()->getRegionText()); |
197
|
|
|
self::assertNull($existedCustomer->getBillingAddress()->getRegionText()); |
198
|
|
|
|
199
|
|
|
$exceptedRegion = $this->getContainer()->get('doctrine')->getRepository('OroAddressBundle:Region') |
200
|
|
|
->findOneBy( |
201
|
|
|
[ |
202
|
|
|
'country' => $country, |
203
|
|
|
'name' => 'Arizona' |
204
|
|
|
] |
205
|
|
|
); |
206
|
|
|
|
207
|
|
|
self::assertEquals($exceptedRegion, $existedCustomer->getShippingAddress()->getRegion()); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function testNewB2bCustomerWithRegionText() |
211
|
|
|
{ |
212
|
|
|
$country = new Country('US'); |
213
|
|
|
|
214
|
|
|
$address = new Address(); |
215
|
|
|
$address->setStreet('1215 Caldwell Road'); |
216
|
|
|
$address->setCity('Rochester'); |
217
|
|
|
$address->setPostalCode('14608'); |
218
|
|
|
$address->setCountry($country); |
219
|
|
|
$address->setRegionText('Arizona'); |
220
|
|
|
|
221
|
|
|
$account = new Account(); |
222
|
|
|
$account->setName('some account name 1'); |
223
|
|
|
|
224
|
|
|
$channel = new Channel(); |
225
|
|
|
$channel->setName('b2b Channel'); |
226
|
|
|
|
227
|
|
|
$newB2bCustomer = new B2bCustomer(); |
228
|
|
|
$newB2bCustomer->setName('b2bCustomer name1'); |
229
|
|
|
$newB2bCustomer->setAccount($account); |
230
|
|
|
$newB2bCustomer->setDataChannel($channel); |
231
|
|
|
$newB2bCustomer->setBillingAddress($address); |
232
|
|
|
$newB2bCustomer->setShippingAddress($address); |
233
|
|
|
|
234
|
|
|
$this->context->setValue('itemData', [ |
235
|
|
|
'shippingAddress' => ['regionText' => 'Arizona'], |
236
|
|
|
'billingAddress' => ['regionText' => 'Arizona'] |
237
|
|
|
]); |
238
|
|
|
|
239
|
|
|
/** @var B2bCustomer $existedCustomer */ |
240
|
|
|
$entity = $this->strategy->process($newB2bCustomer); |
241
|
|
|
self::assertNull($entity->getShippingAddress()->getRegionText()); |
242
|
|
|
self::assertNull($entity->getBillingAddress()->getRegionText()); |
243
|
|
|
|
244
|
|
|
$exceptedRegion = $this->getContainer()->get('doctrine')->getRepository('OroAddressBundle:Region') |
245
|
|
|
->findOneBy( |
246
|
|
|
[ |
247
|
|
|
'country' => $country, |
248
|
|
|
'name' => 'Arizona' |
249
|
|
|
] |
250
|
|
|
); |
251
|
|
|
|
252
|
|
|
self::assertEquals($exceptedRegion, $entity->getShippingAddress()->getRegion()); |
253
|
|
|
self::assertNull($entity->getId()); |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
|