Completed
Push — master ( 74d39c...908185 )
by
unknown
13:49
created

CartControllerTest::gridProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 91
Code Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 91
rs 8.518
cc 1
eloc 59
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Oro\Bundle\MagentoBundle\Tests\Functional\Controller;
4
5
use Oro\Bundle\OrganizationBundle\Entity\Organization;
6
7
/**
8
 * @outputBuffering enabled
9
 * @dbIsolation
10
 */
11
class CartControllerTest extends AbstractController
12
{
13
    /** @var \Oro\Bundle\MagentoBundle\Entity\Cart */
14
    public static $cart;
15
16
    protected function postFixtureLoad()
17
    {
18
        parent::postFixtureLoad();
19
20
        self::$cart = $this->getReference('cart');
21
    }
22
23
    /**
24
     * @afterClass
25
     */
26
    public function clear()
27
    {
28
        self::$cart = null;
29
        gc_collect_cycles();
30
    }
31
32
    /**
33
     * @return int
34
     */
35
    protected function getMainEntityId()
36
    {
37
        $this->assertNotEmpty(self::$cart);
38
39
        return self::$cart->getId();
40
    }
41
42
    public function testView()
43
    {
44
        $this->client->request(
45
            'GET',
46
            $this->getUrl(
47
                'oro_magento_cart_view',
48
                ['id' => $this->getMainEntityId(), 'isRemoved' => 0]
49
            )
50
        );
51
        $result = $this->client->getResponse();
52
        $this->assertHtmlResponseStatusCodeEquals($result, 200);
53
        $this->assertContains('Cart Information', $result->getContent());
54
        $this->assertContains('[email protected]', $result->getContent());
55
        $this->assertContains('Customer Information', $result->getContent());
56
        $this->assertContains('[email protected]', $result->getContent());
57
        $this->assertContains('Cart Items', $result->getContent());
58
        $this->assertContains('Demo Web store', $result->getContent());
59
        $this->assertContains('Sync Data', $result->getContent());
60
        $this->assertContains('Open', $result->getContent());
61
        $this->assertContains('web site', $result->getContent());
62
        $this->assertContains('demo store', $result->getContent());
63
        $this->assertContains('Send email', $result->getContent());
64
65
        $filteredHtml = str_replace(['<br/>', '<br />'], ' ', $result->getContent());
66
67
        /** @var Organization $organization */
68
        $organization = $this->client
69
            ->getContainer()
70
            ->get('doctrine')
71
            ->getRepository('OroOrganizationBundle:Organization')
72
            ->getFirst();
73
74
        $this->assertContains(
75
            'John Doe ' . $organization->getName() . ' street CITY AZ US 123456',
76
            preg_replace('#\s+#', ' ', $filteredHtml)
77
        );
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function gridProvider()
84
    {
85
        return [
86
            'Magento cart grid' => [
87
                [
88
                    'gridParameters' => [
89
                        'gridName' => 'magento-cart-grid',
90
                        'magento-cart-grid[_sort_by][originId]' => 'ASC',
91
                    ],
92
                    'gridFilters' => [],
93
                    'asserts' => [
94
                        [
95
                            'channelName' => 'Magento channel',
96
                            'firstName' => 'John',
97
                            'lastName' => 'Doe',
98
                            'email' => '[email protected]',
99
                            'regionName' => 'Arizona'
100
                        ],
101
                        [
102
                            'channelName' => 'Magento channel',
103
                            'firstName' => 'Guest Jack',
104
                            'lastName' => 'Guest White',
105
                            'email' => '[email protected]',
106
                            'regionName' => 'Arizona'
107
                        ]
108
                    ],
109
                    'expectedResultCount' => 2
110
                ],
111
            ],
112
            'Magento cart grid with filters' => [
113
                [
114
                    'gridParameters' => [
115
                        'gridName' => 'magento-cart-grid'
116
                    ],
117
                    'gridFilters' => [
118
                        'magento-cart-grid[_filter][lastName][value]' => 'Doe',
119
                        'magento-cart-grid[_filter][firstName][value]' => 'John'
120
                    ],
121
                    'assert' => [
122
                        'channelName' => 'Magento channel',
123
                        'firstName' => 'John',
124
                        'lastName' => 'Doe',
125
                        'email' => '[email protected]',
126
                        'regionName' => 'Arizona'
127
                    ],
128
                    'expectedResultCount' => 1
129
                ],
130
            ],
131
            'Magento cart grid with filters without result' => [
132
                [
133
                    'gridParameters' => [
134
                        'gridName' => 'magento-cart-grid'
135
                    ],
136
                    'gridFilters' => [
137
                        'magento-cart-grid[_filter][lastName][value]' => 'Doe',
138
                        'magento-cart-grid[_filter][firstName][value]' => 'Doe'
139
                    ],
140
                    'assert' => [],
141
                    'expectedResultCount' => 0
142
                ]
143
            ],
144
            'Cart item grid' => [
145
                [
146
                    'gridParameters' => [
147
                        'gridName' => 'magento-cartitem-active-grid',
148
                        'id' => 'id',
149
                    ],
150
                    'gridFilters' => [],
151
                    'assert' => [
152
                        'sku' => 'sku',
153
                        'qty' => 0,
154
                        'rowTotal' => 'USD 100.00',
155
                        'taxAmount' => 'USD 10.00',
156
                        'discountAmount' => 'USD 0.00'
157
                    ],
158
                    'expectedResultCount' => 1
159
                ],
160
            ],
161
            'Cart item grid removed' => [
162
                [
163
                    'gridParameters' => [
164
                        'gridName' => 'magento-cartitem-removed-grid',
165
                        'id' => 'id',
166
                    ],
167
                    'gridFilters' => [],
168
                    'assert' => [],
169
                    'expectedResultCount' => 0
170
                ],
171
            ],
172
        ];
173
    }
174
}
175