mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 22:01:48 +00:00
fix tests
This commit is contained in:
+27
-1
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Wearepixel\Cart;
|
namespace Wearepixel\Cart;
|
||||||
|
|
||||||
|
use Wearepixel\Cart\Exceptions\InvalidConditionException;
|
||||||
use Wearepixel\Cart\Helpers\Helpers;
|
use Wearepixel\Cart\Helpers\Helpers;
|
||||||
use Wearepixel\Cart\Validators\CartItemValidator;
|
use Wearepixel\Cart\Validators\CartItemValidator;
|
||||||
use Wearepixel\Cart\Exceptions\InvalidItemException;
|
use Wearepixel\Cart\Exceptions\InvalidItemException;
|
||||||
@@ -296,6 +297,11 @@ public function clear()
|
|||||||
/**
|
/**
|
||||||
* Adds a condition to the cart
|
* Adds a condition to the cart
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* Adds a condition to the cart
|
||||||
|
*
|
||||||
|
* @throws InvalidConditionException
|
||||||
|
*/
|
||||||
public function condition(array|CartCondition $condition): self
|
public function condition(array|CartCondition $condition): self
|
||||||
{
|
{
|
||||||
if (is_array($condition)) {
|
if (is_array($condition)) {
|
||||||
@@ -306,7 +312,27 @@ public function condition(array|CartCondition $condition): self
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->condition($condition);
|
if (! $condition instanceof CartCondition) {
|
||||||
|
throw new InvalidConditionException('Argument 1 must be an instance of \'Wearepixel\Cart\CartCondition\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
$conditions = $this->getConditions();
|
||||||
|
|
||||||
|
// Check if order has been applied
|
||||||
|
if ($condition->getOrder() == 0) {
|
||||||
|
$last = $conditions->last();
|
||||||
|
$condition->setOrder(! is_null($last) ? $last->getOrder() + 1 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$conditions->put($condition->getName(), $condition);
|
||||||
|
|
||||||
|
$conditions = $conditions->sortBy(function ($condition, $key) {
|
||||||
|
return $condition->getOrder();
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->saveConditions($conditions);
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1077,13 +1077,13 @@
|
|||||||
|
|
||||||
$this->cart->add($item);
|
$this->cart->add($item);
|
||||||
|
|
||||||
$this->cart->addConditions([$shipping, $tax]);
|
$this->cart->condition([$shipping, $tax]);
|
||||||
|
|
||||||
// let's prove first we have now two conditions in the cart
|
// let's prove first we have now two conditions in the cart
|
||||||
expect($this->cart->getConditions()->count())->toEqual(2, 'Cart should have two conditions');
|
expect($this->cart->getConditions()->count())->toEqual(2, 'Cart should have two conditions');
|
||||||
|
|
||||||
// now let's remove a specific condition by condition name
|
// now let's remove a specific condition by condition name
|
||||||
$this->cart->removeCondition('Tax');
|
$this->cart->removeCartCondition('Tax');
|
||||||
|
|
||||||
// cart should have now only 1 condition
|
// cart should have now only 1 condition
|
||||||
expect($this->cart->getConditions()->count())->toEqual(1, 'Cart should have one condition');
|
expect($this->cart->getConditions()->count())->toEqual(1, 'Cart should have one condition');
|
||||||
|
|||||||
Reference in New Issue
Block a user