저자: Hugo Briand (briand@ekino.com)
상속: implements Sonata\Component\Currency\CurrencyInterface
 public function getBasketElement($product = null)
 {
     $product = $this->getMock('Sonata\\Component\\Product\\ProductInterface', array(), array(), 'BasketTest_Product');
     $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(15));
     $product->expects($this->any())->method('isPriceIncludingVat')->will($this->returnValue(false));
     $product->expects($this->any())->method('getVatRate')->will($this->returnValue(19.6));
     $product->expects($this->any())->method('getOptions')->will($this->returnValue(array('option1' => 'toto')));
     $product->expects($this->any())->method('getDescription')->will($this->returnValue('product description'));
     $productProvider = new ProductProviderTest($this->getMock('JMS\\Serializer\\SerializerInterface'));
     $productProvider->setCurrencyPriceCalculator(new CurrencyPriceCalculator());
     $productProvider->setEventDispatcher($this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'));
     $productManager = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $productDefinition = new ProductDefinition($productProvider, $productManager);
     $basketElement = new BasketElement();
     $basketElement->setProduct('product_code', $product);
     $basketElement->setProductDefinition($productDefinition);
     $currency = new Currency();
     $currency->setLabel('EUR');
     $basket = $this->getMockBuilder('Sonata\\Component\\Basket\\BasketInterface')->getMock();
     $basket->expects($this->any())->method('getCurrency')->will($this->returnValue($currency));
     $productProvider->updateComputationPricesFields($basket, $basketElement, $product);
     return $basketElement;
 }
예제 #2
0
 public function testValidSendbankPayment()
 {
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $templating = $this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface');
     $templating->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'callbackValidsendbank')));
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $date = new \DateTime();
     $date->setTimeStamp(strtotime('30/11/1981'));
     $date->setTimezone(new \DateTimeZone('Europe/Paris'));
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $order = new OgonePaymentTest_Order();
     $order->setCreatedAt($date);
     $order->setId(2);
     $order->setReference('FR');
     $currency = new Currency();
     $currency->setLabel('EUR');
     $order->setCurrency($currency);
     $order->setCustomer($customer);
     $order->setLocale('es');
     $payment = new OgonePayment($router, $logger, $templating, true);
     $payment->setCode('ogone_1');
     $payment->setOptions(array('url_return_ok' => '', 'url_return_ko' => '', 'url_callback' => '', 'template' => '', 'form_url' => '', 'sha_key' => '', 'sha-out_key' => '', 'pspid' => '', 'home_url' => '', 'catalog_url' => ''));
     $response = $payment->sendbank($order);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
 }
예제 #3
0
 public function testConvertToPHPValue()
 {
     $platform = new MockPlatform();
     $currency = new Currency();
     $currency->setLabel("EUR");
     $this->assertEquals($currency, Type::getType('currency')->convertToPHPValue('EUR', $platform));
 }
예제 #4
0
 public function testBasket()
 {
     $provider = $this->getMock('Sonata\\Component\\Product\\ProductProviderInterface');
     $provider->expects($this->once())->method('basketAddProduct')->will($this->returnValue(true));
     $provider->expects($this->once())->method('createBasketElement')->will($this->returnValue($basketElement = new BasketElement()));
     $product = $this->getMock('Sonata\\Component\\Product\\ProductInterface');
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $manager = $this->getMock('Sonata\\Component\\Product\\ProductManagerInterface');
     $manager->expects($this->once())->method('findOneBy')->will($this->returnValue($product));
     $pool = $this->getMock('Sonata\\Component\\Product\\Pool');
     $pool->expects($this->once())->method('getProvider')->will($this->returnValue($provider));
     $pool->expects($this->once())->method('getManager')->will($this->returnValue($manager));
     $basket = $this->getMock('Sonata\\Component\\Basket\\BasketInterface');
     $basket->expects($this->once())->method('reset');
     $basket->expects($this->once())->method('buildPrices');
     $orderElement = $this->getMock('Sonata\\Component\\Order\\OrderElementInterface');
     $orderElement->expects($this->exactly(2))->method('getProductType');
     $orderElement->expects($this->exactly(1))->method('getProductId')->will($this->returnValue(2));
     $orderElement->expects($this->exactly(1))->method('getOptions')->will($this->returnValue(array()));
     $orderElement->expects($this->exactly(1))->method('getQuantity')->will($this->returnValue(2));
     $order = $this->getMock('Sonata\\Component\\Order\\OrderInterface');
     $order->expects($this->once())->method('getOrderElements')->will($this->returnValue(array($orderElement)));
     $order->expects($this->once())->method('getCustomer')->will($this->returnValue($customer));
     $currency = new Currency();
     $currency->setLabel('EUR');
     $order->expects($this->once())->method('getCurrency')->will($this->returnValue($currency));
     $transformer = new OrderTransformer($pool);
     $transformer->transformIntoBasket($order, $basket);
     $this->assertEquals(2, $basketElement->getQuantity());
 }
 public function testReverseTransform()
 {
     $currency = new Currency();
     $currency->setLabel("EUR");
     $this->currencyManager->expects($this->once())->method('findOneByLabel')->will($this->returnValue($currency));
     $this->assertEquals(null, $this->currencyDataTransformer->reverseTransform(null));
     $this->assertEquals("EUR", $this->currencyDataTransformer->reverseTransform("EUR")->getLabel());
 }
 public function testGetPrice()
 {
     $currencyPriceCalculator = new CurrencyPriceCalculator();
     $product = $this->getMock('Sonata\\Component\\Product\\ProductInterface');
     $currency = new Currency();
     $currency->setLabel('EUR');
     $product->expects($this->once())->method('getPrice')->will($this->returnValue(42.0));
     $this->assertEquals(42.0, $currencyPriceCalculator->getPrice($product, $currency));
 }
 /**
  * @covers Sonata\Component\Currency\CurrencyDetector::__construct
  */
 public function testConstruct()
 {
     $currency = new Currency();
     $currency->setLabel('EUR');
     $currencyManager = $this->getMock('Sonata\\Component\\Currency\\CurrencyManagerInterface');
     $currencyManager->expects($this->any())->method('findOneByLabel')->will($this->returnValue($currency));
     $currencyDetector = new CurrencyDetector('EUR', $currencyManager);
     $this->assertEquals('EUR', $currencyDetector->getCurrency()->getLabel());
 }
 /**
  * {@inheritdoc}
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if (!array_key_exists($value, Intl::getCurrencyBundle()->getCurrencyNames())) {
         throw new \RuntimeException(sprintf("'%d' is not a supported currency.", $value));
     }
     $currency = new Currency();
     $currency->setLabel($value);
     return $currency;
 }
예제 #9
0
 public function testSave()
 {
     $basketManager = $this->getMock('Sonata\\Component\\Basket\\BasketManagerInterface');
     $basketBuilder = $this->getMock('Sonata\\Component\\Basket\\BasketBuilderInterface');
     $session = $this->getMock('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface');
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $customer->expects($this->any())->method('getId')->will($this->returnValue(1));
     $basket = $this->getMock('Sonata\\Component\\Basket\\BasketInterface');
     $basket->expects($this->once())->method('getCustomer')->will($this->returnValue($customer));
     $currencyDetector = $this->getMock('Sonata\\Component\\Currency\\CurrencyDetectorInterface');
     $currency = new Currency();
     $currency->setLabel('EUR');
     $currencyDetector->expects($this->any())->method('getCurrency')->will($this->returnValue($currency));
     $factory = new BasketSessionFactory($basketManager, $basketBuilder, $currencyDetector, $session);
     $factory->save($basket);
 }
예제 #10
0
 public function testEquals()
 {
     $currency = new Currency();
     $currency->setLabel('EUR');
     $this->assertFalse($currency->equals(null));
     $this->assertFalse($currency->equals(new Currency()));
     $this->assertTrue($currency->equals($currency));
 }
 public function testTransformFromOrder()
 {
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $orderElement = $this->getMock('Sonata\\Component\\Order\\OrderElementInterface');
     $orderElement->expects($this->once())->method('getDescription');
     $orderElement->expects($this->once())->method('getDesignation');
     $orderElement->expects($this->once())->method('getPrice')->will($this->returnValue(42));
     $orderElement->expects($this->once())->method('getQuantity')->will($this->returnValue(3));
     $orderElement->expects($this->once())->method('getVatRate');
     $order = $this->getMock('Sonata\\Component\\Order\\OrderInterface');
     $order->expects($this->once())->method('getOrderElements')->will($this->returnValue(array($orderElement)));
     $order->expects($this->once())->method('getCustomer')->will($this->returnValue($customer));
     $order->expects($this->once())->method('getBillingAddress1');
     $order->expects($this->once())->method('getBillingAddress2');
     $order->expects($this->once())->method('getBillingAddress3');
     $order->expects($this->once())->method('getBillingCity');
     $order->expects($this->once())->method('getBillingCountryCode');
     $order->expects($this->once())->method('getBillingPostcode');
     $order->expects($this->once())->method('getBillingEmail');
     $order->expects($this->once())->method('getBillingMobile');
     $order->expects($this->once())->method('getBillingFax');
     $order->expects($this->once())->method('getBillingPhone');
     $order->expects($this->once())->method('getReference');
     $currency = new Currency();
     $currency->setLabel('EUR');
     $order->expects($this->once())->method('getCurrency')->will($this->returnValue($currency));
     $order->expects($this->once())->method('getTotalExcl');
     $order->expects($this->once())->method('getTotalInc');
     $invoice = $this->getMock('Sonata\\Component\\Invoice\\InvoiceInterface');
     $invoiceElement = $this->getMock('Sonata\\Component\\Invoice\\InvoiceElementInterface');
     $invoiceElementManager = $this->getMock('Sonata\\Component\\Invoice\\InvoiceElementManagerInterface');
     $invoiceElementManager->expects($this->once())->method('create')->will($this->returnValue($invoiceElement));
     $deliveryPool = new DeliveryPool();
     $eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $invoiceTransformer = new InvoiceTransformer($invoiceElementManager, $deliveryPool, $eventDispatcher);
     $invoiceTransformer->transformFromOrder($order, $invoice);
 }
예제 #12
0
 /**
  * Creates a fake Order.
  *
  * @param BasketInterface $basket
  * @param Customer        $customer
  * @param array           $products
  * @param ObjectManager   $manager
  * @param int             $pos
  *
  * @return OrderInterface
  */
 protected function createOrder(BasketInterface $basket, Customer $customer, array $products, ObjectManager $manager, $pos)
 {
     $orderElements = array();
     $totalExcl = 0;
     $totalInc = 0;
     $order = new Order();
     // customer
     $order->setCustomer($customer);
     $order->setLocale($customer->getLocale());
     $order->setUsername($customer->getFullname());
     $order->setReference(sprintf('%02d%02d%02d%06d', 2013, 7, 1, $pos));
     // Billing
     $customerBillingAddressAddresses = $customer->getAddressesByType(BaseAddress::TYPE_BILLING);
     $customerBillingAddressAddresses = $customerBillingAddressAddresses->current();
     $order->setBillingAddress1($customerBillingAddressAddresses->getAddress1());
     $order->setBillingAddress2($customerBillingAddressAddresses->getAddress2());
     $order->setBillingAddress3($customerBillingAddressAddresses->getAddress3());
     $order->setBillingCity($customerBillingAddressAddresses->getCity());
     $order->setBillingCountryCode($customerBillingAddressAddresses->getCountryCode());
     $order->setBillingEmail($customer->getEmail());
     $order->setBillingName($customer->getFullname());
     $order->setBillingPhone($customerBillingAddressAddresses->getPhone());
     $order->setBillingFax($customer->getFaxNumber());
     $order->setBillingMobile($customer->getMobileNumber());
     $order->setBillingPostcode($customerBillingAddressAddresses->getPostcode());
     // Shipping
     $customerDeliveryAddressAddresses = $customer->getAddressesByType(BaseAddress::TYPE_DELIVERY);
     $customerDeliveryAddressAddresses = $customerDeliveryAddressAddresses->current();
     $order->setShippingAddress1($customerDeliveryAddressAddresses->getAddress1());
     $order->setShippingAddress2($customerDeliveryAddressAddresses->getAddress2());
     $order->setShippingAddress3($customerDeliveryAddressAddresses->getAddress3());
     $order->setShippingCity($customerDeliveryAddressAddresses->getCity());
     $order->setShippingCountryCode($customerDeliveryAddressAddresses->getCountryCode());
     $order->setShippingEmail($customer->getEmail());
     $order->setShippingName($customer->getFullname());
     $order->setShippingPhone($customerDeliveryAddressAddresses->getPhone());
     $order->setShippingFax($customer->getFaxNumber());
     $order->setShippingMobile($customer->getMobileNumber());
     $order->setShippingPostcode($customerDeliveryAddressAddresses->getPostcode());
     // Delivery
     $order->setDeliveryMethod('free');
     // @todo : change Delivery method integration
     $order->setDeliveryCost(rand(5, 40));
     $order->setDeliveryVat(20);
     $order->setDeliveryStatus(array_rand(Delivery::getStatusList()));
     $currency = new Currency();
     $currency->setLabel('EUR');
     // Payment
     $order->setCurrency($currency);
     $order->setPaymentMethod('free');
     // @todo : change Payment method integration
     $order->setPaymentStatus(array_rand(BaseTransaction::getStatusList()));
     // OrderElements
     foreach ($products as $product) {
         $orderElement = $this->createOrderElement($basket, $product);
         $orderElement->setOrder($order);
         $orderElements[] = $orderElement;
         $totalExcl += $orderElement->getUnitPrice(false);
         $totalInc += $orderElement->getUnitPrice(true);
     }
     $order->setOrderElements($orderElements);
     $order->setTotalExcl($totalExcl);
     $order->setTotalInc($totalInc);
     $order->setStatus(array_rand(BaseOrder::getStatusList()));
     if (OrderInterface::STATUS_VALIDATED == $order->getStatus()) {
         $order->setValidatedAt(new \DateTime());
     }
     $manager->persist($order);
     return $order;
 }
예제 #13
0
 public function testSaveNoExistingCustomer()
 {
     $basket = $this->getMock('Sonata\\Component\\Basket\\BasketInterface');
     $basket->expects($this->once())->method('getCustomerId')->will($this->returnValue(false));
     $basketManager = $this->getMock('Sonata\\Component\\Basket\\BasketManagerInterface');
     $basketBuilder = $this->getMock('Sonata\\Component\\Basket\\BasketBuilderInterface');
     $session = $this->getMock('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface');
     $tester = $this;
     $session->expects($this->once())->method('set')->will($this->returnCallback(function ($key, $value) use($tester, $basket) {
         $tester->assertEquals($basket, $value);
         $tester->assertEquals('sonata/basket/factory/customer/new', $key);
     }));
     $currencyDetector = $this->getMock('Sonata\\Component\\Currency\\CurrencyDetectorInterface');
     $currency = new Currency();
     $currency->setLabel("EUR");
     $currencyDetector->expects($this->any())->method('getCurrency')->will($this->returnValue($currency));
     $factory = new BasketEntityFactory($basketManager, $basketBuilder, $currencyDetector, $session);
     $factory->save($basket);
 }
예제 #14
0
 /**
  * {@inheritdoc}
  */
 public function findOneByLabel($currencyLabel)
 {
     $currency = new Currency();
     $currency->setLabel($currencyLabel);
     return $currency;
 }
예제 #15
0
 public function testValidSendbankPayment()
 {
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $templating = $this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface');
     $templating->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'callbackValidsendbank')));
     $generator = $this->getMock('Sonata\\Component\\Payment\\Scellius\\ScelliusTransactionGeneratorInterface');
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $date = new \DateTime();
     $date->setTimeStamp(strtotime('30/11/1981'));
     $date->setTimezone(new \DateTimeZone('Europe/Paris'));
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $customer->expects($this->once())->method('getId')->will($this->returnValue(42));
     $customer->expects($this->once())->method('getEmail')->will($this->returnValue('*****@*****.**'));
     $order = new ScelliusPaymentTest_Order();
     $order->setCreatedAt($date);
     $order->setId(2);
     $order->setReference('FR');
     $currency = new Currency();
     $currency->setLabel('EUR');
     $order->setCurrency($currency);
     $order->setCustomer($customer);
     $order->setLocale('es');
     $payment = new ScelliusPayment($router, $logger, $templating, $generator, true);
     $payment->setCode('free_1');
     $payment->setOptions(array('base_folder' => __DIR__, 'request_command' => 'cat request_ok.txt && echo '));
     $response = $payment->sendbank($order);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
 }
예제 #16
0
 public function testCalculatePrice()
 {
     $product = new ProductTest();
     $product->setPrice(42);
     $currency = new Currency();
     $currency->setLabel('EUR');
     $provider = $this->createNewProductProvider();
     $this->assertEquals(42 * 4, $provider->calculatePrice($product, $currency, false, 4));
     $this->assertEquals(42, $provider->calculatePrice($product, $currency, false));
 }
 /**
  * @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');
 }