67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace KupShop\BonusProgramBundle\Tests;
|
|
|
|
use KupShop\KupShopBundle\Context\CurrencyContext;
|
|
|
|
class BonusProgramVariationsTest extends \DatabaseTestCase
|
|
{
|
|
public function testVariationPoints()
|
|
{
|
|
$product = $this->createProduct();
|
|
|
|
$variation = reset($product->variations['variations']);
|
|
|
|
$this->assertNull($variation['bonus_points']);
|
|
|
|
$points = $product->getBonusPoints($variation['id']);
|
|
// 5% of 800 = 40
|
|
$this->assertEquals(40, $points->asFloat());
|
|
}
|
|
|
|
public function testVariationPointsSK()
|
|
{
|
|
$currencyContext = $this->get(CurrencyContext::class);
|
|
$currencyContext->activate('EUR');
|
|
|
|
$product = $this->createProduct();
|
|
|
|
$variation = reset($product->variations['variations']);
|
|
|
|
$points = $product->getBonusPoints($variation['id']);
|
|
// 5% of 800 = 40
|
|
$this->assertEquals(40, $points->asFloat());
|
|
}
|
|
|
|
public function testZeroPoints()
|
|
{
|
|
sqlQueryBuilder()->update('products')
|
|
->set('bonus_points', '0')
|
|
->where('id = 1')->execute();
|
|
|
|
$product = $this->createProduct();
|
|
|
|
$this->assertEquals(0, $product->bonus_points->asInteger());
|
|
|
|
$variation = reset($product->variations['variations']);
|
|
|
|
$this->assertEquals(0, $variation['bonus_points']->asFloat());
|
|
$points = $product->getBonusPoints($variation['id']);
|
|
$this->assertEquals(0, $points->asFloat());
|
|
}
|
|
|
|
private function createProduct()
|
|
{
|
|
$product = new \Product();
|
|
$product->createFromDB(1);
|
|
$product->fetchVariations();
|
|
|
|
return $product;
|
|
}
|
|
|
|
public function getDataSet()
|
|
{
|
|
return $this->getJsonDataSetFromFile();
|
|
}
|
|
}
|