Completed
Push — master ( 95e8d1...b686ff )
by Aimeos
02:04
created

BasketControllerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Aimeos\ShopBundle\Tests\Controller;
4
5
use Symfony\Component\HttpFoundation\Response;
6
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
7
8
9
class BasketControllerTest extends WebTestCase
10
{
11
	protected function setUp()
12
	{
13
		\Aimeos\MShop::cache( false );
14
		\Aimeos\Controller\Frontend::cache( false );
15
	}
16
17
18
	public function testStandardAdd()
19
	{
20
		$client = static::createClient();
21
22
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
23
24
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
25
		$crawler = $client->click( $link );
26
27
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
28
		$crawler = $client->submit( $form );
29
30
		$this->assertEquals( 1, $crawler->filter( '.basket-standard' )->count() );
31
		$this->assertEquals( 1, $crawler->filter( '.basket:contains("Unittest: Bundle")' )->count() );
32
		$this->assertEquals( 1, $crawler->filter( '.basket .product .quantity .value' )->attr('value') );
33
	}
34
35
36
	public function testStandardAddQuantity()
37
	{
38
		$client = static::createClient();
39
40
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
41
42
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
43
		$crawler = $client->click( $link );
44
45
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
46
		$form['b_prod[0][quantity]'] = 2;
47
		$crawler = $client->submit( $form );
0 ignored issues
show
Documentation introduced by
$form is of type array<string,integer,{"b...[quantity]":"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...
48
49
		$this->assertEquals( 1, $crawler->filter( '.basket-standard' )->count() );
50
		$this->assertEquals( 1, $crawler->filter( '.basket:contains("Unittest: Bundle")' )->count() );
51
		$this->assertEquals( 2, $crawler->filter( '.basket .product .quantity .value' )->attr('value') );
52
	}
53
54
55
	public function testStandardAddTwice()
56
	{
57
		$client = static::createClient();
58
59
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
60
61
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
62
		$crawler = $client->click( $link );
63
64
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
65
		$crawler = $client->submit( $form );
66
67
		$this->assertEquals( 1, $crawler->filter( '.basket:contains("Unittest: Bundle")' )->count() );
68
		$this->assertEquals( 1, $crawler->filter( '.basket .product .quantity .value' )->attr('value') );
69
70
71
		$link = $crawler->filter( '.basket-standard .btn-back' )->link();
72
		$crawler = $client->click( $link );
73
74
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
75
		$crawler = $client->submit( $form );
76
77
		$this->assertEquals( 1, $crawler->filter( '.basket:contains("Unittest: Bundle")' )->count() );
78
		$this->assertEquals( 2, $crawler->filter( '.basket .product .quantity .value' )->attr('value') );
79
	}
80
81
82
	public function testStandardDelete()
83
	{
84
		$client = static::createClient();
85
86
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
87
88
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
89
		$crawler = $client->click( $link );
90
91
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
92
		$crawler = $client->submit( $form );
93
94
95
		$link = $crawler->filter( '.basket-standard .product .action .delete' )->link();
96
		$crawler = $client->click( $link );
97
98
		$this->assertEquals( 0, $crawler->filter( '.basket-standard .product' )->count() );
99
	}
100
101
102
	public function testStandardEdit()
103
	{
104
		$client = static::createClient();
105
106
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
107
108
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
109
		$crawler = $client->click( $link );
110
111
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
112
		$crawler = $client->submit( $form );
113
114
115
		$link = $crawler->filter( '.basket-standard .product .quantity .change' )->link();
116
		$crawler = $client->click( $link );
117
118
		$this->assertEquals( 2, $crawler->filter( '.basket-standard .product .quantity .value' )->attr( 'value' ) );
119
120
121
		$link = $crawler->filter( '.basket-standard .product .quantity .change' )->eq( 0 )->link();
122
		$crawler = $client->click( $link );
123
124
		$this->assertEquals( 1, $crawler->filter( '.basket-standard .product .quantity .value' )->attr( 'value' ) );
125
	}
126
127
128
	public function testStandardUpdate()
129
	{
130
		$client = static::createClient();
131
132
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
133
134
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
135
		$crawler = $client->click( $link );
136
137
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
138
		$crawler = $client->submit( $form );
139
140
		$form = $crawler->filter( '.basket-standard .btn-update' )->form();
141
		$form['b_prod[0][quantity]'] = 3;
142
		$crawler = $client->submit( $form );
0 ignored issues
show
Documentation introduced by
$form is of type array<string,integer,{"b...[quantity]":"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...
143
144
		$this->assertEquals( 3, $crawler->filter( '.basket-standard .product .quantity .value' )->attr( 'value' ) );
145
	}
146
147
148
	public function testStandardCoupon()
149
	{
150
		$client = static::createClient();
151
152
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
153
154
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
155
		$crawler = $client->click( $link );
156
157
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
158
		$crawler = $client->submit( $form );
159
160
161
		$form = $crawler->filter( '.basket-standard-coupon .coupon-new button' )->form();
162
		$form['b_coupon'] = '90AB';
163
		$crawler = $client->submit( $form );
0 ignored issues
show
Documentation introduced by
$form is of type array<string,string,{"b_coupon":"string"}>, 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...
164
165
		$this->assertEquals( 1, $crawler->filter( '.basket-standard .product:contains("Geldwerter Nachlass")' )->count() );
166
167
168
		$link = $crawler->filter( '.basket-standard-coupon .delete' )->link();
169
		$crawler = $client->click( $link );
170
171
		$this->assertEquals( 1, $crawler->filter( '.basket-standard .product' )->count() );
172
	}
173
174
175
	public function testStandardRelated()
176
	{
177
		$client = static::createClient();
178
179
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
180
181
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Cafe Noire Expresso")' )->link();
182
		$crawler = $client->click( $link );
183
184
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
185
		$crawler = $client->submit( $form );
186
187
		$this->assertEquals( 1, $crawler->filter( '.basket-related-bought .product' )->count() );
188
	}
189
190
191
	public function testStandardBack()
192
	{
193
		$client = static::createClient();
194
195
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
196
197
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
198
		$crawler = $client->click( $link );
199
200
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
201
		$crawler = $client->submit( $form );
202
203
		$link = $crawler->filter( '.basket-standard .btn-back' )->link();
204
		$crawler = $client->click( $link );
205
206
		$this->assertEquals( 1, $crawler->filter( '.catalog-detail .product:contains("Unittest: Bundle")' )->count() );
207
	}
208
209
210
	public function testMiniComponent()
211
	{
212
		$client = static::createClient();
213
		$client->request( 'GET', '/unittest/de/EUR/test/basketminicomponent' );
214
215
		$this->assertEquals( 200, $client->getResponse()->getStatusCode() );
216
		$this->assertContains( 'aimeos basket-mini', $client->getResponse()->getContent() );
217
	}
218
219
220
	public function testRelatedComponent()
221
	{
222
		$client = static::createClient();
223
		$client->request( 'GET', '/unittest/de/EUR/test/basketrelatedcomponent' );
224
225
		$this->assertEquals( 200, $client->getResponse()->getStatusCode() );
226
		$this->assertContains( 'aimeos basket-related', $client->getResponse()->getContent() );
227
	}
228
229
230
	public function testStandardComponent()
231
	{
232
		$client = static::createClient();
233
		$client->request( 'GET', '/unittest/de/EUR/test/basketstandardcomponent' );
234
235
		$this->assertEquals( 200, $client->getResponse()->getStatusCode() );
236
		$this->assertContains( 'aimeos basket-standard', $client->getResponse()->getContent() );
237
	}
238
}
239