252 lines
7.1 KiB
PHP
252 lines
7.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: ondra
|
|
* Date: 25.10.17
|
|
* Time: 13:38.
|
|
*/
|
|
|
|
namespace KupShop\ContentBundle\Tests;
|
|
|
|
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
|
|
|
class CartDeliveryPriceTest extends \DatabaseTestCase
|
|
{
|
|
use CartTestTrait;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->prepareCart();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
parent::tearDown();
|
|
|
|
\Delivery::clearCache();
|
|
}
|
|
|
|
public function testFreeDeliveryPriceDontCountinFromDeliveryType()
|
|
{
|
|
$this->insertProduct(1, 16);
|
|
$this->cart->setTransport(3);
|
|
|
|
$this->cart->createFromDB();
|
|
|
|
$deliveryPrice = $this->cart->getDeliveryType()->getDelivery()->getPrice()->getPriceWithVat();
|
|
|
|
$this->assertEquals(0, $deliveryPrice->asFloat());
|
|
|
|
$this->orderDeliveryTypePriceIsSameAsCart();
|
|
}
|
|
|
|
public function testFreeDeliveryForProduct()
|
|
{
|
|
$this->insertProduct(9);
|
|
$this->cart->createFromDB();
|
|
|
|
$this->cart->setTransport(1);
|
|
$deliveryTypePrice = $this->cart->getDeliveryType()->getPrice()->getPriceWithVat();
|
|
|
|
$this->assertEquals(0, $deliveryTypePrice->asFloat());
|
|
|
|
$this->orderDeliveryTypePriceIsSameAsCart();
|
|
}
|
|
|
|
public function testDeliveryTypePrice()
|
|
{
|
|
$this->insertProduct(1, 16);
|
|
$this->cart->createFromDB();
|
|
|
|
$this->cart->setTransport(1);
|
|
$deliveryTypePrice = $this->cart->getDeliveryType()->getPrice()->getPriceWithVat();
|
|
|
|
$this->assertEquals(104, $deliveryTypePrice->asFloat());
|
|
|
|
$this->orderDeliveryTypePriceIsSameAsCart();
|
|
}
|
|
|
|
public function testDeliveryTypePriceDontCountinFrom()
|
|
{
|
|
$this->insertProduct(1, 16, 15);
|
|
$this->cart->createFromDB();
|
|
|
|
$this->cart->setTransport(1);
|
|
$deliveryTypePrice = $this->cart->getDeliveryType()->getPrice()->getPriceWithVat();
|
|
|
|
$this->assertEquals(0, $deliveryTypePrice->asFloat());
|
|
|
|
$this->orderDeliveryTypePriceIsSameAsCart();
|
|
}
|
|
|
|
public function testDeliveryPriceDontCountinFrom()
|
|
{
|
|
$this->insertProduct(1, 16, 5);
|
|
$this->cart->setTransport(2);
|
|
|
|
$this->cart->createFromDB();
|
|
|
|
$deliveryTypePrice = $this->cart->getDeliveryType()->getPrice()->getPriceWithVat();
|
|
|
|
$this->assertEquals(24, $deliveryTypePrice->asFloat());
|
|
|
|
$this->orderDeliveryTypePriceIsSameAsCart();
|
|
}
|
|
|
|
public function testFreeDeliveryCartVSOrder()
|
|
{
|
|
// bug kdy v kosiku bylo spravne, ze doprava neni zdarma, ale do objednavky se propsala
|
|
// doprava zadarmo, protoze se v objednavce pro vypocet vzala cena, kde byla uz prictena doprava
|
|
$this->insertProduct(1, 16, 1);
|
|
$this->cart->setTransport(4);
|
|
$this->cart->createFromDB();
|
|
|
|
$this->orderDeliveryTypePriceIsSameAsCart();
|
|
}
|
|
|
|
public function getDataSet()
|
|
{
|
|
return $this->getJsonDataSet('
|
|
{
|
|
"delivery_type_delivery": [
|
|
{
|
|
"id":1,
|
|
"currency":"CZK",
|
|
"name":"Česká pošta",
|
|
"price":"70.3",
|
|
"photo":null,
|
|
"class":"BalikDoRuky",
|
|
"time_days":null,
|
|
"time_hours":null,
|
|
"description":null,
|
|
"currencies":null,
|
|
"id_pricelist":null,
|
|
"price_dont_countin_from":null
|
|
},
|
|
{
|
|
"id":2,
|
|
"currency":"CZK",
|
|
"name":"PPL",
|
|
"price":"30.23",
|
|
"photo":null,
|
|
"class":null,
|
|
"time_days":null,
|
|
"time_hours":null,
|
|
"description":null,
|
|
"currencies":null,
|
|
"id_pricelist":null,
|
|
"price_dont_countin_from":"2000"
|
|
},
|
|
{
|
|
"id":3,
|
|
"currency":"CZK",
|
|
"name":"Delivery",
|
|
"price":"30.23",
|
|
"photo":null,
|
|
"class":null,
|
|
"time_days":null,
|
|
"time_hours":null,
|
|
"description":null,
|
|
"currencies":null,
|
|
"id_pricelist":null,
|
|
"price_dont_countin_from":"820"
|
|
}
|
|
],
|
|
"delivery_type_payment": [
|
|
{
|
|
"id":1,
|
|
"currency":"CZK",
|
|
"name":"dobírka",
|
|
"price":"20.123",
|
|
"class":null,
|
|
"photo":null,
|
|
"description":null
|
|
},
|
|
{
|
|
"id":2,
|
|
"currency":"CZK",
|
|
"name":"hotovost",
|
|
"price":"0",
|
|
"class":null,
|
|
"photo":null,
|
|
"description":null
|
|
}
|
|
],
|
|
"delivery_type": [
|
|
{
|
|
"id":1,
|
|
"currency":"CZK",
|
|
"id_delivery":1,
|
|
"id_payment":1,
|
|
"price":"90.25",
|
|
"vat":2,
|
|
"price_dont_countin_from":"10000.0000",
|
|
"format":null,
|
|
"figure":"Y",
|
|
"description":null,
|
|
"payment_class":null
|
|
},
|
|
{
|
|
"id":2,
|
|
"currency":"CZK",
|
|
"id_delivery":2,
|
|
"id_payment":1,
|
|
"price":null,
|
|
"vat":1,
|
|
"price_dont_countin_from":null,
|
|
"format":null,
|
|
"figure":"Y",
|
|
"description":null,
|
|
"payment_class":null
|
|
},
|
|
{
|
|
"id":3,
|
|
"currency":"CZK",
|
|
"id_delivery":1,
|
|
"id_payment":1,
|
|
"price":null,
|
|
"vat":1,
|
|
"price_dont_countin_from":"500.0000",
|
|
"format":null,
|
|
"figure":"Y",
|
|
"description":null,
|
|
"payment_class":null
|
|
},
|
|
{
|
|
"id":4,
|
|
"currency":"CZK",
|
|
"id_delivery":3,
|
|
"id_payment":2,
|
|
"price":null,
|
|
"vat":1,
|
|
"price_dont_countin_from":null,
|
|
"format":null,
|
|
"figure":"Y",
|
|
"description":null,
|
|
"payment_class":null
|
|
}
|
|
]
|
|
}
|
|
');
|
|
}
|
|
|
|
private function orderDeliveryTypePriceIsSameAsCart()
|
|
{
|
|
$this->visitStep('user');
|
|
$this->cart->createFromDB();
|
|
$orderCartPrice = $this->cart->totalPricePay;
|
|
$deliveryPrice = $this->cart->getDeliveryType()->getPrice()->getPriceWithVat();
|
|
$order = $this->cart->submitOrder();
|
|
|
|
/** @var \Decimal $orderDeliveryPrice */
|
|
$orderDeliveryPrice = $order->getDeliveryPrice()['value_with_vat'];
|
|
$orderPrice = $order->total_price;
|
|
|
|
$this->assertEquals($deliveryPrice->asFloat(), $orderDeliveryPrice->asFloat());
|
|
$this->assertEquals($orderCartPrice->asFloat(), $orderPrice->asFloat());
|
|
}
|
|
}
|