1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\MagentoBundle\Tests\Functional\Command; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase; |
6
|
|
|
|
7
|
|
|
use OroCRM\Bundle\MagentoBundle\Entity\Customer; |
8
|
|
|
use OroCRM\Bundle\MagentoBundle\Tests\Functional\Fixture\CopyCustomerAddressToContact\LoadMagentoChannel; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @dbIsolationPerTest |
12
|
|
|
*/ |
13
|
|
|
class CopyCustomerAddressesToContactCommandTest extends WebTestCase |
14
|
|
|
{ |
15
|
|
|
public function setUp() |
16
|
|
|
{ |
17
|
|
|
$this->initClient(); |
18
|
|
|
$this->loadFixtures([LoadMagentoChannel::class]); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testCommand() |
22
|
|
|
{ |
23
|
|
|
$entityManager = $this->getContainer()->get('doctrine'); |
24
|
|
|
$repo = $entityManager->getRepository('OroCRM\Bundle\MagentoBundle\Entity\Customer'); |
25
|
|
|
$customers = $repo->findAll(); |
26
|
|
|
/** @var Customer $customer */ |
27
|
|
|
foreach ($customers as $customer) { |
28
|
|
|
self::assertEquals(0, $customer->getContact()->getAddresses()->count()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$result = $this->runCommand('oro:magento:copy-data-to-contact:addresses', ['--batch-size=2']); |
32
|
|
|
|
33
|
|
|
$customers = $repo->findAll(); |
34
|
|
|
/** @var Customer $customer */ |
35
|
|
|
foreach ($customers as $customer) { |
36
|
|
|
self::assertEquals(1, $customer->getContact()->getAddresses()->count()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$this->assertContains('Executing command started.', $result); |
40
|
|
|
$this->assertContains('Executing command finished.', $result); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function testConvertAddressForCustomerById() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$testCustomer = $this->getReference('customer_1'); |
46
|
|
|
$id = $testCustomer->getId(); |
47
|
|
|
|
48
|
|
|
$entityManager = $this->getContainer()->get('doctrine'); |
49
|
|
|
$repo = $entityManager->getRepository('OroCRM\Bundle\MagentoBundle\Entity\Customer'); |
50
|
|
|
/** @var Customer $customer */ |
51
|
|
|
$customer = $repo->find($id); |
52
|
|
|
self::assertEquals(0, $customer->getContact()->getAddresses()->count()); |
53
|
|
|
|
54
|
|
|
$result = $this->runCommand('oro:magento:copy-data-to-contact:addresses', ['--id=' . $id]); |
55
|
|
|
|
56
|
|
|
/** @var Customer $customer */ |
57
|
|
|
$customer = $repo->find($id); |
58
|
|
|
self::assertEquals(1, $customer->getContact()->getAddresses()->count()); |
59
|
|
|
|
60
|
|
|
$this->assertContains('Executing command started.', $result); |
61
|
|
|
$this->assertContains('Executing command finished.', $result); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testConvertAddressForCustomerByIds() |
65
|
|
|
{ |
66
|
|
|
$testCustomerId1 = $this->getReference('customer_1')->getId(); |
67
|
|
|
$testCustomerId2 = $this->getReference('customer_2')->getId(); |
68
|
|
|
|
69
|
|
|
$entityManager = $this->getContainer()->get('doctrine'); |
70
|
|
|
$repo = $entityManager->getRepository('OroCRM\Bundle\MagentoBundle\Entity\Customer'); |
71
|
|
|
$customers = $repo->findBy(['id' => [$testCustomerId1, $testCustomerId2]]); |
72
|
|
|
/** @var Customer $customer */ |
73
|
|
|
foreach ($customers as $customer) { |
74
|
|
|
self::assertEquals(0, $customer->getContact()->getAddresses()->count()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$result = $this->runCommand('oro:magento:copy-data-to-contact:addresses', [ |
78
|
|
|
'--id=' . $testCustomerId1, |
79
|
|
|
'--id=' . $testCustomerId2 |
80
|
|
|
]); |
81
|
|
|
|
82
|
|
|
$customers = $repo->findBy(['id' => [$testCustomerId1, $testCustomerId2]]); |
83
|
|
|
/** @var Customer $customer */ |
84
|
|
|
foreach ($customers as $customer) { |
85
|
|
|
self::assertEquals(1, $customer->getContact()->getAddresses()->count()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$this->assertContains('Executing command started.', $result); |
89
|
|
|
$this->assertContains('Executing command finished.', $result); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testConvertAddressForCustomerByIntegrationId() |
93
|
|
|
{ |
94
|
|
|
$integrationId = $this->getReference('integration')->getId(); |
95
|
|
|
$entityManager = $this->getContainer()->get('doctrine'); |
96
|
|
|
$repo = $entityManager->getRepository('OroCRM\Bundle\MagentoBundle\Entity\Customer'); |
97
|
|
|
$customers = $repo->findBy(['channel' => $integrationId]); |
98
|
|
|
/** @var Customer $customer */ |
99
|
|
|
foreach ($customers as $customer) { |
100
|
|
|
self::assertEquals(0, $customer->getContact()->getAddresses()->count()); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$result = $this->runCommand('oro:magento:copy-data-to-contact:addresses', [ |
104
|
|
|
'--integration-id=' . $integrationId, |
105
|
|
|
'--batch-size=2' |
106
|
|
|
]); |
107
|
|
|
|
108
|
|
|
$customers = $repo->findBy(['channel' => $integrationId]); |
109
|
|
|
/** @var Customer $customer */ |
110
|
|
|
foreach ($customers as $customer) { |
111
|
|
|
self::assertEquals(1, $customer->getContact()->getAddresses()->count()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$this->assertContains('Executing command started.', $result); |
115
|
|
|
$this->assertContains('Executing command finished.', $result); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
View Code Duplication |
public function testConvertAddressForCustomerByIdAndAccountHasAddress() |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
$testCustomerId1 = $this->getReference('customer_1')->getId(); |
121
|
|
|
|
122
|
|
|
$entityManager = $this->getContainer()->get('doctrine'); |
123
|
|
|
$repo = $entityManager->getRepository('OroCRM\Bundle\MagentoBundle\Entity\Customer'); |
124
|
|
|
/** @var Customer $customer */ |
125
|
|
|
$customer = $repo->find($testCustomerId1); |
126
|
|
|
self::assertEquals(0, $customer->getContact()->getAddresses()->count()); |
127
|
|
|
|
128
|
|
|
for ($i = 0; $i < 2; $i++) { |
129
|
|
|
$result = $this->runCommand('oro:magento:copy-data-to-contact:addresses', [ |
130
|
|
|
'--id=' . $testCustomerId1 |
131
|
|
|
]); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** @var Customer $customer */ |
135
|
|
|
$customer = $repo->find($testCustomerId1); |
136
|
|
|
self::assertEquals(1, $customer->getContact()->getAddresses()->count()); |
137
|
|
|
|
138
|
|
|
$this->assertContains('Executing command started.', $result); |
|
|
|
|
139
|
|
|
$this->assertContains('Executing command finished.', $result); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.