Beispiel #1
0
 /**
  * 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());
 }
Beispiel #2
0
 /**
  * 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());
 }
Beispiel #3
0
 /**
  * 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());
     }
 }