Completed
Push — master ( 76ac09...8c1d79 )
by Aimeos
04:15
created

BasketControllerTest::testStandardComponent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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