mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
Added test for model using trait
Added readme for CanBeBoughtTrait https://github.com/Crinsane/LaravelShoppingcart/issues/427
This commit is contained in:
@@ -16,6 +16,7 @@ use Gloudemans\Shoppingcart\ShoppingcartServiceProvider;
|
||||
use Gloudemans\Tests\Shoppingcart\Fixtures\ProductModel;
|
||||
use Gloudemans\Tests\Shoppingcart\Fixtures\BuyableProduct;
|
||||
use Gloudemans\Tests\Shoppingcart\Fixtures\Identifiable;
|
||||
use Gloudemans\Tests\Shoppingcart\Fixtures\BuyableProductTrait;
|
||||
|
||||
class CartTest extends TestCase
|
||||
{
|
||||
@@ -1096,6 +1097,28 @@ class CartTest extends TestCase
|
||||
$this->assertItemsInCart(2, $cart);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function cart_can_create_items_from_models_using_the_canbebought_trait()
|
||||
{
|
||||
$cart = $this->getCartDiscount( 50 );
|
||||
|
||||
$cart->add(new BuyableProductTrait(1, 'First item', 10.00), 2);
|
||||
|
||||
$cartItem = $cart->get('027c91341fd5cf4d2579b49c4b6a90da');
|
||||
|
||||
$cart->setTax('027c91341fd5cf4d2579b49c4b6a90da', 19);
|
||||
|
||||
$this->assertEquals(10.00, $cartItem->price(2));
|
||||
$this->assertEquals(5.00, $cartItem->discount(2));
|
||||
$this->assertEquals(10.00, $cartItem->discountTotal(2));
|
||||
$this->assertEquals(5.00, $cartItem->priceTarget(2));
|
||||
$this->assertEquals(10.00, $cartItem->subtotal(2));
|
||||
$this->assertEquals(0.95, $cartItem->tax(2));
|
||||
$this->assertEquals(1.90, $cartItem->taxTotal(2));
|
||||
$this->assertEquals(5.95, $cartItem->priceTax(2));
|
||||
$this->assertEquals(11.90, $cartItem->total(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of the cart.
|
||||
*
|
||||
|
||||
45
tests/Fixtures/BuyableProductTrait.php
Normal file
45
tests/Fixtures/BuyableProductTrait.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Gloudemans\Tests\Shoppingcart\Fixtures;
|
||||
|
||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||
|
||||
class BuyableProductTrait implements Buyable
|
||||
{
|
||||
use \Gloudemans\Shoppingcart\CanBeBought;
|
||||
|
||||
/**
|
||||
* @var int|string
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $price;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $weight;
|
||||
|
||||
/**
|
||||
* BuyableProduct constructor.
|
||||
*
|
||||
* @param int|string $id
|
||||
* @param string $name
|
||||
* @param float $price
|
||||
*/
|
||||
public function __construct($id = 1, $name = 'Item name', $price = 10.00, $weight = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->price = $price;
|
||||
$this->weight = $weight;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user