This reverts commit 5d117a0acd.
This commit is contained in:
Patrick Henninger
2019-01-09 12:22:25 +01:00
parent 13238f9883
commit 55f1c4617f
7 changed files with 21 additions and 211 deletions

View File

@@ -22,7 +22,7 @@ class CartItemTest extends TestCase
/** @test */
public function it_can_be_cast_to_an_array()
{
$cartItem = new CartItem(1, 'Some item', 10.00, 550, ['size' => 'XL', 'color' => 'red']);
$cartItem = new CartItem(1, 'Some item', 10.00, ['size' => 'XL', 'color' => 'red']);
$cartItem->setQuantity(2);
$this->assertEquals([
@@ -37,20 +37,19 @@ class CartItemTest extends TestCase
],
'tax' => 0,
'subtotal' => 20.00,
'discount' => 0.0,
'weight' => 550.0
'discount' => 0.0
], $cartItem->toArray());
}
/** @test */
public function it_can_be_cast_to_json()
{
$cartItem = new CartItem(1, 'Some item', 10.00, 550, ['size' => 'XL', 'color' => 'red']);
$cartItem = new CartItem(1, 'Some item', 10.00, ['size' => 'XL', 'color' => 'red']);
$cartItem->setQuantity(2);
$this->assertJson($cartItem->toJson());
$json = '{"rowId":"07d5da5550494c62daf9993cf954303f","id":1,"name":"Some item","qty":2,"price":10,"weight":550,"options":{"size":"XL","color":"red"},"discount":0,"tax":0,"subtotal":20}';
$json = '{"rowId":"07d5da5550494c62daf9993cf954303f","id":1,"name":"Some item","qty":2,"price":10,"options":{"size":"XL","color":"red"},"discount":0,"tax":0,"subtotal":20}';
$this->assertEquals($json, $cartItem->toJson());
}

View File

@@ -488,8 +488,7 @@ class CartTest extends TestCase
'tax' => 2.10,
'subtotal' => 10.0,
'options' => [],
'discount' => 0.0,
'weight' => 0.0
'discount' => 0.0
],
'370d08585360f5c568b18d1f2e4ca1df' => [
'rowId' => '370d08585360f5c568b18d1f2e4ca1df',
@@ -500,8 +499,7 @@ class CartTest extends TestCase
'tax' => 2.10,
'subtotal' => 10.0,
'options' => [],
'discount' => 0.0,
'weight' => 0.0
'discount' => 0.0
]
], $content->toArray());
}
@@ -999,101 +997,6 @@ class CartTest extends TestCase
$this->assertEquals(10, $cart3->totalFloat());
}
/** @test */
public function it_cant_merge_non_existing_cart()
{
$this->artisan('migrate', [
'--database' => 'testing',
]);
Event::fake();
$cart = $this->getCartDiscount(50);
$cart->add( new BuyableProduct(1, 'Item', 10.00), 1);
$cart->add( new BuyableProduct(2, 'Item 2', 10.00), 1);
$this->assertEquals(false, $cart->merge('doesNotExist'));
$this->assertEquals(2, $cart->countInstances());
}
/** @test */
public function cart_can_calculate_all_values()
{
$cart = $this->getCartDiscount( 50 );
$cart->add(new BuyableProduct(1, 'First item', 10.00), 1);
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
$cart->setTax('027c91341fd5cf4d2579b49c4b6a90da', 19);
$this->assertEquals('10.00', $cart->initial(2));
$this->assertEquals(10.00, $cart->initialFloat());
$this->assertEquals('5.00', $cart->discount(2));
$this->assertEquals(5.00, $cart->discountFloat());
$this->assertEquals('5.00', $cart->subtotal(2));
$this->assertEquals(5.00, $cart->subtotalFloat());
$this->assertEquals('0.95', $cart->tax(2));
$this->assertEquals(0.95, $cart->taxFloat());
$this->assertEquals('5.95', $cart->total(2));
$this->assertEquals(5.95, $cart->totalFloat());
}
/** @test */
public function can_access_cart_item_propertys()
{
$cart = $this->getCartDiscount( 50 );
$cart->add(new BuyableProduct(1, 'First item', 10.00), 1);
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
$this->assertEquals(50, $cartItem->discountRate);
}
/** @test */
public function cant_access_non_existant_propertys()
{
$cart = $this->getCartDiscount( 50 );
$cart->add(new BuyableProduct(1, 'First item', 10.00), 1);
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
$this->assertEquals(null, $cartItem->doesNotExist);
$this->assertEquals(null, $cart->doesNotExist);
}
/** @test */
public function can_set_cart_item_discount()
{
$cart = $this->getCart();
$cart->add(new BuyableProduct(1, 'First item', 10.00), 1);
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
$cart->setDiscount('027c91341fd5cf4d2579b49c4b6a90da', 50);
$this->assertEquals(50, $cartItem->discountRate);
}
/** @test */
public function can_set_cart_item_weight_and_calculate_total_weight()
{
$cart = $this->getCart();
$cart->add(new BuyableProduct(1, 'First item', 10.00, 250), 2);
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
$cart->setDiscount('027c91341fd5cf4d2579b49c4b6a90da', 50);
$this->assertEquals('500.00', $cart->weight(2));
$this->assertEquals(500.00, $cart->weightFloat());
$this->assertEquals(500.00, $cartItem->weightTotal);
}
/**
* Get an instance of the cart.
*

View File

@@ -28,12 +28,11 @@ class BuyableProduct implements Buyable
* @param string $name
* @param float $price
*/
public function __construct($id = 1, $name = 'Item name', $price = 10.00, $weight = 0)
public function __construct($id = 1, $name = 'Item name', $price = 10.00)
{
$this->id = $id;
$this->name = $name;
$this->price = $price;
$this->weight = $weight;
}
/**
@@ -65,14 +64,4 @@ class BuyableProduct implements Buyable
{
return $this->price;
}
/**
* Get the price of the Buyable item.
*
* @return float
*/
public function getBuyableWeight($options = null)
{
return $this->weight;
}
}