setProduct() public method

public setProduct ( $productCode, Sonata\Component\Product\ProductInterface $product )
$product Sonata\Component\Product\ProductInterface
 public function testGettersSetters()
 {
     $currency = $this->getMock('Sonata\\Component\\Currency\\Currency');
     $productProvider = $this->getMock('Sonata\\Component\\Product\\ProductProviderInterface');
     $productManager = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $productDefinition = new ProductDefinition($productProvider, $productManager);
     $basketElement = new BasketElement();
     $basketElement->setProductDefinition($productDefinition);
     $this->assertEquals(0, $basketElement->getVatRate());
     $this->assertEquals(0, $basketElement->getUnitPrice($currency));
     $this->assertFalse($basketElement->isValid());
     $provider = $this->getMock('Sonata\\Component\\Product\\ProductProviderInterface');
     $manager = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $productDefinition = new ProductDefinition($provider, $manager);
     // Tests getProduct
     $this->assertNull($basketElement->getProduct());
     $basketElement->setProductDefinition($productDefinition);
     $this->assertNull($basketElement->getProduct());
     $product = $this->getMock('Sonata\\Component\\Product\\ProductInterface');
     $product->expects($this->any())->method('getId')->will($this->returnValue(42));
     $basketElement->setProduct('product_code', $product);
     $this->assertEquals($product, $basketElement->getProduct());
     // Tests setProductId
     $basketElement->setProductId(42);
     $this->assertEquals(42, $basketElement->getProductId());
     $basketElement->setProductId(24);
     $this->assertNull($basketElement->getProductId());
     $manager->expects($this->any())->method('findOneBy')->will($this->returnValue($product));
     $basketElement->setProductDefinition(new ProductDefinition($provider, $manager));
     $basketElement->setProductId(42);
     $basketElement->setProduct('product_code', $product);
     // Done by the provider hereby mocked, hence we do it manually
     $this->assertEquals($product->getId(), $basketElement->getProductId());
     // Options
     $options = array('option1' => 'value1', 'option2' => 'value2');
     $basketElement->setOptions($options);
     $this->assertNull($basketElement->getOption('unexisting_option'));
     $this->assertEquals(42, $basketElement->getOption('unexisting_option', 42));
     $this->assertEquals('value1', $basketElement->getOption('option1'));
     $this->assertEquals($options, $basketElement->getOptions());
     $basketElement->setOption('option3', 'value3');
     $this->assertEquals('value3', $basketElement->getOption('option3'));
     // Other getters & setters
     $this->assertEquals($provider, $basketElement->getProductProvider());
     $this->assertEquals($manager, $basketElement->getProductManager());
     $this->assertEquals('product_code', $basketElement->getProductCode());
     $basketElement->setDelete(false);
     $this->assertFalse($basketElement->getDelete());
 }
示例#2
0
 public function testGettersSetters()
 {
     $basket = $this->getPreparedBasket();
     $product = $this->getMockProduct();
     $basketElement = new BasketElement();
     $basketElement->setProduct('product_code', $product);
     $basket->setBasketElements(array($basketElement));
     $this->assertEquals(array($basketElement), $basket->getBasketElements());
     $basket->setDeliveryAddressId(1);
     $this->assertEquals(1, $basket->getDeliveryAddressId());
     $basket->setBillingAddressId(1);
     $this->assertEquals(1, $basket->getBillingAddressId());
     $deliveryMethod = $this->getMock('Sonata\\Component\\Delivery\\ServiceDeliveryInterface');
     $deliveryMethod->expects($this->any())->method('getCode')->will($this->returnValue(1));
     $basket->setDeliveryMethod($deliveryMethod);
     $this->assertEquals(1, $basket->getDeliveryMethodCode());
     $paymentMethod = $this->getMock('Sonata\\Component\\Payment\\PaymentInterface');
     $paymentMethod->expects($this->any())->method('getCode')->will($this->returnValue(1));
     $basket->setPaymentMethod($paymentMethod);
     $this->assertEquals(1, $basket->getPaymentMethodCode());
     $basket->setCustomerId(1);
     $this->assertEquals(1, $basket->getCustomerId());
     $options = array('option1' => 'value1', 'option2' => 'value2');
     $basket->setOptions($options);
     $this->assertNull($basket->getOption('unexisting_option'));
     $this->assertEquals(42, $basket->getOption('unexisting_option', 42));
     $this->assertEquals('value1', $basket->getOption('option1'));
     $this->assertEquals($options, $basket->getOptions());
     $basket->setOption('option3', 'value3');
     $this->assertEquals('value3', $basket->getOption('option3'));
     $basket->setLocale('en');
     $this->assertEquals('en', $basket->getLocale());
 }
 public function testOrderElement()
 {
     $product = $this->getMock('Sonata\\Component\\Product\\ProductInterface');
     $product->expects($this->any())->method('getId')->will($this->returnValue(42));
     $product->expects($this->any())->method('getName')->will($this->returnValue('Product name'));
     $product->expects($this->any())->method('getPrice')->will($this->returnValue(9.99));
     $product->expects($this->any())->method('getOptions')->will($this->returnValue(array('foo' => 'bar')));
     $product->expects($this->any())->method('getDescription')->will($this->returnValue('product description'));
     $productProvider = new ProductProviderTest($this->getMock('JMS\\Serializer\\SerializerInterface'));
     $productProvider->setCurrencyPriceCalculator(new CurrencyPriceCalculator());
     $productManager = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $productDefinition = new ProductDefinition($productProvider, $productManager);
     $basketElement = new BasketElement();
     $basketElement->setProduct('product_code', $product);
     $basketElement->setProductDefinition($productDefinition);
     $provider = $this->getBaseProvider();
     $orderElement = $provider->createOrderElement($basketElement);
     $this->assertInstanceOf('Sonata\\Component\\Order\\OrderElementInterface', $orderElement);
     $this->assertEquals(OrderInterface::STATUS_PENDING, $orderElement->getStatus());
     $this->assertEquals('Product name', $orderElement->getDesignation());
     $this->assertEquals(1, $orderElement->getQuantity());
 }