Skip to content

Commit f7997c7

Browse files
authored
fix response when increasing number of item in cart is successful (#847)
* fix response when increasing number of item in cart is successful * fix tests to expect 302 redirect after adding a product to the cart
1 parent 99672e8 commit f7997c7

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/Cart/ShoppingCartController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ public function add($request): string|HTTPResponse|null
197197

198198
$result = $this->cart->add($product, $quantity, $request->getVars());
199199

200-
if ($result) {
201-
$response = $this->cart->getMessage();
202-
} else {
200+
if (!$result) {
203201
$response = $this->httpError(400, $this->cart->getMessage());
204202
}
205203
} else {

tests/php/Cart/ShoppingCartControllerTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ public function testAddToCart(): void
9898
$url = ShoppingCartController::add_item_link($this->mp3player);
9999
$httpResponse = $this->get($url);
100100

101-
$this->assertEquals(200, $httpResponse->getStatusCode(), "Adding the mp3 player should work");
101+
$this->assertEquals(302, $httpResponse->getStatusCode(), "Adding the mp3 player should work");
102102

103103
$secondMp3 = $this->get(ShoppingCartController::add_item_link($this->mp3player));
104-
$this->assertEquals(200, $secondMp3->getStatusCode(), "Adding a second mp3 player should work");
104+
$this->assertEquals(302, $secondMp3->getStatusCode(), "Adding a second mp3 player should work");
105105

106106
$socks = $this->get(ShoppingCartController::add_item_link($this->socks));
107-
$this->assertEquals(200, $socks->getStatusCode(), "Adding socks should work");
107+
$this->assertEquals(302, $socks->getStatusCode(), "Adding socks should work");
108108

109109
// add a product that you can't add
110110
$noPurchaseProduct = $this->get(ShoppingCartController::add_item_link($this->noPurchaseProduct));
@@ -220,7 +220,7 @@ public function testSecurityToken(): void
220220
$this->assertMatchesRegularExpression('{^shoppingcart/add/SilverShop-Page-Product/' . $productId . '\?SecurityID=[a-f0-9]+$}', $link);
221221

222222
$response = $this->get($link);
223-
$this->assertEquals($response->getStatusCode(), 200);
223+
$this->assertEquals(302, $response->getStatusCode());
224224

225225
// disable security token for cart-links
226226
Config::modify()->set(ShoppingCartController::class, 'disable_security_token', true);
@@ -229,7 +229,7 @@ public function testSecurityToken(): void
229229
$this->assertEquals('shoppingcart/add/SilverShop-Page-Product/' . $productId, $link);
230230

231231
$response = $this->get($link);
232-
$this->assertEquals($response->getStatusCode(), 200);
232+
$this->assertEquals(302, $response->getStatusCode());
233233

234234
SecurityToken::disable();
235235

@@ -238,12 +238,12 @@ public function testSecurityToken(): void
238238
$this->assertEquals('shoppingcart/add/SilverShop-Page-Product/' . $productId, $link);
239239

240240
$response = $this->get($link);
241-
$this->assertEquals($response->getStatusCode(), 200);
241+
$this->assertEquals(302, $response->getStatusCode());
242242

243243
SecurityToken::enable();
244244
// should now return a 400 status
245245
$response = $this->get($link);
246-
$this->assertEquals($response->getStatusCode(), 400);
246+
$this->assertEquals(400, $response->getStatusCode());
247247

248248
// restore previous setting
249249
if (!$enabled) {

0 commit comments

Comments
 (0)