/** * Test get weight. */ public function testGetWeight() { $purchasable = $this->getMock('Elcodi\\Component\\Product\\Entity\\Interfaces\\PurchasableInterface'); $purchasable->method('getWeight')->will($this->returnValue(5)); $cartLine = new CartLine(); $cartLine->setPurchasable($purchasable); $cartLine->setQuantity(2); $this->assertEquals(10, $cartLine->getWeight()); $variant = $this->getMock('Elcodi\\Component\\Product\\Entity\\Interfaces\\VariantInterface'); $variant->method('getPurchasable')->will($this->returnValue($purchasable)); $variant->method('getWeight')->will($this->returnValue(10)); $cartLine = new CartLine(); $cartLine->setPurchasable($variant); $cartLine->setQuantity(3); $this->assertEquals(30, $cartLine->getWeight()); }
/** * 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()); }
/** * increaseCartLineQuantity with empty Cart * * @dataProvider dataDecreaseCartLineQuantityRemove * @group cart */ public function testDecreaseCartLineQuantityRemove($initialQuantity, $quantityToIncrease) { $cart = new Cart(); $cartLine = new CartLine(); $cartLine->setCart($cart); $cartLine->setQuantity($initialQuantity); $cart->setCartLines(new ArrayCollection(array($cartLine))); $this->cartManager->decreaseCartLineQuantity($cartLine, $quantityToIncrease); $this->assertEmpty($cart->getCartLines()); }