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

CatalogControllerTest::testStockComponent()   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 CatalogControllerTest extends WebTestCase
9
{
10
	public function testCount()
11
	{
12
		$client = static::createClient();
13
		$client->request( 'GET', '/unittest/de/EUR/count' );
14
		$content = $client->getResponse()->getContent();
15
16
		$this->assertContains( '".catalog-filter-count li.cat-item"', $content );
17
		$this->assertContains( '".catalog-filter-attribute .attribute-lists li.attr-item"', $content );
18
	}
19
20
21
	public function testFilterSearch()
22
	{
23
		$client = static::createClient();
24
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
25
26
		$this->assertEquals( 1, $crawler->filter( '.catalog-filter-search' )->count() );
27
28
		$form = $crawler->filter( '.catalog-filter-search button' )->form();
29
		$form['f_search'] = 'Unit';
30
		$crawler = $client->submit( $form );
0 ignored issues
show
Documentation introduced by
$form is of type array<string,string,{"f_search":"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...
31
32
		$this->assertEquals( 1, $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Test Selection")' )->count() );
33
		$this->assertEquals( 1, $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Empty Selection")' )->count() );
34
		$this->assertEquals( 1, $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->count() );
35
	}
36
37
38
 	public function testFilterTree()
39
	{
40
		$client = static::createClient();
41
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
42
43
		$this->assertEquals( 1, $crawler->filter( '.catalog-filter-tree' )->count() );
44
45
		$link = $crawler->filter( '.catalog-filter-tree a.cat-item' )->link();
46
		$crawler = $client->click( $link );
47
48
		$link = $crawler->filter( '.catalog-filter-tree .categories a.cat-item' )->link();
49
		$crawler = $client->click( $link );
50
51
		$link = $crawler->filter( '.catalog-filter-tree .coffee a.cat-item' )->link();
52
		$crawler = $client->click( $link );
53
54
		$this->assertEquals( 3, $crawler->filter( '.catalog-stage-breadcrumb li' )->count() );
55
		$this->assertEquals( 1, $crawler->filter( '.catalog-list-promo .product a:contains("Cafe Noire Expresso")' )->count() );
56
	}
57
58
59
	public function testFilterAttribute()
60
	{
61
		$client = static::createClient();
62
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
63
64
		$this->assertEquals( 1, $crawler->filter( '.catalog-filter-attribute' )->count() );
65
66
		$nodes = $crawler->filter( '.catalog-filter-attribute .attr-size span:contains("XS")' );
67
		$id = $nodes->parents()->filter( '.attr-item' )->attr( 'data-id');
68
69
		$form = $crawler->filter( '.catalog-filter .btn-action' )->form();
70
		$form['f_attrid'] = array( $id => 'xs' );
71
		$crawler = $client->submit( $form );
0 ignored issues
show
Documentation introduced by
$form is of type array<string,array<?,str...id":"array<?,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...
72
73
		$this->assertEquals( 1, $crawler->filter( '.catalog-list-items .product a:contains("Cafe Noire Expresso")' )->count() );
74
		$this->assertEquals( 1, $crawler->filter( '.catalog-list-items .product a:contains("Cafe Noire Cappuccino")' )->count() );
75
	}
76
77
78
	public function testStageBreadcrumb()
79
	{
80
		$client = static::createClient();
81
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
82
83
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Cafe Noire Expresso")' )->link();
84
		$crawler = $client->click( $link );
85
86
		$this->assertEquals( 1, $crawler->filter( '.catalog-stage-breadcrumb li' )->count() );
87
88
		$link = $crawler->filter( '.catalog-stage-breadcrumb a' )->link();
89
		$crawler = $client->click( $link );
90
91
		$this->assertEquals( 1, $crawler->filter( '.catalog-list' )->count() );
92
		$this->assertEquals( 1, $crawler->filter( '.catalog-list-items .product a:contains("Cafe Noire Expresso")' )->count() );
93
		$this->assertEquals( 1, $crawler->filter( '.catalog-list-items .product a:contains("Cafe Noire Cappuccino")' )->count() );
94
	}
95
96
97
	public function testStageNavigator()
98
	{
99
		$client = static::createClient();
100
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
101
102
		$link = $crawler->filter( '.catalog-list-pagination .option-name' )->link();
103
		$crawler = $client->click( $link );
104
105
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
106
		$crawler = $client->click( $link );
107
108
		$this->assertEquals( 1, $crawler->filter( '.catalog-detail' )->count() );
109
		$this->assertEquals( 1, $crawler->filter( '.catalog-detail:contains("Unittest: Bundle")' )->count() );
110
111
		$link = $crawler->filter( '.catalog-stage-navigator a.next' )->link();
112
		$crawler = $client->click( $link );
113
114
		$this->assertEquals( 1, $crawler->filter( '.catalog-detail' )->count() );
115
		$this->assertEquals( 1, $crawler->filter( '.catalog-detail:contains("Unittest: Empty Selection")' )->count() );
116
117
		$link = $crawler->filter( '.catalog-stage-navigator a.prev' )->link();
118
		$crawler = $client->click( $link );
119
120
		$this->assertEquals( 1, $crawler->filter( '.catalog-detail' )->count() );
121
		$this->assertEquals( 1, $crawler->filter( '.catalog-detail:contains("Unittest: Bundle")' )->count() );
122
	}
123
124
125
	public function testListSortationName()
126
	{
127
		$client = static::createClient();
128
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
129
130
		$link = $crawler->filter( '.catalog-list-pagination .option-name' )->link();
131
		$crawler = $client->click( $link );
132
133
		$products = $crawler->filter( '.catalog-list-items .product' );
134
		$this->assertEquals( 1, $products->eq( 1 )->filter( 'h2:contains("Unittest: Bundle")' )->count() );
135
		$this->assertEquals( 1, $products->eq( 2 )->filter( 'h2:contains("Unittest: Empty Selection")' )->count() );
136
137
		$link = $crawler->filter( '.catalog-list-pagination .option-name' )->link();
138
		$crawler = $client->click( $link );
139
140
		$products = $crawler->filter( '.catalog-list-items .product' );
141
		$count = $products->count();
142
143
		$this->assertGreaterThan( 2, $count );
144
		$this->assertEquals( 1, $products->eq( $count - 3 )->filter( 'h2:contains("Unittest: Empty Selection")' )->count() );
145
		$this->assertEquals( 1, $products->eq( $count - 2 )->filter( 'h2:contains("Unittest: Bundle")' )->count() );
146
	}
147
148
149
	public function testListSortationPrice()
150
	{
151
		$client = static::createClient();
152
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
153
154
		$link = $crawler->filter( '.catalog-list-pagination .option-price' )->link();
155
		$crawler = $client->click( $link );
156
157
		$products = $crawler->filter( '.catalog-list-items .product' );
158
		$count = $products->count();
159
160
		$this->assertGreaterThan( 2, $count );
161
		$this->assertEquals( 1, $products->eq( $count - 2 )->filter( '.value:contains("600.00 €")' )->count() );
162
		$this->assertEquals( 1, $products->eq( $count - 1 )->filter( '.value:contains("600.00 €")' )->count() );
163
164
		$link = $crawler->filter( '.catalog-list-pagination .option-price' )->link();
165
		$crawler = $client->click( $link );
166
167
		$products = $crawler->filter( '.catalog-list-items .product' );
168
		$this->assertEquals( 1, $products->eq( 0 )->filter( '.value:contains("600.00 €")' )->count() );
169
		$this->assertEquals( 1, $products->eq( 1 )->filter( '.value:contains("600.00 €")' )->count() );
170
	}
171
172
173
	public function testDetailPinned()
174
	{
175
		$client = static::createClient();
176
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
177
178
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Cafe Noire Expresso")' )->link();
179
		$crawler = $client->click( $link );
180
181
		$link = $crawler->filter( '.catalog-detail a.actions-button-pin' )->link();
182
		$crawler = $client->click( $link );
183
184
		$this->assertEquals( 1, $crawler->filter( '.catalog-session-pinned .pinned-item' )->count() );
185
	}
186
187
188
	public function testDetailLastSeen()
189
	{
190
		$client = static::createClient();
191
		$crawler = $client->request( 'GET', '/unittest/de/EUR/list' );
192
193
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Cafe Noire Expresso")' )->link();
194
		$crawler = $client->click( $link );
195
196
		$this->assertEquals( 1, $crawler->filter( '.catalog-session-seen .seen-item' )->count() );
197
	}
198
199
200
	public function testSuggest()
201
	{
202
		$client = static::createClient();
203
		$client->request( 'GET', '/unittest/de/EUR/suggest', array( 'f_search' => 'unit' ) );
204
		$content = $client->getResponse()->getContent();
205
206
		$this->assertStringStartsWith( '[{', $content );
207
	}
208
209
210
	public function testStock()
211
	{
212
		$client = static::createClient();
213
		$client->request( 'GET', '/unittest/de/EUR/stock' );
214
		$content = $client->getResponse()->getContent();
215
216
		$this->assertContains( '.aimeos .product .stock', $content );
217
		$this->assertContains( '.aimeos .catalog-detail-basket', $content );
218
	}
219
220
221
	public function testCountComponent()
222
	{
223
		$mock = $this->getMockBuilder( 'Aimeos\ShopBundle\Controller\CatalogController' )
224
			->setMethods( array( 'getOutput' ) )
225
			->disableOriginalConstructor()
226
			->getMock();
227
228
		$mock->expects( $this->once() )->method( 'getOutput' )->will( $this->returnValue( 'test' ) );
229
230
		$this->assertEquals( 'test', $mock->countComponentAction() );
231
	}
232
233
234
	public function testDetailComponent()
235
	{
236
		$mock = $this->getMockBuilder( 'Aimeos\ShopBundle\Controller\CatalogController' )
237
			->setMethods( array( 'getOutput' ) )
238
			->disableOriginalConstructor()
239
			->getMock();
240
241
		$mock->expects( $this->once() )->method( 'getOutput' )->will( $this->returnValue( 'test' ) );
242
243
		$this->assertEquals( 'test', $mock->detailComponentAction() );
244
	}
245
246
247
	public function testFilterComponent()
248
	{
249
		$mock = $this->getMockBuilder( 'Aimeos\ShopBundle\Controller\CatalogController' )
250
			->setMethods( array( 'getOutput' ) )
251
			->disableOriginalConstructor()
252
			->getMock();
253
254
		$mock->expects( $this->once() )->method( 'getOutput' )->will( $this->returnValue( 'test' ) );
255
256
		$this->assertEquals( 'test', $mock->filterComponentAction() );
257
	}
258
259
260
	public function testListComponent()
261
	{
262
		$mock = $this->getMockBuilder( 'Aimeos\ShopBundle\Controller\CatalogController' )
263
			->setMethods( array( 'getOutput' ) )
264
			->disableOriginalConstructor()
265
			->getMock();
266
267
		$mock->expects( $this->once() )->method( 'getOutput' )->will( $this->returnValue( 'test' ) );
268
269
		$this->assertEquals( 'test', $mock->listComponentAction() );
270
	}
271
272
273
	public function testSessionComponent()
274
	{
275
		$mock = $this->getMockBuilder( 'Aimeos\ShopBundle\Controller\CatalogController' )
276
			->setMethods( array( 'getOutput' ) )
277
			->disableOriginalConstructor()
278
			->getMock();
279
280
		$mock->expects( $this->once() )->method( 'getOutput' )->will( $this->returnValue( 'test' ) );
281
282
		$this->assertEquals( 'test', $mock->sessionComponentAction() );
283
	}
284
285
286
	public function testStageComponent()
287
	{
288
		$mock = $this->getMockBuilder( 'Aimeos\ShopBundle\Controller\CatalogController' )
289
			->setMethods( array( 'getOutput' ) )
290
			->disableOriginalConstructor()
291
			->getMock();
292
293
		$mock->expects( $this->once() )->method( 'getOutput' )->will( $this->returnValue( 'test' ) );
294
295
		$this->assertEquals( 'test', $mock->stageComponentAction() );
296
	}
297
298
299
	public function testStockComponent()
300
	{
301
		$mock = $this->getMockBuilder( 'Aimeos\ShopBundle\Controller\CatalogController' )
302
			->setMethods( array( 'getOutput' ) )
303
			->disableOriginalConstructor()
304
			->getMock();
305
306
		$mock->expects( $this->once() )->method( 'getOutput' )->will( $this->returnValue( 'test' ) );
307
308
		$this->assertEquals( 'test', $mock->stockComponentAction() );
309
	}
310
}
311