Passed
Push — master ( 5c3d72...4f9848 )
by Aimeos
03:17
created

BasketControllerTest::testRelatedComponent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 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
	protected function setUp() : void
11
	{
12
		\Aimeos\MShop::cache( false );
13
		\Aimeos\Controller\Frontend::cache( false );
14
15
		(new \Symfony\Component\Filesystem\Filesystem())->remove( __DIR__ . '/../Fixtures/var/cache/sessions' );
16
	}
17
18
19
	public function testStandardAdd()
20
	{
21
		$client = static::createClient();
22
23
		$crawler = $client->request( 'GET', '/unittest/de/EUR/shop/' );
24
25
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
26
		$crawler = $client->click( $link );
27
28
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
29
		$crawler = $client->submit( $form );
30
31
		$this->assertEquals( 1, $crawler->filter( '.basket:contains("Unittest: Bundle")' )->count() );
32
		$this->assertEquals( 1, $crawler->filter( '.basket .product-item .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/shop/' );
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 );
48
49
		$this->assertEquals( 1, $crawler->filter( '.basket:contains("Unittest: Bundle")' )->count() );
50
		$this->assertEquals( 2, $crawler->filter( '.basket .product-item .quantity .value' )->attr( 'value' ) );
51
	}
52
53
54
	public function testStandardAddTwice()
55
	{
56
		$client = static::createClient();
57
58
		$crawler = $client->request( 'GET', '/unittest/de/EUR/shop/' );
59
60
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
61
		$crawler = $client->click( $link );
62
63
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
64
		$crawler = $client->submit( $form );
65
66
		$this->assertEquals( 1, $crawler->filter( '.basket:contains("Unittest: Bundle")' )->count() );
67
		$this->assertEquals( 1, $crawler->filter( '.basket .product-item .quantity .value' )->attr( 'value' ) );
68
69
70
		$link = $crawler->filter( '.basket-standard .btn-back' )->link();
71
		$crawler = $client->click( $link );
72
73
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
74
		$crawler = $client->submit( $form );
75
76
		$this->assertEquals( 1, $crawler->filter( '.basket:contains("Unittest: Bundle")' )->count() );
77
		$this->assertEquals( 2, $crawler->filter( '.basket .product-item .quantity .value' )->attr( 'value' ) );
78
	}
79
80
81
	public function testStandardDelete()
82
	{
83
		$client = static::createClient();
84
85
		$crawler = $client->request( 'GET', '/unittest/de/EUR/shop/' );
86
87
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
88
		$crawler = $client->click( $link );
89
90
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
91
		$crawler = $client->submit( $form );
92
93
94
		$link = $crawler->filter( '.basket-standard .product-item .action .delete' )->link();
95
		$crawler = $client->click( $link );
96
97
		$this->assertEquals( 0, $crawler->filter( '.basket-standard .product' )->count() );
98
	}
99
100
101
	public function testStandardEdit()
102
	{
103
		$client = static::createClient();
104
105
		$crawler = $client->request( 'GET', '/unittest/de/EUR/shop/' );
106
107
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
108
		$crawler = $client->click( $link );
109
110
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
111
		$crawler = $client->submit( $form );
112
113
114
		$link = $crawler->filter( '.basket-standard .product-item .quantity .change' )->link();
115
		$crawler = $client->click( $link );
116
117
		$this->assertEquals( 2, $crawler->filter( '.basket-standard .product-item .quantity .value' )->attr( 'value' ) );
118
119
120
		$link = $crawler->filter( '.basket-standard .product-item .quantity .change' )->eq( 0 )->link();
121
		$crawler = $client->click( $link );
122
123
		$this->assertEquals( 1, $crawler->filter( '.basket-standard .product-item .quantity .value' )->attr( 'value' ) );
124
	}
125
126
127
	public function testStandardUpdate()
128
	{
129
		$client = static::createClient();
130
131
		$crawler = $client->request( 'GET', '/unittest/de/EUR/shop/' );
132
133
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
134
		$crawler = $client->click( $link );
135
136
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
137
		$crawler = $client->submit( $form );
138
139
		$form = $crawler->filter( '.basket-standard .btn-update' )->form();
140
		$form['b_prod[0][quantity]'] = 3;
141
		$crawler = $client->submit( $form );
142
143
		$this->assertEquals( 3, $crawler->filter( '.basket-standard .product-item .quantity .value' )->attr( 'value' ) );
144
	}
145
146
147
	public function testStandardCoupon()
148
	{
149
		$client = static::createClient();
150
151
		$crawler = $client->request( 'GET', '/unittest/de/EUR/shop/' );
152
153
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
154
		$crawler = $client->click( $link );
155
156
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
157
		$crawler = $client->submit( $form );
158
159
160
		$form = $crawler->filter( '.basket-standard-coupon .coupon-new button' )->form();
161
		$form['b_coupon'] = '90AB';
162
		$crawler = $client->submit( $form );
163
164
		$this->assertEquals( 1, $crawler->filter( '.basket .product-name:contains("Geldwerter Nachlass")' )->count() );
165
166
167
		$link = $crawler->filter( '.basket-standard-coupon .delete' )->link();
168
		$crawler = $client->click( $link );
169
170
		$this->assertEquals( 1, $crawler->filter( '.basket-standard .product-item' )->count() );
171
	}
172
173
174
	public function testStandardRelated()
175
	{
176
		$client = static::createClient();
177
178
		$crawler = $client->request( 'GET', '/unittest/de/EUR/shop/' );
179
180
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Cafe Noire Expresso")' )->link();
181
		$crawler = $client->click( $link );
182
183
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
184
		$crawler = $client->submit( $form );
185
186
		$this->assertEquals( 1, $crawler->filter( '.basket-related-bought .product' )->count() );
187
	}
188
189
190
	public function testStandardBack()
191
	{
192
		$client = static::createClient();
193
194
		$crawler = $client->request( 'GET', '/unittest/de/EUR/shop/' );
195
196
		$link = $crawler->filter( '.catalog-list-items .product a:contains("Unittest: Bundle")' )->link();
197
		$crawler = $client->click( $link );
198
199
		$form = $crawler->filter( '.catalog-detail .addbasket .btn-primary' )->form();
200
		$crawler = $client->submit( $form );
201
202
		$link = $crawler->filter( '.basket-standard .btn-back' )->link();
203
		$crawler = $client->click( $link );
204
205
		$this->assertEquals( 1, $crawler->filter( '.catalog-detail .product:contains("Unittest: Bundle")' )->count() );
206
	}
207
}
208