143 lines
4.8 KiB
PHP
143 lines
4.8 KiB
PHP
<?php
|
|
|
|
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
|
use KupShop\KupShopBundle\Context\PriceLevelContext;
|
|
|
|
class PriceLevelTestTest extends \DatabaseTestCase
|
|
{
|
|
use CartTestTrait;
|
|
|
|
/** @var PriceLevelContext */
|
|
protected $priceLevelContext;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->priceLevelContext = $this->get(PriceLevelContext::class);
|
|
}
|
|
|
|
private $pid = 123;
|
|
|
|
private function getProduct()
|
|
{
|
|
$product = new \Product();
|
|
$product->createFromDB($this->pid);
|
|
|
|
return $product;
|
|
}
|
|
|
|
private function getPriceLevel($id)
|
|
{
|
|
$this->priceLevelContext->activate($id);
|
|
}
|
|
|
|
/** sleva 17% na cenove hladine - rozsahu */
|
|
public function testPriceLevelRange()
|
|
{
|
|
$this->getPriceLevel(14);
|
|
$product = $this->getProduct();
|
|
|
|
$this->assertEquals('1041', $product->price_array['value_with_vat']->asFloat());
|
|
$this->assertEquals('860.3305', $product->price_array['value_without_vat']->asFloat(), '', 0.0001);
|
|
}
|
|
|
|
/** sleva 17% na cenove hladine - sekci*/
|
|
public function testPriceLevelSections()
|
|
{
|
|
$this->getPriceLevel(15);
|
|
$product = $this->getProduct();
|
|
|
|
$this->assertEquals('1029', $product->price_array['value_with_vat']->asFloat());
|
|
$this->assertEquals('850.4132', $product->price_array['value_without_vat']->asFloat(), '', 0.0001);
|
|
|
|
$this->prepareCart();
|
|
$this->insertProduct($this->pid, null, 2);
|
|
$this->assertEquals(1029 * 2, $this->recalculateCart()->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
/** sleva 17% na cenove hladine - vyrobci*/
|
|
public function testPriceLevelProducers()
|
|
{
|
|
$this->getPriceLevel(16);
|
|
$product = $this->getProduct();
|
|
|
|
$this->assertEquals('1016', $product->price_array['value_with_vat']->asFloat());
|
|
$this->assertEquals('839.6694', $product->price_array['value_without_vat']->asFloat(), '', 0.0001);
|
|
|
|
$this->prepareCart();
|
|
$this->insertProduct($this->pid, null, 2);
|
|
$this->assertEquals(1016 * 2, $this->recalculateCart()->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
/** sleva 17% na cenove hladine - produktu*/
|
|
public function testPriceLevelProduct()
|
|
{
|
|
$this->getPriceLevel(17);
|
|
$product = $this->getProduct();
|
|
|
|
$this->assertEquals('1004', $product->price_array['value_with_vat']->asFloat());
|
|
$this->assertEquals('829.7520', $product->price_array['value_without_vat']->asFloat(), '', 0.0001);
|
|
|
|
$this->prepareCart();
|
|
$this->insertProduct($this->pid, null, 2);
|
|
$this->assertEquals(1004 * 2, $this->recalculateCart()->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
/** sleva predefinovana 20% na produktu*/
|
|
public function testPriceLevelProductDiscount()
|
|
{
|
|
$this->getPriceLevel(17);
|
|
$this->updateSQL('products', ['discount' => 20], ['id' => $this->pid]);
|
|
$product = $this->getProduct();
|
|
|
|
$this->assertEquals('968', $product->price_array['value_with_vat']->asFloat());
|
|
$this->assertEquals('800', $product->price_array['value_without_vat']->asFloat(), '', 0.0001);
|
|
|
|
$this->prepareCart();
|
|
$this->insertProduct($this->pid, null, 2);
|
|
$this->assertEquals(968 * 2, $this->recalculateCart()->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
/** Kombinace slevy na produktu 20% + globalni 17% */
|
|
public function testPriceLevelProductCombineDiscount()
|
|
{
|
|
$this->getPriceLevel(18);
|
|
$this->updateSQL('products', ['discount' => 20], ['id' => $this->pid]);
|
|
$product = $this->getProduct();
|
|
|
|
$this->assertEquals('803', $product->price_array['value_with_vat']->asFloat());
|
|
$this->assertEquals('663.6363', $product->price_array['value_without_vat']->asFloat(), '', 0.0001);
|
|
|
|
$this->prepareCart();
|
|
$this->insertProduct($this->pid, null, 2);
|
|
$this->assertEquals(803 * 2, $this->recalculateCart()->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
/** Kombinace slevy na slevu */
|
|
public function testPriceLevelProductCombineDiscountDiscount()
|
|
{
|
|
$this->getPriceLevel(19);
|
|
$this->updateSQL('products', ['discount' => 20], ['id' => $this->pid]);
|
|
$product = $this->getProduct();
|
|
|
|
$this->assertEquals('784', $product->price_array['value_with_vat']->asFloat());
|
|
$this->assertEquals('647.9338', $product->price_array['value_without_vat']->asFloat(), '', 0.0001);
|
|
|
|
$this->prepareCart();
|
|
$this->insertProduct($this->pid, null, 2);
|
|
$this->assertEquals(784 * 2, $this->recalculateCart()->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
public function getDataSet()
|
|
{
|
|
return $this->getJsonDataSetFromFile();
|
|
}
|
|
}
|