mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-23 07:31:31 +00:00
Remove item when qty is a negative number + test, also added test for multiple options
This commit is contained in:
@@ -427,6 +427,7 @@ class Cart {
|
|||||||
*/
|
*/
|
||||||
protected function updateQty($rowId, $qty)
|
protected function updateQty($rowId, $qty)
|
||||||
{
|
{
|
||||||
|
if($qty <= 0)
|
||||||
if($qty == 0)
|
if($qty == 0)
|
||||||
{
|
{
|
||||||
return $this->remove($rowId);
|
return $this->remove($rowId);
|
||||||
|
|||||||
@@ -50,6 +50,19 @@ class CartTest extends PHPUnit_Framework_TestCase {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCartCanAddMultipleOptions()
|
||||||
|
{
|
||||||
|
$this->events->shouldReceive('fire')->once()->with('cart.add', m::type('array'));
|
||||||
|
|
||||||
|
$this->cart->add('293ad', 'Product 1', 1, 9.99, array('size' => 'large', 'color' => 'red'));
|
||||||
|
|
||||||
|
$cartRow = $this->cart->get('c5417b5761c7fb837e4227a38870dd4d');
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Gloudemans\Shoppingcart\CartRowOptionsCollection', $cartRow->options);
|
||||||
|
$this->assertEquals('large', $cartRow->options->size);
|
||||||
|
$this->assertEquals('red', $cartRow->options->color);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Gloudemans\Shoppingcart\Exceptions\ShoppingcartInvalidItemException
|
* @expectedException Gloudemans\Shoppingcart\Exceptions\ShoppingcartInvalidItemException
|
||||||
*/
|
*/
|
||||||
@@ -154,6 +167,18 @@ class CartTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertTrue($this->cart->content()->isEmpty());
|
$this->assertTrue($this->cart->content()->isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCartCanRemoveOnNegativeUpdate()
|
||||||
|
{
|
||||||
|
$this->events->shouldReceive('fire')->once()->with('cart.add', m::type('array'));
|
||||||
|
$this->events->shouldReceive('fire')->once()->with('cart.update', m::type('string'));
|
||||||
|
$this->events->shouldReceive('fire')->once()->with('cart.remove', m::type('string'));
|
||||||
|
|
||||||
|
$this->cart->add('293ad', 'Product 1', 1, 9.99);
|
||||||
|
$this->cart->update('8cbf215baa3b757e910e5305ab981172', -1);
|
||||||
|
|
||||||
|
$this->assertTrue($this->cart->content()->isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
public function testCartCanGet()
|
public function testCartCanGet()
|
||||||
{
|
{
|
||||||
$this->events->shouldReceive('fire')->once()->with('cart.add', m::type('array'));
|
$this->events->shouldReceive('fire')->once()->with('cart.add', m::type('array'));
|
||||||
|
|||||||
Reference in New Issue
Block a user