Skip to content

Commit f2f4c62

Browse files
committed
[TASK] Add some more acceptance tests for adding products to cart
Relates: #250
1 parent 3a60aba commit f2f4c62

5 files changed

+247
-2
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Extcode\CartProducts\Tests\Acceptance;
6+
7+
/*
8+
* This file is part of the package extcode/cart-products.
9+
*
10+
* For the full copyright and license information, please read the
11+
* LICENSE file that was distributed with this source code.
12+
*/
13+
14+
use Extcode\CartProducts\Tests\Acceptance\Support\Tester;
15+
16+
class AddConfigurableProductWithStockHandlingToCartCest
17+
{
18+
public function testAddDifferentItemsWithinAvailableAmountToCart(Tester $I): void
19+
{
20+
$I->amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=6&cHash=93520e7d2c5c85e6563ce0e5b8eba102');
21+
22+
$I->see('Configurable Product 2', 'h1');
23+
$I->see(' ', '#product-price .in-stock');
24+
25+
$I->dontSeeElement('#product-6 .form-message .form-success');
26+
$I->dontSeeElement('#product-6 .form-message .form-error');
27+
28+
$I->fillField('tx_cart_cart[quantity]', 1);
29+
$I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red');
30+
$I->click('#product-6.add-to-cart-form input.btn[type="submit"]');
31+
$I->see('In stock (5 pieces)', '#product-price .in-stock');
32+
33+
$I->see('Item was added to cart.', '#product-6 .form-message .form-success');
34+
$I->dontSeeElement('#product-6 .form-message .form-error');
35+
$I->wait(3);
36+
37+
$I->dontSeeElement('#product-6 .form-message .form-success');
38+
$I->dontSeeElement('#product-6 .form-message .form-error');
39+
40+
$I->fillField('tx_cart_cart[quantity]', 2);
41+
$I->selectOption('tx_cart_cart[beVariants][1]', 'M - green');
42+
$I->click('#product-6.add-to-cart-form input.btn[type="submit"]');
43+
$I->see('In stock (3 pieces)', '#product-price .in-stock');
44+
45+
$I->see('2 Items were added to cart.', '#product-6 .form-message .form-success');
46+
$I->dontSeeElement('#product-6 .form-message .form-error');
47+
$I->wait(3);
48+
49+
$I->dontSeeElement('#product-6 .form-message .form-success');
50+
$I->dontSeeElement('#product-6 .form-message .form-error');
51+
52+
$I->fillField('tx_cart_cart[quantity]', 4);
53+
$I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red');
54+
$I->click('#product-6.add-to-cart-form input.btn[type="submit"]');
55+
$I->see('In stock (5 pieces)', '#product-price .in-stock');
56+
57+
$I->see('4 Items were added to cart.', '#product-6 .form-message .form-success');
58+
$I->dontSeeElement('#product-6 .form-message .form-error');
59+
$I->wait(3);
60+
61+
$I->dontSeeElement('#product-6 .form-message .form-success');
62+
$I->dontSeeElement('#product-6 .form-message .form-error');
63+
}
64+
65+
public function testAddMoreItemsThanInStockOfASimpleProductToCart(Tester $I): void
66+
{
67+
$I->amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=6&cHash=93520e7d2c5c85e6563ce0e5b8eba102');
68+
69+
$I->see('Configurable Product 2', 'h1');
70+
$I->see(' ', '#product-price .in-stock');
71+
72+
$I->dontSeeElement('#product-6 .form-message .form-success');
73+
$I->dontSeeElement('#product-6 .form-message .form-error');
74+
75+
$I->fillField('tx_cart_cart[quantity]', 6);
76+
$I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red');
77+
$I->click('#product-6.add-to-cart-form input.btn[type="submit"]');
78+
$I->see('In stock (5 pieces)', '#product-price .in-stock');
79+
80+
$I->dontSeeElement('#product-6 .form-message .form-success');
81+
$I->see('Desired number of this item not available.', '#product-6 .form-message .form-error');
82+
83+
$I->wait(3);
84+
85+
$I->dontSeeElement('#product-6 .form-message .form-success');
86+
$I->dontSeeElement('#product-6 .form-message .form-error');
87+
}
88+
89+
public function testAddOneAndThanMoreItemsThanInStockOfASimpleProductToCart(Tester $I): void
90+
{
91+
$I->amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=6&cHash=93520e7d2c5c85e6563ce0e5b8eba102');
92+
93+
$I->see('Configurable Product 2', 'h1');
94+
$I->see(' ', '#product-price .in-stock');
95+
96+
$I->dontSeeElement('#product-6 .form-message .form-success');
97+
$I->dontSeeElement('#product-6 .form-message .form-error');
98+
99+
$I->fillField('tx_cart_cart[quantity]', 1);
100+
$I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red');
101+
$I->click('#product-6.add-to-cart-form input.btn[type="submit"]');
102+
$I->see('In stock (5 pieces)', '#product-price .in-stock');
103+
104+
$I->see('Item was added to cart.', '#product-6 .form-message .form-success');
105+
$I->dontSeeElement('#product-6 .form-message .form-error');
106+
$I->wait(3);
107+
108+
$I->dontSeeElement('#product-6 .form-message .form-success');
109+
$I->dontSeeElement('#product-6 .form-message .form-error');
110+
111+
$I->fillField('tx_cart_cart[quantity]', 5);
112+
$I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red');
113+
$I->click('#product-6.add-to-cart-form input.btn[type="submit"]');
114+
$I->see('In stock (5 pieces)', '#product-price .in-stock');
115+
116+
$I->dontSeeElement('#product-6 .form-message .form-success');
117+
$I->see('Desired number of this item not available.', '#product-6 .form-message .form-error');
118+
119+
$I->wait(3);
120+
121+
$I->dontSeeElement('#product-6 .form-message .form-success');
122+
$I->dontSeeElement('#product-6 .form-message .form-error');
123+
}
124+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Extcode\CartProducts\Tests\Acceptance;
6+
7+
/*
8+
* This file is part of the package extcode/cart-products.
9+
*
10+
* For the full copyright and license information, please read the
11+
* LICENSE file that was distributed with this source code.
12+
*/
13+
14+
use Extcode\CartProducts\Tests\Acceptance\Support\Tester;
15+
16+
class AddConfigurableProductWithoutStockHandlingToCartCest
17+
{
18+
public function testAddDifferentItemsToCart(Tester $I): void
19+
{
20+
$I->amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=5&cHash=4c2d7ef7c3ec394907ad93a1a0434fc8');
21+
22+
$I->see('Configurable Product 1', 'h1');
23+
$I->dontSeeElement('#product-price .in-stock');
24+
25+
$I->dontSeeElement('#product-5 .form-message .form-success');
26+
$I->dontSeeElement('#product-5 .form-message .form-error');
27+
28+
$I->fillField('tx_cart_cart[quantity]', 1);
29+
$I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red');
30+
$I->click('#product-5.add-to-cart-form input.btn[type="submit"]');
31+
32+
$I->see('Item was added to cart.', '#product-5 .form-message .form-success');
33+
$I->dontSeeElement('#product-5 .form-message .form-error');
34+
$I->wait(3);
35+
36+
$I->dontSeeElement('#product-5 .form-message .form-success');
37+
$I->dontSeeElement('#product-5 .form-message .form-error');
38+
39+
$I->fillField('tx_cart_cart[quantity]', 2);
40+
$I->selectOption('tx_cart_cart[beVariants][1]', 'M - green');
41+
$I->click('#product-5.add-to-cart-form input.btn[type="submit"]');
42+
43+
$I->see('2 Items were added to cart.', '#product-5 .form-message .form-success');
44+
$I->dontSeeElement('#product-5 .form-message .form-error');
45+
$I->wait(3);
46+
47+
$I->dontSeeElement('#product-5 .form-message .form-success');
48+
$I->dontSeeElement('#product-5 .form-message .form-error');
49+
50+
$I->fillField('tx_cart_cart[quantity]', 100);
51+
$I->selectOption('tx_cart_cart[beVariants][1]', 'XL - red');
52+
$I->click('#product-5.add-to-cart-form input.btn[type="submit"]');
53+
54+
$I->see('100 Items were added to cart.', '#product-5 .form-message .form-success');
55+
$I->dontSeeElement('#product-5 .form-message .form-error');
56+
$I->wait(3);
57+
58+
$I->dontSeeElement('#product-5 .form-message .form-success');
59+
$I->dontSeeElement('#product-5 .form-message .form-error');
60+
}
61+
}

Tests/Acceptance/AddSimpleProductToCartCest.php renamed to Tests/Acceptance/AddSimpleProductWithStockHandlingToCartCest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
use Extcode\CartProducts\Tests\Acceptance\Support\Tester;
1515

16-
class AddSimpleProductToCartCest
16+
class AddSimpleProductWithStockHandlingToCartCest
1717
{
18-
public function testAddOneAndTwoItemsOfASimpleProductToCart(Tester $I): void
18+
public function testAddDifferentItemsWithinAvailableAmountToCart(Tester $I): void
1919
{
2020
$I->amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=1&cHash=275cce22d935c04473314c31f46f7ada');
2121

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Extcode\CartProducts\Tests\Acceptance;
6+
7+
/*
8+
* This file is part of the package extcode/cart-products.
9+
*
10+
* For the full copyright and license information, please read the
11+
* LICENSE file that was distributed with this source code.
12+
*/
13+
14+
use Extcode\CartProducts\Tests\Acceptance\Support\Tester;
15+
16+
class AddSimpleProductWithoutStockHandlingToCartCest
17+
{
18+
public function testAddDifferentItemsToCart(Tester $I): void
19+
{
20+
$I->amOnUrl('http://127.0.0.1:8080/product?tx_cartproducts_showproduct%5Baction%5D=show&tx_cartproducts_showproduct%5Bcontroller%5D=Product&tx_cartproducts_showproduct%5Bproduct%5D=2&cHash=36af38e6c5bbac81dcd80c3a3c53f4a1');
21+
22+
$I->see('Simple Product 2', 'h1');
23+
$I->dontSeeElement('#product-price .in-stock');
24+
25+
$I->dontSeeElement('#product-2 .form-message .form-success');
26+
$I->dontSeeElement('#product-2 .form-message .form-error');
27+
28+
$I->fillField('tx_cart_cart[quantity]', 1);
29+
$I->click('#product-2.add-to-cart-form input.btn[type="submit"]');
30+
31+
$I->see('Item was added to cart.', '#product-2 .form-message .form-success');
32+
$I->dontSeeElement('#product-2 .form-message .form-error');
33+
$I->wait(3);
34+
35+
$I->dontSeeElement('#product-2 .form-message .form-success');
36+
$I->dontSeeElement('#product-2 .form-message .form-error');
37+
38+
$I->fillField('tx_cart_cart[quantity]', 2);
39+
$I->click('#product-2.add-to-cart-form input.btn[type="submit"]');
40+
41+
$I->see('2 Items were added to cart.', '#product-2 .form-message .form-success');
42+
$I->dontSeeElement('#product-2 .form-message .form-error');
43+
$I->wait(3);
44+
45+
$I->dontSeeElement('#product-2 .form-message .form-success');
46+
$I->dontSeeElement('#product-2 .form-message .form-error');
47+
48+
$I->fillField('tx_cart_cart[quantity]', 100);
49+
$I->click('#product-2.add-to-cart-form input.btn[type="submit"]');
50+
51+
$I->see('100 Items were added to cart.', '#product-2 .form-message .form-success');
52+
$I->dontSeeElement('#product-2 .form-message .form-error');
53+
$I->wait(3);
54+
55+
$I->dontSeeElement('#product-2 .form-message .form-success');
56+
$I->dontSeeElement('#product-2 .form-message .form-error');
57+
}
58+
}

Tests/Fixtures/ProductsDatabase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
'description' => '',
2929
'path_segment' => 'simple-product-2',
3030
'price' => 19.99,
31+
'handle_stock' => 0,
32+
'stock' => 10,
3133
'related_products' => 1,
3234
],
3335
2 => [

0 commit comments

Comments
 (0)