setDeliveryMethod() публичный Метод

public setDeliveryMethod ( Sonata\Component\Delivery\ServiceDeliveryInterface $method = null )
$method Sonata\Component\Delivery\ServiceDeliveryInterface
Пример #1
0
 public function testTotal()
 {
     $currency = $this->getMock('Sonata\\Component\\Currency\\Currency');
     $basket = new Basket();
     $basket->setCurrency($currency);
     $manager = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $manager->expects($this->any())->method('getClass')->will($this->returnValue('BasketTest_Product'));
     $productProvider = new ProductProviderTest($this->getMock('JMS\\Serializer\\SerializerInterface'));
     $productProvider->setCurrencyPriceCalculator(new CurrencyPriceCalculator());
     $productProvider->setEventDispatcher($this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'));
     $productDefinition = new ProductDefinition($productProvider, $manager);
     $product = $this->getMockProduct();
     $product->expects($this->any())->method('isRecurrentPayment')->will($this->returnValue(false));
     $pool = new Pool();
     $pool->addProduct('product_code', $productDefinition);
     $basket->setProductPool($pool);
     $this->assertFalse($basket->hasProduct($product), '::hasProduct() - The product is not present in the basket');
     $basketElement = new BasketElement();
     $basketElement->setProductDefinition($productDefinition);
     $basketElement->setProduct('product_code', $product);
     $basket->addBasketElement($basketElement);
     $this->assertTrue($basket->hasProduct($product), '::hasProduct() - The product is present in the basket');
     $this->assertEquals(1, $basketElement->getQuantity(), '::getQuantity() - return 1');
     $this->assertEquals(15, $basketElement->getUnitPrice(false), '::getQuantity() - return 2');
     $this->assertEquals(15, $basketElement->getTotal(false), '::getQuantity() - return 2');
     $this->assertEquals(15, $basket->getTotal(false), '::getTotal() w/o vat return 15');
     $this->assertEquals(17.94, $basket->getTotal(true), '::getTotal() w/ vat return 18');
     $basketElement->setQuantity(2);
     $this->assertEquals(2, $basketElement->getQuantity(), '::getQuantity() - return 2');
     $this->assertEquals(15, $basketElement->getUnitPrice(false), '::getQuantity() - return 2');
     $this->assertEquals(30, $basketElement->getTotal(false), '::getQuantity() - return 2');
     $this->assertEquals(30, $basket->getTotal(false), '::getTotal() w/o vat return 30');
     $this->assertEquals(35.88, $basket->getTotal(true), '::getTotal() w/ vat return true');
     // Recurrent payments
     $this->assertEquals(0, $basket->getTotal(false, true), '::getTotal() for recurrent payments only');
     $newProduct = $this->getMockProduct();
     $newProduct->expects($this->any())->method('isRecurrentPayment')->will($this->returnValue(true));
     $basketElement = new BasketElement();
     $basketElement->setProduct('product_code', $newProduct);
     $basket->addBasketElement($basketElement);
     $this->assertEquals(30, $basket->getTotal(false, false), '::getTotal() for non-recurrent payments only');
     $basket->removeElement($basketElement);
     // Delivery
     $delivery = new Delivery();
     $basket->setDeliveryMethod($delivery);
     $this->assertEquals(150, $basket->getTotal(false), '::getTotal() - return 150');
     $this->assertEquals(179.4, $basket->getTotal(true), '::getTotal() w/o vat return 179.40');
     $this->assertEquals(29.4, $basket->getVatAmount(), '::getVatAmount() w/o vat return 29.4');
 }
 /**
  * @return void
  */
 public function testOrder()
 {
     $basket = new Basket();
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $billingAddress = $this->getMock('Sonata\\Component\\Customer\\AddressInterface');
     $deliveryMethod = $this->getMock('Sonata\\Component\\Delivery\\ServiceDeliveryInterface');
     $deliveryMethod->expects($this->exactly(2))->method('isAddressRequired')->will($this->returnValue(true));
     $deliveryAddress = $this->getMock('Sonata\\Component\\Customer\\AddressInterface');
     $paymentMethod = $this->getMock('Sonata\\Component\\Payment\\PaymentInterface');
     $basket->setCustomer($customer);
     $basket->setBillingAddress($billingAddress);
     $basket->setDeliveryMethod($deliveryMethod);
     $basket->setDeliveryAddress($deliveryAddress);
     $basket->setPaymentMethod($paymentMethod);
     $currency = new Currency();
     $currency->setLabel('EUR');
     $basket->setCurrency($currency);
     $order = $this->getBasketTransform()->transformIntoOrder($basket);
     $this->assertInstanceOf('Sonata\\Component\\Order\\OrderInterface', $order, '::transformIntoOrder() returns an OrderInstance object');
 }