コード例 #1
0
 public function testStackableCouponCalculatedAmount()
 {
     /**
      * Stackable Coupons from fixtures
      *
      * id 3: 12 % discount
      * id 4: 2 USD discount
      *
      * See CouponData fixtures for details
      *
      * @var Coupon $stacableCouponPercent
      * @var Coupon $stackableCouponAmount
      */
     $stackableCouponPercent = $this->find('coupon', 3);
     $stackableCouponAmount = $this->find('coupon', 4);
     $this->cartCouponManager->addCoupon($this->cart, $stackableCouponPercent->setEnabled(true));
     $this->cartCouponManager->addCoupon($this->cart, $stackableCouponAmount->setEnabled(true));
     /**
      * Dispatching cart.load events will recalculate
      * cart coupon amount
      */
     $this->cartEventDispatcher->dispatchCartLoadEvents($this->cart);
     $appliedCouponsAmount = $this->cart->getCouponAmount()->getAmount();
     $this->assertEquals(560, $appliedCouponsAmount);
 }
コード例 #2
0
ファイル: CartManagerTest.php プロジェクト: pramoddas/elcodi
 /**
  * removeProduct.
  *
  * @dataProvider dataRemoveProduct
  * @group        cart
  */
 public function testRemoveProduct($quantity, $productId, $quantityExpected)
 {
     /**
      * @var ProductInterface $product
      */
     $product = $this->getMock('Elcodi\\Component\\Product\\Entity\\Interfaces\\ProductInterface');
     $productToRemove = $this->getMock('Elcodi\\Component\\Product\\Entity\\Interfaces\\ProductInterface');
     $product->expects($this->any())->method('getId')->willReturn('1001');
     $cart = new Cart();
     $cartLine = new CartLine();
     $cartLine->setPurchasable($product);
     $cart->setCartLines(new ArrayCollection([$cartLine]));
     $cartLine->setCart($cart);
     $this->assertCount(1, $cart->getCartLines());
     $productToRemove->expects($this->any())->method('getId')->willReturn($productId);
     $this->cartManager->removePurchasable($cart, $productToRemove, $quantity);
     $this->assertCount($quantityExpected, $cart->getCartLines());
 }
コード例 #3
0
ファイル: CartTest.php プロジェクト: pramoddas/elcodi
 /**
  * Test get width.
  *
  * @dataProvider dataGetWeight
  */
 public function testGetWeight(array $weights, $total)
 {
     $cartLines = new ArrayCollection([]);
     foreach ($weights as $weight) {
         $cartLine = $this->getMock('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartLineInterface');
         $cartLine->method('getWeight')->will($this->returnValue($weight));
         $cartLines->add($cartLine);
     }
     $cart = new Cart();
     $cart->setCartLines($cartLines);
     $this->assertEquals($total, $cart->getWeight());
 }
コード例 #4
0
 /**
  * test Create Order from Cart.
  *
  * @group order
  */
 public function testCreateOrderFromCartNewOrderExistingOrder()
 {
     /**
      * @var OrderInterface    $order
      * @var CurrencyInterface $currency
      */
     $order = $this->getMock('Elcodi\\Component\\Cart\\Entity\\Order', null);
     $currency = $this->getMock('Elcodi\\Component\\Currency\\Entity\\Currency', null);
     $currency->setIso('EUR');
     $this->orderFactory->expects($this->never())->method('create')->will($this->returnValue($order));
     $this->cartLineOrderLineTransformer->expects($this->any())->method('createOrderLinesByCartLines')->will($this->returnValue(new ArrayCollection()));
     $customer = new Customer();
     $cart = new Cart();
     $cart->setCustomer($customer)->setPurchasableAmount(Money::create(20, $currency))->setCouponAmount(Money::create(0, $currency))->setOrder($order)->setShippingAmount($this->getMock('Elcodi\\Component\\Currency\\Entity\\Interfaces\\MoneyInterface'))->setAmount(Money::create(20, $currency))->setCartLines(new ArrayCollection());
     $this->cartOrderTransformer->createOrderFromCart($cart);
 }
コード例 #5
0
ファイル: CartManagerTest.php プロジェクト: hd-deman/elcodi
 /**
  * addProduct
  *
  * @dataProvider dataAddProduct
  * @group cart
  */
 public function testAddProduct($quantity, $productCreated, $quantityExpected)
 {
     $cartLine = new CartLine();
     $this->cartLineFactory->expects($this->exactly(intval($productCreated)))->method('create')->will($this->returnValue($cartLine));
     /**
      * @var ProductInterface $product
      */
     $product = $this->getMock('Elcodi\\Component\\Product\\Entity\\Interfaces\\ProductInterface');
     $cart = new Cart();
     $cart->setCartLines(new ArrayCollection());
     $this->cartManager->addProduct($cart, $product, $quantity);
     if ($productCreated) {
         $createdLine = $cart->getCartLines()->first();
         $createdProduct = $createdLine->getProduct();
         $this->assertCount(1, $cart->getCartLines());
         $this->assertInstanceOf('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartLineInterface', $createdLine);
         $this->assertSame($createdProduct, $product);
         $this->assertEquals($createdLine->getQuantity(), $quantityExpected);
     } else {
         $this->assertCount(0, $cart->getCartLines());
     }
 }