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

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