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

OpportunityControllersTest::testDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 17
rs 9.4285
cc 1
eloc 11
nc 1
nop 1
1
<?php
2
3
namespace OroCRM\Bundle\SalesBundle\Tests\Functional\Controller;
4
5
use Symfony\Component\DomCrawler\Form;
6
7
use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;
8
use Oro\Bundle\DataGridBundle\Tests\Functional\AbstractDatagridTestCase;
9
10
use OroCRM\Bundle\ChannelBundle\Entity\Channel;
11
use OroCRM\Bundle\SalesBundle\Tests\Functional\Fixture\LoadSalesBundleFixtures;
12
use OroCRM\Bundle\SalesBundle\Entity\B2bCustomer;
13
14
/**
15
 * @outputBuffering enabled
16
 * @dbIsolation
17
 */
18
class OpportunityControllersTest extends AbstractDatagridTestCase
19
{
20
    /** @var B2bCustomer */
21
    protected static $customer;
22
23
    /** @var  Channel */
24
    protected static $dataChannel;
25
26
    /** @var bool */
27
    protected $isRealGridRequest = false;
28
29
    protected function setUp()
30
    {
31
        $this->initClient(
32
            ['debug' => false],
33
            array_merge($this->generateBasicAuthHeader(), array('HTTP_X-CSRF-Header' => 1))
34
        );
35
        $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...
36
        $this->loadFixtures(['OroCRM\Bundle\SalesBundle\Tests\Functional\Fixture\LoadSalesBundleFixtures']);
37
    }
38
39
    protected function postFixtureLoad()
40
    {
41
        self::$customer = $this->getReference('default_b2bcustomer');
42
        self::$dataChannel = $this->getReference('default_channel');
43
    }
44
45
    public function testIndex()
46
    {
47
        $this->client->request('GET', $this->getUrl('orocrm_sales_opportunity_index'));
48
        $result = $this->client->getResponse();
49
        $this->assertHtmlResponseStatusCodeEquals($result, 200);
50
    }
51
52
    public function testCreate()
53
    {
54
        $crawler = $this->client->request('GET', $this->getUrl('orocrm_sales_opportunity_create'));
55
56
        /** @var Form $form */
57
        $form = $crawler->selectButton('Save and Close')->form();
58
        $name = 'name' . $this->generateRandomString();
59
        $form['orocrm_sales_opportunity_form[name]']         = $name;
60
        $form['orocrm_sales_opportunity_form[customer]']     = self::$customer->getId();
61
        $form['orocrm_sales_opportunity_form[probability]']  = 50;
62
        $form['orocrm_sales_opportunity_form[budgetAmount]'] = 10000;
63
        $form['orocrm_sales_opportunity_form[customerNeed]'] = 10001;
64
        $form['orocrm_sales_opportunity_form[closeReason]']  = 'cancelled';
65
        $form['orocrm_sales_opportunity_form[owner]']        = 1;
66
        $form['orocrm_sales_opportunity_form[dataChannel]']  = $this->getReference('default_channel')->getId();
67
68
        $this->client->followRedirects(true);
69
        $crawler = $this->client->submit($form);
70
71
        $result = $this->client->getResponse();
72
        $this->assertHtmlResponseStatusCodeEquals($result, 200);
73
        $this->assertContains("Opportunity saved", $crawler->html());
74
75
        return $name;
76
    }
77
78
     /**
79
     * @param string $name
80
     * @depends testCreate
81
     *
82
     * @return string
83
     */
84 View Code Duplication
    public function testUpdate($name)
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...
85
    {
86
        $response = $this->client->requestGrid(
87
            'sales-opportunity-grid',
88
            [
89
                'sales-opportunity-grid[_filter][name][type]' => '1',
90
                'sales-opportunity-grid[_filter][name][value]' => $name,
91
            ]
92
        );
93
94
        $result = $this->getJsonResponseContent($response, 200);
95
        $result = reset($result['data']);
96
        $returnValue = $result;
97
        $crawler = $this->client->request(
98
            'GET',
99
            $this->getUrl('orocrm_sales_opportunity_update', ['id' => $result['id']])
100
        );
101
102
        /** @var Form $form */
103
        $form = $crawler->selectButton('Save and Close')->form();
104
        $name = 'name' . $this->generateRandomString();
105
        $form['orocrm_sales_opportunity_form[name]'] = $name;
106
107
        $this->client->followRedirects(true);
108
        $crawler = $this->client->submit($form);
109
110
        $result = $this->client->getResponse();
111
        $this->assertHtmlResponseStatusCodeEquals($result, 200);
112
        $this->assertContains("Opportunity saved", $crawler->html());
113
114
        $returnValue['name'] = $name;
115
116
        return $returnValue;
117
    }
118
119
    /**
120
     * @param array $returnValue
121
     * @depends testUpdate
122
     *
123
     * @return string
124
     */
125 View Code Duplication
    public function testView(array $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...
126
    {
127
        $crawler = $this->client->request(
128
            'GET',
129
            $this->getUrl('orocrm_sales_opportunity_view', ['id' => $returnValue['id']])
130
        );
131
132
        $result = $this->client->getResponse();
133
        $this->assertHtmlResponseStatusCodeEquals($result, 200);
134
        $this->assertContains("{$returnValue['name']} - Opportunities - Sales", $crawler->html());
135
    }
136
137
    /**
138
     * @param array $returnValue
139
     * @depends testUpdate
140
     *
141
     * @return string
142
     */
143
    public function testInfo(array $returnValue)
144
    {
145
        $this->client->request(
146
            'GET',
147
            $this->getUrl(
148
                'orocrm_sales_opportunity_info',
149
                ['id' => $returnValue['id'], '_widgetContainer' => 'block']
150
            )
151
        );
152
153
        $result = $this->client->getResponse();
154
        $this->assertHtmlResponseStatusCodeEquals($result, 200);
155
    }
156
157
    /**
158
     * @param array $returnValue
159
     * @depends testUpdate
160
     */
161
    public function testDelete(array $returnValue)
162
    {
163
        $this->client->request(
164
            'DELETE',
165
            $this->getUrl('oro_api_delete_opportunity', ['id' => $returnValue['id']])
166
        );
167
168
        $result = $this->client->getResponse();
169
        $this->assertEmptyResponseStatusCodeEquals($result, 204);
170
171
        $this->client->request(
172
            'GET',
173
            $this->getUrl('orocrm_sales_opportunity_view', ['id' => $returnValue['id']])
174
        );
175
        $result = $this->client->getResponse();
176
        $this->assertHtmlResponseStatusCodeEquals($result, 404);
177
    }
178
179
    /**
180
     * @return array
181
     */
182
    public function gridProvider()
183
    {
184
        return [
185
            'Opportunity grid'                => [
186
                [
187
                    'gridParameters'      => [
188
                        'gridName' => 'sales-opportunity-grid'
189
                    ],
190
                    'gridFilters'         => [],
191
                    'assert'              => [
192
                        'name'         => 'opname',
193
                        'channelName'  => LoadSalesBundleFixtures::CHANNEL_NAME,
194
                        'budgetAmount' => 50.00,
195
                        'probability'  => 10,
196
                    ],
197
                    'expectedResultCount' => 1
198
                ],
199
            ],
200
            'Opportunity grid with filter'    => [
201
                [
202
                    'gridParameters'      => [
203
                        'gridName' => 'sales-opportunity-grid'
204
                    ],
205
                    'gridFilters'         => [
206
                        'sales-opportunity-grid[_filter][budgetAmount][value]' => 50.00,
207
                    ],
208
                    'assert'              => [
209
                        'name'         => 'opname',
210
                        'channelName'  => LoadSalesBundleFixtures::CHANNEL_NAME,
211
                        'budgetAmount' => 50.00,
212
                        'probability'  => 10,
213
                    ],
214
                    'expectedResultCount' => 1
215
                ]
216
            ],
217
            'Opportunity grid without result' => [
218
                [
219
                    'gridParameters'      => [
220
                        'gridName' => 'sales-opportunity-grid'
221
                    ],
222
                    'gridFilters'         => [
223
                        'sales-opportunity-grid[_filter][budgetAmount][value]' => 150.00,
224
                    ],
225
                    'assert'              => [],
226
                    'expectedResultCount' => 0
227
                ],
228
            ]
229
        ];
230
    }
231
}
232