Skip to content

Commit

Permalink
Fix leftover test data between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Oct 12, 2023
1 parent 72cc666 commit a492947
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public function actionUpdateCart(): ?Response
$qty = (int)$this->request->getParam('qty', 1);

if ($qty > 0) {

// We only want a new line item if they cleared the cart
if ($clearLineItems) {
$lineItem = Plugin::getInstance()->getLineItems()->createLineItem($this->_cart, $purchasableId, $options);
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/controllers/CartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ public function testAddSinglePurchasable(): void
self::assertCount(1, $cart->getLineItems());
self::assertSame(2, $cart->getTotalQty());
self::assertSame($variant->getSalePrice() * 2, $cart->getTotal());

if ($cart->id) {
Craft::$app->getElements()->deleteElement($cart, true);
}
}

/**
Expand Down Expand Up @@ -255,6 +259,10 @@ public function testAddMultiplePurchasablesLite(): void
self::assertSame($lastItem['qty'], $cart->getTotalQty());
$lineItem = $cart->getLineItems()[0];
self::assertEquals($lastItem['id'], $lineItem->purchasableId, 'The last line item to be added is the one in the cart');

if ($cart->id) {
Craft::$app->getElements()->deleteElement($cart, true);
}
}

/**
Expand Down Expand Up @@ -285,6 +293,10 @@ public function testAddMultiplePurchasables(): void
$cart = Plugin::getInstance()->getCarts()->getCart();

self::assertCount(2, $cart->getLineItems(), 'Has all items in the car');

if ($cart->id) {
Craft::$app->getElements()->deleteElement($cart, true);
}
}

/**
Expand Down Expand Up @@ -326,6 +338,10 @@ public function testAddAddressCustomFieldsOnUpdateCart(): void
self::assertEquals($shippingAddress['fields']['testPhone'], $cartShippingAddress->testPhone);
self::assertEquals($billingAddress['addressLine1'], $cartBillingAddress->addressLine1);
self::assertEquals($billingAddress['fields']['testPhone'], $cartBillingAddress->testPhone);

if ($cart->id) {
Craft::$app->getElements()->deleteElement($cart, true);
}
}

/**
Expand Down

0 comments on commit a492947

Please sign in to comment.