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