1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\MagentoBundle\Tests\Functional\Controller; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
6
|
|
|
|
7
|
|
|
use Oro\Bundle\ImportExportBundle\Job\JobExecutor; |
8
|
|
|
use Oro\Bundle\ImportExportBundle\Job\JobResult; |
9
|
|
|
use OroCRM\Bundle\MagentoBundle\Entity\NewsletterSubscriber; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @dbIsolation |
13
|
|
|
*/ |
14
|
|
|
class NewsletterSubscriberControllerTest extends AbstractController |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var NewsletterSubscriber |
18
|
|
|
*/ |
19
|
|
|
protected $subscriber; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var JobExecutor |
23
|
|
|
*/ |
24
|
|
|
protected $baseJobExecutor; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var bool |
28
|
|
|
*/ |
29
|
|
|
protected $isRealGridRequest = true; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected function getMainEntityId() |
35
|
|
|
{ |
36
|
|
|
return $this->subscriber->getid(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function setUp() |
40
|
|
|
{ |
41
|
|
|
$this->initClient(['debug' => false], $this->generateBasicAuthHeader(), true); |
42
|
|
|
|
43
|
|
|
$this->loadFixtures( |
44
|
|
|
['OroCRM\Bundle\MagentoBundle\Tests\Functional\Fixture\LoadNewsletterSubscriberData'], |
45
|
|
|
true |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->subscriber = $this->getReference('newsletter_subscriber'); |
49
|
|
|
|
50
|
|
|
$this->baseJobExecutor = $this->getContainer()->get('oro_importexport.job_executor'); |
51
|
|
|
|
52
|
|
|
$jobExecutor = $this->getMockBuilder('Oro\Bundle\ImportExportBundle\Job\JobExecutor') |
53
|
|
|
->disableOriginalConstructor() |
54
|
|
|
->getMock(); |
55
|
|
|
|
56
|
|
|
$jobResult = new JobResult(); |
57
|
|
|
$jobResult->setSuccessful(true); |
58
|
|
|
|
59
|
|
|
$jobExecutor->expects($this->any()) |
60
|
|
|
->method('executeJob') |
61
|
|
|
->willReturn($jobResult); |
62
|
|
|
|
63
|
|
|
$this->getContainer()->set('oro_importexport.job_executor', $jobExecutor); |
64
|
|
|
|
65
|
|
|
$this->getContainer()->get('akeneo_batch.job_repository')->getJobManager()->beginTransaction(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
protected function tearDown() |
69
|
|
|
{ |
70
|
|
|
// clear DB from separate connection, close to avoid connection limit and memory leak |
71
|
|
|
$manager = $this->getContainer()->get('akeneo_batch.job_repository')->getJobManager(); |
72
|
|
|
$manager->rollback(); |
73
|
|
|
$manager->getConnection()->close(); |
74
|
|
|
|
75
|
|
|
$this->getContainer()->set('oro_importexport.job_executor', $this->baseJobExecutor); |
76
|
|
|
unset($this->transport, $this->baseJobExecutor); |
77
|
|
|
|
78
|
|
|
parent::tearDown(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testView() |
82
|
|
|
{ |
83
|
|
|
$this->client->request( |
84
|
|
|
'GET', |
85
|
|
|
$this->getUrl('orocrm_magento_newsletter_subscriber_view', ['id' => $this->getMainEntityId()]) |
86
|
|
|
); |
87
|
|
|
$result = $this->client->getResponse(); |
88
|
|
|
$this->assertHtmlResponseStatusCodeEquals($result, 200); |
89
|
|
|
$this->assertContains('General Information', $result->getContent()); |
90
|
|
|
$this->assertContains($this->subscriber->getCustomer()->getFirstName(), $result->getContent()); |
91
|
|
|
$this->assertContains($this->subscriber->getCustomer()->getLastName(), $result->getContent()); |
92
|
|
|
$this->assertContains($this->subscriber->getEmail(), $result->getContent()); |
93
|
|
|
$this->assertContains($this->subscriber->getStatus()->getName(), $result->getContent()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function gridProvider() |
100
|
|
|
{ |
101
|
|
|
return [ |
102
|
|
|
'default' => [ |
103
|
|
|
[ |
104
|
|
|
'gridParameters' => [ |
105
|
|
|
'gridName' => 'magento-newsletter-subscriber-grid', |
106
|
|
|
'magento-newsletter-subscriber-grid[_sort_by][customerName]' => 'DESC', |
107
|
|
|
], |
108
|
|
|
'gridFilters' => [], |
109
|
|
|
'assert' => [ |
110
|
|
|
'channelName' => 'Magento channel', |
111
|
|
|
'email' => '[email protected]', |
112
|
|
|
'status' => 'Subscribed', |
113
|
|
|
'customerName' => 'John Doe', |
114
|
|
|
'customerEmail' => '[email protected]' |
115
|
|
|
], |
116
|
|
|
'expectedResultCount' => 3 |
117
|
|
|
] |
118
|
|
|
], |
119
|
|
|
'filters' => [ |
120
|
|
|
[ |
121
|
|
|
'gridParameters' => ['gridName' => 'magento-newsletter-subscriber-grid'], |
122
|
|
|
'gridFilters' => [ |
123
|
|
|
'magento-newsletter-subscriber-grid[_filter][status][value]' => '1' |
124
|
|
|
], |
125
|
|
|
'assert' => [ |
126
|
|
|
'channelName' => 'Magento channel', |
127
|
|
|
'email' => '[email protected]', |
128
|
|
|
'status' => 'Subscribed', |
129
|
|
|
'customerName' => 'John Doe', |
130
|
|
|
'customerEmail' => '[email protected]' |
131
|
|
|
], |
132
|
|
|
'expectedResultCount' => 3 |
133
|
|
|
] |
134
|
|
|
], |
135
|
|
|
'no result' => [ |
136
|
|
|
[ |
137
|
|
|
'gridParameters' => ['gridName' => 'magento-newsletter-subscriber-grid'], |
138
|
|
|
'gridFilters' => [ |
139
|
|
|
'magento-newsletter-subscriber-grid[_filter][email][value]' => '[email protected]' |
140
|
|
|
], |
141
|
|
|
'assert' => [], |
142
|
|
|
'expectedResultCount' => 0 |
143
|
|
|
] |
144
|
|
|
] |
145
|
|
|
]; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @depends testView |
150
|
|
|
*/ |
151
|
|
View Code Duplication |
public function testUnsubscribe() |
|
|
|
|
152
|
|
|
{ |
153
|
|
|
$this->client->request( |
154
|
|
|
'GET', |
155
|
|
|
$this->getUrl('orocrm_magento_newsletter_subscriber_unsubscribe', ['id' => $this->getMainEntityId()]) |
156
|
|
|
); |
157
|
|
|
|
158
|
|
|
$result = $this->getJsonResponseContent($this->client->getResponse(), 200); |
|
|
|
|
159
|
|
|
$this->assertTrue($result['successful']); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @depends testUnsubscribe |
164
|
|
|
*/ |
165
|
|
View Code Duplication |
public function testSubscribe() |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
$this->client->request( |
168
|
|
|
'GET', |
169
|
|
|
$this->getUrl('orocrm_magento_newsletter_subscriber_subscribe', ['id' => $this->getMainEntityId()]) |
170
|
|
|
); |
171
|
|
|
|
172
|
|
|
$result = $this->getJsonResponseContent($this->client->getResponse(), 200); |
|
|
|
|
173
|
|
|
$this->assertTrue($result['successful']); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
View Code Duplication |
public function testUnsubscribeByCustomer() |
|
|
|
|
177
|
|
|
{ |
178
|
|
|
$this->client->request( |
179
|
|
|
'GET', |
180
|
|
|
$this->getUrl( |
181
|
|
|
'orocrm_magento_newsletter_subscriber_unsubscribe_customer', |
182
|
|
|
['id' => $this->subscriber->getCustomer()->getId()] |
183
|
|
|
) |
184
|
|
|
); |
185
|
|
|
|
186
|
|
|
$result = $this->getJsonResponseContent($this->client->getResponse(), 200); |
|
|
|
|
187
|
|
|
$this->assertTrue($result['successful']); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
View Code Duplication |
public function testSubscribeByCustomer() |
|
|
|
|
191
|
|
|
{ |
192
|
|
|
$subscriber = $this->getReference('newsletter_subscriber3'); |
193
|
|
|
$this->client->request( |
194
|
|
|
'GET', |
195
|
|
|
$this->getUrl( |
196
|
|
|
'orocrm_magento_newsletter_subscriber_subscribe_customer', |
197
|
|
|
['id' => $subscriber->getCustomer()->getId()] |
198
|
|
|
) |
199
|
|
|
); |
200
|
|
|
$result = $this->getJsonResponseContent($this->client->getResponse(), 200); |
|
|
|
|
201
|
|
|
$this->assertTrue($result['successful']); |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
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.