246 lines
10 KiB
PHP
246 lines
10 KiB
PHP
<?php
|
|
|
|
namespace KupShop\ContentBundle\Tests;
|
|
|
|
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
|
use KupShop\OrderDiscountBundle\Tests\OrderTestDiscountTrait;
|
|
|
|
class OrderDiscountCartPriceDontCountinTest extends \DatabaseTestCase
|
|
{
|
|
use CartTestTrait;
|
|
use OrderTestDiscountTrait;
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom */
|
|
public function testDeliveryTypeDontCountinFrom($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
$this->createCart();
|
|
$this->setDeliveryType($deliveryTypeId);
|
|
$this->setInvoice();
|
|
$this->insertProduct(3, null, $itemPieces);
|
|
$this->visitStep('delivery');
|
|
$this->cart->createFromDB();
|
|
|
|
$this->assertEquals($expectedCartPrice, $this->cart->totalPricePay->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is used (DeliveryType dont_countin_from = 500)
|
|
[1, 800, 1],
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// product 661.1570*1.21 + delivery 70.3*1.15 (15% vat) = 880.84497 (see getDataSet())
|
|
[2, 881, 1],
|
|
// Delivery dont_countin_from is used (Delivery dont_countin_from = 999)
|
|
[2, 1600, 2],
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom_coupon500 */
|
|
public function testDeliveryTypeDontCountinFromCoupon500($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
$this->activateDiscount([11]); // Discount 500 CZK
|
|
$this->createCart();
|
|
$this->setDeliveryType($deliveryTypeId);
|
|
$this->setInvoice();
|
|
$this->insertProduct(3, null, $itemPieces); // product price = 800
|
|
$this->cart->addCoupon('TEST500'); // -500
|
|
$this->visitStep('delivery');
|
|
$this->cart->createFromDB();
|
|
|
|
$this->assertEquals($expectedCartPrice, $this->cart->totalPricePay->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom_coupon500()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is not used (DeliveryType dont_countin_from = 500)
|
|
// max(product 661.1570*1.21 - 500, 0) + delivery 70.3*1.15 (15% vat) = 380.84497 (see getDataSet())
|
|
[1, 381, 1],
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// max(product 661.1570*1.21 - 500, 0) + delivery 70.3*1.15 (15% vat) = 380.84497 (see getDataSet())
|
|
[2, 381, 1],
|
|
// Delivery dont_countin_from is used (Delivery dont_countin_from = 999)
|
|
// max(product 2*661.1570*1.21 - 500, 0) + free delivery = 1099.99994 (see getDataSet())
|
|
[2, 1100, 2],
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom_coupon1000 */
|
|
public function testDeliveryTypeDontCountinFromCoupon1000($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
$this->activateDiscount([12]); // Discount 1000 CZK
|
|
$this->createCart();
|
|
$this->setDeliveryType($deliveryTypeId);
|
|
$this->setInvoice();
|
|
$this->insertProduct(3, null, $itemPieces); // product price = 800
|
|
$this->cart->addCoupon('TEST1000'); // -1000
|
|
$this->visitStep('delivery');
|
|
$this->cart->createFromDB();
|
|
|
|
$this->assertEquals($expectedCartPrice, $this->cart->totalPricePay->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom_coupon1000()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is not used (DeliveryType dont_countin_from = 500)
|
|
// max(product 661.1570*1.21 - 1000, 0) + delivery 70.3*1.15 (15% vat) = 80.845 (see getDataSet())
|
|
[1, 81, 1], // 81 - delivery price
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// max(product 661.1570*1.21 - 1000, 0) + delivery 70.3*1.15 (15% vat) = 80.845 (see getDataSet())
|
|
[2, 81, 1], // 81 - delivery price
|
|
// Delivery dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// max(product 2*661.1570*1.21 - 1000, 0) + delivery 70.3*1.15 (15% vat) = 680.84494 (see getDataSet())
|
|
[2, 681, 2], // 2*800 (products) - 1000 (coupon) + 81 (delivery)
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom_applyDiscountOnDelivery */
|
|
public function testDeliveryTypeDontCountinFromApplyDiscountOnDelivery($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
// apply_discount_on_delivery = Aplikuje slevu (kupon) i na dopravu
|
|
$this->addModule(\Modules::DELIVERY_TYPES, \Modules::SUB_APPLY_DISCOUNT_ON_DELIVERY);
|
|
|
|
$this->testDeliveryTypeDontCountinFromCoupon1000($deliveryTypeId, $expectedCartPrice, $itemPieces);
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom_applyDiscountOnDelivery()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is not used (DeliveryType dont_countin_from = 500)
|
|
[1, 0, 1], // 800 (products) + 81 (delivery) - 1000 (coupon)
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
[2, 0, 1], // 800 (products) + 81 (delivery) - 1000 (coupon)
|
|
// Delivery dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// max(product 2*661.1570*1.21 + delivery 70.3*1.15 (15% vat) - 1000, 0) = 680.84494 (see getDataSet())
|
|
[2, 681, 2], // 2*800 (products) + 81 (delivery) - 1000 (coupon)
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom_freeDeliveryNoDiscount */
|
|
public function testDeliveryTypeDontCountinFromFreeDeliveryNoDiscount($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
// free_delivery_no_discount = Počítá cenu pro dopravu zdarma před odečtením slev
|
|
$this->addModule(\Modules::DELIVERY_TYPES, \Modules::SUB_FREE_DELIVERY_NO_DISCOUNT);
|
|
|
|
$this->testDeliveryTypeDontCountinFromCoupon500($deliveryTypeId, $expectedCartPrice, $itemPieces);
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom_freeDeliveryNoDiscount()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is used (DeliveryType dont_countin_from = 500 (před odečtením slev))
|
|
[1, 300, 1],
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// max(product 661.1570*1.21 - 500, 0) + delivery 70.3*1.15 (15% vat) = 380.84497 (see getDataSet())
|
|
[2, 381, 1],
|
|
// Delivery dont_countin_from is used (Delivery dont_countin_from = 999)
|
|
[2, 1100, 2],
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom_freeDeliveryNoDiscount_applyDiscountOnDelivery */
|
|
public function testDeliveryTypeDontCountinFromFreeDeliveryNoDiscountApplyDiscountOnDelivery($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
// free_delivery_no_discount = Počítá cenu pro dopravu zdarma před odečtením slev
|
|
$this->addModule(\Modules::DELIVERY_TYPES, \Modules::SUB_FREE_DELIVERY_NO_DISCOUNT);
|
|
// apply_discount_on_delivery = Aplikuje slevu (kupon) i na dopravu
|
|
$this->addModule(\Modules::DELIVERY_TYPES, \Modules::SUB_APPLY_DISCOUNT_ON_DELIVERY);
|
|
|
|
$this->testDeliveryTypeDontCountinFromCoupon1000($deliveryTypeId, $expectedCartPrice, $itemPieces);
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom_freeDeliveryNoDiscount_applyDiscountOnDelivery()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is used (DeliveryType dont_countin_from = 500 (před odečtením slev))
|
|
[1, 0, 1], // 800 (products) + 0 (delivery) - 1000 (coupon)
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999 (před odečtením slev))
|
|
[2, 0, 1], // 800 (products) + 81 (delivery) - 1000 (coupon)
|
|
// Delivery dont_countin_from is used (Delivery dont_countin_from = 999 (před odečtením slev))
|
|
[2, 600, 2], // 2*800 (products) + 0 (delivery) - 1000 (coupon)
|
|
];
|
|
}
|
|
|
|
public function getDataSet()
|
|
{
|
|
$data_from_file = '';
|
|
$file = __DIR__.'/data.json';
|
|
if (file_exists($file)) {
|
|
$data_from_file = trim(file_get_contents($file));
|
|
$data_from_file = ','.trim($data_from_file, '{}');
|
|
}
|
|
|
|
return $this->getJsonDataSet(/* @lang JSON */ '
|
|
{
|
|
"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":"999"
|
|
}
|
|
],
|
|
"delivery_type_payment": [
|
|
{
|
|
"id":1,
|
|
"currency":"CZK",
|
|
"name":"dobírka",
|
|
"price":"0",
|
|
"class":null,
|
|
"photo":null,
|
|
"description":null
|
|
},
|
|
{
|
|
"id":2,
|
|
"currency":"CZK",
|
|
"name":"online",
|
|
"price":"0",
|
|
"class":null,
|
|
"photo":null,
|
|
"description":null
|
|
}
|
|
],
|
|
"delivery_type": [
|
|
{
|
|
"id":1,
|
|
"currency":"CZK",
|
|
"id_delivery":1,
|
|
"id_payment":1,
|
|
"price":null,
|
|
"vat":2,
|
|
"price_dont_countin_from":"500",
|
|
"format":null,
|
|
"figure":"Y",
|
|
"description":null,
|
|
"payment_class":null
|
|
},
|
|
{
|
|
"id":2,
|
|
"currency":"CZK",
|
|
"id_delivery":1,
|
|
"id_payment":2,
|
|
"price":null,
|
|
"vat":2,
|
|
"price_dont_countin_from":null,
|
|
"format":null,
|
|
"figure":"Y",
|
|
"description":null,
|
|
"payment_class":null
|
|
}
|
|
]'.$data_from_file.'}');
|
|
}
|
|
}
|