1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\ChannelBundle\Tests\Functional\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Form\Form; |
6
|
|
|
|
7
|
|
|
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase; |
8
|
|
|
use Oro\Bundle\OrganizationBundle\Entity\Organization; |
9
|
|
|
use Oro\Bundle\OrganizationBundle\Migrations\Data\ORM\LoadOrganizationAndBusinessUnitData; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @outputBuffering enabled |
13
|
|
|
* @dbIsolation |
14
|
|
|
*/ |
15
|
|
|
class ChannelControllerTest extends WebTestCase |
16
|
|
|
{ |
17
|
|
|
const CHANNEL_NAME = 'some name'; |
18
|
|
|
const GRID_NAME = 'orocrm-channels-grid'; |
19
|
|
|
|
20
|
|
|
public function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->initClient( |
23
|
|
|
['debug' => false], |
24
|
|
|
array_merge($this->generateBasicAuthHeader(), ['HTTP_X-CSRF-Header' => 1]) |
25
|
|
|
); |
26
|
|
|
$this->client->useHashNavigation(true); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testCreateChannel() |
30
|
|
|
{ |
31
|
|
|
$crawler = $this->client->request('GET', $this->getUrl('orocrm_channel_create')); |
32
|
|
|
$name = 'Simple channel'; |
33
|
|
|
$form = $crawler->selectButton('Save and Close')->form(); |
34
|
|
|
$channelType = 'custom'; |
35
|
|
|
|
36
|
|
|
$form['orocrm_channel_form[name]'] = $name; |
37
|
|
|
$form['orocrm_channel_form[channelType]'] = $channelType; |
38
|
|
|
$form['orocrm_channel_form[entities]'] = json_encode( |
39
|
|
|
['OroCRM\Bundle\ChannelBundle\Entity\CustomerIdentity'] |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
$this->client->followRedirects(true); |
43
|
|
|
$crawler = $this->client->submit($form); |
|
|
|
|
44
|
|
|
$result = $this->client->getResponse(); |
45
|
|
|
|
46
|
|
|
$this->assertHtmlResponseStatusCodeEquals($result, 200); |
47
|
|
|
$this->assertContains('Channel saved', $crawler->html()); |
48
|
|
|
|
49
|
|
|
return compact('name', 'channelType'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @depends testCreateChannel |
54
|
|
|
*/ |
55
|
|
|
public function testView($data) |
56
|
|
|
{ |
57
|
|
|
$response = $this->client->requestGrid( |
58
|
|
|
self::GRID_NAME, |
59
|
|
|
[ |
60
|
|
|
self::GRID_NAME . '[_filter][name][value]' => $data['name'] |
61
|
|
|
] |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$gridResult = $this->getJsonResponseContent($response, 200); |
65
|
|
|
$gridResult = reset($gridResult['data']); |
66
|
|
|
$id = $gridResult['id']; |
67
|
|
|
|
68
|
|
|
$crawler = $this->client->request( |
69
|
|
|
'GET', |
70
|
|
|
$this->getUrl('orocrm_channel_view', ['id' => $id]) |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$result = $this->client->getResponse(); |
74
|
|
|
|
75
|
|
|
$this->assertHtmlResponseStatusCodeEquals($result, 200); |
76
|
|
|
$this->assertContains('Channels', $crawler->html()); |
77
|
|
|
$this->assertContains($data['name'], $crawler->html()); |
78
|
|
|
$this->assertContains($data['channelType'], $crawler->html()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param array $data |
83
|
|
|
* |
84
|
|
|
* @depends testCreateChannel |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
public function testUpdateChannel($data) |
89
|
|
|
{ |
90
|
|
|
$response = $this->client->requestGrid( |
91
|
|
|
self::GRID_NAME, |
92
|
|
|
[ |
93
|
|
|
self::GRID_NAME . '[_filter][name][value]' => $data['name'] |
94
|
|
|
] |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$result = $this->getJsonResponseContent($response, 200); |
98
|
|
|
$result = reset($result['data']); |
99
|
|
|
$channel = $result; |
100
|
|
|
|
101
|
|
|
$crawler = $this->client->request( |
102
|
|
|
'GET', |
103
|
|
|
$this->getUrl('orocrm_channel_update', ['id' => $result['id']]) |
104
|
|
|
); |
105
|
|
|
/** @var Form $form */ |
106
|
|
|
$form = $crawler->selectButton('Save and Close')->form(); |
107
|
|
|
$name = 'name' . $this->generateRandomString(); |
108
|
|
|
$form['orocrm_channel_form[name]'] = $name; |
109
|
|
|
|
110
|
|
|
$this->client->followRedirects(true); |
111
|
|
|
$crawler = $this->client->submit($form); |
|
|
|
|
112
|
|
|
|
113
|
|
|
$result = $this->client->getResponse(); |
114
|
|
|
$this->assertHtmlResponseStatusCodeEquals($result, 200, 'text/html; charset=UTF-8'); |
115
|
|
|
$this->assertContains('Channel saved', $crawler->html()); |
116
|
|
|
|
117
|
|
|
$channel['name'] = $name; |
118
|
|
|
|
119
|
|
|
return $channel; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @depends testUpdateChannel |
124
|
|
|
* |
125
|
|
|
* @param $channel |
126
|
|
|
*/ |
127
|
|
|
public function testChangeStatusChannel($channel) |
128
|
|
|
{ |
129
|
|
|
$crawler = $this->client->request( |
130
|
|
|
'GET', |
131
|
|
|
$this->getUrl('orocrm_channel_change_status', ['id' => $channel['id']]) |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
$this->client->getResponse(); |
|
|
|
|
135
|
|
|
$this->assertContains('Channel deactivated', $crawler->html()); |
136
|
|
|
|
137
|
|
|
return $channel; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @depends testChangeStatusChannel |
142
|
|
|
* |
143
|
|
|
* @param $channel |
144
|
|
|
*/ |
145
|
|
|
public function testDeleteChannel($channel) |
146
|
|
|
{ |
147
|
|
|
$this->client->request( |
148
|
|
|
'DELETE', |
149
|
|
|
$this->getUrl('orocrm_api_delete_channel', ['id' => $channel['id']]) |
150
|
|
|
); |
151
|
|
|
|
152
|
|
|
$response = $this->client->getResponse(); |
153
|
|
|
$this->assertResponseStatusCodeEquals($response, 204); |
154
|
|
|
|
155
|
|
|
$response = $this->client->requestGrid( |
156
|
|
|
self::GRID_NAME, |
157
|
|
|
[ |
158
|
|
|
self::GRID_NAME . '[_filter][name][value]' => $channel['name'] |
159
|
|
|
] |
160
|
|
|
); |
161
|
|
|
|
162
|
|
|
$result = $this->getJsonResponseContent($response, 200); |
163
|
|
|
|
164
|
|
|
$this->assertEmpty($result['data']); |
165
|
|
|
$this->assertEmpty($result['options']['totalRecords']); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @dataProvider gridProvider |
170
|
|
|
* |
171
|
|
|
* @param array $filters |
172
|
|
|
*/ |
173
|
|
|
public function testGrid($filters) |
174
|
|
|
{ |
175
|
|
|
$this->loadFixtures(['OroCRM\Bundle\ChannelBundle\Tests\Functional\Fixture\LoadChannel']); |
176
|
|
|
|
177
|
|
|
if (isset($filters['gridParameters']['id'])) { |
178
|
|
|
$gridId = $filters['gridParameters']['gridName'] . '[' . $filters['gridParameters']['id'] . ']'; |
179
|
|
|
|
180
|
|
|
$filters['gridParameters'][$gridId] = $this->getReference('default_channel')->getId(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
$response = $this->client->requestGrid($filters['gridParameters'], $filters['gridFilters']); |
184
|
|
|
$result = $this->getJsonResponseContent($response, 200); |
185
|
|
|
|
186
|
|
View Code Duplication |
foreach ($result['data'] as $row) { |
|
|
|
|
187
|
|
|
if ((isset($filters['gridParameters']['id']))) { |
188
|
|
|
foreach ($filters['assert'] as $fieldName => $value) { |
189
|
|
|
$this->assertEquals($value, $row[$fieldName]); |
190
|
|
|
} |
191
|
|
|
break; |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
$this->assertCount((int) $filters['expectedResultCount'], $result['data']); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function gridProvider() |
199
|
|
|
{ |
200
|
|
|
return [ |
201
|
|
|
'Channel grid' => [ |
202
|
|
|
[ |
203
|
|
|
'gridParameters' => [ |
204
|
|
|
'gridName' => self::GRID_NAME |
205
|
|
|
], |
206
|
|
|
'gridFilters' => [], |
207
|
|
|
'assert' => [ |
208
|
|
|
'name' => self::CHANNEL_NAME, |
209
|
|
|
], |
210
|
|
|
'expectedResultCount' => 1 |
211
|
|
|
], |
212
|
|
|
], |
213
|
|
|
'Channel grid without result' => [ |
214
|
|
|
[ |
215
|
|
|
'gridParameters' => [ |
216
|
|
|
'gridName' => self::GRID_NAME |
217
|
|
|
], |
218
|
|
|
'gridFilters' => [ |
219
|
|
|
self::GRID_NAME . '[_filter][name][value]' => 'Not found', |
220
|
|
|
], |
221
|
|
|
'assert' => [ |
222
|
|
|
'name' => self::CHANNEL_NAME, |
223
|
|
|
], |
224
|
|
|
'expectedResultCount' => 0 |
225
|
|
|
], |
226
|
|
|
], |
227
|
|
|
]; |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.