Completed
Push — master ( 9fc944...74d39c )
by
unknown
08:52
created

CartControllerTest::testGrid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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
     * {@inheritdoc}
82
     *
83
     * @dataProvider gridProvider
84
     */
85
    public function testGrid($requestData)
86
    {
87
        parent::testGrid($requestData);
88
    }
89
90
    public function gridProvider()
91
    {
92
        return [
93
            'Magento cart grid' => [
94
                [
95
                    'gridParameters' => [
96
                        'gridName' => 'magento-cart-grid',
97
                        'magento-cart-grid[_sort_by][originId]' => 'ASC',
98
                    ],
99
                    'gridFilters' => [],
100
                    'asserts' => [
101
                        [
102
                            'channelName' => 'Magento channel',
103
                            'firstName' => 'John',
104
                            'lastName' => 'Doe',
105
                            'email' => '[email protected]',
106
                            'regionName' => 'Arizona'
107
                        ],
108
                        [
109
                            'channelName' => 'Magento channel',
110
                            'firstName' => 'Guest Jack',
111
                            'lastName' => 'Guest White',
112
                            'email' => '[email protected]',
113
                            'regionName' => 'Arizona'
114
                        ]
115
                    ],
116
                    'expectedResultCount' => 2
117
                ],
118
            ],
119
            'Magento cart grid with filters' => [
120
                [
121
                    'gridParameters' => [
122
                        'gridName' => 'magento-cart-grid'
123
                    ],
124
                    'gridFilters' => [
125
                        'magento-cart-grid[_filter][lastName][value]' => 'Doe',
126
                        'magento-cart-grid[_filter][firstName][value]' => 'John'
127
                    ],
128
                    'assert' => [
129
                        'channelName' => 'Magento channel',
130
                        'firstName' => 'John',
131
                        'lastName' => 'Doe',
132
                        'email' => '[email protected]',
133
                        'regionName' => 'Arizona'
134
                    ],
135
                    'expectedResultCount' => 1
136
                ],
137
            ],
138
            'Magento cart grid with filters without result' => [
139
                [
140
                    'gridParameters' => [
141
                        'gridName' => 'magento-cart-grid'
142
                    ],
143
                    'gridFilters' => [
144
                        'magento-cart-grid[_filter][lastName][value]' => 'Doe',
145
                        'magento-cart-grid[_filter][firstName][value]' => 'Doe'
146
                    ],
147
                    'assert' => [],
148
                    'expectedResultCount' => 0
149
                ]
150
            ],
151
            'Cart item grid' => [
152
                [
153
                    'gridParameters' => [
154
                        'gridName' => 'magento-cartitem-active-grid',
155
                        'id' => 'id',
156
                    ],
157
                    'gridFilters' => [],
158
                    'assert' => [
159
                        'sku' => 'sku',
160
                        'qty' => 0,
161
                        'rowTotal' => 'USD 100.00',
162
                        'taxAmount' => 'USD 10.00',
163
                        'discountAmount' => 'USD 0.00'
164
                    ],
165
                    'expectedResultCount' => 1
166
                ],
167
            ],
168
            'Cart item grid removed' => [
169
                [
170
                    'gridParameters' => [
171
                        'gridName' => 'magento-cartitem-removed-grid',
172
                        'id' => 'id',
173
                    ],
174
                    'gridFilters' => [],
175
                    'assert' => [],
176
                    'expectedResultCount' => 0
177
                ],
178
            ],
179
        ];
180
    }
181
}
182