Completed
Push — master ( 3b7290...73d268 )
by
unknown
11:56
created

B2bCustomerControllerTest::gridProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 45
rs 8.8571
cc 1
eloc 26
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\SalesBundle\Tests\Functional\Controller;
4
5
use OroCRM\Bundle\SalesBundle\Tests\Functional\Fixture\LoadSalesBundleFixtures;
6
use Symfony\Component\DomCrawler\Form;
7
8
use Oro\Bundle\DataGridBundle\Tests\Functional\AbstractDatagridTestCase;
9
10
use OroCRM\Bundle\AccountBundle\Entity\Account;
11
use OroCRM\Bundle\ChannelBundle\Entity\Channel;
12
use OroCRM\Bundle\SalesBundle\Entity\B2bCustomer;
13
14
/**
15
 * @outputBuffering enabled
16
 * @dbIsolation
17
 */
18
class B2bCustomerControllerTest extends AbstractDatagridTestCase
19
{
20
    /** @var B2bCustomer */
21
    protected static $customer;
22
23
    /** @var Account */
24
    protected static $account;
25
26
    /** @var Channel */
27
    protected static $channel;
28
29
    /** @var bool */
30
    protected $isRealGridRequest = false;
31
32 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
33
    {
34
        $this->initClient(
35
            [],
36
            array_merge($this->generateBasicAuthHeader(), ['HTTP_X-CSRF-Header' => 1])
37
        );
38
        $this->client->useHashNavigation(true);
0 ignored issues
show
Bug introduced by
The method useHashNavigation() does not seem to exist on object<Oro\Bundle\TestFr...workBundle\Test\Client>.

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.

Loading history...
39
        $this->loadFixtures(['OroCRM\Bundle\SalesBundle\Tests\Functional\Fixture\LoadSalesBundleFixtures']);
40
    }
41
42
    protected function postFixtureLoad()
43
    {
44
        self::$account  = $this->getReference('default_account');
45
        self::$customer = $this->getReference('default_b2bcustomer');
46
        self::$channel  = $this->getReference('default_channel');
47
    }
48
49
    public function testIndex()
50
    {
51
        $this->client->request('GET', $this->getUrl('orocrm_sales_b2bcustomer_index'));
52
        $result = $this->client->getResponse();
53
        $this->assertHtmlResponseStatusCodeEquals($result, 200);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     * @dataProvider gridProvider
59
     */
60
    public function testGrid($requestData)
61
    {
62
        parent::testGrid($requestData);
63
    }
64
65
    public function testCreate()
66
    {
67
        $crawler = $this->client->request('GET', $this->getUrl('orocrm_sales_b2bcustomer_create'));
68
        $form = $crawler->selectButton('Save and Close')->form();
69
        $name = 'name' . $this->generateRandomString();
70
71
        $form['orocrm_sales_b2bcustomer_form[name]'] = $name;
72
        $form['orocrm_sales_b2bcustomer_form[account]'] = self::$account->getId();
73
        $form['orocrm_sales_b2bcustomer_form[dataChannel]'] = self::$channel->getId();
74
        $form['orocrm_sales_b2bcustomer_form[owner]']   = 1;
75
76
        $this->client->followRedirects(true);
77
        $crawler = $this->client->submit($form);
0 ignored issues
show
Documentation introduced by
$form is of type array<string,string|inte...orm[owner]":"integer"}>, but the function expects a object<Symfony\Component\DomCrawler\Form>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
78
79
        $result = $this->client->getResponse();
80
        $this->assertHtmlResponseStatusCodeEquals($result, 200);
81
        $this->assertContains("Customer saved", $crawler->html());
82
    }
83
84
    /**
85
     * @param string $name
86
     *
87
     * @depends testCreate
88
     *
89
     * @return string
90
     */
91
    public function testUpdate($name)
92
    {
93
        $response = $this->client->requestGrid(
94
            'orocrm-sales-b2bcustomers-grid',
95
            [
96
                'orocrm-sales-b2bcustomers-grid[_filter][name][channelName]' => 'b2b Channel',
97
                'orocrm-sales-b2bcustomers-grid[_filter][name][value]' => $name,
98
            ]
99
        );
100
101
        $result = $this->getJsonResponseContent($response, 200);
102
        $result = reset($result['data']);
103
        $returnValue = $result;
104
        $crawler = $this->client->request(
105
            'GET',
106
            $this->getUrl('orocrm_sales_b2bcustomer_update', ['id' => $result['id']])
107
        );
108
109
        /** @var Form $form */
110
        $form = $crawler->selectButton('Save and Close')->form();
111
        $name = 'name' . $this->generateRandomString();
112
        $form['orocrm_sales_b2bcustomer_form[name]'] = $name;
113
        $form['orocrm_sales_b2bcustomer_form[owner]']   = 1;
114
115
        $this->client->followRedirects(true);
116
        $crawler = $this->client->submit($form);
117
118
        $result = $this->client->getResponse();
119
        $this->assertHtmlResponseStatusCodeEquals($result, 200);
120
        $this->assertContains("Customer saved", $crawler->html());
121
122
        $returnValue['name'] = $name;
123
124
        return $returnValue;
125
    }
126
127
    /**
128
     * @param array $returnValue
129
     *
130
     * @depends testUpdate
131
     *
132
     * @return string
133
     */
134 View Code Duplication
    public function testView($returnValue)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
135
    {
136
        $crawler = $this->client->request(
137
            'GET',
138
            $this->getUrl('orocrm_sales_b2bcustomer_view', ['id' => $returnValue['id']])
139
        );
140
141
        $result = $this->client->getResponse();
142
        $this->assertHtmlResponseStatusCodeEquals($result, 200);
143
        $this->assertContains($returnValue['name'], $crawler->html());
144
    }
145
146
    /**
147
     * @param array $returnValue
148
     *
149
     * @depends testUpdate
150
     *
151
     * @return string
152
     */
153 View Code Duplication
    public function testInfo($returnValue)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
154
    {
155
        $crawler = $this->client->request(
156
            'GET',
157
            $this->getUrl(
158
                'orocrm_sales_b2bcustomer_widget_info',
159
                ['id' => $returnValue['id'], '_widgetContainer' => 'block']
160
            )
161
        );
162
163
        $result = $this->client->getResponse();
164
        $this->assertHtmlResponseStatusCodeEquals($result, 200);
165
        $this->assertContains($returnValue['name'], $crawler->html());
166
    }
167
168
    /**
169
     * @param array $returnValue
170
     *
171
     * @depends testUpdate
172
     */
173
    public function testDelete($returnValue)
174
    {
175
        $this->client->request(
176
            'DELETE',
177
            $this->getUrl('oro_api_delete_b2bcustomer', ['id' => $returnValue['id']])
178
        );
179
180
        $result = $this->client->getResponse();
181
        $this->assertEmptyResponseStatusCodeEquals($result, 204);
182
183
        $this->client->request(
184
            'GET',
185
            $this->getUrl('orocrm_sales_b2bcustomer_view', ['id' => $returnValue['id']])
186
        );
187
188
        $result = $this->client->getResponse();
189
        $this->assertHtmlResponseStatusCodeEquals($result, 404);
190
    }
191
192
    /**
193
     * @return array
194
     */
195
    public function gridProvider()
196
    {
197
        return [
198
            'B2B Customer grid'              => [
199
                [
200
                    'gridParameters'      => [
201
                        'gridName' => 'orocrm-sales-b2bcustomers-grid'
202
                    ],
203
                    'gridFilters'         => [],
204
                    'assert'              => [
205
                        'name'        => LoadSalesBundleFixtures::CUSTOMER_NAME,
206
                        'channelName' => LoadSalesBundleFixtures::CHANNEL_NAME
207
                    ],
208
                    'expectedResultCount' => 1
209
                ],
210
            ],
211
            'B2B Customer grid with filter'  => [
212
                [
213
                    'gridParameters'      => [
214
                        'gridName' => 'orocrm-sales-b2bcustomers-grid'
215
                    ],
216
                    'gridFilters'         => [
217
                        'orocrm-sales-b2bcustomers-grid[_filter][name][value]' => 'b2bCustomer name',
218
                    ],
219
                    'assert'              => [
220
                        'name'        => LoadSalesBundleFixtures::CUSTOMER_NAME,
221
                        'channelName' => LoadSalesBundleFixtures::CHANNEL_NAME
222
                    ],
223
                    'expectedResultCount' => 1
224
                ],
225
            ],
226
            'B2B Customer grid without data' => [
227
                [
228
                    'gridParameters'      => [
229
                        'gridName' => 'orocrm-sales-b2bcustomers-grid'
230
                    ],
231
                    'gridFilters'         => [
232
                        'orocrm-sales-b2bcustomers-grid[_filter][name][value]' => 'some other type',
233
                    ],
234
                    'assert'              => [],
235
                    'expectedResultCount' => 0
236
                ],
237
            ],
238
        ];
239
    }
240
}
241