first commit
This commit is contained in:
63
tests/functional/AliveTest.php
Normal file
63
tests/functional/AliveTest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Honza
|
||||
* Date: 21/7/16
|
||||
* Time: 9:47 AM.
|
||||
*/
|
||||
class AliveTest extends DatabaseTestCase
|
||||
{
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
if (!findModule('alive')) {
|
||||
self::markTestSkipped('Modul alive je vypnutý.');
|
||||
}
|
||||
}
|
||||
|
||||
public function testConnect()
|
||||
{
|
||||
$aliveCard = new AliveCard();
|
||||
|
||||
$connection = $aliveCard->connect();
|
||||
|
||||
$this->assertNotFalse($connection);
|
||||
}
|
||||
|
||||
public function testTestServer()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$old_cfg = $cfg;
|
||||
|
||||
$cfg['Modules']['isic'] = [
|
||||
'url' => 'https://gts-dm.orchitech.net/api',
|
||||
'username' => 'testdm',
|
||||
'password' => 'testdm',
|
||||
];
|
||||
$name = 'Přemysll Žluťoučký';
|
||||
$card = 'T042532100344J';
|
||||
|
||||
$aliveCard = new AliveCard();
|
||||
|
||||
$info = $aliveCard->validate($card, $name);
|
||||
|
||||
$cfg = $old_cfg;
|
||||
$this->assertNotFalse($info);
|
||||
}
|
||||
|
||||
public function testRealServer()
|
||||
{
|
||||
$name = 'PROKOP Jan';
|
||||
$card = 'S420562002829G';
|
||||
|
||||
// $name = "Jakub Jirouš";
|
||||
// $card = "S420562000568G";
|
||||
|
||||
$aliveCard = new AliveCard();
|
||||
|
||||
$info = $aliveCard->validate($card, $name);
|
||||
|
||||
$this->assertNotFalse($info);
|
||||
}
|
||||
}
|
||||
199
tests/functional/ApiTest.php
Normal file
199
tests/functional/ApiTest.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Honza
|
||||
* Date: 21/7/16
|
||||
* Time: 9:47 AM.
|
||||
*/
|
||||
class ApiTest extends DatabaseTestCase
|
||||
{
|
||||
public static $printBody = true;
|
||||
public static $url = 'https://www.kupshop.local/api/v1';
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
if (!findModule('api')) {
|
||||
self::markTestSkipped('Modul api je vypnutý.');
|
||||
}
|
||||
}
|
||||
|
||||
public function getPest()
|
||||
{
|
||||
$pest = new PestJSON(self::$url);
|
||||
|
||||
$pest->curl_opts[CURLOPT_SSL_VERIFYHOST] = 0;
|
||||
|
||||
$pest->setupAuth('wpj@wpj.cz', 'HzSlterxIZf22KLBFSw6');
|
||||
$pest->throw_exceptions = true;
|
||||
|
||||
return $pest;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test vlozeni polozky do kosiku
|
||||
*/
|
||||
public function testInsertIntoCart()
|
||||
{
|
||||
$body = $this->insertCartItem();
|
||||
|
||||
$this->printBody($body);
|
||||
$this->assertNotNull($body);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test smazani celeho kosiku
|
||||
*/
|
||||
public function testDeleteCart()
|
||||
{
|
||||
$url = $this->makeURL('/cart');
|
||||
|
||||
$pest = $this->getPest();
|
||||
|
||||
$order = [];
|
||||
|
||||
$body = $pest->delete($url, $order);
|
||||
|
||||
$this->printBody($body);
|
||||
$this->assertNotNull($body);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test dotazani na vsechny polozky v kosiku
|
||||
*/
|
||||
public function testGetAllCart()
|
||||
{
|
||||
$url = $this->makeURL('/cart');
|
||||
|
||||
$pest = $this->getPest();
|
||||
|
||||
$order = [];
|
||||
|
||||
$body = $pest->get($url, $order);
|
||||
|
||||
$this->printBody($body);
|
||||
$this->assertNotNull($body);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test smazani konkretni polozky v kosiku - nejdrive vlozi polozku, pak ji smaze
|
||||
*/
|
||||
public function testDeleteCartItem()
|
||||
{
|
||||
$response = $this->insertCartItem();
|
||||
|
||||
$url = $this->makeURL('/cart/'.$response[2]['id_cart_item']);
|
||||
|
||||
$pest = $this->getPest();
|
||||
|
||||
$order = [];
|
||||
|
||||
$body = $pest->delete($url, $order);
|
||||
|
||||
$this->printBody($body);
|
||||
$this->assertNotNull($body);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test ziskani konkretni polozky v kosiku - nejdrive vlozi polozku, pak ji nacte
|
||||
*/
|
||||
public function testGetCartItem()
|
||||
{
|
||||
$response = $this->insertCartItem();
|
||||
$this->printBody($response);
|
||||
$url = $this->makeURL('/cart/'.$response[2]['id_cart_item']);
|
||||
|
||||
$pest = $this->getPest();
|
||||
|
||||
$body = $pest->get($url);
|
||||
|
||||
$this->printBody($body);
|
||||
$this->assertNotNull($body);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test vytvoreni potvrzeni objednavky
|
||||
*/
|
||||
public function testSubmitCart()
|
||||
{
|
||||
$this->insertCartItem();
|
||||
|
||||
$url = $this->makeURL('/cart/submit');
|
||||
|
||||
$pest = $this->getPest();
|
||||
|
||||
$order = [];
|
||||
|
||||
$body = $pest->post($url, $order);
|
||||
|
||||
$this->printBody($body);
|
||||
$this->assertNotNull($body);
|
||||
}
|
||||
|
||||
public function testGetOrders()
|
||||
{
|
||||
$url = $this->makeURL('/order');
|
||||
|
||||
$pest = $this->getPest();
|
||||
|
||||
$order = [];
|
||||
|
||||
$body = $pest->get($url, $order);
|
||||
|
||||
$order_code = $body['order_numbers'][0];
|
||||
$this->printBody($body);
|
||||
$this->assertNotNull($body);
|
||||
|
||||
return $order_code;
|
||||
}
|
||||
|
||||
public function testGetOrderById()
|
||||
{
|
||||
$order_code = $this->testGetOrders();
|
||||
|
||||
$url = $this->makeURL('/order/'.$order_code);
|
||||
|
||||
$pest = $this->getPest();
|
||||
|
||||
$order = [];
|
||||
|
||||
$body = $pest->get($url, $order);
|
||||
|
||||
$this->printBody($body);
|
||||
$this->assertNotNull($body);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pomocna funkce pro vkladani do kosiku
|
||||
*/
|
||||
private function insertCartItem()
|
||||
{
|
||||
$url = $this->makeURL('/cart');
|
||||
|
||||
$pest = $this->getPest();
|
||||
|
||||
$order = [
|
||||
['code' => 3,
|
||||
'quantity' => 4,
|
||||
],
|
||||
];
|
||||
|
||||
$response = $pest->post($url, $order);
|
||||
|
||||
return $response['items'];
|
||||
}
|
||||
|
||||
private function makeURL($object)
|
||||
{
|
||||
return self::$url.$object.'?XDEBUG_SESSION_START=10312';
|
||||
}
|
||||
|
||||
private function printBody($body)
|
||||
{
|
||||
if (self::$printBody) {
|
||||
echo '<pre>';
|
||||
var_dump($body);
|
||||
echo '</pre>';
|
||||
}
|
||||
}
|
||||
}
|
||||
54
tests/functional/BugsTest/CartBugsTest.php
Normal file
54
tests/functional/BugsTest/CartBugsTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
||||
|
||||
class CartBugsTest extends DatabaseTestCase
|
||||
{
|
||||
use CartTestTrait;
|
||||
|
||||
public function testCartUpdateAddressesUndefinedTotalPricePay()
|
||||
{
|
||||
$this->createCart();
|
||||
$cart = $this->cart;
|
||||
|
||||
$cart->setDeliveryAndPayment(1, 1);
|
||||
$cart->updateAddresses([
|
||||
'email' => 'prokop@wpj.cz',
|
||||
'name' => 'TEST',
|
||||
'surname' => 'test',
|
||||
'phone' => '123456789',
|
||||
'street' => 'cdsa 12',
|
||||
'city' => '441',
|
||||
'zip' => '54303',
|
||||
'country' => 'CZ',
|
||||
'firm' => '',
|
||||
'ico' => '',
|
||||
'dic' => '',
|
||||
], []);
|
||||
}
|
||||
|
||||
public function test200CartStepsResponse()
|
||||
{
|
||||
$this->createCart();
|
||||
$cart = $this->cart;
|
||||
|
||||
$cart->createFromDB();
|
||||
|
||||
$client = $this->createClient();
|
||||
$client->request('POST', '/kosik/', ['act' => 'add', 's' => 'cart', 'IDproduct' => 1]);
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
/* TODO: Tohle je zakomentovany kvuli Smarty bugu. Smarty nejspis dela problem kompilace a spusteni stejny templaty v jednom procesu.
|
||||
$client->request('POST', '/kosik/', ['OrderNext' => 'delivery']);
|
||||
//$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$client->request('POST', '/kosik/', ['act' => 'recount', 'delivery_id' => 1, 'payment_id' => 1]);
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$client->request('POST', '/kosik/', ['OrderNext' => 'user']);
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
*/
|
||||
// $client->request('POST', '/kosik/dodaci-udaje/?invoice%5Bemail%5D=prokop%40wpj.cz&invoice%5Bname%5D=test&invoice%5Bsurname%5D=test&invoice%5Bphone%5D=773568922&invoice%5Bstreet%5D=Fugnerova+1288&invoice%5Bcity%5D=test&invoice%5Bzip%5D=54303&invoice%5Bcountry%5D=CZ&different_address=0&delivery%5Bname%5D=&delivery%5Bsurname%5D=&delivery%5Bfirm%5D=&delivery%5Bstreet%5D=&delivery%5Bcity%5D=&delivery%5Bzip%5D=&delivery%5Bcountry%5D=CZ&firm_address=0&invoice%5Bfirm%5D=&invoice%5Bico%5D=&invoice%5Bdic%5D=¬eUser=&OrderNext=summary');
|
||||
//
|
||||
// $this->assertTrue($client->getResponse()->isSuccessful());
|
||||
}
|
||||
}
|
||||
78
tests/functional/BugsTest/OrderBugsTest.json
Normal file
78
tests/functional/BugsTest/OrderBugsTest.json
Normal file
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"orders":[
|
||||
{
|
||||
"id": 115700,
|
||||
"order_no": "3617115700",
|
||||
"currency": "EUR",
|
||||
"currency_rate": 25.6450,
|
||||
"id_user": null,
|
||||
"date_created": "2017-10-31 12:50:14",
|
||||
"date_accept": "2017-10-31 13:39:12",
|
||||
"date_handle": "2017-10-31 14:21:20",
|
||||
"date_updated": "2017-10-31 14:21:20",
|
||||
"date_due": null,
|
||||
"status": 7,
|
||||
"status_payed": 0,
|
||||
"status_dispatch": 0,
|
||||
"status_storno": 0,
|
||||
"total_price": 13,
|
||||
"invoice_name": "Miela",
|
||||
"invoice_surname": "iková",
|
||||
"invoice_firm": "",
|
||||
"invoice_ico": "",
|
||||
"invoice_dic": "",
|
||||
"invoice_street": "25",
|
||||
"invoice_city": "Pstrica",
|
||||
"invoice_zip": "01701",
|
||||
"invoice_country": "SK",
|
||||
"invoice_phone": "+4219090",
|
||||
"invoice_email": "ail.com",
|
||||
"delivery_name": "Miela",
|
||||
"delivery_surname": "iková",
|
||||
"delivery_firm": "",
|
||||
"delivery_street": "",
|
||||
"delivery_city": "",
|
||||
"delivery_zip": "01701",
|
||||
"delivery_country": "SK",
|
||||
"delivery_type": "Dobírkou - PPL Slovensko",
|
||||
"id_delivery": 8,
|
||||
"delivery_complete": "",
|
||||
"note_user": "",
|
||||
"note_admin": "{\"discount_data\":{\"product\":{\"27\":\"380101\"},\"variation\":{\"27\":\"114537\"}},\"payment_data\":{\"method\":\"BANK_ACCOUNT__GIBASKBX\"},\"conversion_sent\":1,\"enableEdit\":true}",
|
||||
"flags": "",
|
||||
"admin": null
|
||||
}
|
||||
],
|
||||
"order_items": [
|
||||
{
|
||||
"id": 368193,
|
||||
"id_order": 115700,
|
||||
"id_product": 1,
|
||||
"id_variation": 2,
|
||||
"pieces": 1,
|
||||
"pieces_reserved": 1,
|
||||
"piece_price": 10,
|
||||
"total_price": 10,
|
||||
"descr": "Frais Monde Pleťová maska Frais Monde Organic Spa Mask Yellow Clay 75 ml",
|
||||
"tax": 21.0,
|
||||
"date": "2017-10-31 11:50:14",
|
||||
"note": "",
|
||||
"discount": 0.0000
|
||||
},
|
||||
{
|
||||
"id": 368212,
|
||||
"id_order": 115700,
|
||||
"id_product": null,
|
||||
"id_variation": null,
|
||||
"pieces": 1,
|
||||
"pieces_reserved": 1,
|
||||
"piece_price": 3,
|
||||
"total_price": 3,
|
||||
"descr": "Dobírkou - PPL Slovensko",
|
||||
"tax": 21.0,
|
||||
"date": "2017-10-30 23:00:00",
|
||||
"note": "{\"item_type\":\"delivery\"}",
|
||||
"discount": 0.0000
|
||||
}
|
||||
]
|
||||
}
|
||||
39
tests/functional/BugsTest/OrderBugsTest.php
Normal file
39
tests/functional/BugsTest/OrderBugsTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
class OrderBugsTest extends DatabaseTestCase
|
||||
{
|
||||
use \KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
||||
|
||||
public function testBug6320()
|
||||
{
|
||||
global $dbcfg;
|
||||
$dbcfg->currencies['CZK']['value'] = 1;
|
||||
|
||||
$user = User::createFromId(2);
|
||||
$this->getContextManager()->activateUser($user, function () {
|
||||
$this->createCart();
|
||||
|
||||
$this->cart->createFromDB();
|
||||
$this->cart->delivery['name'] = 'test';
|
||||
$this->cart->delivery['surname'] = 'test';
|
||||
$this->cart->delivery['firm'] = null; // Caused delivery_firm cannot be null in INSERT
|
||||
unset($this->cart->delivery['city']); // Caused undefined index in submitOrder
|
||||
|
||||
$this->assertInstanceOf('Order', $this->cart->submitOrder());
|
||||
});
|
||||
}
|
||||
|
||||
public function testChangeDeliveryInEurOrder()
|
||||
{
|
||||
$order = new Order();
|
||||
$order->createFromDB(115700);
|
||||
|
||||
$order->changeDeliveryType(3);
|
||||
$this->assertEquals('16.85', $order->total_price->asFloat());
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->getJsonDataSetFromFile();
|
||||
}
|
||||
}
|
||||
55
tests/functional/CNBTest.php
Normal file
55
tests/functional/CNBTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Context\CurrencyContext;
|
||||
|
||||
class CNBTest extends \DatabaseTestCase
|
||||
{
|
||||
public function testCNBTest()
|
||||
{
|
||||
CNB::setUrl(__DIR__.'/CNBTest.txt');
|
||||
|
||||
CNB::updateSharedCurrencies();
|
||||
CNB::updateCurrencies();
|
||||
|
||||
$context = $this->get(CurrencyContext::class);
|
||||
$this->assertEquals('26.17', $context->getSupported()['EUR']->getRate()->asFloat());
|
||||
}
|
||||
|
||||
public function testForeignCurrencyCNBTest()
|
||||
{
|
||||
$dbcfg = Settings::getDefault();
|
||||
$dbcfg->currency = 'EUR';
|
||||
|
||||
$this->tearDownContainer();
|
||||
|
||||
/** @var CurrencyContext $context */
|
||||
$context = $this->get(CurrencyContext::class);
|
||||
$context->getSupported()['EUR']->setRate(toDecimal(1.02));
|
||||
$context->getSupported()['CZK']->setRate(toDecimal(0.0380));
|
||||
$context->getSupported()['CZK']->setSync('Y');
|
||||
|
||||
CNB::setUrl(__DIR__.'/CNBTest.txt');
|
||||
|
||||
CNB::updateSharedCurrencies();
|
||||
CNB::updateCurrencies();
|
||||
|
||||
$context = $this->get(CurrencyContext::class);
|
||||
$this->assertEquals('1', $context->getSupported()['EUR']->getRate()->asFloat());
|
||||
$this->assertEqualsWithDelta(0.03821169277799, $context->getSupported()['CZK']->getRate()->asFloat(), 0.00000000000001);
|
||||
}
|
||||
|
||||
public function testCNBCorrections()
|
||||
{
|
||||
/** @var CurrencyContext $context */
|
||||
$context = $this->get(CurrencyContext::class);
|
||||
|
||||
$context->getSupported()['EUR']->setCorrections(toDecimal(0.83));
|
||||
|
||||
CNB::setUrl(__DIR__.'/CNBTest.txt');
|
||||
|
||||
CNB::updateSharedCurrencies();
|
||||
CNB::updateCurrencies(true);
|
||||
|
||||
$this->assertEquals('27', $context->getSupported()['EUR']->getRate()->asFloat());
|
||||
}
|
||||
}
|
||||
34
tests/functional/CNBTest.txt
Normal file
34
tests/functional/CNBTest.txt
Normal file
@@ -0,0 +1,34 @@
|
||||
19.06.2017 #117
|
||||
země|měna|množství|kód|kurz
|
||||
Austrálie|dolar|1|AUD|17,799
|
||||
Brazílie|real|1|BRL|7,083
|
||||
Bulharsko|lev|1|BGN|13,381
|
||||
Čína|renminbi|1|CNY|3,429
|
||||
Dánsko|koruna|1|DKK|3,519
|
||||
EMU|euro|1|EUR|26,170
|
||||
Filipíny|peso|100|PHP|46,724
|
||||
Hongkong|dolar|1|HKD|2,996
|
||||
Chorvatsko|kuna|1|HRK|3,530
|
||||
Indie|rupie|100|INR|36,273
|
||||
Indonesie|rupie|1000|IDR|1,759
|
||||
Izrael|šekel|1|ILS|6,634
|
||||
Japonsko|jen|100|JPY|21,060
|
||||
Jihoafrická rep.|rand|1|ZAR|1,801
|
||||
Jižní Korea|won|100|KRW|2,061
|
||||
Kanada|dolar|1|CAD|17,652
|
||||
Maďarsko|forint|100|HUF|8,522
|
||||
Malajsie|ringgit|1|MYR|5,463
|
||||
Mexiko|peso|1|MXN|1,301
|
||||
MMF|SDR|1|XDR|32,270
|
||||
Norsko|koruna|1|NOK|2,769
|
||||
Nový Zéland|dolar|1|NZD|16,982
|
||||
Polsko|zlotý|1|PLN|6,212
|
||||
Rumunsko|nové leu|1|RON|5,701
|
||||
Rusko|rubl|100|RUB|40,152
|
||||
Singapur|dolar|1|SGD|16,903
|
||||
Švédsko|koruna|1|SEK|2,686
|
||||
Švýcarsko|frank|1|CHF|24,076
|
||||
Thajsko|baht|100|THB|68,855
|
||||
Turecko|lira|1|TRY|6,663
|
||||
USA|dolar|1|USD|23,369
|
||||
Velká Británie|libra|1|GBP|29,901
|
||||
619
tests/functional/CartTest.php
Normal file
619
tests/functional/CartTest.php
Normal file
@@ -0,0 +1,619 @@
|
||||
<?php
|
||||
|
||||
use Heureka\ShopCertification;
|
||||
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
||||
use KupShop\DevelopmentBundle\Util\Tests\RequestCookiesTrait;
|
||||
use KupShop\KupShopBundle\Config;
|
||||
use KupShop\KupShopBundle\Context\ContextManager;
|
||||
use KupShop\KupShopBundle\Context\CurrencyContext;
|
||||
use KupShop\KupShopBundle\Context\UserContext;
|
||||
use KupShop\MarketingBundle\EventListener\OrderConversionListener;
|
||||
use KupShop\OrderingBundle\Util\CartFactory;
|
||||
use KupShop\OrderingBundle\Util\Order\OrderInfo;
|
||||
use KupShop\OrderingBundle\Util\Purchase\PurchaseUtil;
|
||||
|
||||
class CartTest extends DatabaseTestCase
|
||||
{
|
||||
use CartTestTrait;
|
||||
use RequestCookiesTrait;
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
Delivery::clearCache();
|
||||
}
|
||||
|
||||
public function testSharedAndNonSharedCart(): void
|
||||
{
|
||||
$cartFactory = $this->get(CartFactory::class);
|
||||
|
||||
$sharedCartFromPurchaseUtil = $this->get(PurchaseUtil::class)->getCart();
|
||||
$sharedCartFromDI = $this->get(\KupShop\OrderingBundle\Cart::class);
|
||||
|
||||
$this->assertSame(spl_object_id($sharedCartFromDI), spl_object_id($sharedCartFromPurchaseUtil), 'Rikam si o shared Cart, takze musi byt vzdy stejny ID objektu v pameti');
|
||||
|
||||
$nonSharedCartFromFactory = $cartFactory->create();
|
||||
|
||||
$this->assertNotSame(spl_object_id($sharedCartFromDI), spl_object_id($nonSharedCartFromFactory), 'Shared a non-shared cart nesmi byt stejny');
|
||||
$this->assertNotSame(spl_object_id($nonSharedCartFromFactory), spl_object_id($cartFactory->create()), 'Mam non-shared cart a vytvarim dalsi non-shared cart, ktery nesmi byt stejny jako ten predesly');
|
||||
}
|
||||
|
||||
public function testNonSharedCartDependencies(): void
|
||||
{
|
||||
$cart = $this->get(CartFactory::class)->create();
|
||||
|
||||
$requiredProperties = $this->getRequiredProperties($cart);
|
||||
|
||||
$reflection = new ReflectionClass($cart);
|
||||
|
||||
// test that all required properties are not null
|
||||
foreach ($reflection->getProperties() as $property) {
|
||||
if (!in_array($property->getName(), $requiredProperties)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$property->setAccessible(true);
|
||||
|
||||
$this->assertNotNull($property->getValue($cart), '#[Required] property nemuze byt null pokud se vytvari non-shared kosik pres CartFactory!');
|
||||
}
|
||||
}
|
||||
|
||||
// otestuje, ze se objednavka vytvori po novu pres PurchaseState
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testOrderSubmitFromPurchaseState($applyModule): void
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
$this->addModule(Modules::ORDERS, Modules::SUB_ORDERS_FROM_PURCHASE_STATE);
|
||||
|
||||
$this->prepareCart();
|
||||
$this->insertProduct(1, 16, 3);
|
||||
$this->insertProduct(10);
|
||||
|
||||
$order = $this->submitOrder();
|
||||
|
||||
$this->removeModule(Modules::ORDERS, Modules::SUB_ORDERS_FROM_PURCHASE_STATE);
|
||||
|
||||
$this->assertInstanceOf(Order::class, $order);
|
||||
|
||||
$this->assertCount(2, $order->items);
|
||||
$this->assertEquals(4009, $order->getTotalPrice()->getPriceWithVat()->asFloat());
|
||||
$this->assertEqualsWithDelta($this->cart->totalPricePay->asFloat(), $this->order->total_price->asFloat(), 0.01);
|
||||
|
||||
$this->assertEquals(OrderInfo::ORDER_SOURCE_SHOP, $order->source);
|
||||
}
|
||||
|
||||
/** @dataProvider data_DeliveryPriceNotOnFirstStep */
|
||||
public function testCartDeliveryPriceNotOnFirstStep($goBack, $expectedPrice)
|
||||
{
|
||||
$this->createCart();
|
||||
$this->insertProduct(1, 16, 1);
|
||||
$this->setDeliveryType(2);
|
||||
|
||||
$this->visitStep('delivery');
|
||||
|
||||
if ($goBack) {
|
||||
$this->cart->actualStep = 'cart';
|
||||
}
|
||||
|
||||
$this->cart->createFromDB();
|
||||
|
||||
$this->assertEquals($expectedPrice, $this->cart->totalPricePay->asFloat());
|
||||
}
|
||||
|
||||
public function data_DeliveryPriceNotOnFirstStep()
|
||||
{
|
||||
yield [true, 800];
|
||||
yield [false, 870];
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testOrderingRegistrationInForeignCurrency($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
$order = $this->getContextManager()->activateContexts(
|
||||
[
|
||||
CurrencyContext::class => 'EUR',
|
||||
UserContext::class => ContextManager::FORCE_EMPTY,
|
||||
],
|
||||
function () {
|
||||
$this->createCart();
|
||||
|
||||
$this->insertProduct(1, 16, 1);
|
||||
$this->setInvoice();
|
||||
$this->setDeliveryType();
|
||||
|
||||
$this->cart->register = true;
|
||||
$this->cart->createFromDB();
|
||||
|
||||
return $this->cart->submitOrder();
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertEquals('EUR', $order->currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_orderingRegistration
|
||||
*/
|
||||
public function testOrderingRegistration($newsletterEnable, $getNewsExpect)
|
||||
{
|
||||
$settings = Settings::getDefault();
|
||||
$settings->newsletter['enable'] = $newsletterEnable;
|
||||
|
||||
$this->createCart();
|
||||
|
||||
$this->insertProduct(1, 16, 1);
|
||||
$this->setInvoice();
|
||||
$this->setDeliveryType();
|
||||
|
||||
$this->cart->register = true;
|
||||
$this->cart->createFromDB();
|
||||
$order = $this->cart->submitOrder();
|
||||
|
||||
// createFromLogin to avoid cached user when using getCurrentUser
|
||||
$user = User::createFromLogin('test@wpj.cz');
|
||||
|
||||
$this->assertInstanceOf(Order::class, $order);
|
||||
$this->assertEquals('800', $order->total_price->asFloat());
|
||||
$this->assertEquals($user['email'], 'test@wpj.cz');
|
||||
$this->assertEquals($user['get_news'], $getNewsExpect);
|
||||
}
|
||||
|
||||
public function data_orderingRegistration()
|
||||
{
|
||||
return [
|
||||
['Y', 'N'],
|
||||
['N', 'Y'],
|
||||
];
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testGetPayments($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
$this->createCart();
|
||||
$this->cart->createFromDB();
|
||||
$payments = $this->cart->getPayments();
|
||||
|
||||
$this->assertEquals(12, $payments[1]['price']['value_with_vat']->asFloat());
|
||||
$this->assertEquals(round(12 / 1.21, 4), $payments[1]['price']['value_without_vat']->asFloat());
|
||||
$this->assertEquals(24, $payments[2]['price']['value_with_vat']->asFloat());
|
||||
$this->assertEquals(36, $payments[3]['price']['value_with_vat']->asFloat());
|
||||
$this->assertEquals(48, $payments[4]['price']['value_with_vat']->asFloat());
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testAddItemToCart($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
$this->loginUser(1);
|
||||
|
||||
$this->createCart();
|
||||
$this->insertProduct(1, 16);
|
||||
|
||||
$this->cart->createFromDB();
|
||||
|
||||
$this->assertEquals(800, $this->cart->totalPriceWithVat->asFloat());
|
||||
|
||||
$this->checkOrderPriceIsSameAsCart();
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testAddItemToCartNegativePieces($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
$this->createCart();
|
||||
$item = ['id_product' => 1, 'id_variation' => 16, 'pieces' => -1];
|
||||
$itemId = $this->cart->addItem($item);
|
||||
$this->assertEmpty($itemId);
|
||||
$item = ['id_product' => 1, 'id_variation' => 16, 'pieces' => 0];
|
||||
$itemId = $this->cart->addItem($item);
|
||||
$this->assertEmpty($itemId);
|
||||
|
||||
$this->cart->createFromDB();
|
||||
|
||||
$this->assertEquals(0, $this->cart->totalPriceWithVat->asFloat());
|
||||
$this->assertEmpty($this->cart->products);
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testCheckItemsInCartNotInStore($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
// order_not_in_store == Y
|
||||
$this->createCart();
|
||||
$this->insertProduct(1, 16, 2);
|
||||
$this->cart->createFromDB();
|
||||
$return = $this->cart->checkCartItems();
|
||||
|
||||
$this->assertEquals(null, $return);
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testCheckItemsInCartInStore($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
global $dbcfg, $cfg;
|
||||
|
||||
$cfg['Modules']['products_suppliers'] = false;
|
||||
|
||||
$dbcfg->order_not_in_store = 'N';
|
||||
// order_not_in_store == N
|
||||
$this->createCart();
|
||||
$this->insertProduct(1, 16, 2);
|
||||
$this->cart->createFromDB();
|
||||
|
||||
$this->expectException(\KupShop\OrderingBundle\Exception\CartValidationException::class);
|
||||
|
||||
$return = $this->cart->checkCartItems();
|
||||
|
||||
$this->assertEquals(30, $return);
|
||||
}
|
||||
|
||||
public function testCheckItemsInCartVisibility()
|
||||
{
|
||||
$this->createCart();
|
||||
$this->insertProduct(4, 1, 1);
|
||||
$this->cart->createFromDB();
|
||||
// cart product variation is visible
|
||||
$return = $this->cart->checkCartItems();
|
||||
$this->assertEquals(null, $return);
|
||||
|
||||
$qb = sqlQueryBuilder()->update('products_variations')
|
||||
->directValues(['figure' => 'N'])
|
||||
->andWhere('id=1')->execute();
|
||||
// cart product variation is not visible
|
||||
$return = $this->cart->checkCartItems();
|
||||
$this->assertEquals(31, $return);
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testCheckItemsInCartInSupplierStore($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
global $dbcfg, $cfg;
|
||||
|
||||
$cfg['Modules']['products_suppliers'] = ['delivery_time' => -2];
|
||||
$dbcfg->order_not_in_store = 'N';
|
||||
// order_not_in_store == N
|
||||
$this->createCart();
|
||||
$this->insertProduct(1, 16, 2);
|
||||
$this->cart->createFromDB();
|
||||
$return = $this->cart->checkCartItems();
|
||||
|
||||
$this->assertEquals(null, $return);
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->getJsonDataSet(
|
||||
/* @lang JSON */ '
|
||||
{"products_of_suppliers" : [
|
||||
{
|
||||
"id":1,
|
||||
"id_product":1,
|
||||
"id_variation":16,
|
||||
"id_supplier":1,
|
||||
"code":123,
|
||||
"in_store":2
|
||||
}
|
||||
]}'
|
||||
);
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testAddItemToCartInEuro($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
$this->loginUser(1);
|
||||
|
||||
$c = $this->get(\KupShop\KupShopBundle\Context\CurrencyContext::class);
|
||||
$c->activate('EUR');
|
||||
$currency = $this->get(\KupShop\KupShopBundle\Context\CurrencyContext::class)->getActive();
|
||||
$currency->setRate(toDecimal(26));
|
||||
$currency->setPriceRoundOrder('0');
|
||||
$currency->setPriceRound('0');
|
||||
|
||||
$this->createCart();
|
||||
$this->insertProduct(1, 16);
|
||||
|
||||
$this->cart->createFromDB();
|
||||
|
||||
$this->assertEquals(800 / 26, $this->cart->totalPricePay->asFloat(), '', 0.01);
|
||||
|
||||
$this->checkOrderPriceIsSameAsCart();
|
||||
|
||||
changeCurrency();
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testAddItemToCartInEuroWithRounding($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
$this->loginUser(1);
|
||||
|
||||
$context = $this->get(\KupShop\KupShopBundle\Context\CurrencyContext::class);
|
||||
$context->activate('EUR');
|
||||
$currency = $context->getActive();
|
||||
$currency->setRate(26);
|
||||
$currency->setPriceRoundOrder('100');
|
||||
|
||||
$this->createCart();
|
||||
$this->insertProduct(1, 16);
|
||||
|
||||
$this->cart->createFromDB();
|
||||
|
||||
$this->assertEquals(round(800 / 26), $this->cart->totalPricePay->asFloat(), '', 0.01);
|
||||
|
||||
$this->checkOrderPriceIsSameAsCart();
|
||||
}
|
||||
|
||||
public function testSendZboziConversion()
|
||||
{
|
||||
// Prepare settings
|
||||
Settings::getDefault()->analytics = [
|
||||
'zbozi_cz_feedback' => [
|
||||
'ID' => '129931',
|
||||
'secret_key' => 'CXIGnEMhnOrP32au62B7k5tgAOhiTiyK',
|
||||
],
|
||||
];
|
||||
|
||||
// Restart container to force reload event listeners
|
||||
$this->tearDownContainer();
|
||||
$this->restoreDefaultCtrl();
|
||||
|
||||
$zboziClientMock = $this->getMockBuilder(\Soukicz\Zbozicz\Client::class)
|
||||
->setMethods(['sendOrder'])
|
||||
->setConstructorArgs(['129931', 'CXIGnEMhnOrP32au62B7k5tgAOhiTiyK'])
|
||||
->getMock();
|
||||
|
||||
$data = [];
|
||||
$zboziClientMock->expects($this->once())->method('sendOrder')->with(
|
||||
$this->callback(function (Soukicz\Zbozicz\Order $order) use (&$data, $zboziClientMock) {
|
||||
$data = json_decode_strict($zboziClientMock->createRequest($order)->getBody(), true);
|
||||
|
||||
return true;
|
||||
})
|
||||
);
|
||||
|
||||
$requestStack = $this->getRequestStackWithCookies('cookie-bar', 'analytics_storage');
|
||||
|
||||
$listenerMock = $this->getMockBuilder(OrderConversionListener::class)
|
||||
->setMethods(['getZboziClient'])
|
||||
->setConstructorArgs(
|
||||
[
|
||||
$this->get(\KupShop\KupShopBundle\Util\Price\PriceUtil::class),
|
||||
$requestStack,
|
||||
$this->get(\KupShop\KupShopBundle\Context\CountryContext::class),
|
||||
$this->get(\KupShop\KupShopBundle\Context\CurrencyContext::class),
|
||||
]
|
||||
)
|
||||
->getMock();
|
||||
$listenerMock->method('getZboziClient')->willReturn($zboziClientMock);
|
||||
$listenerMock->setDomainContext(\KupShop\KupShopBundle\Util\Contexts::get(\KupShop\KupShopBundle\Context\DomainContext::class));
|
||||
$this->set(OrderConversionListener::class, $listenerMock);
|
||||
|
||||
$this->loginUser(2);
|
||||
|
||||
$context = $this->get(\KupShop\KupShopBundle\Context\CurrencyContext::class);
|
||||
$context->activate('EUR');
|
||||
|
||||
$this->createCart();
|
||||
$this->insertProduct(1, 16);
|
||||
|
||||
$this->cart->createFromDB();
|
||||
|
||||
$order = $this->cart->submitOrder();
|
||||
|
||||
$this->assertInstanceOf('\Order', $order);
|
||||
|
||||
$this->assertNotEmpty($data);
|
||||
$this->assertEquals([
|
||||
'PRIVATE_KEY' => 'CXIGnEMhnOrP32au62B7k5tgAOhiTiyK',
|
||||
'orderId' => $order->order_no,
|
||||
'email' => 'wpj@wpj.cz',
|
||||
'deliveryType' => 'GLS',
|
||||
'deliveryPrice' => 104,
|
||||
'paymentType' => 'dobírka PPL',
|
||||
'cart' => [
|
||||
[
|
||||
'productName' => 'DeWALT DeWALT DCD780C2 aku vrtačka',
|
||||
'itemId' => '9',
|
||||
'unitPrice' => 6000,
|
||||
'quantity' => '1',
|
||||
],
|
||||
[
|
||||
'productName' => 'Nike NIKE Capri LACE Test Dlouheho Nazvu Produktu Test Dlouheho Produktu Tes (Velikost: 45)',
|
||||
'itemId' => '1_16',
|
||||
'unitPrice' => 800,
|
||||
'quantity' => '1',
|
||||
],
|
||||
],
|
||||
'sandbox' => false,
|
||||
'otherCosts' => 0,
|
||||
], $data);
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testHeurekaConversionOptions($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
/** @var OrderConversionListener $listener */
|
||||
$listener = $this->get(OrderConversionListener::class);
|
||||
/** @var \KupShop\KupShopBundle\Context\CountryContext $countryContext */
|
||||
$countryContext = $this->get(\KupShop\KupShopBundle\Context\CountryContext::class);
|
||||
$languageContext = $this->get(\KupShop\KupShopBundle\Context\LanguageContext::class);
|
||||
|
||||
// Prepare settings
|
||||
Settings::getDefault()->analytics = [
|
||||
'heureka_overeno' => [
|
||||
'ID' => 'dksag41s2fdsd10vs',
|
||||
],
|
||||
];
|
||||
$this->assertEquals(
|
||||
['heureka_id' => 'dksag41s2fdsd10vs', 'options' => ['service' => ShopCertification::HEUREKA_CZ]],
|
||||
$listener->getHeurekaOptions()
|
||||
);
|
||||
|
||||
$languageContext->activate('sk');
|
||||
Settings::getDefault()->analytics = [
|
||||
'heureka_overeno' => [
|
||||
'ID' => 'dksag41s2fdsd10vs',
|
||||
],
|
||||
];
|
||||
$this->assertEquals(
|
||||
['heureka_id' => 'dksag41s2fdsd10vs', 'options' => ['service' => ShopCertification::HEUREKA_SK]],
|
||||
$listener->getHeurekaOptions()
|
||||
);
|
||||
|
||||
$cfg = Config::get();
|
||||
$languageContext->activate('cs');
|
||||
$cfg['Modules']['translations'] = false;
|
||||
\Settings::clearCache(true);
|
||||
Settings::getDefault()->analytics = [
|
||||
'heureka_overeno' => [
|
||||
'ID' => 'dksag41s2fdsd10vs',
|
||||
],
|
||||
];
|
||||
$this->assertEquals(
|
||||
['heureka_id' => 'dksag41s2fdsd10vs', 'options' => ['service' => ShopCertification::HEUREKA_CZ]],
|
||||
$listener->getHeurekaOptions()
|
||||
);
|
||||
|
||||
Settings::getDefault()->analytics = [
|
||||
'heureka_overeno' => [
|
||||
'ID' => 'dksag41s2fdsd10vs',
|
||||
'ID_SK' => 'SKdksag41s2fdsd10vsSK',
|
||||
],
|
||||
];
|
||||
$languageContext->activate('sk');
|
||||
$countryContext->activate('SK');
|
||||
Settings::getDefault()->analytics = [
|
||||
'heureka_overeno' => [
|
||||
'ID' => 'dksag41s2fdsd10vs',
|
||||
'ID_SK' => 'SKdksag41s2fdsd10vsSK',
|
||||
],
|
||||
];
|
||||
$this->assertEquals(
|
||||
['heureka_id' => 'SKdksag41s2fdsd10vsSK', 'options' => ['service' => ShopCertification::HEUREKA_SK]],
|
||||
$listener->getHeurekaOptions()
|
||||
);
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testFreeDelivery($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
sqlQuery('UPDATE delivery_type SET price_dont_countin_from=800 WHERE id=4');
|
||||
|
||||
$this->createCart();
|
||||
$this->setInvoice();
|
||||
$this->insertProduct(1, 16);
|
||||
$this->setDeliveryType(4);
|
||||
|
||||
$this->checkOrderPriceIsSameAsCart();
|
||||
|
||||
$this->assertEquals('800', $this->cart->totalPricePay->asFloat());
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testFreeDeliveryForUnregisteredWithUser($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
// pro neregistrované je nastaveno 800, ale melo by platit i pro registrovane.
|
||||
sqlQuery('UPDATE delivery_type SET price_dont_countin_from=800 WHERE id=4');
|
||||
|
||||
$user = User::createFromId(1);
|
||||
$user->activateUser();
|
||||
|
||||
$this->createCart();
|
||||
$this->insertProduct(1, 16);
|
||||
$this->setDeliveryType(4);
|
||||
|
||||
$this->checkOrderPriceIsSameAsCart();
|
||||
|
||||
$this->assertEquals('800', $this->cart->totalPricePay->asFloat());
|
||||
}
|
||||
|
||||
public function testFreeDeliveryForRegisteredWithoutUser()
|
||||
{
|
||||
// Pro neregistrované není nic nastaveno, pro registrované od 400, tzn tento neni registrovany a ma se mu pricist doprava
|
||||
sqlQuery('UPDATE delivery_type SET price_dont_countin_from_reg=400 WHERE id=4');
|
||||
|
||||
$this->createCart();
|
||||
$this->setInvoice();
|
||||
$this->insertProduct(1, 16);
|
||||
$this->setDeliveryType(4);
|
||||
$this->visitStep('delivery');
|
||||
$this->checkOrderPriceIsSameAsCart();
|
||||
|
||||
$this->assertEquals('904', $this->cart->totalPricePay->asFloat());
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testFreeDeliveryForRegisteredWithtUser($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
// Pro neregistrované není nic nastaveno, pro registrované od 400, tzn tento neni registrovany a nema se mu pricist doprava
|
||||
sqlQuery('UPDATE delivery_type SET price_dont_countin_from_reg=400 WHERE id=4');
|
||||
|
||||
$user = User::createFromId(1);
|
||||
$user->activateUser();
|
||||
|
||||
$this->createCart();
|
||||
$this->insertProduct(1, 16);
|
||||
$this->setDeliveryType(4);
|
||||
$this->visitStep('delivery');
|
||||
$this->checkOrderPriceIsSameAsCart();
|
||||
|
||||
$this->assertEquals('800', $this->cart->totalPricePay->asFloat());
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testCartClean($applyModule)
|
||||
{
|
||||
$applyModule();
|
||||
// vytvoříme nový košík, který by neměl být smazán - ostatní jsou staršího data, tak dojde k jejich smazání
|
||||
$this->createCart();
|
||||
$this->insertProduct(1, 16);
|
||||
|
||||
$cl = new \KupShop\OrderingBundle\EventListener\CronListener();
|
||||
$cl->cartCleanup();
|
||||
$this->assertTableRowCount('cart', 2);
|
||||
}
|
||||
|
||||
/** @dataProvider data_purchaseStateProvider */
|
||||
public function testDeliveryPrice(callable $applyModule): void
|
||||
{
|
||||
$applyModule();
|
||||
|
||||
$cart = $this->prepareCart();
|
||||
$cart->setTransport(3);
|
||||
$product = [
|
||||
'id_product' => 7,
|
||||
'id_variation' => 8,
|
||||
'pieces' => 1,
|
||||
];
|
||||
$cart->addItem($product);
|
||||
|
||||
$cart->createFromDB();
|
||||
|
||||
$order = $cart->submitOrder();
|
||||
$price = $order->getTotalPrice();
|
||||
|
||||
$this->assertEqualsWithDelta(922.0, $price->getPriceWithVat()->asFloat(), 1);
|
||||
}
|
||||
}
|
||||
46
tests/functional/ContentTest/EmailTest.json
Normal file
46
tests/functional/ContentTest/EmailTest.json
Normal file
File diff suppressed because one or more lines are too long
288
tests/functional/ContentTest/EmailTest.php
Normal file
288
tests/functional/ContentTest/EmailTest.php
Normal file
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
|
||||
use KupShop\DevelopmentBundle\MailArchive;
|
||||
use KupShop\KupShopBundle\Email\OrderCreateAdminEmail;
|
||||
|
||||
class EmailTest extends \DatabaseTestCase
|
||||
{
|
||||
use \KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
||||
|
||||
/** @var MailArchive */
|
||||
protected $mailArchive;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$conn = $this->getConnection();
|
||||
$conn->getConnection()->query('set foreign_key_checks=0');
|
||||
parent::setUp();
|
||||
$conn->getConnection()->query('set foreign_key_checks=1');
|
||||
|
||||
$this->mailArchive = $this->get(MailArchive::class);
|
||||
|
||||
$this->setTelfaSettings();
|
||||
}
|
||||
|
||||
public function testEmailInChangeStatus()
|
||||
{
|
||||
$cfg = \KupShop\KupShopBundle\Config::get();
|
||||
|
||||
$this->mailArchive->clearArchive();
|
||||
|
||||
$order = new Order();
|
||||
$order->createFromDB(2);
|
||||
$order->changeStatus(2);
|
||||
|
||||
$this->assertContains("stav Vaší objednávky číslo <strong>{$order->order_no}</strong> byl změněn na <strong>{$cfg['Order']['Status']['global'][2]}", $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains("Demo Kupshop.cz - změna stavu objednávky {$order->order_no}", $this->mailArchive->getArchive()[0]['subject']);
|
||||
|
||||
$this->assertContains('utm_source=notification&utm_medium=email&utm_campaign=order_status_change', $this->mailArchive->getArchive()[0]['body']);
|
||||
}
|
||||
|
||||
public function testEmailInChangeStatusComment()
|
||||
{
|
||||
$cfg = \KupShop\KupShopBundle\Config::get();
|
||||
|
||||
$this->mailArchive->clearArchive();
|
||||
|
||||
$order = new Order();
|
||||
$order->createFromDB(2);
|
||||
$order->changeStatus(2, 'Komentář');
|
||||
|
||||
$this->assertContains("stav Vaší objednávky číslo <strong>{$order->order_no}</strong> byl změněn na <strong>{$cfg['Order']['Status']['global'][2]}", $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains('Komentář', $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains("Demo Kupshop.cz - změna stavu objednávky {$order->order_no}", $this->mailArchive->getArchive()[0]['subject']);
|
||||
|
||||
$this->assertContains('utm_source=notification&utm_medium=email&utm_campaign=order_status_change', $this->mailArchive->getArchive()[0]['body']);
|
||||
}
|
||||
|
||||
public function testEmailInChangeStatusCommentPlaceholders()
|
||||
{
|
||||
$cfg = \KupShop\KupShopBundle\Config::get();
|
||||
|
||||
$this->mailArchive->clearArchive();
|
||||
|
||||
$order = new Order();
|
||||
$order->createFromDB(2);
|
||||
$order->changeStatus(2, '<p>Kód objednávky: {KOD}</p><p>{POLOZKY_OBJEDNAVKY}</p>');
|
||||
|
||||
$this->assertContains("stav Vaší objednávky číslo <strong>{$order->order_no}</strong> byl změněn na <strong>{$cfg['Order']['Status']['global'][2]}", $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains("Kód objednávky: {$order->order_no}", $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains('Seznam objednaného zboží:', $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains('Wilson pure battle crew', $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains("Demo Kupshop.cz - změna stavu objednávky {$order->order_no}", $this->mailArchive->getArchive()[0]['subject']);
|
||||
|
||||
$this->assertContains('utm_source=notification&utm_medium=email&utm_campaign=order_status_change', $this->mailArchive->getArchive()[0]['body']);
|
||||
}
|
||||
|
||||
public function testEmailInCreateOrder()
|
||||
{
|
||||
$this->mailArchive->clearArchive();
|
||||
|
||||
$this->loginUser(1);
|
||||
|
||||
$this->createCart();
|
||||
$cart = $this->cart;
|
||||
|
||||
$item = [
|
||||
'id_product' => 10,
|
||||
'id_variation' => null,
|
||||
'pieces' => 1,
|
||||
];
|
||||
$cart->addItem($item);
|
||||
$cart->setDeliveryAndPayment(1, 2);
|
||||
$cart->save();
|
||||
$cart->fetchAddresses();
|
||||
$cart->createFromDB();
|
||||
|
||||
$order = $cart->submitOrder('cs');
|
||||
|
||||
$this->assertContains(" potvrzovacím emailem.</p><p>Objednávka číslo: <strong>{$order->order_no}", $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains("Demo Kupshop.cz - přijata objednávka {$order->order_no}", $this->mailArchive->getArchive()[0]['subject']);
|
||||
|
||||
$this->assertContains('utm_source=notification&utm_medium=email&utm_campaign=order_create', $this->mailArchive->getArchive()[0]['body']);
|
||||
}
|
||||
|
||||
public function testEmailInSentMessage()
|
||||
{
|
||||
$this->mailArchive->clearArchive();
|
||||
|
||||
$order = new Order();
|
||||
$order->createFromDB(2);
|
||||
$order->changeStatus(1, null, true, 'Kurýr');
|
||||
|
||||
$this->assertContains('<strong>Objednávka odeslána obchodním balíkem české pošty.</strong><br>', $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains('<strong>Číslo balíku: <br>', $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains("Demo Kupshop.cz - objednávka {$order->order_no} byla odeslána", $this->mailArchive->getArchive()[0]['subject']);
|
||||
|
||||
$this->assertContains('utm_source=notification&utm_medium=email&utm_campaign=order_message', $this->mailArchive->getArchive()[0]['body']);
|
||||
}
|
||||
|
||||
public function testEmailInSentMessageComment()
|
||||
{
|
||||
$this->mailArchive->clearArchive();
|
||||
|
||||
$order = new Order();
|
||||
$order->createFromDB(2);
|
||||
$comment = '<p><strong>Objednávka odeslána obchodním balíkem české pošty.</strong><br>
|
||||
<strong>Číslo balíku: 1234567890<br></p>';
|
||||
$order->changeStatus(1, $comment, true, 'Kurýr');
|
||||
|
||||
$this->assertContains($comment, $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains("Demo Kupshop.cz - objednávka {$order->order_no} byla odeslána", $this->mailArchive->getArchive()[0]['subject']);
|
||||
|
||||
$this->assertContains('utm_source=notification&utm_medium=email&utm_campaign=order_message', $this->mailArchive->getArchive()[0]['body']);
|
||||
}
|
||||
|
||||
public function testEmailInSentMessageCommentPlaceholders()
|
||||
{
|
||||
$this->mailArchive->clearArchive();
|
||||
|
||||
$order = new Order();
|
||||
$order->createFromDB(2);
|
||||
$comment = '<p><strong>Objednávka odeslána obchodním balíkem české pošty.</strong><br>
|
||||
<strong>Číslo balíku: 1234567890<br>
|
||||
Dobírka: {ZAPLATIT}</strong></p>
|
||||
<p>{POLOZKY_OBJEDNAVKY}</p>';
|
||||
$comment_expected = '<p><strong>Objednávka odeslána obchodním balíkem české pošty.</strong><br>
|
||||
<strong>Číslo balíku: 1234567890<br>
|
||||
Dobírka: 822 Kč</strong></p>';
|
||||
$order->changeStatus(1, $comment, true, 'Kurýr');
|
||||
|
||||
$this->assertContains($comment_expected, $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains('Seznam objednaného zboží:', $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains('Wilson pure battle crew', $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains("Demo Kupshop.cz - objednávka {$order->order_no} byla odeslána", $this->mailArchive->getArchive()[0]['subject']);
|
||||
|
||||
$this->assertContains('utm_source=notification&utm_medium=email&utm_campaign=order_message', $this->mailArchive->getArchive()[0]['body']);
|
||||
}
|
||||
|
||||
public function testTranslatedEmail()
|
||||
{
|
||||
$this->mailArchive->clearArchive();
|
||||
$this->loginUser(1);
|
||||
|
||||
$this->createCart();
|
||||
$cart = $this->cart;
|
||||
|
||||
$item = [
|
||||
'id_product' => 10,
|
||||
'id_variation' => null,
|
||||
'pieces' => 1,
|
||||
];
|
||||
$cart->addItem($item);
|
||||
$cart->setDeliveryAndPayment(1, 2);
|
||||
$cart->save();
|
||||
$cart->fetchAddresses();
|
||||
$cart->createFromDB();
|
||||
|
||||
$order = $cart->submitOrder('sk');
|
||||
|
||||
$this->assertContains("SK | 6 | přijata objednávka {$order->order_no}", $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains("SK | 6 | Demo Kupshop.cz - přijata objednávka {$order->order_no}", $this->mailArchive->getArchive()[0]['subject']);
|
||||
|
||||
$this->assertContains('utm_source=notification&utm_medium=email&utm_campaign=order_create', $this->mailArchive->getArchive()[0]['body']);
|
||||
}
|
||||
|
||||
public function testEmailInCreateOrderPaidGenerateCoupon()
|
||||
{
|
||||
$this->mailArchive->clearArchive();
|
||||
|
||||
$this->loginUser(1);
|
||||
|
||||
$this->updateSQL('products', ['data' => '{"generate_coupon":"Y","generate_coupon_discount":"124"}'], ['id' => 3]);
|
||||
|
||||
$this->createCart();
|
||||
$cart = $this->cart;
|
||||
|
||||
$item = [
|
||||
'id_product' => 3,
|
||||
'id_variation' => null,
|
||||
'pieces' => 1,
|
||||
];
|
||||
$cart->addItem($item);
|
||||
$cart->save();
|
||||
$cart->createFromDB();
|
||||
|
||||
$order = $cart->submitOrder('cs');
|
||||
|
||||
$payment_id = $order->insertPayment($order->total_price, 'test', null, false, \Payment::METHOD_ONLINE);
|
||||
$order->sendPaymentReceipt($payment_id);
|
||||
|
||||
$this->assertEquals(3, count($this->mailArchive->getArchive()));
|
||||
|
||||
$this->assertContains("Demo Kupshop.cz - přijata objednávka {$order->order_no}", $this->mailArchive->getArchive()[0]['subject']);
|
||||
$this->assertContains("Děkujeme za zaplacení objednávky {$order->order_no}", $this->mailArchive->getArchive()[2]['subject']);
|
||||
$this->assertContains("Dárkový poukaz k objednávce {$order->order_no}", $this->mailArchive->getArchive()[1]['subject']);
|
||||
|
||||
$coupon = $this->selectSQL('discounts_coupons', ['id_order_purchased' => $order->id])->fetch();
|
||||
$this->assertNotFalse($coupon);
|
||||
|
||||
$this->assertContains($coupon['code'], $this->mailArchive->getArchive()[1]['body']);
|
||||
$url = "/objednavka/{$order->id}/coupon/{$coupon['id']}?cf=";
|
||||
$this->assertContains($url, $this->mailArchive->getArchive()[1]['body']);
|
||||
}
|
||||
|
||||
public function testEmailInOrderStorno()
|
||||
{
|
||||
$this->mailArchive->clearArchive();
|
||||
|
||||
$order = new Order();
|
||||
$order->createFromDB(2);
|
||||
$order->storno();
|
||||
|
||||
$this->assertContains("stornovali jsme Vaši objednávku <strong>{$order->order_no}</strong>", $this->mailArchive->getArchive()[0]['body']);
|
||||
$this->assertContains("Storno objednávky {$order->order_no}", $this->mailArchive->getArchive()[0]['subject']);
|
||||
|
||||
$this->assertContains('utm_source=notification&utm_medium=email&utm_campaign=order_storno', $this->mailArchive->getArchive()[0]['body']);
|
||||
}
|
||||
|
||||
public function testEmailShopkeeper()
|
||||
{
|
||||
$this->mailArchive->clearArchive();
|
||||
$email = $this->get(OrderCreateAdminEmail::class);
|
||||
$order = new Order();
|
||||
$order->createFromDB(1);
|
||||
|
||||
$email->setOrder($order);
|
||||
$email->getEmail();
|
||||
}
|
||||
|
||||
private function setTelfaSettings()
|
||||
{
|
||||
$telfaSettings = [
|
||||
'phone' => '499111062',
|
||||
'phone_id' => '825',
|
||||
'active_phone' => '499111062',
|
||||
'phones' => 'volání;volání_vip;test',
|
||||
'username' => 'jebavy@wpj.cz',
|
||||
'password' => 'kupkolo',
|
||||
'sms_number_id' => '979',
|
||||
'status' => [
|
||||
0 => '2424',
|
||||
1 => '2423',
|
||||
2 => '2436',
|
||||
3 => '2437',
|
||||
4 => '2438',
|
||||
5 => '2439',
|
||||
6 => '2440',
|
||||
7 => '2421',
|
||||
8 => '2441',
|
||||
9 => '2442',
|
||||
10 => '',
|
||||
'storno' => '2443',
|
||||
'get_number' => '2420',
|
||||
'non_exists' => '2425',
|
||||
'interrupt' => '2430',
|
||||
],
|
||||
];
|
||||
|
||||
$dbcfg = Settings::getDefault();
|
||||
|
||||
$dbcfg->telfa = $telfaSettings;
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->getJsonDataSetFromFile();
|
||||
}
|
||||
}
|
||||
325
tests/functional/DatabaseTestCase.php
Normal file
325
tests/functional/DatabaseTestCase.php
Normal file
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
|
||||
use KupShop\DevelopmentBundle\Util\Tests\ContainerAwareTestTrait;
|
||||
use KupShop\KupShopBundle\Config;
|
||||
use KupShop\KupShopBundle\Context\ContextManager;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
use KupShop\KupShopBundle\Util\Contexts;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class DatabaseTestCase extends \PHPUnit\DbUnit\TestCase
|
||||
{
|
||||
use ContainerAwareTestTrait;
|
||||
use DatabaseCommunication;
|
||||
|
||||
private static $cfg;
|
||||
private static $dbcfg;
|
||||
private static $txt_str;
|
||||
|
||||
private $transactionActivated = false;
|
||||
private $contextManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->getTestResultObject()->stopOnError(true);
|
||||
$this->getTestResultObject()->stopOnFailure(true);
|
||||
|
||||
$this->restoreDefaultConfig();
|
||||
$this->restoreDefaultSettings();
|
||||
$this->restoreDefaultCtrl();
|
||||
$this->restoreDefaultLanguage();
|
||||
|
||||
// Clear caches
|
||||
$this->clearCaches();
|
||||
|
||||
// Clear cache by generating new BUILD_ID for each test
|
||||
static $iteration = 0;
|
||||
$iteration++;
|
||||
$db = TEST_DB_NAME;
|
||||
putenv("BUILD_ID={$db}_{$iteration}");
|
||||
|
||||
$this->suspendLogging(true);
|
||||
$this->assertSame(0, sqlGetConnection()->getTransactionNestingLevel(), 'The test itself must not be in a transaction.');
|
||||
|
||||
sqlStartTransaction();
|
||||
$this->transactionActivated = true;
|
||||
|
||||
$this->setTestDefaults();
|
||||
|
||||
$this->suspendLogging(false);
|
||||
|
||||
$this->updateModules();
|
||||
|
||||
parent::setUp();
|
||||
|
||||
// todo find how to restore previous values, not force false. This unfortunately overrides respective cli flags
|
||||
$this->getTestResultObject()->stopOnError(false);
|
||||
$this->getTestResultObject()->stopOnFailure(false);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
$this->suspendLogging(true);
|
||||
$this->assertSameTransactionLevel();
|
||||
sqlRollbackTransaction();
|
||||
$this->assertNoChangesLeftInDatabase();
|
||||
$this->suspendLogging(false);
|
||||
$this->tearDownContainer();
|
||||
|
||||
// Reverting sql_mode
|
||||
// sqlQuery("SET sql_mode = 'NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'");
|
||||
}
|
||||
|
||||
public function addModule($module, $submodule = null, $restartContainer = false)
|
||||
{
|
||||
$cfg = \KupShop\KupShopBundle\Config::get();
|
||||
|
||||
if ($submodule) {
|
||||
if (is_array($cfg['Modules'][$module])) {
|
||||
$cfg['Modules'][$module][$submodule] = true;
|
||||
} else {
|
||||
$cfg['Modules'][$module] = [$submodule => true];
|
||||
}
|
||||
} else {
|
||||
$cfg['Modules'][$module] = true;
|
||||
}
|
||||
|
||||
if ($restartContainer) {
|
||||
$this->tearDownContainer();
|
||||
// Nemelo by byt třeba spouštět, všechny migrace proběhnou na začátku díky config.test.php
|
||||
// $this->createSchema();
|
||||
}
|
||||
}
|
||||
|
||||
public function removeModule($module, $submodule = null)
|
||||
{
|
||||
$cfg = \KupShop\KupShopBundle\Config::get();
|
||||
|
||||
if ($submodule) {
|
||||
$cfg['Modules'][$module][$submodule] = false;
|
||||
} else {
|
||||
$cfg['Modules'][$module] = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the test database connection.
|
||||
*
|
||||
* @return \PHPUnit\DbUnit\Database\DefaultConnection
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return new \PHPUnit\DbUnit\Database\DefaultConnection(sqlGetConnection()->getWrappedConnection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the test dataset.
|
||||
*
|
||||
* @return \PHPUnit\DbUnit\DataSet\DefaultDataSet
|
||||
*/
|
||||
protected function getDataSet()
|
||||
{
|
||||
return new \PHPUnit\DbUnit\DataSet\DefaultDataSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database operation executed in test setup.
|
||||
*
|
||||
* @return \PHPUnit\DbUnit\Operation\Composite
|
||||
*/
|
||||
protected function getSetUpOperation()
|
||||
{
|
||||
return new \PHPUnit\DbUnit\Operation\Composite([
|
||||
new \PHPUnit\DbUnit\Operation\DeleteAll(),
|
||||
new \PHPUnit\DbUnit\Operation\Insert(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function skipIfNoModule($moduleName)
|
||||
{
|
||||
if (!findModule($moduleName)) {
|
||||
$this->markTestSkipped("Module '{$moduleName}' is disabled");
|
||||
}
|
||||
}
|
||||
|
||||
protected function suspendLogging($suspend)
|
||||
{
|
||||
static $logger = null;
|
||||
|
||||
if ($suspend) {
|
||||
$this->assertNull($logger);
|
||||
// Suspend SQL logging
|
||||
$logger = sqlGetConnection()->getConfiguration()->getSQLLogger();
|
||||
sqlGetConnection()->getConfiguration()->setSQLLogger(null);
|
||||
} else {
|
||||
// Resume SQL logging
|
||||
sqlGetConnection()->getConfiguration()->setSQLLogger($logger);
|
||||
$logger = null;
|
||||
}
|
||||
}
|
||||
|
||||
private function restoreDefaultLanguage()
|
||||
{
|
||||
global $txt_str;
|
||||
|
||||
if (is_null(self::$txt_str)) {
|
||||
self::$txt_str = $txt_str;
|
||||
}
|
||||
|
||||
$txt_str = self::$txt_str;
|
||||
}
|
||||
|
||||
private function restoreDefaultConfig()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
if (is_null(self::$cfg)) {
|
||||
self::$cfg = Config::get()->getContainer();
|
||||
}
|
||||
|
||||
$cfg = self::$cfg;
|
||||
}
|
||||
|
||||
protected function restoreDefaultCtrl()
|
||||
{
|
||||
global $ctrl;
|
||||
|
||||
$defaults = [
|
||||
'id' => 0,
|
||||
'admin' => 0,
|
||||
'logged' => false,
|
||||
'user_key' => '123456test123456',
|
||||
'currency' => 'CZK',
|
||||
'currUrl' => [
|
||||
'Abs' => '',
|
||||
'Rel' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$ctrl = ServiceContainer::getService(\KupShop\KupShopBundle\Util\Compat\CtrlLoader::class);
|
||||
$ctrl->setContainer($defaults);
|
||||
|
||||
return $ctrl;
|
||||
}
|
||||
|
||||
private function restoreDefaultSettings()
|
||||
{
|
||||
global $dbcfg;
|
||||
|
||||
if (is_null(self::$dbcfg)) {
|
||||
self::$dbcfg = Settings::getDefault();
|
||||
}
|
||||
|
||||
$dbcfg = clone self::$dbcfg;
|
||||
Settings::setDefault(['cs' => $dbcfg]);
|
||||
}
|
||||
|
||||
protected function getContextManager()
|
||||
{
|
||||
if (!isset($this->contextManager)) {
|
||||
$this->contextManager = ServiceContainer::getService(ContextManager::class);
|
||||
}
|
||||
|
||||
return $this->contextManager;
|
||||
}
|
||||
|
||||
private function setTestDefaults()
|
||||
{
|
||||
Cart::setCartID('123456');
|
||||
$this->getContextManager()->forceEmptyContexts();
|
||||
}
|
||||
|
||||
private function assertSameTransactionLevel()
|
||||
{
|
||||
$transactionLevel = sqlGetConnection()->getTransactionNestingLevel();
|
||||
if ($this->transactionActivated && 1 !== $transactionLevel) {
|
||||
$this->getTestResultObject()->stop();
|
||||
$this->getTestResultObject()->addError(
|
||||
$this,
|
||||
new Exception($this->getTestMethodName().": The tested code ended up in a different transaction level ({$transactionLevel}) than it started in (1). Maybe missing parent::setUp() ?"),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function assertNoChangesLeftInDatabase()
|
||||
{
|
||||
global $db;
|
||||
if (!$db->checkDatabaseNotChanged()) {
|
||||
$this->getTestResultObject()->stop();
|
||||
$this->getTestResultObject()->addError(
|
||||
$this,
|
||||
new Exception($this->getTestMethodName().': Test left behind changes in the database.'),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dataset from JSON-encoded string.
|
||||
*
|
||||
* @param $string string JSON-encoded dataset
|
||||
*
|
||||
* @return \PHPUnit\DbUnit\DataSet\ArrayDataSet
|
||||
*/
|
||||
protected function getJsonDataSet($string)
|
||||
{
|
||||
return new \PHPUnit\DbUnit\DataSet\ArrayDataSet(json_decode_strict($string, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dataset from JSON file.
|
||||
*
|
||||
* @param $file string|null file name to load data from. Can be absolute, relative to test or null to use <testFileName>.json
|
||||
*
|
||||
* @return \PHPUnit\DbUnit\DataSet\ArrayDataSet
|
||||
*/
|
||||
protected function getJsonDataSetFromFile($file = null)
|
||||
{
|
||||
if ($file === null || !file_exists($file)) {
|
||||
$classFile = (new ReflectionClass($this))->getFileName();
|
||||
|
||||
if ($file) {
|
||||
$file = dirname($classFile).'/'.$file;
|
||||
} else {
|
||||
$file = str_replace('.php', '.json', $classFile);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->getJsonDataSet(file_get_contents($file));
|
||||
}
|
||||
|
||||
public function getTestMethodName()
|
||||
{
|
||||
return get_class($this).'::'.$this->getName();
|
||||
}
|
||||
|
||||
protected function clearCaches()
|
||||
{
|
||||
Delivery::clearCache();
|
||||
$this->get(\KupShop\CatalogBundle\Section\SectionTree::class)->clearCache();
|
||||
Contexts::clear();
|
||||
getLocalCache()->clear();
|
||||
}
|
||||
|
||||
protected function updateModules()
|
||||
{
|
||||
}
|
||||
|
||||
public function initializeRequestStack(): void
|
||||
{
|
||||
ServiceContainer::getService('request_stack')->push(Request::createFromGlobals());
|
||||
}
|
||||
|
||||
protected function switchLanguage($language = 'sk')
|
||||
{
|
||||
/** @var \KupShop\KupShopBundle\Context\LanguageContext $languageContext */
|
||||
$languageContext = Contexts::get(\KupShop\KupShopBundle\Context\LanguageContext::class);
|
||||
$languageContext->activate($language);
|
||||
|
||||
global $txt_str;
|
||||
$translator = $this->get(\KupShop\KupShopBundle\Util\Locale\PHPArrayTranslator::class);
|
||||
$txt_str = $translator->loadShopMainTranslations();
|
||||
}
|
||||
}
|
||||
43
tests/functional/DecimalTest.php
Normal file
43
tests/functional/DecimalTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
class DecimalTest extends DatabaseTestCase
|
||||
{
|
||||
public function testMax()
|
||||
{
|
||||
$first = toDecimal('1.2');
|
||||
$second = toDecimal('1.5');
|
||||
|
||||
$this->assertEquals($second, Decimal::max($first, $second));
|
||||
}
|
||||
|
||||
public function testDecimalComma()
|
||||
{
|
||||
$this->assertEquals(toDecimal('1,2'), toDecimal('1.2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_testCompare
|
||||
*/
|
||||
public function testCompareSurprisinglyWorks($lower, $greater)
|
||||
{
|
||||
$this->assertTrue($lower < $greater);
|
||||
$this->assertTrue($greater > $lower);
|
||||
$this->assertFalse($lower > $greater);
|
||||
$this->assertFalse($greater < $lower);
|
||||
}
|
||||
|
||||
public function data_testCompare()
|
||||
{
|
||||
return [
|
||||
[toDecimal('0.1'), toDecimal('0.2')],
|
||||
[toDecimal('5'), toDecimal('10')],
|
||||
[toDecimal('01'), toDecimal('2')],
|
||||
[toDecimal('-1'), DecimalConstants::zero()],
|
||||
[toDecimal('-2'), DecimalConstants::negativeOne()],
|
||||
[\Decimal::fromString('-2', 8), \Decimal::fromString('-1', 4)],
|
||||
[\Decimal::fromString('-2', 4), \Decimal::fromString('-1', 8)],
|
||||
[toDecimal('0.1'), '0.2'],
|
||||
['0.1', toDecimal('0.2')],
|
||||
];
|
||||
}
|
||||
}
|
||||
28
tests/functional/DeliveryTest.php
Normal file
28
tests/functional/DeliveryTest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
class DeliveryTest extends \DatabaseTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider data_testWorkdays
|
||||
*/
|
||||
public function testWorkdays($date, $isWorkday)
|
||||
{
|
||||
$delivery = Delivery::getAll()[3];
|
||||
$this->assertSame($isWorkday, $delivery->isWorkday($date));
|
||||
}
|
||||
|
||||
public function data_testWorkdays()
|
||||
{
|
||||
return [
|
||||
[new DateTime('2017-01-01'), false], // Novy rok
|
||||
[new DateTime('2017-07-06'), false], // Hus
|
||||
[new DateTime('2017-05-01'), false], // Prace
|
||||
[new DateTime('2017-05-02'), true], // Nic
|
||||
[new DateTime('2017-04-17'), false], // Pondeli
|
||||
[new DateTime('2017-04-14'), false], // Velky patek
|
||||
[new DateTime('2017-04-13'), true], // Nic
|
||||
[new DateTime('2017-07-29'), false], // Sobota
|
||||
[new DateTime('2017-07-30'), false], // Neděle
|
||||
];
|
||||
}
|
||||
}
|
||||
86
tests/functional/FilterTest/FilterCampaignsTest.php
Normal file
86
tests/functional/FilterTest/FilterCampaignsTest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
use PHPUnit\DbUnit\DataSet\YamlDataSet;
|
||||
|
||||
class FilterCampaignsTest extends \DatabaseTestCase
|
||||
{
|
||||
/** @var \Filter */
|
||||
private $filter;
|
||||
|
||||
/** @var \FilterParams */
|
||||
private $filterParams;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->filter = new \Filter();
|
||||
$this->filterParams = new \FilterParams();
|
||||
$this->filterParams->setSections([1, 2]);
|
||||
$this->filter->setFilterParams($this->filterParams);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testSetCampaign
|
||||
*/
|
||||
public function testSetCampaign(array $campaigns, $expectedResultsCount)
|
||||
{
|
||||
foreach ($campaigns as $campaign) {
|
||||
$this->filterParams->setCampaign($campaign);
|
||||
}
|
||||
|
||||
$resultsCount = sqlQueryBuilder()
|
||||
->select('p.id')->fromProducts()->where($this->filterParams->getSpec())->execute()->rowCount();
|
||||
|
||||
$this->assertSame($expectedResultsCount, $resultsCount);
|
||||
}
|
||||
|
||||
public function dataSet_testSetCampaign()
|
||||
{
|
||||
return [
|
||||
[['N'], 3],
|
||||
[['S'], 2],
|
||||
[['N', 'S'], 1],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testGetCampaigns
|
||||
*/
|
||||
public function testGetCampaigns($resultEntity, array $setCampaigns, array $expectedCounts)
|
||||
{
|
||||
$this->filterParams->setResultEntity($resultEntity);
|
||||
foreach ($setCampaigns as $setCampaign) {
|
||||
$this->filterParams->setCampaign($setCampaign);
|
||||
}
|
||||
|
||||
$expected = [];
|
||||
foreach ($expectedCounts as $campaign => $count) {
|
||||
$expected['values'][$campaign] = ['count' => $count];
|
||||
}
|
||||
|
||||
$result = $this->filter->getCampaigns(array_keys($expectedCounts));
|
||||
$resultCache = $this->filter->getCampaigns(array_keys($expectedCounts));
|
||||
|
||||
$this->assertSame($expected, $result);
|
||||
$this->assertSame($expected, $resultCache);
|
||||
$this->assertSame(['values' => ['S' => $expected['values']['S']]], $this->filter->getCampaigns(['S']));
|
||||
}
|
||||
|
||||
public function dataSet_testGetCampaigns()
|
||||
{
|
||||
return [
|
||||
'all campaigns of products' => [\FilterParams::ENTITY_PRODUCT, [], ['N' => 3, 'S' => 2, 'D' => 1, 'A' => 1]],
|
||||
'all campaigns of variations' => [\FilterParams::ENTITY_VARIATION, [], ['N' => 5, 'S' => 2, 'D' => 1, 'A' => 1]],
|
||||
'campaigns of products with N only' => [\FilterParams::ENTITY_PRODUCT, ['N'], ['N' => 3, 'S' => 1, 'D' => 1, 'A' => 0]],
|
||||
'campaigns of variations with N only' => [\FilterParams::ENTITY_VARIATION, ['N'], ['N' => 5, 'S' => 1, 'D' => 1, 'A' => 0]],
|
||||
];
|
||||
}
|
||||
|
||||
public function getDataset()
|
||||
{
|
||||
return new YamlDataSet(__DIR__.'/FilterVariationsTest.yml');
|
||||
}
|
||||
}
|
||||
88
tests/functional/FilterTest/FilterDefaultQuerysetTest.php
Normal file
88
tests/functional/FilterTest/FilterDefaultQuerysetTest.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
class FilterDefaultQuerysetTest extends \DatabaseTestCase
|
||||
{
|
||||
/** @var \FilterParams */
|
||||
private $filterParams;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->filterParams = new \FilterParams();
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testDefaultQueryset
|
||||
*/
|
||||
public function testInStore($showNotInStore, $expectedResult)
|
||||
{
|
||||
if (!is_null($showNotInStore)) {
|
||||
\Settings::getDefault()->prod_show_not_in_store = $showNotInStore;
|
||||
}
|
||||
|
||||
$this->assertSame($expectedResult, $this->filterParams->getInStore());
|
||||
}
|
||||
|
||||
public function dataSet_testDefaultQueryset()
|
||||
{
|
||||
return [
|
||||
[null, null],
|
||||
['Y', null],
|
||||
['N', 'inStoreSupplier'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testVisible()
|
||||
{
|
||||
$this->filterParams->setResultEntity(\FilterParams::ENTITY_PRODUCT);
|
||||
$this->assertSame(\FilterParams::ENTITY_PRODUCT, $this->filterParams->getVisible());
|
||||
$this->filterParams->setResultEntity(\FilterParams::ENTITY_VARIATION);
|
||||
$this->assertSame(\FilterParams::ENTITY_VARIATION, $this->filterParams->getVisible());
|
||||
}
|
||||
|
||||
public function testQuerysetProducts()
|
||||
{
|
||||
$productList = new \ProductList();
|
||||
$productList->andSpec($this->filterParams->getSpec());
|
||||
$this->assertEquals(11, $productList->getProductsCount());
|
||||
|
||||
$this->updateSQL('products', ['figure' => 'N'], ['id' => 1]);
|
||||
|
||||
$this->assertEquals(10, $productList->getProductsCount());
|
||||
}
|
||||
|
||||
public function testQuerysetVariations()
|
||||
{
|
||||
$productList = new \ProductList(true);
|
||||
$this->filterParams->setResultEntity(\FilterParams::ENTITY_VARIATION);
|
||||
$productList->andSpec($this->filterParams->getSpec());
|
||||
$this->assertEquals(22, $productList->getProductsCount());
|
||||
|
||||
$this->updateSQL('products_variations', ['figure' => 'N'], ['id' => 1]);
|
||||
|
||||
$this->assertEquals(21, $productList->getProductsCount());
|
||||
|
||||
$this->updateSQL('products', ['figure' => 'N'], ['id' => 11]);
|
||||
|
||||
$this->assertEquals(18, $productList->getProductsCount());
|
||||
}
|
||||
|
||||
public function testProductListDefaultFilterParams()
|
||||
{
|
||||
$productList = new \ProductList(true);
|
||||
$productList->applyDefaultFilterParams();
|
||||
|
||||
$this->assertEquals(22, $productList->getProductsCount());
|
||||
|
||||
$this->updateSQL('products_variations', ['figure' => 'N'], ['id' => 1]);
|
||||
|
||||
$this->assertEquals(21, $productList->getProductsCount());
|
||||
|
||||
$this->updateSQL('products', ['figure' => 'N'], ['id' => 11]);
|
||||
|
||||
$this->assertEquals(18, $productList->getProductsCount());
|
||||
}
|
||||
}
|
||||
18
tests/functional/FilterTest/FilterFetchVariationsTest.php
Normal file
18
tests/functional/FilterTest/FilterFetchVariationsTest.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
class FilterFetchVariationsTest extends \DatabaseTestCase
|
||||
{
|
||||
public function testGetProducers()
|
||||
{
|
||||
$filterParams = new \FilterParams();
|
||||
$filter = new \Filter($filterParams);
|
||||
|
||||
$filterParams->setResultEntity(\FilterParams::ENTITY_VARIATION);
|
||||
|
||||
$variationsCount = array_sum(array_column($filter->getProducers()['values'], 'count'));
|
||||
|
||||
$this->assertSame(16, $variationsCount);
|
||||
}
|
||||
}
|
||||
67
tests/functional/FilterTest/FilterInStoreTest.php
Normal file
67
tests/functional/FilterTest/FilterInStoreTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
class FilterStoreTest extends \DatabaseTestCase
|
||||
{
|
||||
/** @var \Filter */
|
||||
private $filter;
|
||||
|
||||
/** @var \FilterParams */
|
||||
private $filterParams;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->filter = new \Filter();
|
||||
$this->filterParams = new \FilterParams();
|
||||
$this->filter->setFilterParams($this->filterParams);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testSetInStore()
|
||||
{
|
||||
$this->filterParams->setSections([3]);
|
||||
$this->filterParams->setInStore(\Filter::IN_STORE);
|
||||
|
||||
$this->assertCount(1, $this->filter->getProducers()['values']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider_testGetInStore
|
||||
*
|
||||
* @param string $productOrVariation
|
||||
* @param array $sections
|
||||
* @param string $expectedCount
|
||||
*/
|
||||
public function testGetInStore($productOrVariation, $sections, $expectedCount)
|
||||
{
|
||||
$this->filterParams->setResultEntity($productOrVariation);
|
||||
$this->filterParams->setSections($sections);
|
||||
|
||||
$this->assertEquals($expectedCount, $this->filter->getInStore()['count']);
|
||||
}
|
||||
|
||||
public function dataProvider_testGetInStore()
|
||||
{
|
||||
return [
|
||||
[\FilterParams::ENTITY_PRODUCT, [3], '1'],
|
||||
[\FilterParams::ENTITY_VARIATION, [2, 5, 6], '11'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetInStoreChecksIfSetInStoreWasCalled()
|
||||
{
|
||||
\Settings::getDefault()->loadFromArray(['prod_show_not_in_store' => 'N'], true);
|
||||
|
||||
$this->assertSame('inStoreSupplier', $this->filterParams->getInStore());
|
||||
$this->filterParams->setInStore(null);
|
||||
$this->assertNull($this->filterParams->getInStore());
|
||||
}
|
||||
|
||||
public function testSetInStoreAndGetVariation()
|
||||
{
|
||||
$this->filterParams->setInStore(\Filter::IN_STORE);
|
||||
$this->filter->getVariation(1);
|
||||
}
|
||||
}
|
||||
267
tests/functional/FilterTest/FilterParametersTest.php
Normal file
267
tests/functional/FilterTest/FilterParametersTest.php
Normal file
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
use KupShop\KupShopBundle\Config;
|
||||
use PHPUnit\DbUnit\DataSet\YamlDataSet;
|
||||
|
||||
class FilterParametersTest extends \DatabaseTestCase
|
||||
{
|
||||
private $param = [
|
||||
'color' => 2,
|
||||
'size' => 1,
|
||||
'size2' => 3,
|
||||
'descr' => 4,
|
||||
];
|
||||
|
||||
private $paramValue = [
|
||||
'black' => 1,
|
||||
'white' => 2,
|
||||
];
|
||||
|
||||
/** @var \Filter */
|
||||
private $filter;
|
||||
|
||||
/** @var \FilterParams */
|
||||
private $filterParams;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$cfg = Config::get();
|
||||
$cfg['Modules']['indexed_filter'] = false;
|
||||
|
||||
$this->filter = new \Filter();
|
||||
$this->filterParams = new \FilterParams();
|
||||
$this->filterParams->setSections([1, 2]);
|
||||
$this->filter->setFilterParams($this->filterParams);
|
||||
}
|
||||
|
||||
public function testFiltersDeepBySectionOnly()
|
||||
{
|
||||
$producers = $this->filter->getProducers()['values'];
|
||||
|
||||
$this->assertCount(2, $producers);
|
||||
|
||||
$this->assertArrayHasKey(1, $producers);
|
||||
$this->assertEquals(3, $producers[1]['count']);
|
||||
$this->assertSame('Producer 1', $producers[1]['name']);
|
||||
|
||||
$this->assertArrayHasKey(2, $producers);
|
||||
$this->assertEquals(1, $producers[2]['count']);
|
||||
$this->assertSame('Producer 2', $producers[2]['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testSectionAndParameters
|
||||
*/
|
||||
public function testSectionAndParameters(array $params, array $expectedProducersValuesArray)
|
||||
{
|
||||
foreach ($params as $param) {
|
||||
$this->filterParams->setParameter($param[0], $param[1], $param[2]);
|
||||
}
|
||||
|
||||
$producersValuesArray = $this->filter->getProducers()['values'];
|
||||
|
||||
$this->assertEquals($expectedProducersValuesArray, $producersValuesArray);
|
||||
}
|
||||
|
||||
public function dataSet_testSectionAndParameters()
|
||||
{
|
||||
return [
|
||||
[
|
||||
[
|
||||
[$this->param['color'], [$this->paramValue['black']], \Filter::PARAM_LIST],
|
||||
],
|
||||
[1 => ['id' => '1', 'name' => 'Producer 1', 'photo' => 'x.jpg', 'count' => '2']],
|
||||
],
|
||||
[
|
||||
[
|
||||
[$this->param['color'], [$this->paramValue['white']], \Filter::PARAM_LIST],
|
||||
],
|
||||
[],
|
||||
],
|
||||
[
|
||||
[
|
||||
[$this->param['color'], [$this->paramValue['black'], $this->paramValue['white']], \Filter::PARAM_LIST],
|
||||
],
|
||||
[1 => ['id' => '1', 'name' => 'Producer 1', 'photo' => 'x.jpg', 'count' => '2']],
|
||||
],
|
||||
[
|
||||
[
|
||||
[$this->param['color'], [$this->paramValue['black']], \Filter::PARAM_LIST],
|
||||
[$this->param['size'], ['min' => 5, 'max' => 5], \Filter::PARAM_INT],
|
||||
],
|
||||
[1 => ['id' => '1', 'name' => 'Producer 1', 'photo' => 'x.jpg', 'count' => '1']],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testTranslateParameters()
|
||||
{
|
||||
$this->switchLanguage();
|
||||
|
||||
$parameter = $this->filter->getParameter($this->param['color'], \Filter::PARAM_LIST);
|
||||
|
||||
$expected = [
|
||||
'param_name' => 'Farba',
|
||||
'values' => [
|
||||
'1' => [
|
||||
'id' => '1',
|
||||
'param_name' => 'Farba',
|
||||
'name' => 'čierna',
|
||||
'description' => 'čierna desc',
|
||||
'count' => '2',
|
||||
'position' => 2,
|
||||
'unit' => '',
|
||||
'data' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $parameter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testGetParameter
|
||||
*/
|
||||
public function testGetParameterCountsProducts($paramId, $paramType, $expectedResult)
|
||||
{
|
||||
$parameter = $this->filter->getParameter($paramId, $paramType);
|
||||
$this->assertEquals($expectedResult, $parameter, '', 0.0, 10, true);
|
||||
}
|
||||
|
||||
public function dataSet_testGetParameter()
|
||||
{
|
||||
$result[] = [
|
||||
$this->param['color'],
|
||||
\Filter::PARAM_LIST,
|
||||
[
|
||||
'param_name' => 'Color',
|
||||
'values' => [
|
||||
'1' => [
|
||||
'id' => '1',
|
||||
'param_name' => 'Color',
|
||||
'name' => 'black',
|
||||
'description' => 'black descr',
|
||||
'count' => '2',
|
||||
'unit' => '',
|
||||
'data' => [],
|
||||
'position' => 2,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$result[] = array_merge_strict(end($result), [
|
||||
3 => ['values' => ['1' => ['count' => '3']]],
|
||||
]);
|
||||
|
||||
$result[] = [
|
||||
$this->param['size'],
|
||||
\Filter::PARAM_INT,
|
||||
[
|
||||
'param_name' => 'Size',
|
||||
'values' => [
|
||||
'min' => '5',
|
||||
'max' => '10',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$result[] = [
|
||||
$this->param['size2'],
|
||||
\Filter::PARAM_INT,
|
||||
[
|
||||
'param_name' => 'Size2',
|
||||
'values' => null,
|
||||
],
|
||||
];
|
||||
|
||||
$result[] = [
|
||||
$this->param['descr'],
|
||||
\Filter::PARAM_CHAR,
|
||||
[
|
||||
'param_name' => 'Descr',
|
||||
'values' => [
|
||||
'Popisek' => [
|
||||
'id' => 'Popisek',
|
||||
'param_name' => 'Descr',
|
||||
'name' => 'Popisek',
|
||||
'count' => '2',
|
||||
'unit' => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function testSetFilterData()
|
||||
{
|
||||
$filterData = [
|
||||
'producerIds' => [1, 2, 3],
|
||||
'campaigns' => ['A', 'B', 'C'],
|
||||
'inStore' => 42,
|
||||
'inSupplier' => 42,
|
||||
'price' => [
|
||||
'min' => 5,
|
||||
'max' => 500,
|
||||
'value' => '4,5-100',
|
||||
],
|
||||
'parameters' => [
|
||||
5 => [
|
||||
'value' => '6 - 8',
|
||||
'min' => 5,
|
||||
'max' => 10,
|
||||
'type' => 'int',
|
||||
],
|
||||
10 => [
|
||||
'value' => [7, 8, 9],
|
||||
'type' => 'list',
|
||||
],
|
||||
],
|
||||
'variations' => [
|
||||
10 => [
|
||||
'value' => [50, 100],
|
||||
],
|
||||
],
|
||||
'sectionIDsFilter' => [3, 4],
|
||||
];
|
||||
|
||||
$expected = [
|
||||
'sectionIds' => [1, 2],
|
||||
'sectionIdsFilter' => [3, 4],
|
||||
'variations' => [10 => [50, 100]],
|
||||
'producers' => [1, 2, 3],
|
||||
'parameters' => [
|
||||
5 => ['values' => ['min' => 6.0, 'max' => 8.0], 'type' => 'int'],
|
||||
10 => ['values' => [7, 8, 9], 'type' => 'list'],
|
||||
],
|
||||
'inStore' => \Filter::IN_STORE_SUPPLIER,
|
||||
'priceRange' => new \Range(null, 100),
|
||||
'campaigns' => ['A', 'B', 'C'],
|
||||
'invertParameters' => [],
|
||||
'relatedProducts' => [],
|
||||
'stores' => [],
|
||||
'variationsSizeConvertion' => [],
|
||||
'labels' => [],
|
||||
'inSale' => null,
|
||||
'productCodes' => [],
|
||||
'andParameters' => [],
|
||||
'search' => null,
|
||||
'products' => [],
|
||||
'quantityDiscounts' => [],
|
||||
'showInSearch' => false,
|
||||
];
|
||||
|
||||
$this->filter->setFilterData($filterData);
|
||||
$this->assertEquals($expected, $this->filterParams->getParams());
|
||||
}
|
||||
|
||||
public function getDataset()
|
||||
{
|
||||
return new YamlDataSet(__DIR__.'/FilterParametersTest.yml');
|
||||
}
|
||||
}
|
||||
211
tests/functional/FilterTest/FilterParametersTest.yml
Normal file
211
tests/functional/FilterTest/FilterParametersTest.yml
Normal file
@@ -0,0 +1,211 @@
|
||||
sections:
|
||||
-
|
||||
id: 1
|
||||
name: Has children
|
||||
lead_text: text
|
||||
|
||||
-
|
||||
id: 2
|
||||
name: Child
|
||||
lead_text: text
|
||||
|
||||
-
|
||||
id: 3
|
||||
name: No children
|
||||
lead_text: text
|
||||
|
||||
sections_relation:
|
||||
-
|
||||
id_section: 1
|
||||
id_topsection:
|
||||
position: 1
|
||||
-
|
||||
id_section: 2
|
||||
id_topsection: 1
|
||||
position: 2
|
||||
-
|
||||
id_section: 3
|
||||
id_topsection:
|
||||
position: 3
|
||||
|
||||
producers:
|
||||
-
|
||||
id: 1
|
||||
name: Producer 1
|
||||
photo: x.jpg
|
||||
web: http://www.example.com
|
||||
|
||||
-
|
||||
id: 2
|
||||
name: Producer 2
|
||||
photo: x.jpg
|
||||
web: http://www.example.com
|
||||
|
||||
products:
|
||||
-
|
||||
id: 1
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 1
|
||||
vat: 1
|
||||
campaign: N
|
||||
-
|
||||
id: 2
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 2
|
||||
vat: 1
|
||||
campaign: N
|
||||
-
|
||||
id: 3
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 1
|
||||
vat: 1
|
||||
campaign: N
|
||||
-
|
||||
id: 4
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 1
|
||||
vat: 1
|
||||
campaign: N
|
||||
-
|
||||
id: 5
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 1
|
||||
vat: 1
|
||||
campaign: N
|
||||
|
||||
products_in_sections:
|
||||
-
|
||||
id_section: 1
|
||||
id_product: 1
|
||||
-
|
||||
id_section: 2
|
||||
id_product: 2
|
||||
-
|
||||
id_section: 2
|
||||
id_product: 3
|
||||
-
|
||||
id_section: 2
|
||||
id_product: 4
|
||||
-
|
||||
id_section: 3
|
||||
id_product: 5
|
||||
|
||||
parameters:
|
||||
-
|
||||
id: 1
|
||||
name: Size
|
||||
value_type: int
|
||||
-
|
||||
id: 2
|
||||
name: Color
|
||||
value_type: list
|
||||
-
|
||||
id: 3
|
||||
name: Size2
|
||||
value_type: int
|
||||
-
|
||||
id: 4
|
||||
name: Descr
|
||||
value_type: char
|
||||
|
||||
parameters_list:
|
||||
-
|
||||
id: 1
|
||||
id_parameter: 2
|
||||
value: black
|
||||
description: black descr
|
||||
position: 2
|
||||
-
|
||||
id: 2
|
||||
id_parameter: 2
|
||||
value: white
|
||||
description: white descr
|
||||
position: 1
|
||||
|
||||
parameters_products:
|
||||
-
|
||||
id: 1
|
||||
id_product: 3
|
||||
id_parameter: 1
|
||||
value_list:
|
||||
value_char:
|
||||
value_float: 5
|
||||
|
||||
-
|
||||
id: 2
|
||||
id_product: 3
|
||||
id_parameter: 2
|
||||
value_list: 1
|
||||
value_char:
|
||||
value_float:
|
||||
-
|
||||
id: 3
|
||||
id_product: 4
|
||||
id_parameter: 2
|
||||
value_list: 1
|
||||
value_char:
|
||||
value_float:
|
||||
-
|
||||
id: 4
|
||||
id_product: 4
|
||||
id_parameter: 1
|
||||
value_list:
|
||||
value_char:
|
||||
value_float: 10
|
||||
-
|
||||
id: 5
|
||||
id_product: 4
|
||||
id_parameter: 3
|
||||
value_list:
|
||||
value_char:
|
||||
value_float: 5
|
||||
-
|
||||
id: 6
|
||||
id_product: 3
|
||||
id_parameter: 4
|
||||
value_list:
|
||||
value_char: Popisek
|
||||
value_float:
|
||||
-
|
||||
id: 7
|
||||
id_product: 4
|
||||
id_parameter: 4
|
||||
value_list:
|
||||
value_char: Popisek
|
||||
value_float:
|
||||
|
||||
products_variations:
|
||||
-
|
||||
id: 1
|
||||
id_product: 3
|
||||
title: Variation 1
|
||||
-
|
||||
id: 2
|
||||
id_product: 3
|
||||
title: Variation 2
|
||||
|
||||
parameters_translations:
|
||||
-
|
||||
id: 1
|
||||
id_parameter: 2
|
||||
id_language: sk
|
||||
name: Farba
|
||||
|
||||
parameters_list_translations:
|
||||
-
|
||||
id_parameters_list: 1
|
||||
id_language: sk
|
||||
value: čierna
|
||||
description: čierna desc
|
||||
|
||||
|
||||
97
tests/functional/FilterTest/FilterParamsTest.php
Normal file
97
tests/functional/FilterTest/FilterParamsTest.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: filip
|
||||
* Date: 5/27/16
|
||||
* Time: 1:39 PM.
|
||||
*/
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
use Query\Operator;
|
||||
|
||||
class FilterParamsTest extends \DatabaseTestCase
|
||||
{
|
||||
/** @var \FilterParams */
|
||||
private $filterParams;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->filterParams = new \FilterParams();
|
||||
$this->filterParams->setSections([3]);
|
||||
}
|
||||
|
||||
public function testGetSpecWithoutParametersAndsAllSpecs()
|
||||
{
|
||||
$this->filterParams->setPriceRange(1000, 5000);
|
||||
|
||||
$count = sqlQueryBuilder()->select('*')->fromProducts()->where($this->filterParams->getSpec())->execute()->rowCount();
|
||||
$this->assertSame(2, $count);
|
||||
}
|
||||
|
||||
public function testAddSpec()
|
||||
{
|
||||
$this->filterParams->andSpec(Operator::between('price', new \Range(1000, 5000)));
|
||||
|
||||
$count = sqlQueryBuilder()->select('*')->fromProducts()->where($this->filterParams->getSpec())->execute()->rowCount();
|
||||
$this->assertSame(2, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testSetResultEntityThrows()
|
||||
{
|
||||
$this->filterParams->setResultEntity('invalid');
|
||||
}
|
||||
|
||||
public function testGetResultEntityDefault()
|
||||
{
|
||||
$this->assertSame(\FilterParams::ENTITY_PRODUCT, $this->filterParams->getResultEntity());
|
||||
}
|
||||
|
||||
public function testSetAndGetResultEntity()
|
||||
{
|
||||
$this->filterParams->setResultEntity(\FilterParams::ENTITY_VARIATION);
|
||||
$this->assertSame(\FilterParams::ENTITY_VARIATION, $this->filterParams->getResultEntity());
|
||||
}
|
||||
|
||||
public function testConvenienceMethods()
|
||||
{
|
||||
$this->assertTrue($this->filterParams->resultEntityIsProduct());
|
||||
$this->filterParams->setResultEntity(\FilterParams::ENTITY_VARIATION);
|
||||
$this->assertTrue($this->filterParams->resultEntityIsVariation());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider_testGetInStore
|
||||
*/
|
||||
public function testGetInStoreReturnsDomainDefaultIfNotOverridenBySetInStore($setting, $supplierStoreModuleExists, $expectedResult)
|
||||
{
|
||||
\Settings::getDefault()->loadFromArray(['prod_show_not_in_store' => $setting], true);
|
||||
global $cfg;
|
||||
$cfg['Modules']['products_suppliers'] = $supplierStoreModuleExists;
|
||||
|
||||
$result = $this->filterParams->getInStore();
|
||||
|
||||
$this->assertSame($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function dataProvider_testGetInStore()
|
||||
{
|
||||
return [
|
||||
'Show not in store' => ['Y', null, null],
|
||||
'Show in store' => ['N', false, \Filter::IN_STORE],
|
||||
'Show in store supplier' => ['N', true, \Filter::IN_STORE_SUPPLIER],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetInStoreReturnsValueSetBySetInStore()
|
||||
{
|
||||
$this->filterParams->setInStore('Wrong');
|
||||
$this->assertSame('Wrong', $this->filterParams->getInStore());
|
||||
}
|
||||
}
|
||||
57
tests/functional/FilterTest/FilterPriceTest.php
Normal file
57
tests/functional/FilterTest/FilterPriceTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
class FilterPriceTest extends \DatabaseTestCase
|
||||
{
|
||||
/** @var \Filter */
|
||||
private $filter;
|
||||
|
||||
/** @var \FilterParams */
|
||||
private $filterParams;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->filter = new \Filter();
|
||||
$this->filterParams = new \FilterParams();
|
||||
$this->filter->setFilterParams($this->filterParams);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testSetPriceRange
|
||||
*/
|
||||
public function testSetPriceRange($min, $max, $count)
|
||||
{
|
||||
$this->filterParams->setPriceRange($min, $max);
|
||||
|
||||
$producers = $this->filter->getProducers()['values'];
|
||||
|
||||
$this->assertCount(1, $producers);
|
||||
$this->assertEquals($count, $producers[1]['count']);
|
||||
}
|
||||
|
||||
public function dataSet_testSetPriceRange()
|
||||
{
|
||||
return [
|
||||
[100, 1000, 1],
|
||||
'edge case' => [108, 9681, 3],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetPriceRange()
|
||||
{
|
||||
$result = $this->filter->getPriceRange();
|
||||
|
||||
$this->assertEquals([
|
||||
'min' => 108.9,
|
||||
'max' => 9680,
|
||||
], $result);
|
||||
}
|
||||
|
||||
public function getDataset()
|
||||
{
|
||||
return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__.'/FilterPriceTest.yml');
|
||||
}
|
||||
}
|
||||
85
tests/functional/FilterTest/FilterPriceTest.yml
Normal file
85
tests/functional/FilterTest/FilterPriceTest.yml
Normal file
@@ -0,0 +1,85 @@
|
||||
sections:
|
||||
-
|
||||
id: 1
|
||||
name: Has children
|
||||
lead_text: text
|
||||
|
||||
-
|
||||
id: 2
|
||||
name: Child
|
||||
lead_text: text
|
||||
|
||||
sections_relation:
|
||||
-
|
||||
id_section: 1
|
||||
id_topsection:
|
||||
position: 1
|
||||
-
|
||||
id_section: 2
|
||||
id_topsection: 1
|
||||
position: 2
|
||||
|
||||
producers:
|
||||
-
|
||||
id: 1
|
||||
name: Producer 1
|
||||
photo: x.jpg
|
||||
web: http://www.example.com
|
||||
|
||||
products:
|
||||
-
|
||||
id: 1
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 1
|
||||
vat: 1
|
||||
campaign: N
|
||||
price: 100
|
||||
discount: 10
|
||||
-
|
||||
id: 2
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 1
|
||||
vat: 1
|
||||
campaign: N
|
||||
price: 1000
|
||||
discount: 0
|
||||
-
|
||||
id: 3
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 1
|
||||
vat: 1
|
||||
campaign: N
|
||||
price: 10000
|
||||
discount: 20
|
||||
|
||||
products_in_sections:
|
||||
-
|
||||
id_section: 1
|
||||
id_product: 1
|
||||
-
|
||||
id_section: 2
|
||||
id_product: 2
|
||||
-
|
||||
id_section: 2
|
||||
id_product: 3
|
||||
|
||||
parameters:
|
||||
-
|
||||
id: 1
|
||||
name: Size
|
||||
value_type: int
|
||||
|
||||
parameters_products:
|
||||
-
|
||||
id: 1
|
||||
id_product: 3
|
||||
id_parameter: 1
|
||||
value_list:
|
||||
value_char:
|
||||
value_float: 5
|
||||
43
tests/functional/FilterTest/FilterRelatedProductsTest.php
Normal file
43
tests/functional/FilterTest/FilterRelatedProductsTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
class FilterRelatedProductsTest extends \DatabaseTestCase
|
||||
{
|
||||
/** @var \Filter */
|
||||
private $filter;
|
||||
|
||||
/** @var \FilterParams */
|
||||
private $filterParams;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->filter = new \Filter();
|
||||
$this->filterParams = new \FilterParams();
|
||||
$this->filter->setFilterParams($this->filterParams);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testRelatedProductsFilter()
|
||||
{
|
||||
$this->filterParams->setSections([5, 6]);
|
||||
$this->filterParams->setRelatedProducts([3]);
|
||||
|
||||
$result = sqlFetchAll(sqlQueryBuilder()
|
||||
->select('p.id')->fromProducts()
|
||||
->where($this->filterParams->getSpec())
|
||||
->groupBy('p.id')
|
||||
->execute(), 'id');
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertEquals([1, 6], array_keys($result));
|
||||
}
|
||||
|
||||
public function testGetRelatedProducts()
|
||||
{
|
||||
$this->filterParams->setSections([5, 6]);
|
||||
|
||||
$this->assertCount(5, $this->filter->getRelatedProducts()['values']);
|
||||
}
|
||||
}
|
||||
49
tests/functional/FilterTest/FilterSQLInjectionTest.php
Normal file
49
tests/functional/FilterTest/FilterSQLInjectionTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
use KupShop\CatalogBundle\ProductList\ProductList;
|
||||
use KupShop\CatalogBundle\Util\ProductsFilterSpecs;
|
||||
|
||||
class FilterSQLInjectionTest extends \DatabaseTestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->filterSpec = $this->get(ProductsFilterSpecs::class);
|
||||
}
|
||||
|
||||
public function testFigureInjection()
|
||||
{
|
||||
$specs = $this->filterSpec->getSpecs(['figure' => ['Y', 'Y AND testicek = 1 ']]);
|
||||
|
||||
$productList = new ProductList();
|
||||
$productList->andSpec($specs);
|
||||
|
||||
// Potřebuju pro to aby to nespadlo mít tam i figure=Y, proto mi to vrátí většinu produktů. Hlavně že to nežuchne.
|
||||
$this->assertGreaterThan(0, $productList->getProductsCount());
|
||||
}
|
||||
|
||||
public function testVariationsInjection()
|
||||
{
|
||||
$specs = $this->filterSpec->getSpecs(['variations' => ['25 AND testicek = 1 OR p'], 'variationsValuesOperator' => 'AND']);
|
||||
|
||||
$productList = new ProductList();
|
||||
$productList->andSpec($specs);
|
||||
|
||||
// Filtruju nesmysl, vrátím prázdno
|
||||
$this->assertEquals(0, $productList->getProductsCount());
|
||||
}
|
||||
|
||||
public function testParametersInjection()
|
||||
{
|
||||
$specs = $this->filterSpec->getSpecs(['parameters' => ['25 hacked'], 'parametersValuesOperator' => 'AND']);
|
||||
|
||||
$productList = new ProductList();
|
||||
$productList->andSpec($specs);
|
||||
|
||||
// Filtruju nesmysl, vrátím prázdno
|
||||
$this->assertEquals(0, $productList->getProductsCount());
|
||||
}
|
||||
}
|
||||
82
tests/functional/FilterTest/FilterSectionsByLevelTest.php
Normal file
82
tests/functional/FilterTest/FilterSectionsByLevelTest.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: filip
|
||||
* Date: 11/3/16
|
||||
* Time: 2:58 PM.
|
||||
*/
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
class FilterSectionsByLevelTest extends \DatabaseTestCase
|
||||
{
|
||||
/** @var \Filter */
|
||||
private $filter;
|
||||
|
||||
/** @var \FilterParams */
|
||||
private $filterParams;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->filter = new \Filter();
|
||||
$this->filterParams = new \FilterParams();
|
||||
$this->filter->setFilterParams($this->filterParams);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testGetSectionsWithSelectedFilter()
|
||||
{
|
||||
$expected = [
|
||||
'5' => [
|
||||
'id' => '5', // 5,6
|
||||
'name' => 'Pánská obuv',
|
||||
'count' => '2',
|
||||
],
|
||||
'6' => [
|
||||
'id' => '6',
|
||||
'name' => 'Dámská obuv',
|
||||
'count' => '2',
|
||||
],
|
||||
];
|
||||
$this->filterParams->setSectionsByLevel(4, 1, [5, 6]);
|
||||
$result = $this->filter->getSectionsByLevel(4, 1)['values'];
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testGetSectionsWithNoSelectedFilter()
|
||||
{
|
||||
$expected = [
|
||||
'2' => [
|
||||
'id' => '2',
|
||||
'name' => 'Aku baterie',
|
||||
'count' => '2',
|
||||
],
|
||||
'3' => [
|
||||
'id' => '3',
|
||||
'name' => 'Aku vrtačky',
|
||||
'count' => '3',
|
||||
],
|
||||
];
|
||||
$this->filterParams->setSectionsByLevel(1, 1, []);
|
||||
$result = $this->filter->getSectionsByLevel(1, 1)['values'];
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testIncludeSelectedSectionWithNoProducts()
|
||||
{
|
||||
$expected = [
|
||||
'2' => [
|
||||
'id' => '2',
|
||||
'name' => 'Aku baterie',
|
||||
'count' => '0',
|
||||
],
|
||||
];
|
||||
// set both Obuv and Aku vrtačky to match 0 products
|
||||
$this->filterParams->setSectionsByLevel(4, 1, [5]);
|
||||
$this->filterParams->setSectionsByLevel(1, 1, [2]);
|
||||
$result = $this->filter->getSectionsByLevel(1, 1)['values'];
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
48
tests/functional/FilterTest/FilterSectionsTest.php
Normal file
48
tests/functional/FilterTest/FilterSectionsTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: filip
|
||||
* Date: 11/3/16
|
||||
* Time: 2:58 PM.
|
||||
*/
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
class FilterSectionsTest extends \DatabaseTestCase
|
||||
{
|
||||
/** @var \Filter */
|
||||
private $filter;
|
||||
|
||||
/** @var \FilterParams */
|
||||
private $filterParams;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->filter = new \Filter();
|
||||
$this->filterParams = new \FilterParams();
|
||||
$this->filter->setFilterParams($this->filterParams);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testGetSections()
|
||||
{
|
||||
$expected = [
|
||||
'4' => [
|
||||
'id' => '4', // 5,6
|
||||
'name' => 'Obuv',
|
||||
'count' => '4',
|
||||
],
|
||||
'3' => [
|
||||
'id' => '3',
|
||||
'name' => 'Aku vrtačky',
|
||||
'count' => '3',
|
||||
],
|
||||
];
|
||||
|
||||
$this->filterParams->setSectionsFilter([4, 3]);
|
||||
$result = $this->filter->getSections()['values'];
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
88
tests/functional/FilterTest/FilterVariationsTest.php
Normal file
88
tests/functional/FilterTest/FilterVariationsTest.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace FilterTest;
|
||||
|
||||
class FilterVariationsTest extends \DatabaseTestCase
|
||||
{
|
||||
/** @var \Filter */
|
||||
private $filter;
|
||||
|
||||
/** @var \FilterParams */
|
||||
private $filterParams;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->filter = new \Filter();
|
||||
$this->filterParams = new \FilterParams();
|
||||
$this->filterParams->setSections([1, 2]);
|
||||
$this->filter->setFilterParams($this->filterParams);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testSetVariation
|
||||
*/
|
||||
public function testSetVariation($labelId, array $valueIds, array $expectedResult)
|
||||
{
|
||||
$this->filterParams->setVariation($labelId, $valueIds);
|
||||
|
||||
$result = $this->filter->getProducers()['values'];
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function dataSet_testSetVariation()
|
||||
{
|
||||
return [
|
||||
[
|
||||
1,
|
||||
[1],
|
||||
[
|
||||
1 => ['id' => '1', 'name' => 'Producer 1', 'photo' => 'x.jpg', 'count' => '1', 'filter_url' => null],
|
||||
],
|
||||
],
|
||||
[
|
||||
1,
|
||||
[1, 2],
|
||||
[
|
||||
2 => ['id' => '2', 'name' => 'Producer 2', 'photo' => 'x.jpg', 'count' => '1', 'filter_url' => null],
|
||||
1 => ['id' => '1', 'name' => 'Producer 1', 'photo' => 'x.jpg', 'count' => '1', 'filter_url' => null],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetVariationCountProduct()
|
||||
{
|
||||
$expected = [
|
||||
'param_name' => 'size',
|
||||
'values' => [
|
||||
'2' => ['code' => null, 'value_data' => null, 'count' => '2', 'name' => '42', 'filter_url' => null],
|
||||
'1' => ['code' => null, 'value_data' => null, 'count' => '1', 'name' => '41', 'filter_url' => null],
|
||||
],
|
||||
];
|
||||
$result = $this->filter->getVariation(1);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testGetVariationCountVariation()
|
||||
{
|
||||
$expected = [
|
||||
'param_name' => 'size',
|
||||
'values' => [
|
||||
'2' => ['code' => null, 'value_data' => null, 'count' => '2', 'name' => '42', 'filter_url' => null],
|
||||
'1' => ['code' => null, 'value_data' => null, 'count' => '2', 'name' => '41', 'filter_url' => null],
|
||||
],
|
||||
];
|
||||
$this->filterParams->setResultEntity(\FilterParams::ENTITY_VARIATION);
|
||||
$result = $this->filter->getVariation(1);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function getDataset()
|
||||
{
|
||||
return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__.'/FilterVariationsTest.yml');
|
||||
}
|
||||
}
|
||||
172
tests/functional/FilterTest/FilterVariationsTest.yml
Normal file
172
tests/functional/FilterTest/FilterVariationsTest.yml
Normal file
@@ -0,0 +1,172 @@
|
||||
sections:
|
||||
-
|
||||
id: 1
|
||||
name: Has children
|
||||
lead_text: text
|
||||
|
||||
-
|
||||
id: 2
|
||||
name: Child
|
||||
lead_text: text
|
||||
|
||||
-
|
||||
id: 3
|
||||
name: No children
|
||||
lead_text: text
|
||||
|
||||
sections_relation:
|
||||
-
|
||||
id_section: 1
|
||||
id_topsection:
|
||||
position: 1
|
||||
-
|
||||
id_section: 2
|
||||
id_topsection: 1
|
||||
position: 2
|
||||
-
|
||||
id_section: 3
|
||||
id_topsection:
|
||||
position: 3
|
||||
|
||||
producers:
|
||||
-
|
||||
id: 1
|
||||
name: Producer 1
|
||||
photo: x.jpg
|
||||
web: http://www.example.com
|
||||
position: 2
|
||||
|
||||
-
|
||||
id: 2
|
||||
name: Producer 2
|
||||
photo: x.jpg
|
||||
web: http://www.example.com
|
||||
position: 1
|
||||
|
||||
products:
|
||||
-
|
||||
id: 1
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 1
|
||||
vat: 1
|
||||
campaign: N
|
||||
-
|
||||
id: 2
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 2
|
||||
vat: 1
|
||||
campaign: N,S
|
||||
-
|
||||
id: 3
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 1
|
||||
vat: 1
|
||||
campaign: N,D
|
||||
-
|
||||
id: 4
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 1
|
||||
vat: 1
|
||||
campaign: S,A
|
||||
-
|
||||
id: 5
|
||||
short_descr: short
|
||||
long_descr: long
|
||||
parameters: params
|
||||
producer: 1
|
||||
vat: 1
|
||||
campaign: ''
|
||||
|
||||
products_in_sections:
|
||||
-
|
||||
id_section: 1
|
||||
id_product: 1
|
||||
-
|
||||
id_section: 2
|
||||
id_product: 2
|
||||
-
|
||||
id_section: 2
|
||||
id_product: 3
|
||||
-
|
||||
id_section: 2
|
||||
id_product: 4
|
||||
-
|
||||
id_section: 3
|
||||
id_product: 5
|
||||
|
||||
products_variations:
|
||||
-
|
||||
id: 1
|
||||
id_product: 1
|
||||
title: size 41
|
||||
-
|
||||
id: 2
|
||||
id_product: 1
|
||||
title: size 42
|
||||
-
|
||||
id: 3
|
||||
id_product: 2
|
||||
title: size 42
|
||||
-
|
||||
id: 4
|
||||
id_product: 3
|
||||
title: red
|
||||
-
|
||||
id: 5
|
||||
id_product: 1
|
||||
title: size 41
|
||||
|
||||
products_variations_choices_labels:
|
||||
-
|
||||
id: 1
|
||||
label: size
|
||||
-
|
||||
id: 2
|
||||
label: color
|
||||
|
||||
products_variations_choices_values:
|
||||
-
|
||||
id: 1
|
||||
id_label: 1
|
||||
value: 41
|
||||
sort: 3
|
||||
-
|
||||
id: 2
|
||||
id_label: 1
|
||||
value: 42
|
||||
sort: 2
|
||||
-
|
||||
id: 3
|
||||
id_label: 2
|
||||
value: red
|
||||
sort: 1
|
||||
|
||||
products_variations_combination:
|
||||
-
|
||||
id_variation: 1
|
||||
id_label: 1
|
||||
id_value: 1
|
||||
-
|
||||
id_variation: 2
|
||||
id_label: 1
|
||||
id_value: 2
|
||||
-
|
||||
id_variation: 3
|
||||
id_label: 1
|
||||
id_value: 2
|
||||
-
|
||||
id_variation: 4
|
||||
id_label: 2
|
||||
id_value: 3
|
||||
-
|
||||
id_variation: 5
|
||||
id_label: 1
|
||||
id_value: 1
|
||||
192
tests/functional/FunctionsCommonTest.php
Normal file
192
tests/functional/FunctionsCommonTest.php
Normal file
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: filip
|
||||
* Date: 7/15/16
|
||||
* Time: 11:47 AM.
|
||||
*/
|
||||
require_once __DIR__.'/../../web/functions.common.php';
|
||||
|
||||
class FunctionsCommonTest extends DatabaseTestCase
|
||||
{
|
||||
public function testImplodeKeyValue()
|
||||
{
|
||||
$array = [
|
||||
'one' => 1,
|
||||
'two' => 2,
|
||||
];
|
||||
|
||||
$expected = 'one-1|two-2';
|
||||
|
||||
$this->assertSame($expected, implodeKeyValue($array, '-', '|'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_testPrintPrice
|
||||
*/
|
||||
public function testPrintPrice($price, $printedPrice, $printPriceOptions, $price_round, $price_round_direction, $price_precision, $price_decimal_mark = null)
|
||||
{
|
||||
$currency = $this->get(\KupShop\KupShopBundle\Context\CurrencyContext::class)->getActive();
|
||||
$currency->setPriceRound($price_round);
|
||||
$currency->setPriceRoundDirection($price_round_direction);
|
||||
$currency->setPricePrecision($price_precision);
|
||||
|
||||
if ($price_decimal_mark) {
|
||||
$currency->setPriceDecimalMark($price_decimal_mark);
|
||||
}
|
||||
|
||||
$this->assertEquals($printedPrice, printPrice($price, $printPriceOptions));
|
||||
}
|
||||
|
||||
public function data_testPrintPrice()
|
||||
{
|
||||
return [
|
||||
// Price rounding
|
||||
[toDecimal('10.123'), '10,12 Kč', [], '0', 'math', '2'], // 0
|
||||
[toDecimal('10.123'), '10,12 Kč', [], '1', 'math', '2'], // 1
|
||||
[toDecimal('10.654'), '10,50 Kč', [], '50', 'math', '2'], // 2
|
||||
[toDecimal('10.123'), '10,00 Kč', [], '100', 'math', '2'], // 3
|
||||
[toDecimal('10.123'), '10 Kč', [], '0', 'math', '0'], // 4
|
||||
[toDecimal('10.123'), '10,12 Kč', [], '0', 'math', '2'], // 5
|
||||
[toDecimal('10.123'), '10,12 Kč', [], '0', 'math', 'dynamic'], // 6
|
||||
[toDecimal('10.123'), '10 Kč', [], '100', 'math', '0'], // 7
|
||||
[toDecimal('10.123'), '10,00 Kč', [], '100', 'math', '2'], // 8
|
||||
[toDecimal('10.123'), '10 Kč', [], '100', 'math', 'dynamic'], // 9
|
||||
[toDecimal('10'), '10 Kč', [], '0', 'math', 'dynamic'], // 10
|
||||
[toDecimal('10.2'), '10,20 Kč', [], '0', 'math', 'dynamic'], // 11
|
||||
[toDecimal('10.2'), '10,20 Kč', [], '10', 'up', '2'], // 12
|
||||
[toDecimal('10.2')->removeVat(21)->addVat(21), '10,20 Kč', [], '10', 'up', '2'], // 13
|
||||
[toDecimal('10.23'), '10,25 Kč', [], '5', 'math', '2'], // 14
|
||||
[toDecimal('10.234'), '10,25 Kč', [], '5', 'math', '2'], // 15
|
||||
[toDecimal('10.222'), '10,20 Kč', [], '5', 'math', '2'], // 15
|
||||
[toDecimal('10.222'), '10.20 Kč', [], '5', 'math', '2', '.'], // 15
|
||||
[toDecimal('10.222'), '10,20 Kč', [], '5', 'math', '2', ','], // 15
|
||||
[toDecimal('10.10'), '10,00 Kč', [], '25', 'math', 2, ','],
|
||||
[toDecimal('10.16'), '10,25 Kč', [], '25', 'math', 2, ','],
|
||||
[toDecimal('10.61'), '10,50 Kč', [], '25', 'math', 2, ','],
|
||||
[toDecimal('10.69'), '10,75 Kč', [], '25', 'math', 2, ','],
|
||||
[toDecimal('10.83'), '10,75 Kč', [], '25', 'math', 2, ','],
|
||||
[toDecimal('10.88'), '11,00 Kč', [], '25', 'math', 2, ','],
|
||||
];
|
||||
}
|
||||
|
||||
public function testJsonDecodeStrictWorks()
|
||||
{
|
||||
$this->assertSame(['test' => 1], json_decode_strict('{"test": 1}', 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \JsonException
|
||||
*
|
||||
* @expectedExceptionCode 3
|
||||
*
|
||||
* @expectedExceptionMessage Error
|
||||
*/
|
||||
public function testJsonDecodeStrictThrows()
|
||||
{
|
||||
json_decode_strict('{"}');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_testPageUrl
|
||||
*/
|
||||
public function testPageUrl($url, $params)
|
||||
{
|
||||
$this->assertEquals($url, createScriptURL($params));
|
||||
}
|
||||
|
||||
public function data_testPageUrl()
|
||||
{
|
||||
return [
|
||||
['/kontakt/', ['s' => 'page', 'label' => 'contact']],
|
||||
['/reklamace/', ['s' => 'page', 'label' => 'complaint-rules']],
|
||||
['/reklamace', ['s' => 'page', 'ID' => '1']],
|
||||
['/obchodni-podminky_p2.html', ['s' => 'page', 'ID' => '2']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_testPreparePrice
|
||||
*/
|
||||
public function testPreparePrice($string, $float)
|
||||
{
|
||||
$price = $this->preparePrice($string);
|
||||
$this->assertEquals($float, $price);
|
||||
$this->assertIsFloat($price);
|
||||
}
|
||||
|
||||
public function data_testPreparePrice()
|
||||
{
|
||||
return [
|
||||
['-123', -123],
|
||||
['123.55', 123.55],
|
||||
['123,55', 123.55],
|
||||
['12 000,5', 12000.5],
|
||||
['ahoj123', 123],
|
||||
['.5', 0.5],
|
||||
['0', 0],
|
||||
];
|
||||
}
|
||||
|
||||
public function testPreparePriceNull()
|
||||
{
|
||||
$string = null;
|
||||
$this->assertNull($this->preparePrice($string));
|
||||
$string = '';
|
||||
$this->assertNull($this->preparePrice($string));
|
||||
}
|
||||
|
||||
public function testRequestFromConsole()
|
||||
{
|
||||
$this->assertEquals('https://www.kupshop.local/', path('home', [], 0));
|
||||
}
|
||||
|
||||
protected function getDataSet()
|
||||
{
|
||||
return $this->getJsonDataSet(/* @lang JSON */ '{
|
||||
"menu_links": [
|
||||
{
|
||||
"id":31,
|
||||
"id_menu":null,
|
||||
"type":2,
|
||||
"parent":null,
|
||||
"list_order":4,
|
||||
"name":"Reklamační řád",
|
||||
"name_short":"",
|
||||
"url":"reklamace",
|
||||
"link":null,
|
||||
"target":"",
|
||||
"figure":"Y",
|
||||
"data":null,
|
||||
"id_block":null,
|
||||
"template":"",
|
||||
"meta_title":null,
|
||||
"meta_description":null,
|
||||
"meta_keywords":null,
|
||||
"old_id_page":1
|
||||
},
|
||||
{
|
||||
"id":32,
|
||||
"id_menu":null,
|
||||
"type":2,
|
||||
"parent":null,
|
||||
"list_order":4,
|
||||
"name":"Obchodní podmínky",
|
||||
"name_short":"",
|
||||
"url":"obchodni-podminky_p2.html",
|
||||
"link":null,
|
||||
"target":"",
|
||||
"figure":"Y",
|
||||
"data":null,
|
||||
"id_block":null,
|
||||
"template":"",
|
||||
"meta_title":null,
|
||||
"meta_description":null,
|
||||
"meta_keywords":null,
|
||||
"old_id_page":2
|
||||
}
|
||||
]
|
||||
}');
|
||||
}
|
||||
}
|
||||
154
tests/functional/InsertProductsTypesTest.json
Normal file
154
tests/functional/InsertProductsTypesTest.json
Normal file
@@ -0,0 +1,154 @@
|
||||
{
|
||||
"products_collections": [
|
||||
{
|
||||
"id_product": "1",
|
||||
"id_product_related": "2"
|
||||
},
|
||||
{
|
||||
"id_product": "1",
|
||||
"id_product_related": "3"
|
||||
},
|
||||
{
|
||||
"id_product": "1",
|
||||
"id_product_related": "4"
|
||||
},
|
||||
{
|
||||
"id_product": "4",
|
||||
"id_product_related": "5"
|
||||
},
|
||||
{
|
||||
"id_product": "4",
|
||||
"id_product_related": "6"
|
||||
}
|
||||
],
|
||||
"photos_products_relation": [
|
||||
{
|
||||
"id_photo": 1,
|
||||
"id_product": 1,
|
||||
"id_variation": null,
|
||||
"show_in_lead": "Y",
|
||||
"active": "Y",
|
||||
"date_added": "2013-09-13 11:08:27",
|
||||
"position": 0
|
||||
},
|
||||
{
|
||||
"id_photo": 2,
|
||||
"id_product": 1,
|
||||
"id_variation": null,
|
||||
"show_in_lead": "N",
|
||||
"active": "Y",
|
||||
"date_added": "2013-09-13 11:08:36",
|
||||
"position": 1
|
||||
},
|
||||
{
|
||||
"id_photo": 3,
|
||||
"id_product": 1,
|
||||
"id_variation": null,
|
||||
"show_in_lead": "O",
|
||||
"active": "Y",
|
||||
"date_added": "2013-09-13 11:22:49",
|
||||
"position": 0
|
||||
}
|
||||
],
|
||||
"products_in_articles": [
|
||||
{
|
||||
"id_product": 1,
|
||||
"id_article": 2
|
||||
},
|
||||
{
|
||||
"id_product": 2,
|
||||
"id_article": 3
|
||||
}
|
||||
],
|
||||
"orders": [
|
||||
{
|
||||
"id": 1,
|
||||
"order_no": 201300025,
|
||||
"currency": "CZK",
|
||||
"currency_rate": "1.0000",
|
||||
"id_user": null,
|
||||
"date_created": "2013-09-13 13:44:00",
|
||||
"date_accept": "2013-09-13 13:50:19",
|
||||
"date_handle": "2013-09-13 13:50:19",
|
||||
"date_updated": "2055-02-16 11:28:32",
|
||||
"date_due": null,
|
||||
"status": 0,
|
||||
"status_payed": 0,
|
||||
"status_dispatch": 0,
|
||||
"status_storno": 0,
|
||||
"total_price": "1692.8000",
|
||||
"invoice_name": "Lukáš",
|
||||
"invoice_surname": "Klíma",
|
||||
"invoice_firm": "WPJ s.r.o.",
|
||||
"invoice_ico": "",
|
||||
"invoice_dic": "",
|
||||
"invoice_street": "Za komínem 5",
|
||||
"invoice_city": "Trutnov",
|
||||
"invoice_zip": 54101,
|
||||
"invoice_country": "Česká Republika",
|
||||
"invoice_phone": 123456789,
|
||||
"invoice_email": "klima@wpj.cz",
|
||||
"delivery_name": "Lukáš",
|
||||
"delivery_surname": "Klíma",
|
||||
"delivery_firm": "WPJ s.r.o.",
|
||||
"delivery_street": "Za komínem 5",
|
||||
"delivery_city": "Trutnov",
|
||||
"delivery_zip": 54101,
|
||||
"delivery_country": "Česká Republika",
|
||||
"delivery_type": "Hotově - Osobní odběr",
|
||||
"id_delivery": null,
|
||||
"delivery_complete": "N",
|
||||
"note_user": "",
|
||||
"note_admin": "",
|
||||
"flags": "",
|
||||
"admin": null
|
||||
}
|
||||
],
|
||||
"order_items": [
|
||||
{
|
||||
"id": 37,
|
||||
"id_order": 1,
|
||||
"id_product": 10,
|
||||
"id_variation": null,
|
||||
"pieces": 1,
|
||||
"pieces_reserved": 0,
|
||||
"piece_price": "1399.0100",
|
||||
"total_price": "1399.0100",
|
||||
"descr": "Black and Decker Core EGBL108K aku vrtačka",
|
||||
"tax": 21,
|
||||
"date": "2015-02-16 00:00:00",
|
||||
"note": "",
|
||||
"discount": "0.0000"
|
||||
},
|
||||
{
|
||||
"id": 38,
|
||||
"id_order": 1,
|
||||
"id_product": 1,
|
||||
"id_variation": null,
|
||||
"pieces": 1,
|
||||
"pieces_reserved": 0,
|
||||
"piece_price": "1399.0100",
|
||||
"total_price": "1399.0100",
|
||||
"descr": "Black and Decker Core EGBL108K aku vrtačka",
|
||||
"tax": 21,
|
||||
"date": "2015-02-16 00:00:00",
|
||||
"note": "",
|
||||
"discount": "0.0000"
|
||||
},
|
||||
{
|
||||
"id": 39,
|
||||
"id_order": 1,
|
||||
"id_product": 2,
|
||||
"id_variation": null,
|
||||
"pieces": 5,
|
||||
"pieces_reserved": 0,
|
||||
"piece_price": "1399.0100",
|
||||
"total_price": "1399.0100",
|
||||
"descr": "Black and Decker Core EGBL108K aku vrtačka",
|
||||
"tax": 21,
|
||||
"date": "2015-02-16 00:00:00",
|
||||
"note": "",
|
||||
"discount": "0.0000"
|
||||
}
|
||||
]
|
||||
}
|
||||
200
tests/functional/InsertProductsTypesTest.php
Normal file
200
tests/functional/InsertProductsTypesTest.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: filip
|
||||
* Date: 11/25/16
|
||||
* Time: 11:43 AM.
|
||||
*/
|
||||
class InsertProductsTypesTest extends DatabaseTestCase
|
||||
{
|
||||
/** @var InsertProductsTypes */
|
||||
private $insertProductsTypes;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->insertProductsTypes = new InsertProductsTypes();
|
||||
}
|
||||
|
||||
public function testInsertProductsTypesUnknownType()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
$params = ['type' => 'nesmysl', 'count' => 1];
|
||||
$this->insertProductsTypes->getProducts($params);
|
||||
}
|
||||
|
||||
public function testFollowsRandomParam()
|
||||
{
|
||||
// It randomly fails - depends on current date, impossible to mock now
|
||||
// $this->assertNotEquals(
|
||||
// $this->insertProductsTypes->getProducts(['type' => 'newest_product']),
|
||||
// $this->insertProductsTypes->getProducts(['type' => 'newest_product', 'random' => 1])
|
||||
// );
|
||||
}
|
||||
|
||||
public function testRandomIsRandomOneADay()
|
||||
{
|
||||
// Hope this tests won't run at midnight
|
||||
$params = ['type' => 'newest_product', 'random' => 1, 'count' => 1];
|
||||
$this->assertEquals(
|
||||
$this->insertProductsTypes->getProducts($params),
|
||||
$this->insertProductsTypes->getProducts($params)
|
||||
);
|
||||
}
|
||||
|
||||
public function testVeryRandomIsRandomEveryTime()
|
||||
{
|
||||
$params = ['type' => 'newest_product', 'random' => 'very_random', 'count' => 1];
|
||||
srand(42);
|
||||
$this->assertNotEquals(
|
||||
$this->insertProductsTypes->getProducts($params),
|
||||
$this->insertProductsTypes->getProducts($params)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testThrowsOnMissingType()
|
||||
{
|
||||
$this->insertProductsTypes->getProducts(['type' => 'nonexistent', 'count' => 1, 'image' => 1]);
|
||||
}
|
||||
|
||||
public function testTypeNewestProduct()
|
||||
{
|
||||
$result = $this->insertProductsTypes->getProducts(['type' => 'newest_product', 'count' => 1, 'image' => 1]);
|
||||
$this->assertEquals('7', $result->first()->id);
|
||||
}
|
||||
|
||||
public function testTypeNewestProductWithPhoto()
|
||||
{
|
||||
$result = $this->insertProductsTypes->getProducts(['type' => 'newest_product', 'count' => 1, 'image' => 1, 'image_exists' => true]);
|
||||
$this->assertEquals('1', $result->first()->id);
|
||||
}
|
||||
|
||||
public function testTypeCampaignProduct()
|
||||
{
|
||||
$result = $this->insertProductsTypes->getProducts(
|
||||
['type' => 'campaign_product', 'count' => 10, 'image' => 1, 'campaign' => 'L']
|
||||
);
|
||||
|
||||
$this->assertCount(7, $result);
|
||||
}
|
||||
|
||||
public function testTypeCartProduct()
|
||||
{
|
||||
$result = $this->insertProductsTypes->getProducts(
|
||||
['type' => 'cart_product', 'count' => 10, 'products' => [new Product(1)], 'order' => 'p.id']
|
||||
);
|
||||
|
||||
$this->assertEquals([2, 10], $result->getKeys());
|
||||
}
|
||||
|
||||
public function testTypeArticleProduct()
|
||||
{
|
||||
$result = $this->insertProductsTypes->getProducts(
|
||||
['type' => 'article_product', 'count' => 10, 'image' => 1, 'article' => '2']
|
||||
);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals(1, $result->first()['id']);
|
||||
}
|
||||
|
||||
public function testTypeAlsoBought()
|
||||
{
|
||||
$result = $this->insertProductsTypes->getProducts(
|
||||
['type' => 'also_bought', 'count' => 10, 'ID' => 1]
|
||||
);
|
||||
|
||||
$result2 = $this->insertProductsTypes->getProducts(
|
||||
['type' => 'also_buyed', 'count' => 10, 'ID' => 1]
|
||||
);
|
||||
|
||||
$this->assertEquals([2, 10], $result->getKeys());
|
||||
$this->assertEquals([2, 10], $result2->getKeys());
|
||||
}
|
||||
|
||||
public function testTypeBestsellingProduct()
|
||||
{
|
||||
$result = $this->insertProductsTypes->getProducts(
|
||||
['type' => 'bestselling_product', 'count' => 3]
|
||||
);
|
||||
|
||||
$this->assertEquals([11, 3, 10], $result->getKeys());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testAcceptsCountParam
|
||||
*/
|
||||
public function testFollowsCountParam($params, $expectedCount)
|
||||
{
|
||||
$this->assertCount($expectedCount, $this->insertProductsTypes->getProducts($params));
|
||||
}
|
||||
|
||||
public function dataSet_testAcceptsCountParam()
|
||||
{
|
||||
return [
|
||||
[['type' => 'newest_product', 'count' => 3], 3],
|
||||
[['type' => 'newest_product', 'count' => 4], 4],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testTypeCollectionProduct
|
||||
*/
|
||||
public function testTypeCollectionProduct($id_product, $expectedIDs)
|
||||
{
|
||||
$result = $this->insertProductsTypes->getProducts(
|
||||
['type' => 'collection_product', 'image' => 1, 'product' => $id_product]
|
||||
);
|
||||
|
||||
$this->assertEquals($expectedIDs, array_keys(array_map(function ($x) {
|
||||
return $x->id;
|
||||
}, $result->toArray())));
|
||||
}
|
||||
|
||||
public function dataSet_testTypeCollectionProduct()
|
||||
{
|
||||
return [
|
||||
[1, [1, 2, 3, 4]],
|
||||
[2, [1, 2, 3, 4]],
|
||||
[3, [1, 2, 3, 4]],
|
||||
[4, [1, 2, 3, 4, 5, 6]],
|
||||
];
|
||||
}
|
||||
|
||||
public function testTypeCollectionProductStillNotRecursive()
|
||||
{
|
||||
$result = $this->insertProductsTypes->getProducts(
|
||||
['type' => 'collection_product', 'image' => 1, 'product' => 1]
|
||||
);
|
||||
|
||||
$this->assertNotEquals([1, 2, 3, 4, 5, 6], [array_map(function ($x) {
|
||||
return $x->id;
|
||||
}, $result->toArray())],
|
||||
'Ha! Že by se rozchodily rekurzni kolekce? :-)');
|
||||
}
|
||||
|
||||
public function testImageType()
|
||||
{
|
||||
$result = $this->insertProductsTypes->getProducts(
|
||||
['type' => 'collection_product', 'count' => 1, 'product' => 1, 'image' => 1, 'image_kind' => 'O']
|
||||
);
|
||||
|
||||
$this->assertEquals(3, $result[1]->photoId);
|
||||
|
||||
$result = $this->insertProductsTypes->getProducts(
|
||||
['type' => 'collection_product', 'count' => 1, 'product' => 1, 'image' => 1]
|
||||
);
|
||||
|
||||
$this->assertEquals(1, $result[1]->photoId);
|
||||
}
|
||||
|
||||
protected function getDataSet()
|
||||
{
|
||||
return parent::getJsonDataSetFromFile();
|
||||
}
|
||||
}
|
||||
186
tests/functional/MenuSectionTreeTest.php
Normal file
186
tests/functional/MenuSectionTreeTest.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
use KupShop\CatalogBundle\Section\SectionTree;
|
||||
use PHPUnit\DbUnit\DataSet\ArrayDataSet;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: filip
|
||||
* Date: 6/6/16
|
||||
* Time: 11:33 AM.
|
||||
*/
|
||||
class MenuSectionTreeTest extends DatabaseTestCase
|
||||
{
|
||||
private $catShowEmpty;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
global $dbcfg;
|
||||
$this->catShowEmpty = $dbcfg->cat_show_empty;
|
||||
$dbcfg->cat_show_empty = 'Y';
|
||||
}
|
||||
|
||||
public function testNameShortOverridesName()
|
||||
{
|
||||
$result = $this->get(SectionTree::class)->getTree();
|
||||
|
||||
$this->assertArrayHasKey(1, $result);
|
||||
$this->assertArrayHasKey(2, $result);
|
||||
|
||||
$this->assertSame('Normal name', $result[1]['title']);
|
||||
$this->assertSame('Long name', $result[2]['title']);
|
||||
$this->assertSame('Normal name', $result[1]['title_short']);
|
||||
$this->assertSame('Short name', $result[2]['title_short']);
|
||||
$this->assertSame('Long name', $result[2]['parents'][2]);
|
||||
$this->assertTrue(isset($result[1]['flags']));
|
||||
$this->assertSame('1', $result[2]['flags']['L']);
|
||||
}
|
||||
|
||||
public function testTranslationsVisibleSection()
|
||||
{
|
||||
$this->switchLanguage();
|
||||
|
||||
$result = $this->get(SectionTree::class)->getTree();
|
||||
|
||||
$this->assertArrayHasKey(2, $result);
|
||||
$this->assertEquals('Y', $result[2]['figure']);
|
||||
}
|
||||
|
||||
public function testTranslationsHiddenSections()
|
||||
{
|
||||
$this->switchLanguage();
|
||||
|
||||
$result = $this->get(SectionTree::class)->getTree();
|
||||
|
||||
$this->assertArrayHasKey(1, $result);
|
||||
$this->assertEquals('N', $result[1]['figure']);
|
||||
}
|
||||
|
||||
public function testMultipleLanguageSectionTree()
|
||||
{
|
||||
$sectionTree = $this->get(SectionTree::class);
|
||||
|
||||
$this->assertEquals('Nářadí/Kleště', $sectionTree->getFullPath(4, 'cs'));
|
||||
|
||||
$this->assertEquals('Náradie/Kliešte', $sectionTree->getFullPath(4, 'sk'));
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return new ArrayDataSet([
|
||||
'sections' => [
|
||||
[
|
||||
'id' => 2,
|
||||
'name' => 'Long name',
|
||||
'name_short' => 'Short name',
|
||||
'flags' => 'A,L',
|
||||
],
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Normal name',
|
||||
'flags' => '',
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'name' => 'Nářadí',
|
||||
'name_short' => 'Short name',
|
||||
'flags' => 'A,L',
|
||||
],
|
||||
[
|
||||
'id' => 4,
|
||||
'name' => 'Kleště',
|
||||
'name_short' => 'Short name',
|
||||
'flags' => '',
|
||||
],
|
||||
],
|
||||
'sections_relation' => [
|
||||
[
|
||||
'id_section' => 3,
|
||||
'id_topsection' => null,
|
||||
'position' => 1,
|
||||
],
|
||||
[
|
||||
'id_section' => 4,
|
||||
'id_topsection' => 3,
|
||||
'position' => 1,
|
||||
],
|
||||
],
|
||||
'sections_translations' => [
|
||||
[
|
||||
'id' => 1,
|
||||
'id_section' => 1,
|
||||
'id_language' => 'sk',
|
||||
'id_admin' => null,
|
||||
'created' => '',
|
||||
'updated' => null,
|
||||
'name' => null,
|
||||
'name_short' => null,
|
||||
'meta_title' => null,
|
||||
'meta_description' => null,
|
||||
'meta_keywords' => null,
|
||||
'lead_text' => null,
|
||||
'url' => null,
|
||||
'figure' => 'N',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'id_section' => 2,
|
||||
'id_language' => 'sk',
|
||||
'id_admin' => null,
|
||||
'created' => '',
|
||||
'updated' => null,
|
||||
'name' => null,
|
||||
'name_short' => null,
|
||||
'meta_title' => null,
|
||||
'meta_description' => null,
|
||||
'meta_keywords' => null,
|
||||
'lead_text' => null,
|
||||
'url' => null,
|
||||
'figure' => 'Y',
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'id_section' => 3,
|
||||
'id_language' => 'sk',
|
||||
'id_admin' => null,
|
||||
'created' => '',
|
||||
'updated' => null,
|
||||
'name' => 'Náradie',
|
||||
'name_short' => null,
|
||||
'meta_title' => null,
|
||||
'meta_description' => null,
|
||||
'meta_keywords' => null,
|
||||
'lead_text' => null,
|
||||
'url' => null,
|
||||
'figure' => 'N',
|
||||
],
|
||||
[
|
||||
'id' => 4,
|
||||
'id_section' => 4,
|
||||
'id_language' => 'sk',
|
||||
'id_admin' => null,
|
||||
'created' => '',
|
||||
'updated' => null,
|
||||
'name' => 'Kliešte',
|
||||
'name_short' => null,
|
||||
'meta_title' => null,
|
||||
'meta_description' => null,
|
||||
'meta_keywords' => null,
|
||||
'lead_text' => null,
|
||||
'url' => null,
|
||||
'figure' => 'Y',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
global $dbcfg;
|
||||
$dbcfg->cat_show_empty = $this->catShowEmpty;
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
242
tests/functional/OrderBaseTest.php
Normal file
242
tests/functional/OrderBaseTest.php
Normal file
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
||||
use KupShop\OrderingBundle\Entity\Order\OrderItem;
|
||||
use KupShop\OrderingBundle\Util\Order\OrderNumberGenerator;
|
||||
|
||||
class OrderBaseTest extends DatabaseTestCase
|
||||
{
|
||||
use CartTestTrait;
|
||||
|
||||
private OrderNumberGenerator $orderNumberGenerator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->orderNumberGenerator = $this->get(OrderNumberGenerator::class);
|
||||
}
|
||||
|
||||
public function testSubmitOrderNewsletter()
|
||||
{
|
||||
$this->createCart();
|
||||
$cart = $this->cart;
|
||||
|
||||
$item = [
|
||||
'id_product' => 1,
|
||||
'id_variation' => 16,
|
||||
'pieces' => 1,
|
||||
];
|
||||
$cart->addItem($item);
|
||||
$cart->setTransport(1);
|
||||
$cart->setNewsletter(true);
|
||||
$cart->createFromDB();
|
||||
$cart->invoice = [
|
||||
'email' => 'benes@wpj.cz',
|
||||
'name' => 'Ondrej',
|
||||
'surname' => 'Benes',
|
||||
'street' => null,
|
||||
'city' => null,
|
||||
'zip' => null,
|
||||
'country' => 'CZ',
|
||||
'phone' => '123456789',
|
||||
];
|
||||
$order = $cart->submitOrder();
|
||||
|
||||
$this->assertInstanceOf(Order::class, $order);
|
||||
}
|
||||
|
||||
public function testFreeDelivery()
|
||||
{
|
||||
$this->createCart();
|
||||
$cart = $this->cart;
|
||||
|
||||
$item = [
|
||||
'id_product' => 1,
|
||||
'id_variation' => 16,
|
||||
'pieces' => 1,
|
||||
];
|
||||
$cart->addItem($item);
|
||||
$cart->setTransport(10);
|
||||
$cart->max_step = 1;
|
||||
$cart->createFromDB();
|
||||
|
||||
$this->assertEquals('800', $cart->totalPricePay->asFloat());
|
||||
}
|
||||
|
||||
public function testUpdateItemUpdatesItemCount()
|
||||
{
|
||||
$this->assertSame(1, $this->itemPieces(36));
|
||||
|
||||
$order = new Order(2);
|
||||
$order->updateItem(36, 2);
|
||||
|
||||
$this->assertSame(2, $this->itemPieces(36));
|
||||
}
|
||||
|
||||
public function testUpdateItemDoesNotDeleteOnZeroPieces()
|
||||
{
|
||||
$this->assertSame(1, $this->itemPieces(36));
|
||||
|
||||
$order = new Order(2);
|
||||
$order->updateItem(36, 0);
|
||||
|
||||
$this->assertSame(0, $this->itemPieces(36));
|
||||
}
|
||||
|
||||
public function testInsertItemInsertsProduct()
|
||||
{
|
||||
$originalItems = (new Order(2))->fetchItems();
|
||||
$originalItemsCount = count($originalItems);
|
||||
$this->assertEquals('-1', sqlFetchAssoc($this->sqlFind('products', 3))['in_store']);
|
||||
|
||||
$order = new Order(2);
|
||||
$order->insertItem(3, null, 2, '{"test":"note"}');
|
||||
|
||||
$currentItems = $order->fetchItems();
|
||||
$newItem = array_diff_key($currentItems, $originalItems);
|
||||
$newItem = current($newItem);
|
||||
|
||||
$this->assertCount($originalItemsCount + 1, $currentItems);
|
||||
$this->assertEquals('3', $newItem['id_product']);
|
||||
$this->assertEquals(['test' => 'note'], $newItem['note']);
|
||||
$this->assertEquals(Decimal::fromString('1322.3140'), $newItem['total_price']['value_without_vat']);
|
||||
$this->assertEquals('-3', sqlFetchAssoc($this->sqlFind('products', 3))['in_store']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \DomainException
|
||||
*/
|
||||
public function testInsertItemDoesNotInsertProductWithVariants()
|
||||
{
|
||||
$originalItems = (new Order(2))->fetchItems();
|
||||
$originalItemsCount = count($originalItems);
|
||||
|
||||
$order = new Order(2);
|
||||
$order->insertItem(4, null, 2, 'Test note');
|
||||
}
|
||||
|
||||
public function testInsertItemInsertsVariant()
|
||||
{
|
||||
$originalItems = (new Order(2))->fetchItems();
|
||||
$originalItemsCount = count($originalItems);
|
||||
$this->assertEquals('5', sqlFetchAssoc($this->sqlFind('products_variations', 17))['in_store']);
|
||||
|
||||
$order = new Order(2);
|
||||
$order->insertItem(6, 17, 2, '{"test":"note"}');
|
||||
|
||||
$currentItems = $order->fetchItems();
|
||||
$newItem = array_diff_key($currentItems, $originalItems);
|
||||
$newItem = current($newItem);
|
||||
|
||||
$this->assertCount($originalItemsCount + 1, $currentItems);
|
||||
$this->assertEquals('6', $newItem['id_product']);
|
||||
$this->assertEquals('17', $newItem['id_variation']);
|
||||
$this->assertEquals(['test' => 'note'], $newItem['note']);
|
||||
$this->assertEquals(Decimal::fromString('4958.6777'), $newItem['total_price']['value_without_vat']);
|
||||
$this->assertEquals('3', sqlFetchAssoc($this->sqlFind('products_variations', 17))['in_store']);
|
||||
}
|
||||
|
||||
public function testCreateFromDbOrderNo()
|
||||
{
|
||||
$order = Order::createFromDbOrderNo('201300025');
|
||||
$this->assertInstanceOf('Order', $order);
|
||||
$this->assertEquals('1', $order->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getOrdernoConfigs
|
||||
*/
|
||||
public function testOrderNoCreate($pattern, $id, $expected)
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$cfg['Order']['number']['pattern'] = $pattern;
|
||||
$this->assertEquals($expected, $this->orderNumberGenerator->generateOrderNumber($id));
|
||||
}
|
||||
|
||||
/** @dataProvider data_testRandomOrderNumber */
|
||||
public function testRandomOrderNumber(int $orderId, string $pattern, int $length, ?string $startsWith): void
|
||||
{
|
||||
$number = $this->orderNumberGenerator->generateOrderNumber($orderId, $pattern);
|
||||
|
||||
$this->assertEquals($length, strlen($number));
|
||||
$this->assertNotEmpty($number);
|
||||
|
||||
if ($startsWith) {
|
||||
$this->assertStringStartsWith($startsWith, $number);
|
||||
}
|
||||
}
|
||||
|
||||
public function testOrderItems(): void
|
||||
{
|
||||
$order = new Order(2);
|
||||
|
||||
$this->assertNotEmpty($order->fetchItems());
|
||||
$this->assertNotEmpty($order->getItems());
|
||||
|
||||
foreach ($order->fetchItems() as $item) {
|
||||
$this->assertIsArray($item, 'Using fetchItems should return historical array structure of item');
|
||||
}
|
||||
|
||||
foreach ($order->getItems() as $item) {
|
||||
$this->assertInstanceOf(OrderItem::class, $item, 'Using getItems should return OrderItem[] objects');
|
||||
}
|
||||
}
|
||||
|
||||
public function data_testRandomOrderNumber(): array
|
||||
{
|
||||
return [
|
||||
// test random cisla, kdyz se nespecifikuje delka
|
||||
[1, '[#RANDOM]', 6, null],
|
||||
// test random cisla s urcitou delkou
|
||||
[1, '[#RANDOM,8]', 8, null],
|
||||
[1, '[#RANDOM,4]', 4, null],
|
||||
// test random cisla s dalsima typama
|
||||
[1, '[Y,2][#RANDOM,8]', 10, date('y')],
|
||||
];
|
||||
}
|
||||
|
||||
public function getOrderNoConfigs()
|
||||
{
|
||||
$year = date('y');
|
||||
$yearFull = date('Y');
|
||||
$day = date('d');
|
||||
|
||||
return [
|
||||
['[Y,2][#ID,5]', 1337, $year.'01337'],
|
||||
['["37"][Y][#ID,1]', 1337, '37'.$yearFull.'1337'],
|
||||
['[D][#ID,2][#USER_ID]', 1, $day.'011'],
|
||||
['[Y,2][#ID,2][#USER_ORDER_INDEX]', 9, $year.'091'],
|
||||
['[Y,2][#ID-10,3]', 20, $year.'010'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testCreateFromDbOrderNoThrows()
|
||||
{
|
||||
Order::createFromDbOrderNo('nonexistent');
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return new \PHPUnit\DbUnit\DataSet\YamlDataSet(__DIR__.'/OrderBaseTest.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $itemId
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function itemPieces($itemId)
|
||||
{
|
||||
return (int) sqlFetchAssoc(sqlQuery('SELECT pieces FROM order_items WHERE id = 36'))['pieces'];
|
||||
}
|
||||
|
||||
private function sqlFind($tableName, $id)
|
||||
{
|
||||
return sqlQuery("SELECT * FROM {$tableName} WHERE id = {$id}");
|
||||
}
|
||||
}
|
||||
55
tests/functional/OrderBaseTest.yml
Normal file
55
tests/functional/OrderBaseTest.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
order_items:
|
||||
-
|
||||
id: 34
|
||||
id_order: 2
|
||||
id_product: 3
|
||||
id_variation: NULL
|
||||
pieces: 1
|
||||
pieces_reserved: 1
|
||||
piece_price: 661.1570
|
||||
total_price: 661.1570
|
||||
descr: Wilson pure battle crew
|
||||
tax: 21
|
||||
date: 0000-00-00
|
||||
note: ''
|
||||
-
|
||||
id: 35
|
||||
id_order: 2
|
||||
id_product: NULL
|
||||
id_variation: NULL
|
||||
pieces: 1
|
||||
pieces_reserved: 0
|
||||
piece_price: -100.0000
|
||||
total_price: -100.0000
|
||||
descr: Sleva 100 korun
|
||||
tax: 0
|
||||
date: 2013-09-13
|
||||
note: ''
|
||||
-
|
||||
id: 36
|
||||
id_order: 2
|
||||
id_product: NULL
|
||||
id_variation: NULL
|
||||
pieces: 1
|
||||
pieces_reserved: 1
|
||||
piece_price: 100.8400
|
||||
total_price: 100.8400
|
||||
descr: Dobírkou - Kurýrem
|
||||
tax: 21
|
||||
date: 2013-09-13
|
||||
note: ''
|
||||
-
|
||||
id: 37
|
||||
id_order: 1
|
||||
id_product: 10
|
||||
id_variation: NULL
|
||||
pieces: 1
|
||||
pieces_reserved: 0
|
||||
piece_price: 1399.0100
|
||||
total_price: 1399.0100
|
||||
descr: Black and Decker Core EGBL108K aku vrtačka
|
||||
tax: 21
|
||||
date: 2015-02-16
|
||||
note: ''
|
||||
|
||||
|
||||
145
tests/functional/OrderNotificationsTest.php
Normal file
145
tests/functional/OrderNotificationsTest.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
class OrderNotificationsTest extends DatabaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var \Order
|
||||
*/
|
||||
private $order;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->order = new \Order();
|
||||
$this->order->createFromDB(1);
|
||||
}
|
||||
|
||||
public function testReplacePlaceholdersMergesCustomPlaceholders()
|
||||
{
|
||||
$this->order->setPlaceholder('DUMMY', 'Hello World!');
|
||||
$result = $this->order->replacePlaceholders('Text is {DUMMY}');
|
||||
|
||||
$this->assertSame('Text is Hello World!', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_testPlaceholder
|
||||
*/
|
||||
public function testPlaceholder($source, $expected)
|
||||
{
|
||||
$text = $this->order->replacePlaceholders("start {$source} end");
|
||||
$this->assertEquals("start {$expected} end", $text);
|
||||
}
|
||||
|
||||
public function data_testPlaceholder()
|
||||
{
|
||||
return [
|
||||
['{KOD}', '201300025'],
|
||||
['{STAV}', 'nová'],
|
||||
['{ODKAZ}', 'https://www.kupshop.local/objednavka/1/?cf=dad3869906bbc5b768a369ea898a1acb'],
|
||||
['{CENA}', '1 692,80 Kč'],
|
||||
// ['{DATUM}', date('d.\&\n\b\s\p\;m.\&\n\b\s\p\;Y')],
|
||||
// ['{CAS}', date('H:i:s')],
|
||||
['{WEB}', 'https://www.kupshop.local/'],
|
||||
['{ZAPLATIT}', '1 693 Kč'],
|
||||
['{OSLOVENI_JMENO}', 'Lukáši'],
|
||||
['{OSLOVENI_PRIJMENI}', 'pane Klímo'],
|
||||
['{POPIS_ZPUSOBU_DORUCENI}', 'popis zpusobu doruceni, popis dopravy, popis platby, kod:201300025'],
|
||||
['{POPIS_DOPRAVY}', 'popis dopravy'],
|
||||
['{POPIS_PLATBY}', 'popis platby, kod:201300025'],
|
||||
['{ODKAZ_SLEDOVANI_BALIKU}', 'https://www.ppl.cz/en/track-a-shipment?shipmentId=123456'],
|
||||
];
|
||||
}
|
||||
|
||||
private function getLastUserMessage()
|
||||
{
|
||||
return end($this->order->getHistory(true))['comment'];
|
||||
}
|
||||
|
||||
protected function getDataSet()
|
||||
{
|
||||
return $this->getJsonDataSet(/* @lang JSON */
|
||||
'{
|
||||
"delivery_type_delivery": [
|
||||
{
|
||||
"id":4,
|
||||
"name":"PPL",
|
||||
"price":0,
|
||||
"photo":null,
|
||||
"class":"PPL",
|
||||
"time_days":null,
|
||||
"time_hours":null,
|
||||
"currencies":null,
|
||||
"description":"popis dopravy"
|
||||
}
|
||||
],
|
||||
"delivery_type_payment": [
|
||||
{
|
||||
"id":1,
|
||||
"name":"Dobírka",
|
||||
"price":0,
|
||||
"class":null,
|
||||
"photo":null,
|
||||
"description":"popis platby, kod:{KOD}"
|
||||
}
|
||||
],
|
||||
"delivery_type": [
|
||||
{
|
||||
"id":4,
|
||||
"id_delivery":4,
|
||||
"id_payment":1,
|
||||
"price":90,
|
||||
"vat":2,
|
||||
"price_dont_countin_from":2000,
|
||||
"format":null,
|
||||
"figure":"Y",
|
||||
"description":"popis zpusobu doruceni, {POPIS_DOPRAVY}, {POPIS_PLATBY}"
|
||||
}
|
||||
],
|
||||
"orders": [
|
||||
{
|
||||
"id":1,
|
||||
"order_no":201300025,
|
||||
"currency":"CZK",
|
||||
"currency_rate":1,
|
||||
"id_user":null,
|
||||
"date_created":"2013-09-13 13:44:00",
|
||||
"date_accept":"2013-09-13 13:50:19",
|
||||
"date_handle":"2013-09-13 13:50:19",
|
||||
"date_updated":"2015-02-16 11:28:32",
|
||||
"status":0,
|
||||
"status_payed":0,
|
||||
"status_dispatch":0,
|
||||
"status_storno":0,
|
||||
"total_price":1692.8,
|
||||
"invoice_name":"Lukáš",
|
||||
"invoice_surname":"Klíma",
|
||||
"invoice_firm":"WPJ s.r.o.",
|
||||
"invoice_ico":"",
|
||||
"invoice_dic":"",
|
||||
"invoice_street":"Za komínem 5",
|
||||
"invoice_city":"Trutnov",
|
||||
"invoice_zip":54101,
|
||||
"invoice_country":"Česká Republika",
|
||||
"invoice_phone":123456789,
|
||||
"invoice_email":"klima@wpj.cz",
|
||||
"delivery_name":"Lukáš",
|
||||
"delivery_surname":"Klíma",
|
||||
"delivery_firm":"WPJ s.r.o.",
|
||||
"delivery_street":"Za komínem 5",
|
||||
"delivery_city":"Trutnov",
|
||||
"delivery_zip":54101,
|
||||
"delivery_country":"Česká Republika",
|
||||
"delivery_type":"Hotově - Osobní odběr",
|
||||
"id_delivery":4,
|
||||
"delivery_complete":"N",
|
||||
"note_user":"",
|
||||
"note_admin":"",
|
||||
"package_id":"123456",
|
||||
"flags":""
|
||||
}
|
||||
]
|
||||
}');
|
||||
}
|
||||
}
|
||||
103
tests/functional/PagerTest.php
Normal file
103
tests/functional/PagerTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Pager\PagerExtraItem;
|
||||
|
||||
class PagerTest extends DatabaseTestCase
|
||||
{
|
||||
/** @dataProvider data_testPagerWithExtraItems */
|
||||
public function testPagerWithExtraItems(array $pagerSettings, ?array $extraItems, int $expectedPagesCount, int $expectedTotalWithExtraItems, array $expectedPagerSpecFromAndLimit): void
|
||||
{
|
||||
$pager = new Pager();
|
||||
|
||||
foreach ($extraItems ?: [] as $extraItem) {
|
||||
$pager->addExtraItems(new PagerExtraItem($extraItem[0], $extraItem[1] ?? null));
|
||||
}
|
||||
|
||||
$pager->setPageNumber($pagerSettings[2]);
|
||||
$pager->setOnPage($pagerSettings[0]);
|
||||
$pager->setTotal($pagerSettings[1]);
|
||||
|
||||
$this->assertEquals($expectedPagesCount, $pager->count);
|
||||
$this->assertEquals($pagerSettings[2], $pager->number);
|
||||
$this->assertEquals($expectedTotalWithExtraItems, $pager->totalWithExtraItems);
|
||||
|
||||
$qb = sqlQueryBuilder()->andWhere($pager->getSpec());
|
||||
|
||||
[$expectedFrom, $expectedLimit] = $expectedPagerSpecFromAndLimit;
|
||||
|
||||
$this->assertEquals($expectedFrom, $qb->getFirstResult(), 'Assert OFFSET set by pager `getSpec` method');
|
||||
$this->assertEquals($expectedLimit, $qb->getMaxResults(), 'Assert LIMIT set by pager `getSpec` method');
|
||||
}
|
||||
|
||||
public function data_testPagerWithExtraItems(): iterable
|
||||
{
|
||||
yield 'Page 1 active, 19/5=4 pages in total, 2 extra items on 1 page, 1 extra item on each next page, so 6 extra items in total, so one page is created by extra items' => [[5, 19, 1], [[1, 1], [1, null]], 5, 25, [0, 3]];
|
||||
yield 'Page 2 active, 19/5=4 pages in total, 2 extra items on 1 page, 1 extra item on each next page, so 6 extra items in total, so one page is created by extra items' => [[5, 19, 2], [[1, 1], [1, null]], 5, 25, [3, 4]];
|
||||
|
||||
yield 'Page 1 active, 15/5=4 pages in total, 0 extra item on 1 page, 1 extra item on each next page until max 3, so 4 extra items in total, so one page is created by extra items' => [[5, 15, 1], [[1, 3]], 4, 18, [0, 4]];
|
||||
yield 'Page 2 active, 15/5=4 pages in total, 0 extra item on 1 page, 1 extra item on each next page until max 3, so 4 extra items in total, so one page is created by extra items' => [[5, 15, 2], [[1, 3]], 4, 18, [4, 4]];
|
||||
|
||||
yield 'Page 1 active, 10/4=3 pages in total, 1 extra item on 1 page, 0 extra items on each next page, so one item is added in total and no next page is created' => [[4, 10, 1], [[1, 1]], 3, 11, [0, 3]];
|
||||
yield 'Page 2 active, 10/4=3 pages in total, 1 extra item on 1 page, 0 extra items on each next page, so one item is added in total and no next page is created' => [[4, 10, 2], [[1, 1]], 3, 11, [3, 4]];
|
||||
yield 'Page 3 active, 10/4=3 pages in total, 1 extra item on 1 page, 0 extra items on each next page, so one item is added in total and no next page is created' => [[4, 10, 3], [[1, 1]], 3, 11, [7, 4]];
|
||||
|
||||
yield 'Page 1 active, pager without extra items 15/5=3' => [[5, 15, 1], null, 3, 15, [0, 5]];
|
||||
yield 'Page 2 active, pager without extra items 15/5=3' => [[5, 15, 2], null, 3, 15, [5, 5]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_testPager
|
||||
*/
|
||||
public function testPager(array $settings, array $expected)
|
||||
{
|
||||
$pager = new Pager();
|
||||
$pager->setPageInside($settings[0]);
|
||||
$pager->setPageSide($settings[1]);
|
||||
$pager->setOnPage($settings[2]);
|
||||
$pager->setPageNumber($settings[3]);
|
||||
$pager->setTotal($settings[4]);
|
||||
|
||||
$this->assertEquals($expected[0], $pager->from());
|
||||
$this->assertEquals($expected[1], $pager->to());
|
||||
$this->assertEquals($expected[2], $pager->first());
|
||||
$this->assertEquals($expected[3], $pager->last());
|
||||
$this->assertEquals($expected[4], $pager->insidePagesFrom());
|
||||
$this->assertEquals($expected[5], $pager->insidePagesTo());
|
||||
$this->assertEquals($expected[6], $pager->firstDots());
|
||||
$this->assertEquals($expected[7], $pager->lastDots());
|
||||
}
|
||||
|
||||
/*
|
||||
* $settings
|
||||
* pageInside = number of pages close between selected page and ...
|
||||
* pageSide = number of pages from start to ... and from ... to the end
|
||||
* onPage = number of records on the page
|
||||
* pageNumber = selected page
|
||||
* total = number of all records
|
||||
* */
|
||||
public function data_testPager()
|
||||
{
|
||||
return [
|
||||
[[5, 1, 2, 1, 15], [0, 1, 0, 1, 1, 6, 0, 1]], // 1 2 3 4 5 6 ... 8 1 page
|
||||
[[5, 1, 2, 2, 15], [2, 3, 0, 1, 1, 7, 0, 0]], // 1 2 3 4 5 6 7 8 2 page
|
||||
[[5, 1, 2, 5, 15], [8, 9, 0, 0, 1, 8, 0, 0]], // 1 2 3 4 5 6 7 8 5 page
|
||||
[[5, 1, 2, 7, 15], [12, 13, 1, 0, 2, 8, 0, 0]], // 1 2 3 4 5 6 7 8 7 page
|
||||
[[5, 1, 2, 8, 15], [14, 15, 1, 0, 3, 8, 1, 0]], // 1 ... 3 4 5 6 7 8 8 page
|
||||
|
||||
[[3, 1, 2, 1, 15], [0, 1, 0, 1, 1, 4, 0, 1]], // 1 2 3 4 ... 8 1 page
|
||||
[[3, 1, 2, 2, 15], [2, 3, 0, 1, 1, 5, 0, 1]], // 1 2 3 4 5 ... 8 2 page
|
||||
[[3, 1, 2, 5, 15], [8, 9, 1, 0, 2, 8, 0, 0]], // 1 2 3 4 5 6 7 8 5 page
|
||||
[[3, 1, 2, 7, 15], [12, 13, 1, 0, 4, 8, 1, 0]], // 1 ... 4 5 6 7 8 7 page
|
||||
[[3, 1, 2, 8, 15], [14, 15, 1, 0, 5, 8, 1, 0]], // 1 ... 5 6 7 8 8 page
|
||||
|
||||
[[2, 1, 2, 1, 15], [0, 1, 0, 1, 1, 3, 0, 1]], // 1 2 3 ... 8 1 page
|
||||
[[2, 1, 2, 2, 15], [2, 3, 0, 1, 1, 4, 0, 1]], // 1 2 3 4 ... 8 2 page
|
||||
[[2, 1, 2, 3, 15], [4, 5, 0, 1, 1, 5, 0, 1]], // 1 2 3 4 5 ... 8 3 page
|
||||
[[2, 1, 2, 4, 15], [6, 7, 1, 1, 2, 6, 0, 1]], // 1 2 3 4 5 6 ... 8 4 page
|
||||
[[2, 1, 2, 5, 15], [8, 9, 1, 1, 3, 7, 1, 0]], // 1 ... 3 4 5 6 7 8 5 page
|
||||
[[2, 1, 2, 6, 15], [10, 11, 1, 0, 4, 8, 1, 0]], // 1 ... 4 5 6 7 8 6 page
|
||||
[[2, 1, 2, 7, 15], [12, 13, 1, 0, 5, 8, 1, 0]], // 1 ... 5 6 7 8 7 page
|
||||
[[2, 1, 2, 8, 15], [14, 15, 1, 0, 6, 8, 1, 0]], // 1 ... 6 7 8 8 page
|
||||
];
|
||||
}
|
||||
}
|
||||
174
tests/functional/ParametersTest.php
Normal file
174
tests/functional/ParametersTest.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
use KupShop\CatalogBundle\Parameters\ParameterFinder;
|
||||
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
||||
|
||||
class ParametersTest extends \DatabaseTestCase
|
||||
{
|
||||
use CartTestTrait;
|
||||
|
||||
public function testFetchParameters()
|
||||
{
|
||||
$params = [
|
||||
14 => [
|
||||
'name' => 'Barva',
|
||||
'unit' => '',
|
||||
'value' => 'červená',
|
||||
'values' => [
|
||||
9 => [
|
||||
'id' => '9',
|
||||
'value' => 'červená',
|
||||
'descr' => '',
|
||||
],
|
||||
],
|
||||
'descr' => '',
|
||||
'value_type' => 'list',
|
||||
'value_id' => '9',
|
||||
],
|
||||
17 => [
|
||||
'name' => 'Typ hlavy',
|
||||
'unit' => '',
|
||||
'value' => 'Bez příklepu',
|
||||
'values' => [
|
||||
14 => [
|
||||
'id' => '14',
|
||||
'value' => 'Bez příklepu',
|
||||
'descr' => '',
|
||||
],
|
||||
],
|
||||
'descr' => '<p>Vrtačka s příklepem. Vratačka bez příklepu</p>',
|
||||
'value_type' => 'list',
|
||||
'value_id' => '14',
|
||||
],
|
||||
];
|
||||
|
||||
$product = new Product();
|
||||
$product->createFromDB(10);
|
||||
$this->assertArraySubset($params, $product->fetchParameters());
|
||||
|
||||
$product = new Product();
|
||||
$product->createFromDB(10);
|
||||
$this->assertCount(1, $product->fetchParameters([17]));
|
||||
|
||||
// Set parameter 14 as configurable
|
||||
$product = new Product();
|
||||
$product->createFromDB(10);
|
||||
ParameterConfiguration::insertValue(14, 10);
|
||||
|
||||
$this->assertArraySubset([17 => $params[17]], $product->fetchParameters());
|
||||
$this->assertCount(1, $product->fetchParameters());
|
||||
$this->assertCount(1, $product->configurations);
|
||||
$this->assertInstanceOf(ParameterConfiguration::class, reset($product->configurations));
|
||||
$this->assertEquals(14, reset($product->configurations)->id);
|
||||
}
|
||||
|
||||
public function testOrderWithConfiguration()
|
||||
{
|
||||
ParameterConfiguration::insertValue(14, 10);
|
||||
|
||||
$this->createCart();
|
||||
$cart = $this->cart;
|
||||
|
||||
$item = [
|
||||
'id_product' => 10,
|
||||
'id_variation' => null,
|
||||
'pieces' => 1,
|
||||
'note' => [
|
||||
'configurations' => [
|
||||
'14' => 16,
|
||||
],
|
||||
],
|
||||
];
|
||||
$cart->addItem($item);
|
||||
$cart->createFromDB();
|
||||
|
||||
$this->assertEquals(round(2011.074 * 0.8 + 50) /* 20% sleva na produktu */ , $cart->totalPriceWithVat->asFloat());
|
||||
}
|
||||
|
||||
/** @dataProvider data_testParameterFinderUpdateProductParameters */
|
||||
public function testParameterFinderUpdateProductParameters(int $productId, int $parameterId, array $values): void
|
||||
{
|
||||
$parameterFinder = $this->get(ParameterFinder::class);
|
||||
|
||||
$parameterFinder->updateProductParameters($productId, $parameterId, $values);
|
||||
|
||||
$parameter = $parameterFinder->getParameterById($parameterId);
|
||||
|
||||
$currentValues = array_map(fn ($x) => $x['value'], sqlQueryBuilder()
|
||||
->select('value_'.$parameter->value_type.' as value')
|
||||
->from('parameters_products')
|
||||
->where(\Query\Operator::equals(['id_product' => $productId, 'id_parameter' => $parameterId]))
|
||||
->execute()->fetchAllAssociative());
|
||||
|
||||
$this->assertEquals($values, $currentValues);
|
||||
}
|
||||
|
||||
protected function data_testParameterFinderUpdateProductParameters(): array
|
||||
{
|
||||
return [
|
||||
// otestovat zmenu poctu hodnot
|
||||
[1, 14, [2]],
|
||||
// otestovat zmenu poctu hodnot a ze se spravne zmeni poradi
|
||||
[1, 14, [2, 13, 1]],
|
||||
// otestovat smazani hodnot
|
||||
[1, 14, []],
|
||||
// otestovat, ze hodnoty zustanou stejne, kdyz poslu stejne hodnoty
|
||||
[1, 14, [2, 1]],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getDataSet()
|
||||
{
|
||||
return $this->getJsonDataSet(/* @lang JSON */
|
||||
'
|
||||
{
|
||||
"parameters_products": [
|
||||
{
|
||||
"id":16,
|
||||
"id_product":10,
|
||||
"id_parameter":14,
|
||||
"value_list":9,
|
||||
"value_char":null,
|
||||
"value_float":null,
|
||||
"unit":null,
|
||||
"weight":null,
|
||||
"configuration_price": 50
|
||||
},
|
||||
{
|
||||
"id":17,
|
||||
"id_product":10,
|
||||
"id_parameter":17,
|
||||
"value_list":14,
|
||||
"value_char":null,
|
||||
"value_float":null,
|
||||
"unit":null,
|
||||
"weight":null,
|
||||
"configuration_price":null
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"id_product": 1,
|
||||
"id_parameter": 14,
|
||||
"value_list": 2,
|
||||
"value_char": null,
|
||||
"value_float": null,
|
||||
"unit": null,
|
||||
"weight": null,
|
||||
"configuration_price": null
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"id_product": 1,
|
||||
"id_parameter": 14,
|
||||
"value_list": 1,
|
||||
"value_char": null,
|
||||
"value_float": null,
|
||||
"unit": null,
|
||||
"weight": null,
|
||||
"configuration_price": null
|
||||
}
|
||||
]
|
||||
}
|
||||
');
|
||||
}
|
||||
}
|
||||
54
tests/functional/PayPalWebhookRequestData.json
Normal file
54
tests/functional/PayPalWebhookRequestData.json
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"id": "WH-2WR32451HC0233532-67976317FL4543714",
|
||||
"create_time": "2014-10-23T17:23:52Z",
|
||||
"resource_type": "sale",
|
||||
"event_type": "PAYMENT.SALE.COMPLETED",
|
||||
"summary": "A successful sale payment was made for $ 822.0160 CZK",
|
||||
"resource": {
|
||||
"amount": {
|
||||
"total": "822.0160",
|
||||
"currency": "CZK"
|
||||
},
|
||||
"id": "80021663DE681814L",
|
||||
"parent_payment": "PAY-8M960553FR6478113LGGEYQA",
|
||||
"update_time": "2014-10-23T17:23:04Z",
|
||||
"clearing_time": "2014-10-30T07:00:00Z",
|
||||
"state": "completed",
|
||||
"payment_mode": "ECHECK",
|
||||
"create_time": "2014-10-23T17:22:56Z",
|
||||
"links": [
|
||||
{
|
||||
"href": "https://api.paypal.com/v1/payments/sale/80021663DE681814L",
|
||||
"rel": "self",
|
||||
"method": "GET"
|
||||
},
|
||||
{
|
||||
"href": "https://api.paypal.com/v1/payments/sale/80021663DE681814L/refund",
|
||||
"rel": "refund",
|
||||
"method": "POST"
|
||||
},
|
||||
{
|
||||
"href": "https://api.paypal.com/v1/payments/payment/PAY-1PA12106FU478450MKRETS4A",
|
||||
"rel": "parent_payment",
|
||||
"method": "GET"
|
||||
}
|
||||
],
|
||||
"protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
|
||||
"protection_eligibility": "ELIGIBLE"
|
||||
},
|
||||
"links": [
|
||||
{
|
||||
"href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-2WR32451HC0233532-67976317FL4543714",
|
||||
"rel": "self",
|
||||
"method": "GET",
|
||||
"encType": "application/json"
|
||||
},
|
||||
{
|
||||
"href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-2WR32451HC0233532-67976317FL4543714/resend",
|
||||
"rel": "resend",
|
||||
"method": "POST",
|
||||
"encType": "application/json"
|
||||
}
|
||||
],
|
||||
"event_version": "1.0"
|
||||
}
|
||||
115
tests/functional/PayPalWebhookTest.php
Normal file
115
tests/functional/PayPalWebhookTest.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
// class PayPalWebhookTest extends DatabaseTestCase
|
||||
// {
|
||||
// /** @var \Symfony\Bundle\FrameworkBundle\Client */
|
||||
// private $client;
|
||||
//
|
||||
// /**
|
||||
// * {@inheritdoc}
|
||||
// */
|
||||
// public static function setUpBeforeClass()
|
||||
// {
|
||||
// parent::setUpBeforeClass();
|
||||
//
|
||||
// if (!class_exists('PayPal\Rest\ApiContext')) {
|
||||
// self::markTestSkipped('PayPal not installed');
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// protected function setUp(): void
|
||||
// {
|
||||
// parent::setUp();
|
||||
//
|
||||
// $this->client = $this->createClient();
|
||||
//
|
||||
// $cfg = &\KupShop\KupShopBundle\Config::get();
|
||||
// $cfg['Modules']['payments']['PayPal'] = [
|
||||
// 'clientID' => 'AaCvpUIjFL3MBl5CwPl7AiaTpLxuhBk3egE3Iq_GvC676KQ3XaumV4RHkFHl_lgeu32dSkXFpt4cq33a',
|
||||
// 'secret' => 'EF_Txa5Oz-_9My-8RTQI6RtNpLil1happlO-4CXl0uKNEvephPwZu_8K_bfpTWR49ZcjfGOVLgaDysMo',
|
||||
// 'mode' => 'sandbox',
|
||||
// 'enableLog' => false,
|
||||
// ];
|
||||
// }
|
||||
//
|
||||
// protected function getDataSet()
|
||||
// {
|
||||
// return $this->getJsonDataSet('{
|
||||
// "orders": [
|
||||
// {
|
||||
// "id":116452,
|
||||
// "order_no":"0391703582",
|
||||
// "currency":"EUR",
|
||||
// "currency_rate":"1.0000",
|
||||
// "id_user":null,
|
||||
// "date_created":"2017-08-10 12:05:00",
|
||||
// "date_accept":"2017-08-10 12:07:12",
|
||||
// "date_handle":null,
|
||||
// "date_updated":"2017-08-10 12:07:12",
|
||||
// "date_due":null,
|
||||
// "status":1,
|
||||
// "status_payed":1,
|
||||
// "status_dispatch":0,
|
||||
// "status_storno":0,
|
||||
// "total_price":"6.5000",
|
||||
// "invoice_name":"Oldřich",
|
||||
// "invoice_surname":"Válek",
|
||||
// "invoice_firm":"",
|
||||
// "invoice_ico":"",
|
||||
// "invoice_dic":"",
|
||||
// "invoice_street":"Ulice 24",
|
||||
// "invoice_city":"Tak určitě",
|
||||
// "invoice_zip":4260,
|
||||
// "invoice_country":"SI",
|
||||
// "invoice_phone":12345678,
|
||||
// "invoice_email":"oldrich@wpj.cz",
|
||||
// "delivery_name":"Oldřich",
|
||||
// "delivery_surname":"Válek",
|
||||
// "delivery_firm":"",
|
||||
// "delivery_street":"Ulice 24",
|
||||
// "delivery_city":"Tak určitě",
|
||||
// "delivery_zip":4260,
|
||||
// "delivery_country":"SI",
|
||||
// "delivery_type":"PayPal - GLS",
|
||||
// "id_delivery":6,
|
||||
// "delivery_complete":"",
|
||||
// "note_user":"TEST",
|
||||
// "note_admin":"{\"payment_data\":[],\"conversion_sent\":1}",
|
||||
// "flags":"R",
|
||||
// "admin":null
|
||||
// }
|
||||
// ],
|
||||
// "order_payments": [
|
||||
// {
|
||||
// "id":2654,
|
||||
// "id_order":116452,
|
||||
// "price":"6.5000",
|
||||
// "date":"2017-08-10 12:07:12",
|
||||
// "note":"Platba modulu PayPal",
|
||||
// "status":1,
|
||||
// "payment_data":"{\"session\":\"PAY-8M960553FR6478113LGGEYQA\"}",
|
||||
// "admin":null,
|
||||
// "method":8
|
||||
// }
|
||||
// ]
|
||||
// }');
|
||||
// }
|
||||
//
|
||||
// public function testPayPalWebhook()
|
||||
// {
|
||||
// $payment = $this->selectSQL('order_payments', ['id' => 2654])->fetch();
|
||||
// $this->assertSame('1', $payment['status']);
|
||||
//
|
||||
// $this->client->request(
|
||||
// 'POST',
|
||||
// '/platby/PayPal/10/',
|
||||
// [],
|
||||
// [],
|
||||
// [],
|
||||
// file_get_contents(__DIR__.'/PayPalWebhookRequestData.json')
|
||||
// );
|
||||
//
|
||||
// $payment = $this->selectSQL('order_payments', ['id' => 2654])->fetch();
|
||||
// $this->assertSame('0', $payment['status']);
|
||||
// }
|
||||
// }
|
||||
169
tests/functional/PriceLevelTest.json
Normal file
169
tests/functional/PriceLevelTest.json
Normal file
@@ -0,0 +1,169 @@
|
||||
{
|
||||
"price_levels": [
|
||||
{
|
||||
"id": 14,
|
||||
"name": "vip - ranges",
|
||||
"descr": "",
|
||||
"discount": 14,
|
||||
"discount_discount": null,
|
||||
"unit": "perc",
|
||||
"combine": "N"
|
||||
},
|
||||
{
|
||||
"id": 15,
|
||||
"name": "vip - sections",
|
||||
"descr": "",
|
||||
"discount": 10,
|
||||
"discount_discount": null,
|
||||
"unit": "perc",
|
||||
"combine": "N"
|
||||
},
|
||||
{
|
||||
"id": 16,
|
||||
"name": "vip - producers",
|
||||
"descr": "",
|
||||
"discount": 10,
|
||||
"discount_discount": null,
|
||||
"unit": "perc",
|
||||
"combine": "N"
|
||||
},
|
||||
{
|
||||
"id": 17,
|
||||
"name": "vip - products",
|
||||
"descr": "",
|
||||
"discount": 17,
|
||||
"discount_discount": null,
|
||||
"unit": "perc",
|
||||
"combine": "N"
|
||||
},
|
||||
{
|
||||
"id": 18,
|
||||
"name": "vip - products",
|
||||
"descr": "",
|
||||
"discount": 17,
|
||||
"discount_discount": null,
|
||||
"unit": "perc",
|
||||
"combine": "Y"
|
||||
},
|
||||
{
|
||||
"id": 19,
|
||||
"name": "vip - products",
|
||||
"descr": "",
|
||||
"discount": 10,
|
||||
"discount_discount": 19,
|
||||
"unit": "perc",
|
||||
"combine": "Y"
|
||||
}
|
||||
],
|
||||
"products" : [
|
||||
{
|
||||
"id": 123,
|
||||
"title": "Test",
|
||||
"code": "QO591",
|
||||
"ean": 45254,
|
||||
"short_descr": "Lorem ipsum dolor sit amet",
|
||||
"long_descr": "",
|
||||
"parameters": "",
|
||||
"price": 1000,
|
||||
"vat": 1,
|
||||
"discount": 0,
|
||||
"producer": 15,
|
||||
"guarantee": 24,
|
||||
"in_store": 0,
|
||||
"pieces_sold": 0,
|
||||
"delivery_time": 0,
|
||||
"campaign": "N,L",
|
||||
"updated": "2015-02-16 11:18:43",
|
||||
"date_added": "2015-02-16 09:41:00",
|
||||
"figure": "Y",
|
||||
"show_raw_price": "N",
|
||||
"position": null,
|
||||
"meta_title": null,
|
||||
"meta_description": null,
|
||||
"meta_keywords": null,
|
||||
"show_in_feed": "N",
|
||||
"max_cpc": 0,
|
||||
"in_store_min": null
|
||||
}
|
||||
],
|
||||
"price_levels_ranges": [
|
||||
{
|
||||
"id_price_level": 14,
|
||||
"range_from": 50,
|
||||
"range_to": 100,
|
||||
"discount": 14,
|
||||
"unit": "perc"
|
||||
},
|
||||
{
|
||||
"id_price_level": 15,
|
||||
"range_from": 50,
|
||||
"range_to": 100,
|
||||
"discount": 20,
|
||||
"unit": "perc"
|
||||
},
|
||||
{
|
||||
"id_price_level": 16,
|
||||
"range_from": 50,
|
||||
"range_to": 100,
|
||||
"discount": 20,
|
||||
"unit": "perc"
|
||||
},
|
||||
{
|
||||
"id_price_level": 17,
|
||||
"range_from": 50,
|
||||
"range_to": 100,
|
||||
"discount": 20,
|
||||
"unit": "perc"
|
||||
}
|
||||
],
|
||||
"price_levels_sections": [
|
||||
{
|
||||
"id_price_level": 15,
|
||||
"id_section": 1,
|
||||
"discount": 15,
|
||||
"unit": "perc"
|
||||
},
|
||||
{
|
||||
"id_price_level": 16,
|
||||
"id_section": 1,
|
||||
"discount": 16,
|
||||
"unit": "perc"
|
||||
},
|
||||
{
|
||||
"id_price_level": 17,
|
||||
"id_section": 1,
|
||||
"discount": 17,
|
||||
"unit": "perc"
|
||||
}
|
||||
],
|
||||
"price_levels_producers": [
|
||||
{
|
||||
"id_price_level": 16,
|
||||
"id_producer": 15,
|
||||
"discount": 16,
|
||||
"unit": "perc"
|
||||
},
|
||||
{
|
||||
"id_price_level": 17,
|
||||
"id_producer": 15,
|
||||
"discount": 17,
|
||||
"unit": "perc"
|
||||
}
|
||||
],
|
||||
"price_levels_products": [
|
||||
{
|
||||
"id_price_level": 17,
|
||||
"id_product": 123,
|
||||
"discount": 17,
|
||||
"unit": "perc"
|
||||
}
|
||||
],
|
||||
"products_in_sections": [
|
||||
{
|
||||
"id_product":123,
|
||||
"id_section":1,
|
||||
"figure":"Y",
|
||||
"generated":0
|
||||
}
|
||||
]
|
||||
}
|
||||
142
tests/functional/PriceLevelTest.php
Normal file
142
tests/functional/PriceLevelTest.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
558
tests/functional/ProductListTest.php
Normal file
558
tests/functional/ProductListTest.php
Normal file
@@ -0,0 +1,558 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Context\ContextManager;
|
||||
use KupShop\KupShopBundle\Context\CountryContext;
|
||||
use KupShop\KupShopBundle\Context\UserContext;
|
||||
|
||||
require_once __DIR__.'/../../class/class.ProductList.php';
|
||||
|
||||
class ProductListTest extends DatabaseTestCase
|
||||
{
|
||||
/** @var ProductListBase */
|
||||
private $productList;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->productList = $this->createProductList();
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Otestuje pocitani cen produktu ze shora.
|
||||
*
|
||||
* Pro zemi CZ je DPH 21%, takze tam by se to melo chovat standartne.
|
||||
* Pro zemi SK je DPH 20%, takze se cena musi prepocitat, aby se zachovala stejna cena jako s defaultnim DPH.
|
||||
*
|
||||
* @dataProvider data_testProductListWithPricesWithVatFromTop
|
||||
*/
|
||||
public function testProductListWithPricesWithVatFromTop(string $country): void
|
||||
{
|
||||
// zapnu pocitani cen produktu ze shora
|
||||
Settings::getDefault()->prod_vats_from_top = 'Y';
|
||||
// zapnu OSS, abych mohl testovat zmeny DPH pri zmene zeme
|
||||
Settings::getDefault()->oss_vats = [
|
||||
'active' => 'Y',
|
||||
];
|
||||
|
||||
$this->get(ContextManager::class)->activateContexts(
|
||||
[CountryContext::class => $country],
|
||||
function () {
|
||||
$this->productList->fetchVariations([1 => true]);
|
||||
|
||||
$product = $this->getProduct();
|
||||
|
||||
$this->assertNotEmpty($product->variations);
|
||||
$this->assertEquals(800, $product->getProductPrice()->getPriceWithVat()->asFloat(), 'Cena na produktu musi byt 800 Kc');
|
||||
|
||||
foreach ($product->variations as $variation) {
|
||||
$this->assertEquals(800, $variation['productPrice']->getPriceWithVat()->asFloat(), 'Cena na variante musi byt 800 Kc');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function data_testProductListWithPricesWithVatFromTop(): array
|
||||
{
|
||||
return [
|
||||
['CZ'],
|
||||
['SK'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Otestuje pocitani cen produktu ze shora pro SK uzivatele s vyplnenym DIC => NO_VAT.
|
||||
*/
|
||||
public function testProductListWithPricesWithVatFromTopNoVat(): void
|
||||
{
|
||||
// zapnu pocitani cen produktu ze shora
|
||||
Settings::getDefault()->prod_vats_from_top = 'Y';
|
||||
// zapnu OSS, abych mohl testovat zmeny DPH pri zmene zeme
|
||||
Settings::getDefault()->oss_vats = [
|
||||
'active' => 'Y',
|
||||
];
|
||||
|
||||
$this->get(ContextManager::class)->activateContexts([
|
||||
CountryContext::class => 'SK',
|
||||
UserContext::class => 10, // SK uzivatel s vyplnenym DIC => NO_VAT
|
||||
],
|
||||
function () {
|
||||
$this->productList->fetchVariations([1 => true]);
|
||||
$product = $this->getProduct();
|
||||
// cena = 800 - 20% DPH = 666.668969293 = 667
|
||||
$this->assertEquals(667, $product->getProductPrice()->getPriceWithVat()->asFloat(), 'Cena na produktu musi byt 667 Kc');
|
||||
|
||||
foreach ($product->variations as $variation) {
|
||||
$this->assertEquals(667, $variation['productPrice']->getPriceWithVat()->asFloat(), 'Cena na variante musi byt 667 Kc');
|
||||
}
|
||||
|
||||
$productList = $this->createProductList(productId: 10); // produkt s vat = 2 (Snížená 15% daň)
|
||||
$product = $this->getProduct($productList);
|
||||
// cena s DPH = 1748.7600 + 15% DPH - 20% sleva = 1608.8592
|
||||
// cena SK = 1608.8592 - 20% = 1340.716
|
||||
$this->assertEquals(1341, $product->getProductPrice()->getPriceWithVat()->asFloat(), 'Cena na produktu musi byt 1341 Kc');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Otestuje pocitani cen produktu ze shora pro SK uzivatele s vyplnenym DIC => NO_VAT.
|
||||
* Se snizenou sazbou DPH.
|
||||
*/
|
||||
public function testProductListWithPricesWithVatFromTopNoVatLevelLow(): void
|
||||
{
|
||||
// zapnu pocitani cen produktu ze shora
|
||||
Settings::getDefault()->prod_vats_from_top = 'Y';
|
||||
// zapnu OSS, abych mohl testovat zmeny DPH pri zmene zeme
|
||||
Settings::getDefault()->oss_vats = [
|
||||
'active' => 'Y',
|
||||
'homeCountry' => 'CZ',
|
||||
'default' => '80200000080', // Snížená sazba DPH -> SK 10%
|
||||
];
|
||||
|
||||
$this->get(ContextManager::class)->activateContexts([
|
||||
CountryContext::class => 'SK',
|
||||
UserContext::class => 10, // SK uzivatel s vyplnenym DIC => NO_VAT
|
||||
],
|
||||
function () {
|
||||
$this->productList->fetchVariations([1 => true]);
|
||||
$product = $this->getProduct();
|
||||
// cena = 800 - 10% DPH = 727.272727273
|
||||
$this->assertEquals(727, $product->getProductPrice()->getPriceWithVat()->asFloat(), 'Cena na produktu musi byt 727 Kc');
|
||||
|
||||
foreach ($product->variations as $variation) {
|
||||
$this->assertEquals(727, $variation['productPrice']->getPriceWithVat()->asFloat(), 'Cena na variante musi byt 727 Kc');
|
||||
}
|
||||
|
||||
$productList = $this->createProductList(productId: 10); // produkt s vat = 2 (Snížená 15% daň)
|
||||
$product = $this->getProduct($productList);
|
||||
// cena s DPH = 1748.7600 + 15% DPH - 20% sleva = 1608.8592
|
||||
// cena SK = 1608.8592 - 10% = 1462.59927273
|
||||
$this->assertEquals(1463, $product->getProductPrice()->getPriceWithVat()->asFloat(), 'Cena na produktu musi byt 1463 Kc');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function testPlainProductHasNoAdditionalData()
|
||||
{
|
||||
$product = $this->getProduct();
|
||||
|
||||
$this->assertEmpty($product->image);
|
||||
$this->assertEmpty($product->variations);
|
||||
$this->assertEmpty($product->param);
|
||||
$this->assertEmpty($product->collections);
|
||||
$this->assertEmpty($product->field_producerTitle());
|
||||
$this->assertEmpty($product['producerTitle']);
|
||||
}
|
||||
|
||||
public function testFetchImages()
|
||||
{
|
||||
$productList = $this->createProductList(false, 2);
|
||||
$productList->fetchImages(1);
|
||||
|
||||
$product = $this->getProduct($productList);
|
||||
|
||||
$this->assertNotEmpty($product->image);
|
||||
}
|
||||
|
||||
public function testFetchImagesOfVariationsOnlyDoesntFetchImageWithNoVariation()
|
||||
{
|
||||
$productList = new ProductListBase(true);
|
||||
$productList->fetchImages(1);
|
||||
$productList->andSpec(function (Query\QueryBuilder $qb) {
|
||||
return $qb->expr()->eq('p.id', 2);
|
||||
});
|
||||
|
||||
/** @var Product $product */
|
||||
$product = $productList->getProducts()->current();
|
||||
$this->assertEmpty($product->image);
|
||||
}
|
||||
|
||||
public function testFetchImagesOfVariationsOnlyDoesFetchImageWithVariation()
|
||||
{
|
||||
$productList = new ProductListBase(true);
|
||||
$productList->fetchImages(1);
|
||||
$productList->andSpec(function (Query\QueryBuilder $qb) {
|
||||
return $qb->expr()->eq('p.id', 1);
|
||||
});
|
||||
|
||||
/** @var Product $product */
|
||||
$product = $productList->getProducts()->current();
|
||||
$this->assertNotEmpty($product->image);
|
||||
}
|
||||
|
||||
public function testFetchProducers()
|
||||
{
|
||||
$this->productList->fetchProducers();
|
||||
|
||||
$product = $this->getProduct();
|
||||
|
||||
$this->assertNotEmpty($product->field_producerTitle());
|
||||
$this->assertNotEmpty($product->field_producerImage());
|
||||
$this->assertNotEmpty($product['producerTitle']);
|
||||
$this->assertNotEmpty($product['producerImage']);
|
||||
}
|
||||
|
||||
public function testFetchSets()
|
||||
{
|
||||
$this->productList->fetchSets(true);
|
||||
|
||||
$product = $this->getProduct();
|
||||
|
||||
$this->assertNotEmpty($product->sets);
|
||||
}
|
||||
|
||||
public function testFetchStoresInStore()
|
||||
{
|
||||
$this->productList->fetchStoresInStore();
|
||||
|
||||
$storesInStore = $this->getProduct()->storesInStore;
|
||||
|
||||
$this->assertEquals(1, $storesInStore[2]['in_store'], 'Na prodejne jsou skladem 3ks');
|
||||
}
|
||||
|
||||
public function testFetchVariations()
|
||||
{
|
||||
$this->skipIfNoModule('products_variations');
|
||||
|
||||
$this->productList->fetchVariations([1 => true]);
|
||||
|
||||
$product = $this->getProduct();
|
||||
|
||||
$this->assertEquals([6, 8], array_keys($product->variations));
|
||||
$this->assertArraySubset([
|
||||
'id' => '6',
|
||||
'id_product' => '7',
|
||||
'code' => null,
|
||||
'ean' => null,
|
||||
'title' => 'Barva: modrá',
|
||||
'in_store' => 0,
|
||||
'delivery_time' => '-1',
|
||||
'figure' => 'Y',
|
||||
'updated' => '0000-00-00 00:00:00',
|
||||
'date_added' => '0000-00-00 00:00:00',
|
||||
'note' => null,
|
||||
'weight' => null,
|
||||
'price_buy' => null,
|
||||
'bonus_points' => null,
|
||||
'width' => null,
|
||||
'height' => null,
|
||||
'depth' => null,
|
||||
'pohoda_sync_date' => null,
|
||||
'data' => [
|
||||
],
|
||||
'price_common' => null,
|
||||
'value_1' => 'Modrá',
|
||||
'value_code_1' => null,
|
||||
'photo' => null,
|
||||
'values' => [
|
||||
1 => 'Modrá',
|
||||
],
|
||||
'values_codes' => [
|
||||
1 => null,
|
||||
],
|
||||
'delivery_time_text' => 'na cestě',
|
||||
], $product->variations[6]);
|
||||
$this->assertCount(2, $product->variations);
|
||||
}
|
||||
|
||||
public function testFetchParameters()
|
||||
{
|
||||
$this->productList->fetchParameters();
|
||||
|
||||
$product = $this->getProduct();
|
||||
|
||||
$this->assertNotEmpty($product->param);
|
||||
}
|
||||
|
||||
public function testFetchCollections()
|
||||
{
|
||||
$this->productList->fetchCollections();
|
||||
|
||||
$product = $this->getProduct();
|
||||
$this->assertNotEmpty($product->collections);
|
||||
$this->assertEquals([1 => 1, 7 => 7, 8 => 8, 9 => 9, 10 => 10], array_map(function ($product) {return $product->id; }, $product->collections));
|
||||
}
|
||||
|
||||
public function testFetchCollectionsMultiple()
|
||||
{
|
||||
$productList = new ProductList();
|
||||
$productList->fetchCollections();
|
||||
|
||||
$products = $productList->getProducts();
|
||||
$collection_arr = [1 => 1, 7 => 7, 8 => 8, 9 => 9, 10 => 10];
|
||||
foreach ($products as $product) {
|
||||
if (!is_null($product->collections)) {
|
||||
$arr = array_map(function ($product) {return $product->id; }, $product->collections);
|
||||
$this->assertEquals($collection_arr, $arr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testOrderBy()
|
||||
{
|
||||
$productListASC = new ProductListBase();
|
||||
$productListDESC = new ProductListBase();
|
||||
|
||||
$ids = function () {
|
||||
return function (Query\QueryBuilder $qb) {
|
||||
return $qb->expr()->in('p.id', [7, 8]);
|
||||
};
|
||||
};
|
||||
|
||||
$productListASC->andSpec($ids);
|
||||
$productListDESC->andSpec($ids);
|
||||
|
||||
$productListASC->orderBy('p.id', 'ASC');
|
||||
$productListDESC->orderBy('p.id', 'DESC');
|
||||
|
||||
$this->assertNotSame(
|
||||
$productListASC->getProducts()->getKeys(),
|
||||
$productListDESC->getProducts()->getKeys()
|
||||
);
|
||||
}
|
||||
|
||||
public function testTotalCount()
|
||||
{
|
||||
$this->productList->getProducts($totalCount);
|
||||
$this->assertSame(1, $totalCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProvider_testGetProductsCount
|
||||
*
|
||||
* @param bool $variationsAsResult
|
||||
* @param int $expectedCount
|
||||
*/
|
||||
public function testGetProductsCount($variationsAsResult, $expectedCount, array $productKeys)
|
||||
{
|
||||
$this->assertSame($expectedCount, (new ProductListBase($variationsAsResult))->getProductsCount());
|
||||
$this->assertSame($expectedCount, count($products = (new ProductListBase($variationsAsResult))->getProducts()));
|
||||
$products = (new ProductListBase($variationsAsResult))->getProducts();
|
||||
$this->assertEquals($productKeys, $products->getKeys(), '', 0.0, 10, true);
|
||||
}
|
||||
|
||||
public function dataProvider_testGetProductsCount()
|
||||
{
|
||||
return [
|
||||
'products' => [false, 11, range(1, 11)],
|
||||
'variations as products' => [
|
||||
true,
|
||||
22,
|
||||
[
|
||||
'1/16',
|
||||
'2/9',
|
||||
'2/10',
|
||||
'2/11',
|
||||
'2/12',
|
||||
3,
|
||||
'4/1',
|
||||
'4/2',
|
||||
'5/13',
|
||||
'5/14',
|
||||
'5/15',
|
||||
'6/17',
|
||||
'6/18',
|
||||
'6/19',
|
||||
'7/6',
|
||||
'7/8',
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
'11/20',
|
||||
'11/21',
|
||||
'11/22',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testCreatesVariations()
|
||||
{
|
||||
$products = (new ProductListBase(true))->getProducts($totalCount);
|
||||
|
||||
foreach ($products as $index => $product) {
|
||||
$expectedClassName = 'Product';
|
||||
if (strpos($index, '/') !== false) {
|
||||
$expectedClassName = 'Variation';
|
||||
}
|
||||
$this->assertInstanceOf($expectedClassName, $product);
|
||||
}
|
||||
|
||||
$this->assertCount(22, $products);
|
||||
}
|
||||
|
||||
public function createProductList($variationsAsResult = false, $productId = 7)
|
||||
{
|
||||
$productList = new ProductListBase($variationsAsResult);
|
||||
$productList->andSpec(function () use ($productId) {
|
||||
return function (Query\QueryBuilder $qb) use ($productId) {
|
||||
return $qb->expr()->eq('p.id', $productId);
|
||||
};
|
||||
});
|
||||
|
||||
return $productList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Product
|
||||
*/
|
||||
private function getProduct(?ProductListBase $productList = null)
|
||||
{
|
||||
if (!$productList) {
|
||||
$productList = $this->productList;
|
||||
}
|
||||
$products = $productList->getProducts();
|
||||
$this->assertCount(1, $products);
|
||||
|
||||
return $products->current();
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return new \PHPUnit\DbUnit\DataSet\ArrayDataSet([
|
||||
'products_sets' => [
|
||||
[
|
||||
'id_product' => 7,
|
||||
'id_product_set' => 1,
|
||||
'price' => 100,
|
||||
],
|
||||
],
|
||||
'products_collections' => [
|
||||
[
|
||||
'id_product' => 1,
|
||||
'id_product_related' => 7,
|
||||
],
|
||||
[
|
||||
'id_product' => 1,
|
||||
'id_product_related' => 8,
|
||||
],
|
||||
[
|
||||
'id_product' => 1,
|
||||
'id_product_related' => 9,
|
||||
],
|
||||
[
|
||||
'id_product' => 1,
|
||||
'id_product_related' => 10,
|
||||
],
|
||||
],
|
||||
'photos_products_relation' => [
|
||||
[
|
||||
'id_photo' => 1,
|
||||
'id_product' => 1,
|
||||
'id_variation' => 16,
|
||||
'show_in_lead' => 'Y',
|
||||
'active' => 'Y',
|
||||
'date_added' => '2013-09-13 11:08:27',
|
||||
'position' => 0,
|
||||
],
|
||||
[
|
||||
'id_photo' => 2,
|
||||
'id_product' => 1,
|
||||
'id_variation' => 16,
|
||||
'show_in_lead' => 'Y',
|
||||
'active' => 'Y',
|
||||
'date_added' => '2013-09-13 11:08:36',
|
||||
'position' => 1,
|
||||
],
|
||||
[
|
||||
'id_photo' => 3,
|
||||
'id_product' => 2,
|
||||
'id_variation' => null,
|
||||
'show_in_lead' => 'Y',
|
||||
'active' => 'Y',
|
||||
'date_added' => '2013-09-13 11:22:49',
|
||||
'position' => 0,
|
||||
],
|
||||
],
|
||||
'stores' => [
|
||||
[
|
||||
'id' => 1,
|
||||
'position' => 0,
|
||||
'name' => 'Hlavní sklad',
|
||||
'type' => 1,
|
||||
'figure' => 'Y',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'position' => 1,
|
||||
'name' => 'Prodejna',
|
||||
'type' => 0,
|
||||
'figure' => 'Y',
|
||||
],
|
||||
],
|
||||
'stores_items' => [
|
||||
[
|
||||
'id' => 400,
|
||||
'id_store' => 2,
|
||||
'id_product' => 7,
|
||||
'id_variation' => 8,
|
||||
'quantity' => 1,
|
||||
],
|
||||
],
|
||||
'users' => [
|
||||
[
|
||||
'id' => 10,
|
||||
'id_language' => 'cs',
|
||||
'passw' => '79c2b46ce2594ecbcb5b73e928345492',
|
||||
'user_key' => '',
|
||||
'figure' => 'Y',
|
||||
'name' => 'Petr',
|
||||
'surname' => 'Jebavý',
|
||||
'firm' => 'wpj s.r.o.',
|
||||
'street' => 'Nádražní 471',
|
||||
'city' => 'Vrchlabí',
|
||||
'zip' => '54301',
|
||||
'country' => 'SK',
|
||||
'currency' => 'CZK',
|
||||
'email' => 'petr@wpj.cz',
|
||||
'ico' => '50649361',
|
||||
'dic' => 'SK2120408730',
|
||||
'phone' => '775131400',
|
||||
'mobile' => '',
|
||||
'fax' => '',
|
||||
'gender' => null,
|
||||
'delivery_name' => '',
|
||||
'delivery_surname' => '',
|
||||
'delivery_firm' => '',
|
||||
'delivery_street' => '',
|
||||
'delivery_city' => '',
|
||||
'delivery_zip' => '',
|
||||
'delivery_country' => '',
|
||||
'account_no' => '',
|
||||
'account_bank' => '',
|
||||
'account_symbol' => '',
|
||||
'get_news' => 'Y',
|
||||
'prefer_transport' => 1,
|
||||
'date_reg' => '2013-09-30 12:09:05',
|
||||
'date_updated' => '2013-09-30 12:12:44',
|
||||
'date_logged' => null,
|
||||
'custom_address' => '',
|
||||
'state' => '',
|
||||
'delivery_custom_address' => '',
|
||||
'delivery_state' => '',
|
||||
'date_subscribe' => '2013-09-30 12:09:05',
|
||||
'date_unsubscribe' => null,
|
||||
'note' => null,
|
||||
'custom_data' => null,
|
||||
'delivery_phone' => '',
|
||||
'delivery_email' => null,
|
||||
'pohoda_id' => null,
|
||||
'pohoda_sync_date' => null,
|
||||
'pohoda_id_address' => null,
|
||||
'id_pricelist' => null,
|
||||
'due_days' => null,
|
||||
'birthdate' => null,
|
||||
'copy_email' => null,
|
||||
],
|
||||
],
|
||||
'vats_cns' => [
|
||||
[
|
||||
'id_cn' => 80200000080,
|
||||
'id_vat' => 15,
|
||||
'automanaged' => 1,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
229
tests/functional/ProductSetTest.json
Normal file
229
tests/functional/ProductSetTest.json
Normal file
@@ -0,0 +1,229 @@
|
||||
{
|
||||
"products": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "NIKE Capri LACE Test Dlouheho Nazvu Produktu Test Dlouheho Produktu Tes",
|
||||
"code": "QO591",
|
||||
"ean": 1001,
|
||||
"short_descr": "Lorem ipsum dolor sit amet",
|
||||
"long_descr": "test",
|
||||
"parameters": "test",
|
||||
"price": 826.4460,
|
||||
"price_common": 1200.0000,
|
||||
"vat": 1,
|
||||
"discount": 20.00,
|
||||
"producer": 12,
|
||||
"guarantee": 24,
|
||||
"in_store": 1,
|
||||
"pieces_sold": 0,
|
||||
"delivery_time": 0,
|
||||
"campaign": "N,L",
|
||||
"updated": "2015-02-16 11:18:43",
|
||||
"date_added": "2015-02-16 09:41:00",
|
||||
"figure": "Y",
|
||||
"show_raw_price": "N",
|
||||
"position": null,
|
||||
"meta_title": null,
|
||||
"meta_description": null,
|
||||
"meta_keywords": null,
|
||||
"show_in_feed": "N",
|
||||
"max_cpc": 0,
|
||||
"in_store_min": null
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "Adidas Mundial Goal Dalsi Test Velmi Dlouheho Produktoveho Nazvu",
|
||||
"code": "JQ671",
|
||||
"ean": 1002,
|
||||
"short_descr": "Lorem ipsum dolor sit amet",
|
||||
"long_descr": "test",
|
||||
"parameters": "test",
|
||||
"price": 2066.1160,
|
||||
"price_common": 2800.0000,
|
||||
"vat": 1,
|
||||
"discount": 10.00,
|
||||
"producer": 10,
|
||||
"guarantee": 24,
|
||||
"in_store": 2,
|
||||
"pieces_sold": 0,
|
||||
"delivery_time": -1,
|
||||
"campaign": "D,L",
|
||||
"updated": "2015-02-16 11:18:47",
|
||||
"date_added": "2015-02-16 09:41:00",
|
||||
"figure": "Y",
|
||||
"show_raw_price": "N",
|
||||
"position": null,
|
||||
"meta_title": null,
|
||||
"meta_description": null,
|
||||
"meta_keywords": null,
|
||||
"show_in_feed": "N",
|
||||
"max_cpc": 0,
|
||||
"in_store_min": null
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "Set",
|
||||
"code": null,
|
||||
"ean": null,
|
||||
"short_descr": "Lorem ipsum dolor sit amet",
|
||||
"long_descr": "test",
|
||||
"parameters": "test",
|
||||
"price": 661.1570,
|
||||
"price_common": 900.0000,
|
||||
"vat": 1,
|
||||
"discount": 0.00,
|
||||
"producer": null,
|
||||
"guarantee": 24,
|
||||
"in_store": 0,
|
||||
"pieces_sold": 1,
|
||||
"delivery_time": -1,
|
||||
"campaign": "S,L,A",
|
||||
"updated": "2015-02-16 11:21:49",
|
||||
"date_added": "2014-09-26 08:27:00",
|
||||
"figure": "Y",
|
||||
"show_raw_price": "N",
|
||||
"position": null,
|
||||
"meta_title": null,
|
||||
"meta_description": null,
|
||||
"meta_keywords": null,
|
||||
"show_in_feed": "N",
|
||||
"max_cpc": 0,
|
||||
"in_store_min": null
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "NIKE Capri LACE Test Dlouheho Nazvu Produktu Test Dlouheho Produktu Tes",
|
||||
"code": "QO5912",
|
||||
"ean": 1003,
|
||||
"short_descr": "Lorem ipsum dolor sit amet",
|
||||
"long_descr": "test",
|
||||
"parameters": "test",
|
||||
"price": 826.4460,
|
||||
"price_common": 1200.0000,
|
||||
"vat": 1,
|
||||
"discount": 20.00,
|
||||
"producer": 12,
|
||||
"guarantee": 24,
|
||||
"in_store": 4,
|
||||
"pieces_sold": 0,
|
||||
"delivery_time": 0,
|
||||
"campaign": "N,L",
|
||||
"updated": "2015-02-16 11:18:43",
|
||||
"date_added": "2015-02-16 09:41:00",
|
||||
"figure": "Y",
|
||||
"show_raw_price": "N",
|
||||
"position": null,
|
||||
"meta_title": null,
|
||||
"meta_description": null,
|
||||
"meta_keywords": null,
|
||||
"show_in_feed": "N",
|
||||
"max_cpc": 0,
|
||||
"in_store_min": null
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Adidas Mundial Goal Dalsi Test Velmi Dlouheho Produktoveho Nazvu",
|
||||
"code": "JQ6712",
|
||||
"ean": 1004,
|
||||
"short_descr": "Lorem ipsum dolor sit amet",
|
||||
"long_descr": "test",
|
||||
"parameters": "test",
|
||||
"price": 2066.1160,
|
||||
"price_common": 2800.0000,
|
||||
"vat": 1,
|
||||
"discount": 10.00,
|
||||
"producer": 10,
|
||||
"guarantee": 24,
|
||||
"in_store": 0,
|
||||
"pieces_sold": 0,
|
||||
"delivery_time": -1,
|
||||
"campaign": "D,L",
|
||||
"updated": "2015-02-16 11:18:47",
|
||||
"date_added": "2015-02-16 09:41:00",
|
||||
"figure": "Y",
|
||||
"show_raw_price": "N",
|
||||
"position": null,
|
||||
"meta_title": null,
|
||||
"meta_description": null,
|
||||
"meta_keywords": null,
|
||||
"show_in_feed": "N",
|
||||
"max_cpc": 0,
|
||||
"in_store_min": null
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "Set",
|
||||
"code": null,
|
||||
"ean": null,
|
||||
"short_descr": "Lorem ipsum dolor sit amet",
|
||||
"long_descr": "test",
|
||||
"parameters": "test",
|
||||
"price": 661.1570,
|
||||
"price_common": 900.0000,
|
||||
"vat": 1,
|
||||
"discount": 0.00,
|
||||
"producer": null,
|
||||
"guarantee": 24,
|
||||
"in_store": 6,
|
||||
"pieces_sold": 1,
|
||||
"delivery_time": -1,
|
||||
"campaign": "S,L,A",
|
||||
"updated": "2015-02-16 11:21:49",
|
||||
"date_added": "2014-09-26 08:27:00",
|
||||
"figure": "Y",
|
||||
"show_raw_price": "N",
|
||||
"position": null,
|
||||
"meta_title": null,
|
||||
"meta_description": null,
|
||||
"meta_keywords": null,
|
||||
"show_in_feed": "N",
|
||||
"max_cpc": 0,
|
||||
"in_store_min": null
|
||||
}
|
||||
],
|
||||
"products_sets": [
|
||||
{
|
||||
"id_product": 3,
|
||||
"id_product_set": 1
|
||||
},
|
||||
{
|
||||
"id_product": 3,
|
||||
"id_product_set": 2
|
||||
},
|
||||
{
|
||||
"id_product": 6,
|
||||
"id_product_set": 4
|
||||
},
|
||||
{
|
||||
"id_product": 6,
|
||||
"id_product_set": 5
|
||||
}
|
||||
],
|
||||
"stores_items" : [
|
||||
{
|
||||
"id_store" : 1,
|
||||
"id_product" : 1,
|
||||
"quantity" : 1
|
||||
},
|
||||
{
|
||||
"id_store" : 1,
|
||||
"id_product" : 2,
|
||||
"quantity" : 2
|
||||
},
|
||||
{
|
||||
"id_store" : 1,
|
||||
"id_product" : 4,
|
||||
"quantity" : 4
|
||||
},
|
||||
{
|
||||
"id_store" : 1,
|
||||
"id_product" : 5,
|
||||
"quantity" : 0
|
||||
},
|
||||
{
|
||||
"id_store" : 1,
|
||||
"id_product" : 6,
|
||||
"quantity" : 6
|
||||
}
|
||||
]
|
||||
}
|
||||
71
tests/functional/ProductSetTest.php
Normal file
71
tests/functional/ProductSetTest.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: filip
|
||||
* Date: 11/14/16
|
||||
* Time: 2:07 PM.
|
||||
*/
|
||||
|
||||
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
||||
use KupShop\OrderingBundle\Exception\CartValidationException;
|
||||
|
||||
class ProductSetTest extends DatabaseTestCase
|
||||
{
|
||||
use CartTestTrait;
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testUpdateSetsStore
|
||||
*/
|
||||
public function testUpdateSetsStore($productId, array $expectedSetsInStore)
|
||||
{
|
||||
/** @var \KupShop\CatalogBundle\Util\SetsUpdateStore $setsUpdateStore */
|
||||
$setsUpdateStore = $this->get(\KupShop\CatalogBundle\Util\SetsUpdateStore::class);
|
||||
$setsUpdateStore->updateSetsStore($productId);
|
||||
|
||||
$query = sqlQuery('SELECT id, in_store FROM products WHERE id IN (?) ORDER BY id', [array_keys($expectedSetsInStore)], [\Doctrine\DBAL\Connection::PARAM_INT_ARRAY]);
|
||||
$result = $query->fetchAll(PDO::FETCH_KEY_PAIR);
|
||||
|
||||
$this->assertEquals($expectedSetsInStore, $result);
|
||||
}
|
||||
|
||||
public function dataSet_testUpdateSetsStore()
|
||||
{
|
||||
return [
|
||||
'only set with product 1 updates' => [1, [
|
||||
'3' => '1',
|
||||
'6' => '6',
|
||||
]],
|
||||
'only set with product 4 updates' => [4, [
|
||||
'3' => '0',
|
||||
'6' => '0',
|
||||
]],
|
||||
'all sets update' => [null, [
|
||||
'3' => '1',
|
||||
'6' => '0',
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
public function testOrderingSetProduct()
|
||||
{
|
||||
$dbcfg = Settings::getDefault();
|
||||
$dbcfg->saveValue('order_availability', \Settings::ORDER_AVAILABILITY_IN_STORE_OR_SUPPLIER_STORE);
|
||||
$dbcfg->clearCache(true);
|
||||
$this->createCart();
|
||||
|
||||
$this->insertProduct(1, null, 3);
|
||||
$this->setInvoice();
|
||||
$this->setDeliveryType();
|
||||
|
||||
$this->cart->createFromDB();
|
||||
$this->expectException(CartValidationException::class);
|
||||
$this->expectExceptionMessage('Produkt <strong>\'NIKE Capri LACE Test Dlouheho Nazvu Produktu Test Dlouheho Produktu Tes\'</strong> není v požadovaném množství skladem.');
|
||||
$this->cart->submitOrder();
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->getJsonDataSetFromFile();
|
||||
}
|
||||
}
|
||||
249
tests/functional/ProductTest.php
Normal file
249
tests/functional/ProductTest.php
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Context\ContextManager;
|
||||
use KupShop\KupShopBundle\Context\CountryContext;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: filip
|
||||
* Date: 11/7/16
|
||||
* Time: 1:15 PM.
|
||||
*/
|
||||
class ProductTest extends \DatabaseTestCase
|
||||
{
|
||||
/**
|
||||
* Otestuje pocitani cen produktu ze shora.
|
||||
*
|
||||
* Pro zemi CZ je DPH 21%, takze tam by se to melo chovat standartne.
|
||||
* Pro zemi SK je DPH 20%, takze se cena musi prepocitat, aby se zachovala stejna cena jako s defaultnim DPH.
|
||||
*
|
||||
* @dataProvider data_testProductWithPricesWithVatFromTop
|
||||
*/
|
||||
public function testProductWithPricesWithVatFromTop(string $country): void
|
||||
{
|
||||
$this->get(ContextManager::class)->activateContexts(
|
||||
[CountryContext::class => $country],
|
||||
function () {
|
||||
$product = new Product();
|
||||
$product->createFromDB(7);
|
||||
$product->fetchVariations();
|
||||
|
||||
$this->assertNotEmpty($product->variations);
|
||||
$this->assertEquals(800, $product->getProductPrice()->getPriceWithVat()->asFloat(), 'Cena na produktu musi byt 800 Kc');
|
||||
|
||||
foreach ($product->variations['variations'] as $variation) {
|
||||
$this->assertEquals(800, $variation['productPrice']->getPriceWithVat()->asFloat(), 'Cena na variante musi byt 800 Kc');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function data_testProductWithPricesWithVatFromTop(): array
|
||||
{
|
||||
return [
|
||||
['CZ'],
|
||||
['SK'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testCreateFromDb()
|
||||
{
|
||||
$product = new Product();
|
||||
$product->createFromDB(11);
|
||||
|
||||
$this->assertSame('66 Kč', $product->price);
|
||||
$this->assertSame('99.6004', (string) $product->priceMax['price_with_vat']);
|
||||
$this->assertSame('1652.0660', (string) $product->priceRaw);
|
||||
$this->assertSame(null, $product->priceCommon);
|
||||
$this->assertSame('55 Kč', $product->priceNoVat);
|
||||
$this->assertSame('66.4668', (string) $product->price_array['price_with_vat']);
|
||||
$this->assertSame('66 Kč', $product->price);
|
||||
$this->assertSame('80.0400', (string) $product->discount);
|
||||
$this->assertSame('1999.0000', (string) $product->priceOriginal['value_with_vat']);
|
||||
$this->assertSame('0.0000', (string) $product->price_buy['value_with_vat']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_roundPrice
|
||||
*/
|
||||
public function testRoundPrice($price, $roundTo, $direction, $result, $bata = null)
|
||||
{
|
||||
$this->assertEquals($result, roundPrice(toDecimal($price), $roundTo, $direction, bata: $bata)->asFloat());
|
||||
}
|
||||
|
||||
public function data_roundPrice()
|
||||
{
|
||||
return [
|
||||
[540, -10, 'DB', 540],
|
||||
[544, -10, 'DB', 540],
|
||||
[545, -10, 'DB', 550],
|
||||
[547, -10, 'DB', 550],
|
||||
|
||||
[552, -5, 'DB', 550],
|
||||
[553, -5, 'DB', 555],
|
||||
[557, -5, 'DB', 555],
|
||||
[558, -5, 'DB', 560],
|
||||
[560, -5, 'DB', 560],
|
||||
|
||||
[31.59, 10, 'up', 31.6],
|
||||
[-31.59, 10, 'up', -31.6],
|
||||
|
||||
// baťovské ceny - XYZ.99 nahoru
|
||||
[0, 100, 'up', 0, 0.01],
|
||||
[5.00, 100, 'up', 5.99, 0.01],
|
||||
[5.20, 100, 'up', 5.99, 0.01],
|
||||
[5.50, 100, 'up', 5.99, 0.01],
|
||||
[-5.00, 100, 'up', -5.99, 0.01],
|
||||
[-5.20, 100, 'up', -5.99, 0.01],
|
||||
[-5.50, 100, 'up', -5.99, 0.01],
|
||||
|
||||
// baťovské ceny - XYZ.99 matematicky
|
||||
[0, 100, 'math', 0, 0.01],
|
||||
[5.00, 100, 'math', 4.99, 0.01],
|
||||
[5.20, 100, 'math', 4.99, 0.01],
|
||||
[5.50, 100, 'math', 5.99, 0.01],
|
||||
[-5.00, 100, 'math', -4.99, 0.01],
|
||||
[-5.20, 100, 'math', -4.99, 0.01],
|
||||
[-5.50, 100, 'math', -5.99, 0.01],
|
||||
|
||||
// baťovské ceny - XYZ.99 dolu
|
||||
[0, 100, 'down', 0, 0.01],
|
||||
[5.00, 100, 'down', 4.99, 0.01],
|
||||
[5.20, 100, 'down', 4.99, 0.01],
|
||||
[5.50, 100, 'down', 4.99, 0.01],
|
||||
[-5.00, 100, 'down', -4.99, 0.01],
|
||||
[-5.20, 100, 'down', -4.99, 0.01],
|
||||
[-5.50, 100, 'down', -4.99, 0.01],
|
||||
|
||||
// baťovské ceny - XYZ.49 nebo XYZ.99 nahoru
|
||||
[0, 50, 'up', 0, 0.01],
|
||||
[5.00, 50, 'up', 5.49, 0.01],
|
||||
[5.20, 50, 'up', 5.49, 0.01],
|
||||
[5.50, 50, 'up', 5.99, 0.01],
|
||||
[-5.00, 50, 'up', -5.49, 0.01],
|
||||
[-5.20, 50, 'up', -5.49, 0.01],
|
||||
[-5.50, 50, 'up', -5.99, 0.01],
|
||||
[-5.90, 50, 'up', -5.99, 0.01],
|
||||
[-5.99, 50, 'up', -5.99, 0.01],
|
||||
[-6.00, 50, 'up', -6.49, 0.01],
|
||||
|
||||
// baťovské ceny - XYZ.49 nebo XYZ.99 matematicky
|
||||
[0, 50, 'math', 0, 0.01],
|
||||
[5.00, 50, 'math', 4.99, 0.01],
|
||||
[5.20, 50, 'math', 4.99, 0.01],
|
||||
[5.50, 50, 'math', 5.49, 0.01],
|
||||
[-5.00, 50, 'math', -4.99, 0.01],
|
||||
[-5.20, 50, 'math', -4.99, 0.01],
|
||||
[-5.50, 50, 'math', -5.49, 0.01],
|
||||
[-5.90, 50, 'math', -5.99, 0.01],
|
||||
[-5.99, 50, 'math', -5.99, 0.01],
|
||||
[-6.00, 50, 'math', -5.99, 0.01],
|
||||
|
||||
// baťovské ceny - XYZ.49 nebo XYZ.99 dolu
|
||||
[0, 50, 'down', 0, 0.01],
|
||||
[5.00, 50, 'down', 4.99, 0.01],
|
||||
[5.20, 50, 'down', 4.99, 0.01],
|
||||
[5.50, 50, 'down', 5.49, 0.01],
|
||||
[-5.00, 50, 'down', -4.99, 0.01],
|
||||
[-5.20, 50, 'down', -4.99, 0.01],
|
||||
[-5.50, 50, 'down', -5.49, 0.01],
|
||||
[-5.90, 50, 'down', -5.49, 0.01],
|
||||
[-5.99, 50, 'down', -5.99, 0.01],
|
||||
[-6.00, 50, 'down', -5.99, 0.01],
|
||||
];
|
||||
}
|
||||
|
||||
public function testVisibleTranslationProduct()
|
||||
{
|
||||
$this->switchLanguage();
|
||||
|
||||
$product = new Product();
|
||||
$product->createFromDB(2);
|
||||
|
||||
$this->assertTrue($product->isVisible());
|
||||
}
|
||||
|
||||
public function testHiddenTranslationProduct()
|
||||
{
|
||||
$this->switchLanguage();
|
||||
|
||||
$product = new Product();
|
||||
$product->createFromDB(1);
|
||||
|
||||
$this->assertFalse($product->isVisible());
|
||||
}
|
||||
|
||||
public function testOldTranslationProduct()
|
||||
{
|
||||
$this->switchLanguage();
|
||||
|
||||
$product = new Product();
|
||||
$product->createFromDB(3);
|
||||
|
||||
$this->assertTrue($product->isOld());
|
||||
}
|
||||
|
||||
public function testShowProduct()
|
||||
{
|
||||
$client = $this->createClient();
|
||||
$client->request('GET', '/nike-capri-lace-test-dlouheho-nazvu-produktu-test-dlouheho-produktu-tes_z1/');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return new \PHPUnit\DbUnit\DataSet\ArrayDataSet([
|
||||
'products_translations' => [
|
||||
[
|
||||
'id' => 1,
|
||||
'id_product' => 1,
|
||||
'id_language' => 'sk',
|
||||
'id_admin' => null,
|
||||
'created' => '',
|
||||
'updated' => null,
|
||||
'title' => null,
|
||||
'short_descr' => null,
|
||||
'long_descr' => null,
|
||||
'meta_title' => null,
|
||||
'meta_description' => null,
|
||||
'meta_keywords' => null,
|
||||
'parameters' => null,
|
||||
'figure' => 'N',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'id_product' => 2,
|
||||
'id_language' => 'sk',
|
||||
'id_admin' => null,
|
||||
'created' => '',
|
||||
'updated' => null,
|
||||
'title' => null,
|
||||
'short_descr' => null,
|
||||
'long_descr' => null,
|
||||
'meta_title' => null,
|
||||
'meta_description' => null,
|
||||
'meta_keywords' => null,
|
||||
'parameters' => null,
|
||||
'figure' => 'Y',
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'id_product' => 3,
|
||||
'id_language' => 'sk',
|
||||
'id_admin' => null,
|
||||
'created' => '',
|
||||
'updated' => null,
|
||||
'title' => null,
|
||||
'short_descr' => null,
|
||||
'long_descr' => null,
|
||||
'meta_title' => null,
|
||||
'meta_description' => null,
|
||||
'meta_keywords' => null,
|
||||
'parameters' => null,
|
||||
'figure' => 'O',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
302
tests/functional/QueryTest/FilterTest.json
Normal file
302
tests/functional/QueryTest/FilterTest.json
Normal file
@@ -0,0 +1,302 @@
|
||||
{
|
||||
"sections": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Has children",
|
||||
"lead_text": "text"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Child",
|
||||
"lead_text": "text"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "No children",
|
||||
"lead_text": "text"
|
||||
}
|
||||
],
|
||||
"sections_relation": [
|
||||
{
|
||||
"id_section": 1,
|
||||
"id_topsection": null,
|
||||
"position": 1
|
||||
},
|
||||
{
|
||||
"id_section": 2,
|
||||
"id_topsection": 1,
|
||||
"position": 2
|
||||
},
|
||||
{
|
||||
"id_section": 3,
|
||||
"id_topsection": null,
|
||||
"position": 3
|
||||
}
|
||||
],
|
||||
"producers": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Producer 1",
|
||||
"photo": "x.jpg",
|
||||
"web": "http://www.example.com"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Producer 2",
|
||||
"photo": "x.jpg",
|
||||
"web": "http://www.example.com"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"name": "Producer 5",
|
||||
"photo": "x.jpg",
|
||||
"web": "http://www.example.com"
|
||||
}
|
||||
],
|
||||
"products": [
|
||||
{
|
||||
"id": 1,
|
||||
"short_descr": "short",
|
||||
"long_descr": "long",
|
||||
"parameters": "params",
|
||||
"producer": 1,
|
||||
"vat": 1,
|
||||
"campaign": "N",
|
||||
"price": 0,
|
||||
"discount": 0,
|
||||
"figure": "Y",
|
||||
"price_for_discount": null
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"short_descr": "short",
|
||||
"long_descr": "long",
|
||||
"parameters": "params",
|
||||
"producer": 2,
|
||||
"vat": 1,
|
||||
"campaign": "N",
|
||||
"price": 10,
|
||||
"discount": 0,
|
||||
"figure": "Y"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"short_descr": "short",
|
||||
"long_descr": "long",
|
||||
"parameters": "params",
|
||||
"producer": 1,
|
||||
"vat": 1,
|
||||
"campaign": "N",
|
||||
"price": 20,
|
||||
"discount": 0,
|
||||
"figure": "Y"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"short_descr": "short",
|
||||
"long_descr": "long",
|
||||
"parameters": "params",
|
||||
"producer": 1,
|
||||
"vat": 1,
|
||||
"campaign": "N",
|
||||
"price": 30,
|
||||
"discount": 0,
|
||||
"figure": "Y"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"short_descr": "short",
|
||||
"long_descr": "long",
|
||||
"parameters": "params",
|
||||
"producer": 1,
|
||||
"vat": 1,
|
||||
"campaign": "N",
|
||||
"price": 40,
|
||||
"discount": 0,
|
||||
"figure": "Y"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"short_descr": "short",
|
||||
"long_descr": "long",
|
||||
"parameters": "params",
|
||||
"producer": 5,
|
||||
"vat": 1,
|
||||
"campaign": "N",
|
||||
"price": 120,
|
||||
"discount": 10,
|
||||
"figure": "Y"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"short_descr": "short",
|
||||
"long_descr": "long",
|
||||
"parameters": "params",
|
||||
"producer": null,
|
||||
"vat": 1,
|
||||
"campaign": "N",
|
||||
"price": 120,
|
||||
"discount": 20,
|
||||
"figure": "Y"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"short_descr": "short",
|
||||
"long_descr": "long",
|
||||
"parameters": "params",
|
||||
"producer": null,
|
||||
"vat": 1,
|
||||
"campaign": "N",
|
||||
"price": 0,
|
||||
"discount": 0,
|
||||
"figure": "N"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"short_descr": "short",
|
||||
"long_descr": "long",
|
||||
"parameters": "params",
|
||||
"producer": null,
|
||||
"vat": 1,
|
||||
"campaign": "N",
|
||||
"price": 120,
|
||||
"discount": 20,
|
||||
"figure": "Y",
|
||||
"price_for_discount": 200
|
||||
}
|
||||
],
|
||||
"products_in_sections": [
|
||||
{
|
||||
"id_section": 1,
|
||||
"id_product": 1
|
||||
},
|
||||
{
|
||||
"id_section": 2,
|
||||
"id_product": 2
|
||||
},
|
||||
{
|
||||
"id_section": 2,
|
||||
"id_product": 3
|
||||
},
|
||||
{
|
||||
"id_section": 2,
|
||||
"id_product": 4
|
||||
},
|
||||
{
|
||||
"id_section": 3,
|
||||
"id_product": 5
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Size",
|
||||
"value_type": "int"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Color",
|
||||
"value_type": "list"
|
||||
}
|
||||
],
|
||||
"parameters_list": [
|
||||
{
|
||||
"id": 1,
|
||||
"id_parameter": 2,
|
||||
"value": "black"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"id_parameter": 2,
|
||||
"value": "white"
|
||||
}
|
||||
],
|
||||
"parameters_products": [
|
||||
{
|
||||
"id": 1,
|
||||
"id_product": 3,
|
||||
"id_parameter": 1,
|
||||
"value_list": null,
|
||||
"value_char": null,
|
||||
"value_float": 5
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"id_product": 3,
|
||||
"id_parameter": 2,
|
||||
"value_list": 1,
|
||||
"value_char": null,
|
||||
"value_float": null
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"id_product": 4,
|
||||
"id_parameter": 2,
|
||||
"value_list": 1,
|
||||
"value_char": null,
|
||||
"value_float": null
|
||||
}
|
||||
],
|
||||
"products_variations": [
|
||||
{
|
||||
"id": 1,
|
||||
"id_product": 4,
|
||||
"title": "title 1",
|
||||
"price": null,
|
||||
"figure": "Y"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"id_product": 4,
|
||||
"title": "title 2",
|
||||
"price": 1,
|
||||
"figure": "N"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"id_product": 5,
|
||||
"title": "title 2",
|
||||
"price": 50,
|
||||
"figure": "Y"
|
||||
}
|
||||
],
|
||||
"pricelists": [
|
||||
{
|
||||
"id": 1,
|
||||
"currency": "CZK",
|
||||
"name": "Test 1"
|
||||
}
|
||||
],
|
||||
"pricelists_products": [
|
||||
{
|
||||
"id": 1,
|
||||
"id_pricelist": 1,
|
||||
"id_product": 1,
|
||||
"id_variation": null,
|
||||
"price": 44.3782,
|
||||
"price_for_discount": null,
|
||||
"discount": 25,
|
||||
"integrity_unique": "1-1"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"id_pricelist": 1,
|
||||
"id_product": 2,
|
||||
"id_variation": null,
|
||||
"price": 41.3223,
|
||||
"price_for_discount": 49.5868,
|
||||
"discount": null,
|
||||
"integrity_unique": "1-2"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"id_pricelist": 1,
|
||||
"id_product": 3,
|
||||
"id_variation": null,
|
||||
"price": 41.3223,
|
||||
"price_for_discount": 61.9835,
|
||||
"discount": 10,
|
||||
"integrity_unique": "1-2"
|
||||
}
|
||||
]
|
||||
}
|
||||
234
tests/functional/QueryTest/FilterTest.php
Normal file
234
tests/functional/QueryTest/FilterTest.php
Normal file
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: filip
|
||||
* Date: 5/17/16
|
||||
* Time: 9:31 AM.
|
||||
*/
|
||||
|
||||
namespace QueryTest;
|
||||
|
||||
use KupShop\CatalogBundle\ProductList\FilterParams;
|
||||
use KupShop\KupShopBundle\Context\UserContext;
|
||||
use KupShop\KupShopBundle\PriceType\PriceForDiscountPriceType;
|
||||
use KupShop\KupShopBundle\PriceType\PriceIfOnlyDiscountPriceType;
|
||||
use KupShop\KupShopBundle\PriceType\PriceTypeInterface;
|
||||
use KupShop\KupShopBundle\PriceType\PriceWithoutDiscountPriceType;
|
||||
use KupShop\KupShopBundle\Util\Contexts;
|
||||
use KupShop\PricelistBundle\Context\PricelistContext;
|
||||
use Query\Filter;
|
||||
use Query\Operator;
|
||||
use Query\Product;
|
||||
|
||||
class FilterTest extends \DatabaseTestCase
|
||||
{
|
||||
/** @dataProvider data_testVisibilityFilter */
|
||||
public function testVisibilityFilter(int $expectedCount, callable $figureSpec, string $type = FilterParams::ENTITY_PRODUCT): void
|
||||
{
|
||||
$qb = sqlQueryBuilder()
|
||||
->select('p.id')
|
||||
->joinVariationsOnProducts()
|
||||
->from('products', 'p')
|
||||
->where($figureSpec);
|
||||
|
||||
if ($type === FilterParams::ENTITY_VARIATION) {
|
||||
$qb->groupBy('p.id, pv.id');
|
||||
} else {
|
||||
$qb->groupBy('p.id');
|
||||
}
|
||||
|
||||
$count = $qb->execute()->rowCount();
|
||||
|
||||
$this->assertEquals($expectedCount, $count);
|
||||
}
|
||||
|
||||
public function data_testVisibilityFilter(): iterable
|
||||
{
|
||||
yield 'Test load visible products' => [8, Filter::isVisible()];
|
||||
yield 'Test load hidden products' => [2, Operator::not(Filter::isVisible())];
|
||||
yield 'Test load sold out products' => [0, Filter::byFigure('O')];
|
||||
yield 'Test load visible and hidden products' => [9, Operator::orX(Filter::isVisible(), Operator::not(Filter::isVisible()))];
|
||||
|
||||
// Variations list - 1 visible variation + 6 visible products = 7
|
||||
yield 'Test load visible variation product list' => [8, Filter::isVisible(), FilterParams::ENTITY_VARIATION];
|
||||
// Variation list - 1 hidden variation and 1 hidden product
|
||||
yield 'Test load hidden variation product list' => [2, Operator::not(Filter::isVisible()), FilterParams::ENTITY_VARIATION];
|
||||
// Variation list - 6 products + 3 variation products
|
||||
yield 'Test load visible and hidden variation product list' => [10, Operator::orX(Filter::isVisible(), Operator::not(Filter::isVisible())), FilterParams::ENTITY_VARIATION];
|
||||
}
|
||||
|
||||
/** @dataProvider dataSet_testByDiscountRange */
|
||||
public function testByDiscountRange(\Range $range, ?int $priceListId, ?PriceTypeInterface $originalPriceType, array $expectedIDs): void
|
||||
{
|
||||
if ($priceListId) {
|
||||
Contexts::get(PricelistContext::class)->activate($priceListId);
|
||||
}
|
||||
|
||||
if ($originalPriceType) {
|
||||
Contexts::clear();
|
||||
$this->withMockedUserContext($originalPriceType);
|
||||
}
|
||||
|
||||
$IDs = sqlQueryBuilder()
|
||||
->select('p.id')
|
||||
->from('products', 'p')
|
||||
->where(Filter::byDiscountRange($range))
|
||||
->groupBy('p.id')
|
||||
->execute()
|
||||
->fetchFirstColumn();
|
||||
|
||||
$this->assertEquals($expectedIDs, $IDs);
|
||||
}
|
||||
|
||||
public function dataSet_testByDiscountRange(): iterable
|
||||
{
|
||||
yield 'Filter discount range 1-5' => [new \Range(1, 5), null, null, []];
|
||||
yield 'Filter discount range 5-12' => [new \Range(5, 12), null, null, [6]];
|
||||
yield 'Filter discount range 10-15' => [new \Range(10, 15), null, null, [6]];
|
||||
yield 'Filter discount range 10-20' => [new \Range(10, 20), null, null, [6, 7]];
|
||||
yield 'Filter discount range 20-35' => [new \Range(20, 35), null, null, [7]];
|
||||
|
||||
yield 'Filter with price list range 1-10' => [new \Range(1, 10), 1, null, []];
|
||||
yield 'Filter with price list range 20-30' => [new \Range(20, 30), 1, null, [1]];
|
||||
yield 'Filter with price list range 15-20 - discount calculated using price_for_discount' => [new \Range(15, 20), 1, null, [2]];
|
||||
yield 'Filter with price list range 15-20 - with explicit discount field' => [new \Range(15, 20), 1, new PriceIfOnlyDiscountPriceType(new PriceForDiscountPriceType()), []];
|
||||
yield 'Filter with price list range 30-40 - with explicit discount field' => [new \Range(30, 40), 1, new PriceIfOnlyDiscountPriceType(new PriceForDiscountPriceType()), [3]];
|
||||
|
||||
yield 'Filter not discounted products' => [new \Range(null, 0), null, null, [1, 2, 3, 4, 5, 8]];
|
||||
yield 'Filter not discounted products for price list' => [new \Range(null, 0), 1, null, [4, 5, 6, 7, 8]];
|
||||
yield 'Filter not discounted products for price list - without price history' => [new \Range(null, 0), 1, new PriceWithoutDiscountPriceType(), [2, 4, 5, 6, 7, 8, 9]];
|
||||
yield 'Filter not discounted products for price list - with explicit discount field' => [new \Range(null, 0), 1, new PriceIfOnlyDiscountPriceType(new PriceForDiscountPriceType()), [2, 4, 5, 6, 7, 8, 9]];
|
||||
}
|
||||
|
||||
/** @dataProvider dataSet_testDiscountFieldDefinition */
|
||||
public function testDiscountFieldDefinition(int $productId, ?int $priceListId, ?PriceTypeInterface $originalPriceType, float $expectedDiscount): void
|
||||
{
|
||||
if ($priceListId) {
|
||||
Contexts::get(PricelistContext::class)->activate($priceListId);
|
||||
}
|
||||
|
||||
if ($originalPriceType) {
|
||||
$this->withMockedUserContext($originalPriceType);
|
||||
}
|
||||
|
||||
$discountFieldDefinition = $this->get(UserContext::class)->getOriginalPriceType()->getDiscountFieldDefinition();
|
||||
|
||||
$discount = sqlQueryBuilder()->select($discountFieldDefinition->getField())
|
||||
->fromProducts()
|
||||
->joinVariationsOnProducts()
|
||||
->where(Operator::equals(['p.id' => $productId]))
|
||||
->andWhere($discountFieldDefinition->getSpec())
|
||||
->execute()
|
||||
->fetchOne();
|
||||
|
||||
$this->assertEqualsWithDelta($expectedDiscount, $discount, 0.1);
|
||||
}
|
||||
|
||||
public function dataSet_testDiscountFieldDefinition(): iterable
|
||||
{
|
||||
yield 'Product with zero price' => [1, null, null, 0];
|
||||
yield 'Product with zero discount' => [2, null, null, 0];
|
||||
yield 'Product with 10% discount' => [6, null, null, 10];
|
||||
yield 'Product with price for discount' => [9, null, null, 100 - (((120 * 0.8) * 100) / 200)];
|
||||
yield 'Product with discount from pricelist' => [1, 1, null, 25];
|
||||
yield 'Product with price for discount from pricelist' => [2, 1, null, 100 - ((41.3223 * 100) / 49.5868)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testByProducers
|
||||
*/
|
||||
public function testByProducers(array $producerIds, int $expectedCount, bool $negative): void
|
||||
{
|
||||
$this->assertSame($expectedCount, sqlQueryBuilder()
|
||||
->select('p.id')
|
||||
->from('products', 'p')
|
||||
->andWhere($negative
|
||||
? Operator::not(Filter::byProducers($producerIds))
|
||||
: Filter::byProducers($producerIds)
|
||||
)
|
||||
->execute()
|
||||
->rowCount()
|
||||
);
|
||||
}
|
||||
|
||||
public function dataSet_testByProducers(): array
|
||||
{
|
||||
return [
|
||||
[[1], 4, false],
|
||||
[[2], 1, false],
|
||||
[[3], 0, false],
|
||||
[[1, 2, 3], 5, false],
|
||||
[[1337], 9, true],
|
||||
[[1337], 0, false],
|
||||
[[1, 2, 3], 4, true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testByPriceRange
|
||||
*/
|
||||
public function testByPriceRange(\Range $range, $expectedCount)
|
||||
{
|
||||
$count = sqlQueryBuilder()
|
||||
->select('p.id')
|
||||
->from('products', 'p')
|
||||
->where(Filter::byPriceRange($range))
|
||||
->execute()
|
||||
->rowCount();
|
||||
|
||||
$this->assertSame($expectedCount, $count);
|
||||
}
|
||||
|
||||
public function dataSet_testByPriceRange()
|
||||
{
|
||||
return [
|
||||
[new \Range(5 * 1.21, 5 * 1.21), 0],
|
||||
[new \Range(10 * 1.21, 10 * 1.21), 1],
|
||||
[new \Range(10 * 1.21, 30 * 1.21), 3],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testByProductPriceRange
|
||||
*/
|
||||
public function testByProductPriceRange(\Range $range, $expectedCount)
|
||||
{
|
||||
$qb = sqlQueryBuilder()
|
||||
->select('p.id')
|
||||
->from('products', 'p')
|
||||
->where(Filter::byProductPriceRange($range))
|
||||
->groupBy('p.id')
|
||||
->execute();
|
||||
|
||||
$count = $qb->rowCount();
|
||||
$this->assertSame($expectedCount, $count);
|
||||
}
|
||||
|
||||
public function dataSet_testByProductPriceRange()
|
||||
{
|
||||
return [
|
||||
[new \Range(5 * 1.21, 5 * 1.21), 0],
|
||||
[new \Range(30 * 1.21, 30 * 1.21), 1],
|
||||
[new \Range(30 * 1.21, 40 * 1.21), 2],
|
||||
];
|
||||
}
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->getJsonDataSetFromFile();
|
||||
}
|
||||
|
||||
private function withMockedUserContext(PriceTypeInterface $originalPriceType): void
|
||||
{
|
||||
$mockedUserContext = $this->getMockBuilder(UserContext::class)
|
||||
->onlyMethods(['loadOriginalPriceType'])
|
||||
->getMock();
|
||||
|
||||
$mockedUserContext->expects(self::once())
|
||||
->method('loadOriginalPriceType')
|
||||
->willReturn($originalPriceType);
|
||||
|
||||
$this->set(UserContext::class, $mockedUserContext);
|
||||
}
|
||||
}
|
||||
0
tests/functional/QueryTest/FilterTest.yml
Normal file
0
tests/functional/QueryTest/FilterTest.yml
Normal file
92
tests/functional/QueryTest/OperatorTest.php
Normal file
92
tests/functional/QueryTest/OperatorTest.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace QueryTest;
|
||||
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use Query\Operator;
|
||||
use Query\Operator as Op;
|
||||
|
||||
class OperatorTest extends \DatabaseTestCase
|
||||
{
|
||||
public function testAndX()
|
||||
{
|
||||
$noName = function (QueryBuilder $qb) {
|
||||
return $this->expr()->isNull('alias.name');
|
||||
};
|
||||
|
||||
$hasPrice = function (QueryBuilder $qb) {
|
||||
return $this->expr()->isNotNull('alias.price');
|
||||
};
|
||||
|
||||
$andExpr = Op::andX($noName, $hasPrice);
|
||||
$where = $andExpr(sqlQueryBuilder());
|
||||
|
||||
$this->assertSame('(alias.name IS NULL) AND (alias.price IS NOT NULL)', (string) $where);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testBetween
|
||||
*/
|
||||
public function testBetween($min, $max, $expected)
|
||||
{
|
||||
$between = Op::between('field', new \Range($min, $max));
|
||||
$where = sqlQueryBuilder()->evaluateClosures([$between])[0];
|
||||
|
||||
$this->assertRegExp("@{$expected}@", (string) $where);
|
||||
}
|
||||
|
||||
public function dataSet_testBetween()
|
||||
{
|
||||
return [
|
||||
[1, 2, '\(field >= :between_min_\d+\) AND \(field <= :between_max_\d+\)'],
|
||||
[1, null, 'field >= :between_min_\d+'],
|
||||
[null, 2, 'field <= :between_max_\d+'],
|
||||
[null, null, ''],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testFindInSetThrows()
|
||||
{
|
||||
Operator::findInSet([1, 2, 3], 'column', 'x');
|
||||
}
|
||||
|
||||
public function testFindInSetAnd()
|
||||
{
|
||||
$expr = Operator::findInSet([1, 2], 'column', 'AND');
|
||||
|
||||
$this->assertRegExp(
|
||||
'@\(FIND_IN_SET\(:needle_\d+, `column`\)\) AND \(FIND_IN_SET\(:needle_\d+, `column`\)\)@',
|
||||
(string) sqlQueryBuilder()->evaluateClosures([$expr])[0]
|
||||
);
|
||||
}
|
||||
|
||||
public function testFindInSetOr()
|
||||
{
|
||||
$expr = Operator::findInSet([1, 2], 'column', 'OR');
|
||||
|
||||
$this->assertRegExp(
|
||||
'@\(FIND_IN_SET\(:needle_\d+, `column`\)\) OR \(FIND_IN_SET\(:needle_\d+, `column`\)\)@',
|
||||
(string) sqlQueryBuilder()->evaluateClosures([$expr])[0]
|
||||
);
|
||||
}
|
||||
|
||||
public function testNot()
|
||||
{
|
||||
$isNull = function (QueryBuilder $qb) {
|
||||
return $this->expr()->isNull('alias.name');
|
||||
};
|
||||
$expr = Operator::not($isNull);
|
||||
$this->assertSame(
|
||||
'NOT (alias.name IS NULL)',
|
||||
(string) sqlQueryBuilder()->evaluateClosures([$expr])[0]
|
||||
);
|
||||
}
|
||||
|
||||
private function expr()
|
||||
{
|
||||
return sqlQueryBuilder()->expr();
|
||||
}
|
||||
}
|
||||
114
tests/functional/QueryTest/ProductTest.php
Normal file
114
tests/functional/QueryTest/ProductTest.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace QueryTest;
|
||||
|
||||
use Query\Filter;
|
||||
use Query\Product;
|
||||
use Query\QueryBuilder;
|
||||
|
||||
class ProductTest extends \DatabaseTestCase
|
||||
{
|
||||
/** @var QueryBuilder */
|
||||
private $qb;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->qb = sqlQueryBuilder();
|
||||
}
|
||||
|
||||
public function testIsVisible()
|
||||
{
|
||||
$this->removeModule(\Modules::TRANSLATIONS, null);
|
||||
|
||||
$isVisible = Product::isVisible();
|
||||
$expression = $isVisible($this->qb);
|
||||
|
||||
$this->assertRegExp('/p.figure = :visible\d+/', $expression);
|
||||
preg_match('/p.figure = :(visible\d+)/', $expression, $matches);
|
||||
$this->assertSame('Y', $this->qb->getParameter($matches[1]));
|
||||
}
|
||||
|
||||
public function testIsVisibleTranslations()
|
||||
{
|
||||
$this->switchLanguage();
|
||||
|
||||
$isVisible = Product::isVisible();
|
||||
$expression = $isVisible($this->qb);
|
||||
|
||||
$join = $this->qb->getQueryPart('join');
|
||||
|
||||
$this->assertEquals([
|
||||
'joinType' => 'left',
|
||||
'joinTable' => 'products_translations',
|
||||
'joinAlias' => 'p_sk',
|
||||
'joinCondition' => 'p_sk.id_product = p.id AND p_sk.id_language = :translation_language_sk',
|
||||
], $join['p'][0]);
|
||||
|
||||
$this->assertRegExp('/COALESCE\(p_sk.figure, p.figure\) = :visible\d+/', $expression);
|
||||
}
|
||||
|
||||
public function testInSection()
|
||||
{
|
||||
$result = $this->qb->select('*')->from('products', 'p')->where(Product::inSection(3))->execute()->fetchAll();
|
||||
|
||||
$this->assertCount(3, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $expectedCount
|
||||
*
|
||||
* @dataProvider productsInSections
|
||||
*/
|
||||
public function testInSections(array $sectionIds, $expectedCount)
|
||||
{
|
||||
$count = $this->qb->select('*')->from('products', 'p')->where(Product::inSections($sectionIds))->execute()->rowCount();
|
||||
$this->assertSame($expectedCount, $count);
|
||||
}
|
||||
|
||||
public function productsInSections()
|
||||
{
|
||||
return [
|
||||
[[3], 3],
|
||||
[[2, 3], 5],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSet_testInStore
|
||||
*
|
||||
* @param bool $useVariations
|
||||
* @param int $expectedCount
|
||||
*/
|
||||
public function testInStore($useVariations, $expectedCount)
|
||||
{
|
||||
$count = $this->qb->select('*')->from('products', 'p')->where(Product::inStore($useVariations))->execute()->rowCount();
|
||||
|
||||
$this->assertSame($expectedCount, $count);
|
||||
}
|
||||
|
||||
public function dataSet_testInStore()
|
||||
{
|
||||
$dataSet = [];
|
||||
$dataSet['no variations'] = [false, 7];
|
||||
if (findModule('products_variations')) {
|
||||
$dataSet['variations'] = [true, 13];
|
||||
}
|
||||
|
||||
return $dataSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo add yml data to products_of_suppliers and refactor this test
|
||||
*
|
||||
* @dataProvider dataSet_testInStore
|
||||
*/
|
||||
public function testInStoreSupplier($useVariations, $expectedCount)
|
||||
{
|
||||
$count = $this->qb->select('*')->from('products', 'p')
|
||||
->andWhere(Filter::byInStore(\Filter::IN_STORE_SUPPLIER, $useVariations))
|
||||
->execute()->rowCount();
|
||||
$this->assertSame($expectedCount, $count);
|
||||
}
|
||||
}
|
||||
369
tests/functional/QueryTest/QueryBuilderTest.php
Normal file
369
tests/functional/QueryTest/QueryBuilderTest.php
Normal file
@@ -0,0 +1,369 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: filip
|
||||
* Date: 5/13/16
|
||||
* Time: 10:30 AM.
|
||||
*/
|
||||
|
||||
namespace QueryTest;
|
||||
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use Query\Operator;
|
||||
|
||||
class QueryBuilderTest extends \DatabaseTestCase
|
||||
{
|
||||
public function testGlobalFactoryFunction()
|
||||
{
|
||||
$this->assertInstanceOf('Query\QueryBuilder', sqlQueryBuilder());
|
||||
$this->assertNotSame(sqlQueryBuilder(), sqlQueryBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGlobalFactoryFunction
|
||||
*/
|
||||
public function testWhereUsesAnd()
|
||||
{
|
||||
$specStub = function ($field, $value) {
|
||||
return function (QueryBuilder $qb) use ($field, $value) {
|
||||
return $qb->expr()->eq($field, $value);
|
||||
};
|
||||
};
|
||||
|
||||
$rowCount = sqlQueryBuilder()->select('*')->from('users')->where(
|
||||
$specStub('city', "'Vrchlabí'"),
|
||||
$specStub('figure', "'Y'")
|
||||
)->execute()->rowCount();
|
||||
|
||||
$this->assertSame(2, $rowCount);
|
||||
}
|
||||
|
||||
public function testOrderBySql()
|
||||
{
|
||||
$qb = sqlQueryBuilder();
|
||||
$qb->orderBySql('expression < 0 Asc');
|
||||
$this->assertSame(['expression < 0 Asc'], $qb->getQueryPart('orderBy'));
|
||||
}
|
||||
|
||||
public function testMultiDirectValuesSql()
|
||||
{
|
||||
$qb = sqlQueryBuilder()
|
||||
->insert('languages')
|
||||
->multiDirectValues(
|
||||
[
|
||||
'id' => 've',
|
||||
'name' => 'veverky',
|
||||
'locale' => 've_VE',
|
||||
'translate' => 0,
|
||||
]
|
||||
)
|
||||
->multiDirectValues(
|
||||
[
|
||||
'id' => 'li',
|
||||
'name' => 'lišky',
|
||||
'locale' => 'li_LI',
|
||||
'translate' => 0,
|
||||
])
|
||||
->multiDirectValues(
|
||||
[
|
||||
'id' => 'ko',
|
||||
'name' => 'kočky',
|
||||
'locale' => 'ko_KO',
|
||||
'translate' => 0,
|
||||
]);
|
||||
$this->assertSame('INSERT INTO languages (`id`,`name`,`locale`,`translate`) VALUES (:multi0_id, :multi0_name, :multi0_locale, :multi0_translate),(:multi1_id, :multi1_name, :multi1_locale, :multi1_translate),(:multi2_id, :multi2_name, :multi2_locale, :multi2_translate) ', $qb->getSQL());
|
||||
}
|
||||
|
||||
public function testMultiValuesSql()
|
||||
{
|
||||
$qb = sqlQueryBuilder()
|
||||
->insert('languages')
|
||||
->multiValues(
|
||||
[
|
||||
[
|
||||
'id' => 've',
|
||||
'name' => 'veverky',
|
||||
'locale' => 've_VE',
|
||||
'translate' => 0,
|
||||
],
|
||||
[
|
||||
'id' => 'li',
|
||||
'name' => 'lišky',
|
||||
'locale' => 'li_LI',
|
||||
'translate' => 0,
|
||||
],
|
||||
[
|
||||
'id' => 'ko',
|
||||
'name' => 'kočky',
|
||||
'locale' => 'ko_KO',
|
||||
'translate' => 0,
|
||||
],
|
||||
]
|
||||
);
|
||||
$this->assertSame('INSERT INTO languages (id,name,locale,translate) VALUES (ve, veverky, ve_VE, 0),(li, lišky, li_LI, 0),(ko, kočky, ko_KO, 0) ', $qb->getSQL());
|
||||
}
|
||||
|
||||
public function testDirectValues(): void
|
||||
{
|
||||
$params = [
|
||||
'foo' => 'fooFoo',
|
||||
'bar' => 10,
|
||||
'baz' => '1970-01-01 00:00:00',
|
||||
];
|
||||
$queryBuilder = sqlQueryBuilder()
|
||||
->insert('users')
|
||||
->directValues($params);
|
||||
|
||||
$this->assertSame('INSERT INTO users (`foo`,`bar`,`baz`) VALUES (:foo, :bar, :baz) ', $queryBuilder->getSQL());
|
||||
$this->assertSame($params, $queryBuilder->getParameters());
|
||||
$this->assertSame(
|
||||
<<<EOT
|
||||
INSERT INTO users (`foo`, `bar`, `baz`)
|
||||
VALUES
|
||||
(
|
||||
'fooFoo', 10, '1970-01-01 00:00:00'
|
||||
)
|
||||
EOT,
|
||||
$queryBuilder->getRunnableSQL()
|
||||
);
|
||||
}
|
||||
|
||||
public function testForUpdate(): void
|
||||
{
|
||||
$queryBuilder = sqlQueryBuilder()
|
||||
->select('count(*)', 'foo', 'baz')
|
||||
->where('a', 'b.c')
|
||||
->forUpdate();
|
||||
|
||||
$this->assertSame('SELECT count(*), foo, baz WHERE (a) AND (b.c) FOR UPDATE', $queryBuilder->getSQL());
|
||||
}
|
||||
|
||||
public function testCalcRows(): void
|
||||
{
|
||||
$queryBuilder = sqlQueryBuilder()
|
||||
->select('*', 'foo')
|
||||
->from('t')
|
||||
->where('id >= :id')
|
||||
->setParameter('id', 1)
|
||||
->addCalcRows();
|
||||
|
||||
$this->assertSame('SELECT SQL_CALC_FOUND_ROWS *, foo FROM t WHERE id >= :id', $queryBuilder->getSQL());
|
||||
$this->assertSame(['id' => 1], $queryBuilder->getParameters());
|
||||
}
|
||||
|
||||
public function testOnDuplicateKeyUpdate(): void
|
||||
{
|
||||
$queryBuilder = sqlQueryBuilder()
|
||||
->insert('foo')
|
||||
->values(['username' => 'jarin'])
|
||||
->onDuplicateKeyUpdate(['foo', 'bar']);
|
||||
|
||||
$this->assertSame('INSERT INTO foo (username) VALUES (jarin) ON DUPLICATE KEY UPDATE foo=VALUES(foo), bar=VALUES(bar) ', $queryBuilder->getSQL());
|
||||
}
|
||||
|
||||
public function testOnDuplicateKeyUpdateException(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Call of "onDuplicateKeyUpdate" is allowed only with insert query');
|
||||
sqlQueryBuilder()
|
||||
->select('foo')
|
||||
->values(['username' => 'jarin'])
|
||||
->onDuplicateKeyUpdate(['foo', 'bar'])
|
||||
->getSQL();
|
||||
}
|
||||
|
||||
public function testSendMaster(): void
|
||||
{
|
||||
$queryBuilder = sqlQueryBuilder()
|
||||
->select('foo')
|
||||
->from('t')
|
||||
->sendToMaster();
|
||||
|
||||
$this->assertSame('SELECT foo FROM t -- maxscale route to master', $queryBuilder->getSQL());
|
||||
}
|
||||
|
||||
public function testAddQueryBuilderParameters(): void
|
||||
{
|
||||
$queryBuilderForParameters = sqlQueryBuilder()
|
||||
->setParameter('foo', 1)
|
||||
->setParameter('bar', 'baz');
|
||||
|
||||
$queryBuilder = sqlQueryBuilder()
|
||||
->select('*')
|
||||
->from('t')
|
||||
->where('foo != :foo')
|
||||
->orWhere('bar = :bar')
|
||||
->addQueryBuilderParameters($queryBuilderForParameters);
|
||||
|
||||
$this->assertSame('SELECT * FROM t WHERE (foo != :foo) OR (bar = :bar)', $queryBuilder->getSQL());
|
||||
$this->assertSame(
|
||||
<<<EOT
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
t
|
||||
WHERE
|
||||
(foo != 1)
|
||||
OR (bar = 'baz')
|
||||
EOT,
|
||||
$queryBuilder->getRunnableSQL()
|
||||
);
|
||||
|
||||
$this->assertSame($queryBuilderForParameters->getParameters(), $queryBuilder->getParameters());
|
||||
}
|
||||
|
||||
public function testSetForceIndexForJoin(): void
|
||||
{
|
||||
$queryBuilder = sqlQueryBuilder()
|
||||
->select('id')
|
||||
->from('t')
|
||||
->setForceIndexForJoin('a', 'a_table');
|
||||
|
||||
// ignore when using non-existing join alias
|
||||
$this->assertSame('SELECT id FROM t', $queryBuilder->getSQL());
|
||||
|
||||
$queryBuilder = sqlQueryBuilder()
|
||||
->select('id', 'MAX(max_1, max_2) as j')
|
||||
->from('t', 'a')
|
||||
->leftJoin('a', 'products', 'p', 'p.id = a.id_product')
|
||||
->setForceIndexForJoin('j', 'pricelist_product')
|
||||
->setForceIndexForJoin('a', 'blbost');
|
||||
|
||||
// ignore when using force index for from clause alias or select clause alias
|
||||
$this->assertSame('SELECT id, MAX(max_1, max_2) as j FROM t a LEFT JOIN products p ON p.id = a.id_product', $queryBuilder->getSQL());
|
||||
|
||||
$queryBuilder = sqlQueryBuilder()
|
||||
->select('id', 'MAX(max_1, max_2) as j')
|
||||
->from('t', 'a')
|
||||
->leftJoin('a', 'products', 'p', 'p.id = a.id_product')
|
||||
->setForceIndexForJoin('p', 'PRIMARY');
|
||||
|
||||
$this->assertSame('SELECT id, MAX(max_1, max_2) as j FROM t a LEFT JOIN products p FORCE INDEX (PRIMARY) ON p.id = a.id_product', $queryBuilder->getSQL());
|
||||
}
|
||||
|
||||
public function testLimitDeleteThrowsMultitable01()
|
||||
{
|
||||
$qb = sqlQueryBuilder()->delete('orders', 'o')
|
||||
->setMaxResults(100);
|
||||
|
||||
$this->expectException(\Doctrine\DBAL\Exception::class);
|
||||
$qb->execute();
|
||||
}
|
||||
|
||||
public function testLimitDeleteThrowsMultitable02()
|
||||
{
|
||||
$qb = sqlQueryBuilder()->delete('orders')
|
||||
->join('orders', 'orders_history', 'oh', 'oh.id_order = orders.id')
|
||||
->setMaxResults(100);
|
||||
|
||||
$this->expectException(\Doctrine\DBAL\Exception::class);
|
||||
$qb->execute();
|
||||
}
|
||||
|
||||
public function testLimitDelete()
|
||||
{
|
||||
$qb = sqlQueryBuilder()->delete('orders')
|
||||
->setMaxResults(1000);
|
||||
|
||||
$qb->execute(); // Should not throw
|
||||
$this->assertSame('DELETE FROM orders LIMIT 1000', $qb->getSQL());
|
||||
|
||||
$qb = sqlQueryBuilder()->delete('orders_history')
|
||||
->andWhere(Operator::exists(
|
||||
sqlQueryBuilder()->select('*')
|
||||
->from('orders', 'o')
|
||||
->where('o.id = id_order')
|
||||
->andWhere('o.date_updated < (NOW() - INTERVAL 5 YEAR)')
|
||||
))
|
||||
->andWhere('custom_data IS NOT NULL')
|
||||
->andWhere("JSON_EXISTS(custom_data, '$.email_type')")
|
||||
->andWhere("JSON_EXTRACT(custom_data, '$.email_type') <> 'ORDER_CREATE'")
|
||||
->orderBy('date', 'DESC')
|
||||
->addOrderBy('id', 'ASC')
|
||||
->setMaxResults(1000);
|
||||
|
||||
$qb->execute(); // Should not throw
|
||||
$this->assertSame(
|
||||
"DELETE FROM orders_history WHERE (EXISTS (SELECT * FROM orders o WHERE (o.id = id_order) AND (o.date_updated < (NOW() - INTERVAL 5 YEAR)))) AND (custom_data IS NOT NULL) AND (JSON_EXISTS(custom_data, '$.email_type')) AND (JSON_EXTRACT(custom_data, '$.email_type') <> 'ORDER_CREATE') ORDER BY date DESC, id ASC LIMIT 1000",
|
||||
$qb->getSQL(),
|
||||
);
|
||||
|
||||
// Test normal delete still functional
|
||||
$qb = sqlQueryBuilder()->delete()
|
||||
->from('orders_history', 'oh')
|
||||
->andWhere(Operator::exists(
|
||||
sqlQueryBuilder()->select('*')
|
||||
->from('orders', 'o')
|
||||
->where('o.id = id_order')
|
||||
->andWhere('o.date_updated < (NOW() - INTERVAL 5 YEAR)')
|
||||
))
|
||||
->andWhere('custom_data IS NOT NULL')
|
||||
->andWhere("JSON_EXISTS(custom_data, '$.email_type')")
|
||||
->andWhere("JSON_EXTRACT(custom_data, '$.email_type') <> 'ORDER_CREATE'");
|
||||
|
||||
$qb->execute(); // Should not throw
|
||||
$this->assertSame(
|
||||
"DELETE oh FROM orders_history oh WHERE (EXISTS (SELECT * FROM orders o WHERE (o.id = id_order) AND (o.date_updated < (NOW() - INTERVAL 5 YEAR)))) AND (custom_data IS NOT NULL) AND (JSON_EXISTS(custom_data, '$.email_type')) AND (JSON_EXTRACT(custom_data, '$.email_type') <> 'ORDER_CREATE')",
|
||||
$qb->getSQL(),
|
||||
);
|
||||
|
||||
$qb = sqlQueryBuilder()->delete('orders_history', 'oh')
|
||||
->andWhere(Operator::exists(
|
||||
sqlQueryBuilder()->select('*')
|
||||
->from('orders', 'o')
|
||||
->where('o.id = id_order')
|
||||
->andWhere('o.date_updated < (NOW() - INTERVAL 5 YEAR)')
|
||||
))
|
||||
->andWhere('custom_data IS NOT NULL')
|
||||
->andWhere("JSON_EXISTS(custom_data, '$.email_type')")
|
||||
->andWhere("JSON_EXTRACT(custom_data, '$.email_type') <> 'ORDER_CREATE'");
|
||||
|
||||
$qb->execute(); // Should not throw
|
||||
$this->assertSame(
|
||||
"DELETE oh FROM orders_history oh WHERE (EXISTS (SELECT * FROM orders o WHERE (o.id = id_order) AND (o.date_updated < (NOW() - INTERVAL 5 YEAR)))) AND (custom_data IS NOT NULL) AND (JSON_EXISTS(custom_data, '$.email_type')) AND (JSON_EXTRACT(custom_data, '$.email_type') <> 'ORDER_CREATE')",
|
||||
$qb->getSQL(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testLimitUpdate()
|
||||
{
|
||||
$qb = sqlQueryBuilder()
|
||||
->update('orders_history', 'oh')
|
||||
->set('oh.comment', 'NULL')
|
||||
->orderBy('oh.date')
|
||||
->setMaxResults(10000);
|
||||
|
||||
$qb->execute();
|
||||
$this->assertSame('UPDATE orders_history oh SET oh.comment = NULL ORDER BY oh.date ASC LIMIT 10000', $qb->getSQL());
|
||||
|
||||
$qb = sqlQueryBuilder()
|
||||
->update('orders_history', 'oh')
|
||||
->set('oh.comment', 'NULL');
|
||||
|
||||
$qb->execute();
|
||||
$this->assertSame('UPDATE orders_history oh SET oh.comment = NULL', $qb->getSQL());
|
||||
|
||||
$qb = sqlQueryBuilder()
|
||||
->update('orders_history', 'oh')
|
||||
->join('oh', 'orders', 'o', 'oh.id_order = o.id')
|
||||
->set('oh.comment', 'NULL');
|
||||
|
||||
$qb->execute();
|
||||
$this->assertSame('UPDATE orders_history oh INNER JOIN orders o ON oh.id_order = o.id SET oh.comment = NULL', $qb->getSQL());
|
||||
|
||||
$qb = sqlQueryBuilder()
|
||||
->update('orders_history', 'oh')
|
||||
->join('oh', 'orders', 'o', 'oh.id_order = o.id')
|
||||
->set('oh.comment', 'NULL')
|
||||
->orderBy('oh.date', 'DESC')
|
||||
->addOrderBy('o.date_updated', 'ASC')
|
||||
->setMaxResults(10000);
|
||||
|
||||
// https://mariadb.com/kb/en/update/#description
|
||||
// "Until MariaDB 10.3.2, for the multiple-table syntax, UPDATE updates rows in each table named in table_references that satisfy the conditions.
|
||||
// In this case, ORDER BY and LIMIT cannot be used. This restriction was lifted in MariaDB 10.3.2 and both clauses can be used with multiple-table updates."
|
||||
$qb->execute(); // Should not throw
|
||||
$this->assertSame('UPDATE orders_history oh INNER JOIN orders o ON oh.id_order = o.id SET oh.comment = NULL ORDER BY oh.date DESC, o.date_updated ASC LIMIT 10000', $qb->getSQL());
|
||||
}
|
||||
}
|
||||
29
tests/functional/TemplateTest/FiltersTest.php
Normal file
29
tests/functional/TemplateTest/FiltersTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace TemplateTest;
|
||||
|
||||
global $cfg;
|
||||
require_once $cfg['Path']['shared_version'].'admin/functions.admin.php';
|
||||
|
||||
class FiltersTest extends TemplateTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider data_testFormatEditablePrice
|
||||
*/
|
||||
public function testFormatEditablePrice($expect, $params)
|
||||
{
|
||||
$this->smarty->loadPlugin('smarty_modifier_format_editable_price');
|
||||
|
||||
$this->assertEquals($expect, call_user_func_array('smarty_modifier_format_editable_price', $params));
|
||||
}
|
||||
|
||||
public function data_testFormatEditablePrice()
|
||||
{
|
||||
return [
|
||||
['11.12', [toDecimal('11.1234')]],
|
||||
['11.1234', [toDecimal('11.1234'), 4]],
|
||||
['11.1234', [toDecimal('11.1234'), -4]],
|
||||
['11.12', [toDecimal('11.12'), -4]],
|
||||
];
|
||||
}
|
||||
}
|
||||
16
tests/functional/TemplateTest/TemplateTestCase.php
Normal file
16
tests/functional/TemplateTest/TemplateTestCase.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace TemplateTest;
|
||||
|
||||
class TemplateTestCase extends \DatabaseTestCase
|
||||
{
|
||||
/** @var \Smarty */
|
||||
protected $smarty;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->smarty = createSmarty(true, true);
|
||||
}
|
||||
}
|
||||
83
tests/functional/UserTest.php
Normal file
83
tests/functional/UserTest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
class UserTest extends \DatabaseTestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$this->assertEquals(1, User::createFromId(1)->id);
|
||||
$this->assertEquals(1, User::createFromLogin('petr@wpj.cz')->id);
|
||||
$this->assertEquals(1, User::createFromUserKey('r90p06rftme6v8dg11j6prcc81')->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_testPhoneNumberProcess
|
||||
*/
|
||||
public function testPhoneNumberProcess($phone, $userData)
|
||||
{
|
||||
$user = new User();
|
||||
$user->updateAddresses(array_merge([
|
||||
'name' => 'Petr',
|
||||
'surname' => 'Jebavý',
|
||||
'email' => 'petr@wpj.cz',
|
||||
'phone' => '',
|
||||
'country' => 'CZ',
|
||||
'currency' => 'CZK', ], $userData), null);
|
||||
|
||||
$this->assertSame($phone, $user->invoice['phone']);
|
||||
}
|
||||
|
||||
public function data_testPhoneNumberProcess()
|
||||
{
|
||||
return [
|
||||
['+420123456789', ['phone' => '123456789']],
|
||||
['+123456789', ['phone' => '00123456789']],
|
||||
['+420123456789', ['phone' => '+420123456789']],
|
||||
['+52123456789', ['phone' => '+52123456789']],
|
||||
['+420739022578', ['phone' => '739022578']],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getDataSet()
|
||||
{
|
||||
return $this->getJsonDataSet(/* @lang JSON */
|
||||
'{
|
||||
"users": [
|
||||
{
|
||||
"id":1,
|
||||
"passw":"79c2b46ce2594ecbcb5b73e928345492",
|
||||
"user_key":"r90p06rftme6v8dg11j6prcc81",
|
||||
"figure":"Y",
|
||||
"name":"Petr",
|
||||
"surname":"Jebavý",
|
||||
"firm":"wpj s.r.o.",
|
||||
"street":"Nádražní 471",
|
||||
"city":"Vrchlabí",
|
||||
"zip":54301,
|
||||
"country":"",
|
||||
"currency":"CZK",
|
||||
"email":"petr@wpj.cz",
|
||||
"ico":"",
|
||||
"dic":"",
|
||||
"phone":775131400,
|
||||
"mobile":"",
|
||||
"fax":"",
|
||||
"delivery_name":"",
|
||||
"delivery_surname":"",
|
||||
"delivery_firm":"",
|
||||
"delivery_street":"",
|
||||
"delivery_city":"",
|
||||
"delivery_zip":"",
|
||||
"delivery_country":"",
|
||||
"account_no":"",
|
||||
"account_bank":"",
|
||||
"account_symbol":"",
|
||||
"get_news":"Y",
|
||||
"prefer_transport":1,
|
||||
"date_reg":"2013-09-30 12:09:05",
|
||||
"date_updated":"2013-09-30 12:12:44",
|
||||
"date_logged":null
|
||||
}
|
||||
]
|
||||
}');
|
||||
}
|
||||
}
|
||||
36
tests/functional/VariationTest.php
Normal file
36
tests/functional/VariationTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: filip
|
||||
* Date: 7/8/16
|
||||
* Time: 1:40 PM.
|
||||
*/
|
||||
class VariationTest extends DatabaseTestCase
|
||||
{
|
||||
public function testCreateFromArray()
|
||||
{
|
||||
$array = [
|
||||
'id' => null,
|
||||
'title' => null,
|
||||
'discount' => null,
|
||||
'vat' => null,
|
||||
'delivery_time' => null,
|
||||
'code' => null,
|
||||
'id_variation' => 5,
|
||||
'variation_title' => 'title',
|
||||
];
|
||||
|
||||
$variation = new Variation();
|
||||
|
||||
$variation->createFromArray($array);
|
||||
|
||||
$this->assertSame([
|
||||
$array['id_variation'],
|
||||
$array['variation_title'],
|
||||
], [
|
||||
$variation->variationId,
|
||||
$variation->variationTitle,
|
||||
]);
|
||||
}
|
||||
}
|
||||
141
tests/functional/bootstrap.php
Normal file
141
tests/functional/bootstrap.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
if (getenv('TEST_SHOP')) {
|
||||
throw new Exception('TEST_SHOP was removed. Use `--testsuite engine` or `shop` instead.');
|
||||
}
|
||||
|
||||
define('TEST_SUITE', getTestSuite());
|
||||
echo 'TEST_SUITE='.TEST_SUITE."\n";
|
||||
|
||||
/* Tells if database query log should be displayed */
|
||||
define('QUERY_LOG', (int) getenv('QUERY_LOG'));
|
||||
echo 'QUERY_LOG='.QUERY_LOG."\n";
|
||||
|
||||
global $cfg, $dbcfg;
|
||||
global $txt_str;
|
||||
$txt_str = [];
|
||||
|
||||
if (!isset($_SESSION)) {
|
||||
$_SESSION = [];
|
||||
}
|
||||
|
||||
// Prepare request superglobals
|
||||
$_SERVER = $_SERVER + [
|
||||
'SERVER_NAME' => 'kupshop.localhost',
|
||||
'QUERY_STRING' => '',
|
||||
'SCRIPT_NAME' => 'index.php',
|
||||
'REMOTE_ADDR' => '127.0.0.1',
|
||||
];
|
||||
|
||||
$shop_dir = getenv('SHOP') ?: __DIR__.'/../../../shop';
|
||||
chdir($shop_dir);
|
||||
|
||||
// Disable stack traces of exception
|
||||
ini_set('xdebug.show_exception_trace', 0);
|
||||
|
||||
$cfg['Cache']['prefix'] = 'tests';
|
||||
|
||||
switch (TEST_SUITE) {
|
||||
case 'shop':
|
||||
require_once './vendor/autoload.php';
|
||||
|
||||
if (file_exists('./config/config.php')) {
|
||||
require_once './config/config.php';
|
||||
} else {
|
||||
require_once './include/config.php';
|
||||
}
|
||||
|
||||
$testConfig = './tests/functional/test.config.php';
|
||||
is_readable($testConfig) && require_once $testConfig;
|
||||
require_once './include/functions.php';
|
||||
break;
|
||||
case 'engine_units_float':
|
||||
require_once __DIR__.'/test.units_float.config.php';
|
||||
require_once '../engine/web/functions.php';
|
||||
|
||||
$cfg['Addr']['print'] = 'www.kupshop.local/';
|
||||
$cfg['Addr']['full'] = 'https://'.$cfg['Addr']['print'];
|
||||
$cfg['Path']['smarty_tpl']['templates'] = 'nic'; // Non-existent folder to skip shop templates
|
||||
break;
|
||||
case 'engine':
|
||||
require_once __DIR__.'/test.config.php';
|
||||
require_once './engine/web/functions.php';
|
||||
|
||||
$cfg['Addr']['print'] = 'www.kupshop.local/';
|
||||
$cfg['Addr']['full'] = 'https://'.$cfg['Addr']['print'];
|
||||
$cfg['Path']['smarty_tpl']['templates'] = 'nic'; // Non-existent folder to skip shop templates
|
||||
break;
|
||||
}
|
||||
|
||||
if (QUERY_LOG) {
|
||||
sqlGetConnection()
|
||||
->getConfiguration()
|
||||
->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
|
||||
}
|
||||
|
||||
require_once $cfg['Path']['shared_version'].'web/lang/lang.cs.php';
|
||||
|
||||
function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext = null)
|
||||
{
|
||||
// TODO(hauschwitz): opravit deprecation warningy místo vypínání
|
||||
if ($errno === E_DEPRECATED || $errno === E_USER_DEPRECATED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (stripos($errfile, '.tpl.php') !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (stripos($errfile, 'smarty_internal_templatebase') !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$errorHandler = new PHPUnit\Util\ErrorHandler(false, true, true, true);
|
||||
|
||||
return $errorHandler($errno, $errstr, $errfile, $errline);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function getTestSuite()
|
||||
{
|
||||
$args = $GLOBALS['argv'];
|
||||
$testSuiteParamIndex = array_search('--testsuite', $args);
|
||||
|
||||
if ($testSuiteParamIndex) {
|
||||
return $args[$testSuiteParamIndex + 1];
|
||||
}
|
||||
|
||||
return 'engine';
|
||||
}
|
||||
|
||||
$GLOBALS['previous'] = set_error_handler('mutingErrorHandler');
|
||||
|
||||
spl_autoload_register(function ($className) {
|
||||
$fileName = __DIR__.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $className).'.php';
|
||||
|
||||
if (!file_exists($fileName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
require $fileName;
|
||||
});
|
||||
|
||||
if (TEST_SUITE == 'shop') {
|
||||
// Autoloader for shop tests
|
||||
spl_autoload_register(function ($className) {
|
||||
$fileName = 'tests/functional'.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $className).'.php';
|
||||
|
||||
if (!file_exists($fileName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
require $fileName;
|
||||
});
|
||||
}
|
||||
|
||||
// Prepare database
|
||||
global $db;
|
||||
$db = new \KupShop\DevelopmentBundle\Util\Tests\DatabaseUtils();
|
||||
$db->prepare();
|
||||
47
tests/functional/phpunit.xml
Normal file
47
tests/functional/phpunit.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<phpunit
|
||||
backupGlobals="false"
|
||||
bootstrap="bootstrap.php"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
colors="true"
|
||||
>
|
||||
<php>
|
||||
<server name="KERNEL_DIR" value="app/" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="engine">
|
||||
<directory suffix="Test.php">.</directory>
|
||||
<directory suffix="Test.php">../../bundles/</directory>
|
||||
</testsuite>
|
||||
<testsuite name="engine_units_float">
|
||||
<directory suffix="FloatSuite.php">../../bundles/</directory>
|
||||
</testsuite>
|
||||
<testsuite name="shop">
|
||||
<directory suffix="Test.php">../../../shop/tests/functional</directory>
|
||||
<directory suffix="Test.php">../../../shop/bundles/</directory>
|
||||
<directory suffix="Test.php">../../../shop/vendor-shared/kupshop/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">../../bundles/</directory>
|
||||
<directory suffix=".php">../../class/</directory>
|
||||
<directory suffix=".php">../../web/</directory>
|
||||
<exclude>
|
||||
<directory suffix=".php">../../class/Smarty</directory>
|
||||
<directory suffix=".php">../../class/highcharts</directory>
|
||||
<directory suffix=".php">../../class/PHPExcel</directory>
|
||||
<directory suffix=".php">../../class/sacy</directory>
|
||||
<directory suffix=".php">../../class/xmlrpc</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
<listeners>
|
||||
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
|
||||
</listeners>
|
||||
|
||||
</phpunit>
|
||||
5
tests/functional/templates/product.tpl
Normal file
5
tests/functional/templates/product.tpl
Normal file
@@ -0,0 +1,5 @@
|
||||
<p class="price" data-price>{$body.product.productPrice|format_price}</p>
|
||||
|
||||
{if $body.product->isold()}
|
||||
{t}Tento produkt je dlouhodobě vyprodaný.{/t}
|
||||
{/if}
|
||||
769
tests/functional/test.config.php
Normal file
769
tests/functional/test.config.php
Normal file
@@ -0,0 +1,769 @@
|
||||
<?php
|
||||
|
||||
// //////////////// CONFIG SOUBOR ESHOPU ////////////////////////////////////
|
||||
// ********************************************************************** //
|
||||
// CONFIG SOUBOR JE SOUBOREM PHP //
|
||||
// RADKY ZAKOMENTUJETE ZNACKAMI // NEBO # //
|
||||
// NEPOUZIVEJTE JEDNODUCHE UVOZOVKY, POUZE DVOJITE //
|
||||
// v pripade problemu kontaktujte autory na: eshop@wpj.cz //
|
||||
// ********************************************************************** //
|
||||
// //////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$cfg['Connection']['database'] = 'phpunit_test';
|
||||
|
||||
$cfg['debug'] = true;
|
||||
$cfg['autoload_web_root'] = false;
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI LICENCE ESHOPU
|
||||
* ======================================================================
|
||||
* licence ID: cislo licence / MUSI BYT UNIKATNI!!!!
|
||||
* licence date: datum zalozeni teto licence
|
||||
* licence dateto: datum platnosti teto licence
|
||||
* version - print: tistena verze eshopu
|
||||
* version - number: verze eshopu v ciselnem formatu pro cteni PHP
|
||||
*/
|
||||
$cfg['Program']['licence']['ID'] = 'tests_1422870539';
|
||||
|
||||
$cfg['Program']['version']['number'] = 220;
|
||||
$cfg['Program']['version']['dotted'] = sprintf('%.1F', $cfg['Program']['version']['number'] / 10);
|
||||
$cfg['Program']['version']['print'] = 'v '.$cfg['Program']['version']['dotted'];
|
||||
$cfg['Program']['version']['folder'] = 'engine';
|
||||
|
||||
$cfg['Modules'] = [];
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI MODULU ESHOPU
|
||||
* ======================================================================
|
||||
* aktivni moduly.
|
||||
*
|
||||
* Pro zruseni modulu staci radku zakomentovat pomoci //
|
||||
*/
|
||||
// Zboží
|
||||
$cfg['Modules']['products'] = [
|
||||
'price_common' => true,
|
||||
'price_buy' => true,
|
||||
'weight' => true,
|
||||
'sets' => true,
|
||||
'note' => true,
|
||||
'units' => true,
|
||||
'descr_plus' => true,
|
||||
];
|
||||
|
||||
// Prevodniky
|
||||
$cfg['Modules']['convertors'] = true;
|
||||
// Produktove rezervace
|
||||
$cfg['Modules']['product_reservations'] = true;
|
||||
|
||||
// Parametry zboží
|
||||
$cfg['Modules']['products_parameters'] = [
|
||||
'configurations' => true,
|
||||
];
|
||||
|
||||
// Skupiny parametrů
|
||||
$cfg['Modules']['parameter_groups'] = true;
|
||||
|
||||
// Sekce zboží
|
||||
$cfg['Modules']['products_sections'] = [
|
||||
// 'elasticsearch' => true,
|
||||
'custom_url' => true,
|
||||
];
|
||||
// Výrobci zboží
|
||||
$cfg['Modules']['producers'] = true;
|
||||
// Jednoduché vyhledávání
|
||||
$cfg['Modules']['eshop_search'] = true;
|
||||
// Editovatelné odkazy v menu
|
||||
$cfg['Modules']['menulinks'] = true;
|
||||
// Uživatelé eshopu
|
||||
$cfg['Modules']['eshop_users'] = [
|
||||
'remember_user_delivery_type' => true,
|
||||
];
|
||||
// WYSIWYG úprava
|
||||
// $cfg['Modules']['wysiwyg'] = true;
|
||||
// Objednávky
|
||||
$cfg['Modules']['orders'] = [
|
||||
'dic_validate' => true,
|
||||
];
|
||||
// Záloha databáze
|
||||
$cfg['Modules']['dbbackup'] = true;
|
||||
|
||||
$cfg['Modules']['automation_configurator'] = true;
|
||||
|
||||
// Způsoby doručení zásilky
|
||||
$cfg['Modules']['eshop_delivery'] = true;
|
||||
// Obrázky
|
||||
$cfg['Modules']['photos'] = true;
|
||||
// Rozšířené vyhledávání
|
||||
// $cfg['Modules']['eshop_exsearch'] = true;
|
||||
// HTML stránky
|
||||
$cfg['Modules']['html_pages'] = true;
|
||||
// Porovnání zboží
|
||||
// $cfg['Modules']['products_compare'] = true;
|
||||
// Oblíbené položky zákazníků
|
||||
$cfg['Modules']['products_favorites'] = true;
|
||||
// Příplatky
|
||||
$cfg['Modules']['products_charges'] = true;
|
||||
// Ankety
|
||||
// $cfg['Modules']['inquiries'] = true;
|
||||
// NewsLetter
|
||||
$cfg['Modules']['newsletter'] = true;
|
||||
// Statistiky
|
||||
$cfg['Modules']['stats'] = true;
|
||||
// Export dat
|
||||
$cfg['Modules']['export'] = true;
|
||||
// Import dat
|
||||
$cfg['Modules']['import'] = true;
|
||||
// Komentáře ke zboží
|
||||
// $cfg['Modules']['products_comments'] = true;
|
||||
// Cenové hladiny zboží
|
||||
$cfg['Modules']['price_levels'] = true;
|
||||
// Články
|
||||
$cfg['Modules']['articles'] = true;
|
||||
// Sekce článků
|
||||
$cfg['Modules']['articles_sections'] = true;
|
||||
// Historie cen
|
||||
$cfg['Modules']['price_history'] = true;
|
||||
// Feed generator
|
||||
$cfg['Modules']['feed_generator'] = true;
|
||||
// Komentáře ke článku
|
||||
// $cfg['Modules']['articles_comments'] = true;
|
||||
// Katalogový Feed
|
||||
$cfg['Modules']['feeds'] = true;
|
||||
// Varianty zboží
|
||||
$cfg['Modules']['products_variations'] = [
|
||||
'variationCode' => true,
|
||||
];
|
||||
// Filtrovani podle kategorii/variant
|
||||
$cfg['Modules']['filter'] = [
|
||||
'totals' => true,
|
||||
'onPage' => [20 => 20, 50 => 50, 100 => 100, 200 => 200, 500 => 500],
|
||||
];
|
||||
$cfg['Modules']['dynamic_filter'] = true;
|
||||
// Automatické importy
|
||||
$cfg['Modules']['automatic_import'] = true;
|
||||
// Dodavatelé produktů/Skladem u dodavatele
|
||||
$cfg['Modules']['products_suppliers'] = [
|
||||
'delivery_time' => -1,
|
||||
];
|
||||
// SEO modul
|
||||
$cfg['Modules']['seo'] = true;
|
||||
// Hlídání produktů které dojdou
|
||||
// $cfg['Modules']['missing_products'] = true;
|
||||
// Dotaz na prodejce
|
||||
// $cfg['Modules']['customer_question'] = true;
|
||||
// Hromadné zpracování objednávek
|
||||
// $cfg['Modules']['orders_mass_process'] = true;
|
||||
// Naskladňovací faktury
|
||||
$cfg['Modules']['stock_in'] = [
|
||||
'weighted_purchase_price' => true,
|
||||
];
|
||||
// Editace objednávek zákazníkem
|
||||
// $cfg['Modules']['order_edit'] = true;
|
||||
// Platby objednávek
|
||||
$cfg['Modules']['order_payment'] = true;
|
||||
// Slidery
|
||||
$cfg['Modules']['sliders'] = true;
|
||||
// ISIC/ALIVE karty
|
||||
// $cfg['Modules']['isic'] = true;
|
||||
// Vratky
|
||||
// $cfg['Modules']['replacement'] = true;
|
||||
// Sety/Dárky
|
||||
$cfg['Modules']['products_sets'] = [
|
||||
'calculate_price' => true,
|
||||
'calculate_stock' => true,
|
||||
];
|
||||
// Dárky
|
||||
$cfg['Modules']['products_gifts'] = true;
|
||||
$cfg['Modules']['skeet'] = true;
|
||||
|
||||
// Šablony produktů
|
||||
$cfg['Modules']['templates'] = true;
|
||||
// Kolekce produktů
|
||||
$cfg['Modules']['products_collections'] = true;
|
||||
// Produkty dodavatelů
|
||||
// $cfg['Modules']['orders_of_suppliers'] = true;
|
||||
// Platebni brany BACHA OSTRA DATA ZKOPIROVANA Z NARADI HORNIG
|
||||
$cfg['Modules']['payments'] = [
|
||||
'ThePay' => [
|
||||
'test' => '1',
|
||||
// 'merchantId' => '457',
|
||||
// 'accountId' => '490',
|
||||
// 'password' => '50973c916453',
|
||||
// 'dataApiPassword' => '0dedd1f91359c4c',
|
||||
],
|
||||
'TestPayment' => true,
|
||||
];
|
||||
// Způsoby dopravy
|
||||
$cfg['Modules']['deliveries'] = true;
|
||||
// Google analytics
|
||||
// $cfg['Modules']['google_analytics'] = true;
|
||||
// Heureka ověřené zákazníky
|
||||
// $cfg['Modules']['heureka_overeno'] = true;
|
||||
// Google konverze
|
||||
// $cfg['Modules']['google_conversion'] = true;
|
||||
// Heureka konverze
|
||||
// $cfg['Modules']['heureka_conversion'] = true;
|
||||
// Zbozi.cz
|
||||
// $cfg['Modules']['zbozi_cz_feedback'] = true;
|
||||
// Sklik konverze
|
||||
// $cfg['Modules']['sklik_conversion'] = true;
|
||||
// Zásilkovna
|
||||
// $cfg['Modules']['zasilkovna'] = true;
|
||||
// Fotky k variantám
|
||||
$cfg['Modules']['products_variations_photos'] = true;
|
||||
// Kontaktní formuláře
|
||||
// $cfg['Modules']['forms'] = [];
|
||||
// Inventura
|
||||
// $cfg['Modules']['inventory'] = true;
|
||||
// ReCaptcha
|
||||
// $cfg['Modules']['recaptcha'] = true;
|
||||
// Pokladna
|
||||
// $cfg['Modules']['pos'] = true;
|
||||
// Abra
|
||||
// $cfg['Modules']['abra'] = [
|
||||
// 'server' => 'http://server18.elnino.cz:777/AWS/wsdl/WebEngine', // Official
|
||||
// //'server' => 'http://gw.it-pro.cz:777/AWS/wsdl/WebEngine', // Testing
|
||||
// 'queue' => 'wpj.Q.abra-stock-koza',
|
||||
// //'web' => 'kosmetika-zdravi.cz',
|
||||
// 'web' => null,
|
||||
// ];
|
||||
// Balíkonoš
|
||||
$cfg['Modules']['balikonos'] = [
|
||||
'provider' => 'balikobot',
|
||||
];
|
||||
|
||||
$cfg['Modules']['fulltext_search'] = true;
|
||||
|
||||
$cfg['Modules']['products_related'] = ['types' => true];
|
||||
|
||||
$cfg['Modules']['dynamic_related_products'] = true;
|
||||
|
||||
// $cfg['Modules']['elnino'] = true;
|
||||
|
||||
$cfg['Modules']['watchdog'] = true;
|
||||
|
||||
$cfg['Modules']['currencies'] = true;
|
||||
$cfg['Modules']['translations'] = true;
|
||||
$cfg['Modules']['reviews'] = true;
|
||||
$cfg['Modules']['symfony'] = true;
|
||||
|
||||
$cfg['Modules']['margins'] = true;
|
||||
|
||||
// Ceníky dopravy
|
||||
$cfg['Modules']['delivery_pricelist'] = true;
|
||||
|
||||
$cfg['Modules']['pricelists'] = [
|
||||
'coefficient' => true,
|
||||
];
|
||||
|
||||
$cfg['Modules']['indexed_filter'] = true;
|
||||
|
||||
$cfg['insert_products_new'] = true;
|
||||
|
||||
$cfg['Modules']['quantity_discount'] = true;
|
||||
|
||||
$cfg['Modules']['pos'] = true;
|
||||
|
||||
$cfg['Modules']['bonus_program'] = true;
|
||||
|
||||
$cfg['Modules']['comments'] = true;
|
||||
|
||||
$cfg['Modules']['db_rewrite'] = true;
|
||||
|
||||
$cfg['Modules']['oss_vats'] = true;
|
||||
|
||||
$cfg['Modules']['bank_auto_payments'] = true;
|
||||
|
||||
$cfg['Modules']['telfa'] = true;
|
||||
$cfg['Modules']['warehouse'] = true;
|
||||
$cfg['Modules']['products_batches'] = true;
|
||||
|
||||
$cfg['Modules']['stores'] = true;
|
||||
$cfg['Modules']['returns'] = true;
|
||||
$cfg['Modules']['reclamations'] = true;
|
||||
$cfg['Modules']['async_emails'] = true;
|
||||
$cfg['Modules']['heureka_cart'] = [
|
||||
'API_ID' => 'API_ID',
|
||||
'API_ID_SK' => 'API_ID_SK',
|
||||
'test' => '1',
|
||||
];
|
||||
$cfg['Modules']['global_discounts'] = true;
|
||||
$cfg['Modules']['order_restrictions'] = true;
|
||||
$cfg['Modules']['pohoda'] = [
|
||||
'users' => true,
|
||||
'orders_import' => true,
|
||||
'invoices' => true,
|
||||
'instant_user_upload' => true,
|
||||
];
|
||||
|
||||
$cfg['Modules']['synchronization'] = true;
|
||||
|
||||
$cfg['Modules']['order_discount'] = true;
|
||||
$cfg['Modules']['restrictions'] = [
|
||||
'objects' => [
|
||||
'categories' => 1,
|
||||
'producers' => 2,
|
||||
'campaigns' => 3,
|
||||
'products' => 4,
|
||||
],
|
||||
'domains' => [
|
||||
'countries' => 1,
|
||||
'users' => 2,
|
||||
'login' => 4,
|
||||
'price_levels' => 5,
|
||||
'users_groups' => 6,
|
||||
],
|
||||
];
|
||||
$cfg['Modules']['webpack'] = true;
|
||||
$cfg['Modules']['new_pos'] = true;
|
||||
|
||||
$cfg['Modules']['graphql'] = [
|
||||
'admin_api' => true,
|
||||
];
|
||||
|
||||
$cfg['Modules']['synchronization'] = true;
|
||||
|
||||
$cfg['Modules']['sellers'] = true;
|
||||
|
||||
$cfg['Modules']['reservations'] = true;
|
||||
|
||||
$cfg['Modules']['dropship'] = true;
|
||||
|
||||
$cfg['Modules']['kafka'] = true;
|
||||
|
||||
$cfg['Modules']['users_groups_types'] = [];
|
||||
|
||||
$cfg['Modules']['user_addresses'] = true;
|
||||
|
||||
$cfg['Modules']['b2b_preorders'] = [
|
||||
'order_status' => 4,
|
||||
];
|
||||
|
||||
$cfg['Modules']['sales'] = true;
|
||||
|
||||
$cfg['Modules']['labels'] = [
|
||||
'product_labels' => true,
|
||||
'colors' => [
|
||||
[
|
||||
'type' => 'green',
|
||||
'descr' => 'Zelená',
|
||||
],
|
||||
[
|
||||
'type' => 'blue',
|
||||
'descr' => 'Modrá',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$cfg['Modules']['recommenders'] = true;
|
||||
|
||||
// $cfg['Modules']['components'] = true;
|
||||
|
||||
$cfg['Modules']['products_shopping_list'] = true;
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI ADRESY ESHOPU
|
||||
* ======================================================================
|
||||
* full: plna cesta k eshopu s http:// domenou a adresarem
|
||||
* print: plna cesta k eshopu bez http - verze k vytisteni
|
||||
* error: soubor s chybovou hlaskou
|
||||
*/
|
||||
$cfg['Addr']['print'] = 'www.kosmetika-zdravi.kupshop.cz/';
|
||||
$cfg['Addr']['full'] = 'http://'.$cfg['Addr']['print'];
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI FTP CESTY K ESHOPU
|
||||
* ======================================================================
|
||||
* eshop_root: cesta v FTP na serveru
|
||||
*
|
||||
* kdyz se pripoji pomoci FTP uctu na kupshop.cz, tak z rootu
|
||||
* je nasledujici cesta
|
||||
*/
|
||||
$cfg['FTP']['use_ftp'] = false;
|
||||
$cfg['FTP']['eshop_root'] = '/';
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI CEST ESHOPU
|
||||
* ======================================================================
|
||||
*/
|
||||
// ## smarty: motiv sablon tahajici se ze sdilene slozky
|
||||
$cfg['Path']['smarty_tpl']['theme'] = 'x';
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI JMEN TABULEK, KTERE POUZIVA ESHOP
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['DbTablePrefix'] = '';
|
||||
$cfg['DbTable']['photos-products'] = 'photos_products_relation';
|
||||
$cfg['DbTable']['products-related'] = 'products_related';
|
||||
$cfg['DbTable']['products-favorites'] = 'products_favorites';
|
||||
$cfg['DbTable']['products-sections'] = 'products_in_sections';
|
||||
$cfg['DbTable']['photos_articles'] = 'photos_articles_relation';
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI JAZYKA
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['Lang']['language'] = 'cs';
|
||||
|
||||
$cfg['Order'] = [];
|
||||
// $cfg['Order']['Status'] = array();
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI OBJEDNAVEK
|
||||
* ======================================================================
|
||||
* Status: nastaveni stavu objednavek
|
||||
|
||||
*/
|
||||
$cfg['Order']['Status']['global'][0] = 'nová';
|
||||
$cfg['Order']['Status']['global'][1] = 'přenesena';
|
||||
$cfg['Order']['Status']['global'][2] = 'potvrzena';
|
||||
$cfg['Order']['Status']['global'][3] = 'vyřízena';
|
||||
|
||||
$cfg['Order']['Status']['payed'][0] = 'čeká na zaplacení';
|
||||
$cfg['Order']['Status']['payed'][1] = 'zaplaceno';
|
||||
|
||||
$cfg['Order']['Status']['dispatch'][0] = 'čeká na odeslání';
|
||||
$cfg['Order']['Status']['dispatch'][1] = 'částečně odesláno';
|
||||
$cfg['Order']['Status']['dispatch'][2] = 'odesláno';
|
||||
|
||||
$cfg['Order']['Status']['storno'][0] = 'nestornována';
|
||||
$cfg['Order']['Status']['storno'][1] = 'stornována';
|
||||
|
||||
$cfg['Order']['Status']['attach_invoice'] = [];
|
||||
|
||||
$cfg['Order']['hideCode'] = true;
|
||||
$cfg['Order']['prependProducer'] = true;
|
||||
|
||||
// Nastaveni statu
|
||||
// $cfg['Order']['Countries'] = array('Česká Republika' => 'Česká Republika', 'Slovensko'=>'Slovensko');
|
||||
|
||||
// Pridavat na konec objednanyho produktu jeho kod? Napr: Tretry (velikost:modra, kod:ab12345)
|
||||
// $cfg['Order']['hideCode'] = true;
|
||||
|
||||
// Zakazat mazani objednavky v adminu
|
||||
// $cfg['Order']['disableDelete'] = true;
|
||||
|
||||
// ## vygenerovani cisla objednavky
|
||||
// D - den, M - mesic, Y - rok, #ID - poradova cislovka, * - nahodne cislo
|
||||
// [Y,2][M][D]["-"][#ID,6]
|
||||
$cfg['Order']['number']['pattern'] = '["36"][Y,2][#USER_ID]["0"][#USER_ORDER_INDEX]';
|
||||
|
||||
// Nastaveni flagu objednavek
|
||||
$cfg['Order']['Flags'] = [
|
||||
'R' => [
|
||||
'name' => 'Nedořešené',
|
||||
],
|
||||
'H' => [
|
||||
'name' => 'Heureka',
|
||||
],
|
||||
];
|
||||
|
||||
$cfg['Currencies'] = [
|
||||
'CZK' => [
|
||||
'name' => 'Česká koruna',
|
||||
'symbol' => 'Kč',
|
||||
'price_round' => '100',
|
||||
'price_round_direction' => 'math',
|
||||
'countries' => [
|
||||
'CZ',
|
||||
],
|
||||
],
|
||||
'EUR' => [
|
||||
'name' => 'Euro',
|
||||
'symbol' => '€',
|
||||
'price_round' => '0',
|
||||
'price_round_direction' => 'math',
|
||||
'countries' => [
|
||||
'SK',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/*
|
||||
$cfg['Currencies'] = [
|
||||
'CZK' => ['name' => 'Česká koruna',
|
||||
'symbol' => 'Kč'],
|
||||
'EUR' => ['name' => 'Euro',
|
||||
'symbol' => '€' ]
|
||||
];
|
||||
*/
|
||||
|
||||
$cfg['Factorage'] = [];
|
||||
$cfg['Factorage']['Status'] = [];
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI PROVIZI
|
||||
* ======================================================================
|
||||
* Status: nastaveni stavu provize
|
||||
*/
|
||||
$cfg['Factorage']['Status']['payed'][0] = 'neproplaceno';
|
||||
$cfg['Factorage']['Status']['payed'][1] = 'proplaceno';
|
||||
|
||||
$cfg['Products']['DeliveryTimeConfig'] = [];
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI ZBOZI V KATALOGU
|
||||
* ======================================================================
|
||||
* DeliveryTime: nastaveni doby doruceni zbozi
|
||||
*/
|
||||
$cfg['Products']['DeliveryTimeConfig']['0'] = [
|
||||
'name' => 'skladem',
|
||||
'allowBuy' => false,
|
||||
'allowWatchdog' => false,
|
||||
'message' => 'skladem',
|
||||
];
|
||||
$cfg['Products']['DeliveryTimeConfig']['-1'] = [
|
||||
'name' => 'na cestě',
|
||||
'allowBuy' => true,
|
||||
'allowWatchdog' => false,
|
||||
'message' => 'na cestě',
|
||||
];
|
||||
$cfg['Products']['DeliveryTimeConfig']['-2'] = [
|
||||
'name' => 'na objednávku',
|
||||
'allowBuy' => true,
|
||||
'allowWatchdog' => false,
|
||||
'message' => 'na objednávku',
|
||||
];
|
||||
$cfg['Products']['DeliveryTimeConfig']['-3'] = [
|
||||
'name' => 'neni skladem',
|
||||
'allowBuy' => false,
|
||||
'allowWatchdog' => true,
|
||||
'message' => 'neni skladem',
|
||||
];
|
||||
$cfg['Products']['DeliveryTimeConfig']['1'] = [
|
||||
'name' => 'dodáváme do %s dnů',
|
||||
'allowBuy' => true,
|
||||
'allowWatchdog' => false,
|
||||
'message' => 'dodáváme do %s dnů',
|
||||
];
|
||||
|
||||
// Zasunujici se nabidka filtru - melo by byt true kvuli rychlosti.
|
||||
$cfg['Filter']['Collapsable'] = false;
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI OBRAZKU
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['Photo'] = [
|
||||
'default' => [
|
||||
'crop' => false,
|
||||
'background' => 0xFFFFFF,
|
||||
'watermark' => false,
|
||||
'logo' => false,
|
||||
'png' => false,
|
||||
],
|
||||
'types' => [
|
||||
'product_large' => [
|
||||
'size' => [1024, 768],
|
||||
'crop' => false,
|
||||
'watermark' => true,
|
||||
'logo' => true,
|
||||
],
|
||||
'product_catalog' => [
|
||||
'size' => [220, 165],
|
||||
'png' => true,
|
||||
],
|
||||
'product_detail' => [
|
||||
'size' => [485, 371],
|
||||
],
|
||||
'product_gallery' => [
|
||||
'size' => [188, 118],
|
||||
// 'crop' => true,
|
||||
],
|
||||
'admin' => [
|
||||
'size' => [64, 48],
|
||||
],
|
||||
'section' => [
|
||||
'size' => [80, 80],
|
||||
],
|
||||
'producer' => [
|
||||
'size' => [120, 60],
|
||||
],
|
||||
'payment' => [
|
||||
'size' => [30, 30],
|
||||
],
|
||||
'delivery' => [
|
||||
'size' => [110, 40],
|
||||
],
|
||||
'news' => [
|
||||
'size' => [250, 250],
|
||||
],
|
||||
'top_product' => [
|
||||
'size' => [130, 110],
|
||||
],
|
||||
'news_lg' => [
|
||||
'size' => [385, 250],
|
||||
'crop' => true,
|
||||
],
|
||||
'swatch' => [
|
||||
'size' => [60, 60],
|
||||
'crop' => true,
|
||||
],
|
||||
'subsections' => [
|
||||
'size' => [53, 53],
|
||||
'type' => 'section',
|
||||
],
|
||||
'product_cart' => [
|
||||
'size' => [53, 53],
|
||||
'type' => 'section',
|
||||
],
|
||||
],
|
||||
'id_to_type' => [
|
||||
0 => 'product_large',
|
||||
1 => 'product_gallery',
|
||||
2 => 'product_catalog',
|
||||
3 => 'product_detail',
|
||||
4 => 'product_gallery',
|
||||
5 => 'admin',
|
||||
6 => 'section',
|
||||
7 => 'producer',
|
||||
8 => 'payment',
|
||||
9 => 'delivery',
|
||||
10 => 'news',
|
||||
11 => 'top_product',
|
||||
12 => 'news_lg',
|
||||
13 => 'swatch',
|
||||
14 => 'subsections',
|
||||
15 => 'product_cart',
|
||||
],
|
||||
'placeholder' => '/templates/images/no-img.png',
|
||||
'kind' => [
|
||||
'Y' => 'Hlavní',
|
||||
'N' => 'Vedlejší',
|
||||
'O' => 'Odstín',
|
||||
],
|
||||
];
|
||||
|
||||
$cfg['Menu'] = [];
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI VLASTNICH EDITOVATELNYCH MENU ESHOPU
|
||||
* ======================================================================
|
||||
* aktivni moduly.
|
||||
*
|
||||
* Pro zruseni modulu staci radku zakomentovat pomoci //
|
||||
*/
|
||||
|
||||
$cfg['Menu']['own'][1] = [
|
||||
'name' => 'Patička',
|
||||
'title' => 'Patička',
|
||||
'default' => true,
|
||||
];
|
||||
|
||||
$cfg['Menu']['own'][2] = [
|
||||
'name' => 'Menu uživatel',
|
||||
'title' => 'Menu uživatel',
|
||||
'default' => true,
|
||||
];
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI MENU ESHOPU
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['Menu']['main']['default'] = 'sections';
|
||||
$cfg['Menu']['sections'] = [
|
||||
'show' => true,
|
||||
'collapse' => true,
|
||||
'collapse_settings' => [
|
||||
'max_levels' => 0,
|
||||
],
|
||||
];
|
||||
$cfg['Menu']['producers'] = [
|
||||
'show' => true,
|
||||
'collapse' => false,
|
||||
];
|
||||
$cfg['Menu']['inquiry'] = [
|
||||
'show' => true,
|
||||
];
|
||||
$cfg['Menu']['index_product'] = [
|
||||
'limit' => 9,
|
||||
'photos' => 2,
|
||||
];
|
||||
$cfg['Menu']['random_product'] = [
|
||||
'show' => true,
|
||||
'limit' => 4,
|
||||
'photos' => 1,
|
||||
];
|
||||
$cfg['Menu']['bestseller_product'] = [
|
||||
'show' => true,
|
||||
'limit' => 4,
|
||||
'photos' => 1,
|
||||
];
|
||||
$cfg['Menu']['newest_product'] = [
|
||||
'show' => true,
|
||||
'limit' => 4,
|
||||
'photos' => 1,
|
||||
];
|
||||
$cfg['Menu']['cart_info'] = [
|
||||
'show' => true,
|
||||
];
|
||||
|
||||
$cfg['Menu']['last_visited'] = [
|
||||
'limit' => 6,
|
||||
'photos' => 2,
|
||||
];
|
||||
|
||||
$cfg['Menu']['related'] = [
|
||||
'limit' => 8,
|
||||
'photos' => 2,
|
||||
];
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI ADMINISTRACE ESHOPU
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['Admin']['Login']['User'] = '_KS_ADMIN';
|
||||
$cfg['Admin']['Login']['Password'] = 'ksadmin21';
|
||||
$cfg['Admin']['Login']['Timeout'] = (int) 7200; // 60 = 1 minuta
|
||||
$cfg['Admin']['settings'] = [
|
||||
'email' => 'helpdesk@kupshop.cz',
|
||||
'id' => 0,
|
||||
'privilege' => '',
|
||||
];
|
||||
|
||||
// # NASTAVENI SSL V ADMINISTRACI
|
||||
// zda ma byt v administraci moznost zvolit SSL pripojeni
|
||||
$cfg['Admin']['SSL']['support'] = false;
|
||||
// zda ma byt administrace automaticky presmerovana na SSL
|
||||
$cfg['Admin']['SSL']['automaticRedirection'] = false;
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI MOD_REWRITE PRO SEO FRIENDLY ODKAZY
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['Mod_rewrite'] = true;
|
||||
|
||||
$cfg['Products']['Flags'] = [
|
||||
'N' => ['plural' => 'Novinky', 'singular' => 'Novinka', 'url' => 'novinky', 'short' => 'N', 'order' => -4],
|
||||
'A' => ['plural' => 'Akce', 'singular' => 'Akce', 'url' => 'akce', 'short' => 'A', 'order' => -6],
|
||||
'C' => ['plural' => 'Na cestě', 'singular' => 'Na cestě', 'url' => 'na-ceste', 'short' => 'C', 'order' => -6],
|
||||
'R' => ['plural' => 'Opět skladem', 'singular' => 'Opět skladem', 'url' => 'opet-skladem', 'short' => 'R', 'order' => -6],
|
||||
'T' => ['plural' => 'Testery', 'singular' => 'Tester', 'url' => 'testery', 'short' => 'T', 'order' => -6],
|
||||
'S' => ['plural' => 'Sety', 'singular' => 'Set', 'url' => 'sety', 'short' => 'S', 'order' => -6],
|
||||
'Z' => ['plural' => 'Zlevněno', 'singular' => 'Zlevněno', 'url' => 'zlevneno', 'short' => 'Z', 'order' => -6],
|
||||
'V' => ['plural' => 'Vzorek', 'singular' => 'Vzorek', 'url' => 'vzorky', 'short' => 'V', 'order' => -6],
|
||||
'O' => ['plural' => 'Odstřik', 'singular' => 'Odstřik', 'url' => 'odstrik', 'short' => 'O', 'order' => -6],
|
||||
'MS' => ['plural' => 'Multisety', 'singular' => 'Multiset', 'url' => 'js-multiset', 'short' => 'X', 'order' => -6],
|
||||
];
|
||||
|
||||
$cfg['Sections']['Flags'] = [
|
||||
'A' => ['plural' => 'Kategorie s akčním zbožím'],
|
||||
'L' => ['plural' => 'Pro lamy'],
|
||||
];
|
||||
|
||||
$cfg['captcha']['size'] = 40;
|
||||
|
||||
require_once dirname(__FILE__).'/../../../config_db.php';
|
||||
|
||||
$cfg['Modules']['cdn'] = true;
|
||||
617
tests/functional/test.units_float.config.php
Normal file
617
tests/functional/test.units_float.config.php
Normal file
@@ -0,0 +1,617 @@
|
||||
<?php
|
||||
|
||||
// //////////////// CONFIG SOUBOR ESHOPU ////////////////////////////////////
|
||||
// ********************************************************************** //
|
||||
// CONFIG SOUBOR JE SOUBOREM PHP //
|
||||
// RADKY ZAKOMENTUJETE ZNACKAMI // NEBO # //
|
||||
// NEPOUZIVEJTE JEDNODUCHE UVOZOVKY, POUZE DVOJITE //
|
||||
// v pripade problemu kontaktujte autory na: eshop@wpj.cz //
|
||||
// ********************************************************************** //
|
||||
// //////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$cfg['Connection']['database'] = 'phpunit_test_units_float';
|
||||
|
||||
$cfg['debug'] = true;
|
||||
$cfg['autoload_web_root'] = false;
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI LICENCE ESHOPU
|
||||
* ======================================================================
|
||||
* licence ID: cislo licence / MUSI BYT UNIKATNI!!!!
|
||||
* licence date: datum zalozeni teto licence
|
||||
* licence dateto: datum platnosti teto licence
|
||||
* version - print: tistena verze eshopu
|
||||
* version - number: verze eshopu v ciselnem formatu pro cteni PHP
|
||||
*/
|
||||
|
||||
$cfg['Program']['version']['number'] = 220;
|
||||
$cfg['Program']['version']['dotted'] = sprintf('%.1F', $cfg['Program']['version']['number'] / 10);
|
||||
$cfg['Program']['version']['print'] = 'v '.$cfg['Program']['version']['dotted'];
|
||||
$cfg['Program']['version']['folder'] = 'v'.$cfg['Program']['version']['dotted'];
|
||||
|
||||
$cfg['Modules'] = [];
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI MODULU ESHOPU
|
||||
* ======================================================================
|
||||
* aktivni moduly.
|
||||
*
|
||||
* Pro zruseni modulu staci radku zakomentovat pomoci //
|
||||
*/
|
||||
// Zboží
|
||||
$cfg['Modules']['products'] = [
|
||||
'price_common' => true,
|
||||
'price_buy' => true,
|
||||
'weight' => true,
|
||||
'sets' => true,
|
||||
'note' => true,
|
||||
'units' => true,
|
||||
'units_float' => true,
|
||||
];
|
||||
|
||||
$cfg['Modules']['convertors'] = true;
|
||||
|
||||
// Parametry zboží
|
||||
$cfg['Modules']['products_parameters'] = [
|
||||
'category_params' => [18, /* 27, 28, 20, 14, 25, */
|
||||
22, 31, 32, 33, 34, 35, 27, 28, 20, ],
|
||||
'campaign_params' => [18],
|
||||
'configurations' => true,
|
||||
];
|
||||
// Sekce zboží
|
||||
$cfg['Modules']['products_sections'] = [
|
||||
'custom_url' => true,
|
||||
];
|
||||
// Výrobci zboží
|
||||
$cfg['Modules']['producers'] = true;
|
||||
// Jednoduché vyhledávání
|
||||
$cfg['Modules']['eshop_search'] = true;
|
||||
// Editovatelné odkazy v menu
|
||||
$cfg['Modules']['menulinks'] = true;
|
||||
// Uživatelé eshopu
|
||||
$cfg['Modules']['eshop_users'] = true;
|
||||
// WYSIWYG úprava
|
||||
// $cfg['Modules']['wysiwyg'] = true;
|
||||
// Objednávky
|
||||
$cfg['Modules']['orders'] = [
|
||||
'dic_validate' => true,
|
||||
];
|
||||
// Záloha databáze
|
||||
$cfg['Modules']['dbbackup'] = true;
|
||||
// Způsoby doručení zásilky
|
||||
$cfg['Modules']['eshop_delivery'] = true;
|
||||
// Obrázky
|
||||
$cfg['Modules']['photos'] = true;
|
||||
// Rozšířené vyhledávání
|
||||
// $cfg['Modules']['eshop_exsearch'] = true;
|
||||
// HTML stránky
|
||||
$cfg['Modules']['html_pages'] = true;
|
||||
// Porovnání zboží
|
||||
// $cfg['Modules']['products_compare'] = true;
|
||||
// Oblíbené položky zákazníků
|
||||
$cfg['Modules']['products_favorites'] = true;
|
||||
// Ankety
|
||||
// $cfg['Modules']['inquiries'] = true;
|
||||
// NewsLetter
|
||||
$cfg['Modules']['newsletter'] = true;
|
||||
// Statistiky
|
||||
$cfg['Modules']['stats'] = true;
|
||||
// Export dat
|
||||
$cfg['Modules']['export'] = true;
|
||||
// Import dat
|
||||
$cfg['Modules']['import'] = true;
|
||||
// Komentáře ke zboží
|
||||
// $cfg['Modules']['products_comments'] = true;
|
||||
// Cenové hladiny zboží
|
||||
$cfg['Modules']['price_levels'] = true;
|
||||
// Články
|
||||
$cfg['Modules']['articles'] = true;
|
||||
// Sekce článků
|
||||
$cfg['Modules']['articles_sections'] = true;
|
||||
// Feed generator
|
||||
$cfg['Modules']['feed_generator'] = true;
|
||||
// Komentáře ke článku
|
||||
// $cfg['Modules']['articles_comments'] = true;
|
||||
// Katalogový Feed
|
||||
$cfg['Modules']['feeds'] = true;
|
||||
// Varianty zboží
|
||||
$cfg['Modules']['products_variations'] = [
|
||||
'variationCode' => true,
|
||||
];
|
||||
// Filtrovani podle kategorii/variant
|
||||
$cfg['Modules']['filter'] = [
|
||||
'totals' => true,
|
||||
'onPage' => [20 => 20, 50 => 50, 100 => 100, 200 => 200, 500 => 500],
|
||||
];
|
||||
$cfg['Modules']['dynamic_filter'] = true;
|
||||
// Automatické importy
|
||||
$cfg['Modules']['automatic_import'] = true;
|
||||
// Dodavatelé produktů/Skladem u dodavatele
|
||||
$cfg['Modules']['products_suppliers'] = [
|
||||
'delivery_time' => -1,
|
||||
];
|
||||
// SEO modul
|
||||
$cfg['Modules']['seo'] = true;
|
||||
// Hlídání produktů které dojdou
|
||||
// $cfg['Modules']['missing_products'] = true;
|
||||
// Dotaz na prodejce
|
||||
// $cfg['Modules']['customer_question'] = true;
|
||||
// Hromadné zpracování objednávek
|
||||
// $cfg['Modules']['orders_mass_process'] = true;
|
||||
// Naskladňovací faktury
|
||||
$cfg['Modules']['stock_in'] = true;
|
||||
// Editace objednávek zákazníkem
|
||||
// $cfg['Modules']['order_edit'] = true;
|
||||
// Platby objednávek
|
||||
$cfg['Modules']['order_payment'] = true;
|
||||
// Slidery
|
||||
$cfg['Modules']['sliders'] = true;
|
||||
// ISIC/ALIVE karty
|
||||
// $cfg['Modules']['isic'] = true;
|
||||
// Vratky
|
||||
// $cfg['Modules']['replacement'] = true;
|
||||
// Sety/Dárky
|
||||
$cfg['Modules']['products_sets'] = [
|
||||
'calculate_price' => true,
|
||||
];
|
||||
// Šablony produktů
|
||||
// $cfg['Modules']['templates'] = true;
|
||||
// Kolekce produktů
|
||||
$cfg['Modules']['products_collections'] = true;
|
||||
// Produkty dodavatelů
|
||||
// $cfg['Modules']['orders_of_suppliers'] = true;
|
||||
// Platebni brany BACHA OSTRA DATA ZKOPIROVANA Z NARADI HORNIG
|
||||
$cfg['Modules']['payments'] = [
|
||||
'ThePay' => [
|
||||
'test' => '1',
|
||||
// 'merchantId' => '457',
|
||||
// 'accountId' => '490',
|
||||
// 'password' => '50973c916453',
|
||||
// 'dataApiPassword' => '0dedd1f91359c4c',
|
||||
],
|
||||
];
|
||||
// Způsoby dopravy
|
||||
$cfg['Modules']['deliveries'] = true;
|
||||
// Google analytics
|
||||
// $cfg['Modules']['google_analytics'] = true;
|
||||
// Heureka ověřené zákazníky
|
||||
// $cfg['Modules']['heureka_overeno'] = true;
|
||||
// Google konverze
|
||||
// $cfg['Modules']['google_conversion'] = true;
|
||||
// Heureka konverze
|
||||
// $cfg['Modules']['heureka_conversion'] = true;
|
||||
// Zbozi.cz
|
||||
// $cfg['Modules']['zbozi_cz_feedback'] = true;
|
||||
// Sklik konverze
|
||||
// $cfg['Modules']['sklik_conversion'] = true;
|
||||
// Zásilkovna
|
||||
// $cfg['Modules']['zasilkovna'] = true;
|
||||
// Fotky k variantám
|
||||
$cfg['Modules']['products_variations_photos'] = true;
|
||||
// Kontaktní formuláře
|
||||
// $cfg['Modules']['forms'] = [];
|
||||
// Inventura
|
||||
// $cfg['Modules']['inventory'] = true;
|
||||
// ReCaptcha
|
||||
// $cfg['Modules']['recaptcha'] = true;
|
||||
// Pokladna
|
||||
// $cfg['Modules']['pos'] = true;
|
||||
// Abra
|
||||
// $cfg['Modules']['abra'] = [
|
||||
// 'server' => 'http://server18.elnino.cz:777/AWS/wsdl/WebEngine', // Official
|
||||
// //'server' => 'http://gw.it-pro.cz:777/AWS/wsdl/WebEngine', // Testing
|
||||
// 'queue' => 'wpj.Q.abra-stock-koza',
|
||||
// //'web' => 'kosmetika-zdravi.cz',
|
||||
// 'web' => null,
|
||||
// ];
|
||||
// Balíkonoš
|
||||
$cfg['Modules']['balikonos'] = true;
|
||||
|
||||
$cfg['Modules']['fulltext_search']['index'] = 'kupshop_kosmetika_zdravi';
|
||||
|
||||
$cfg['Modules']['products_related'] = true;
|
||||
|
||||
// $cfg['Modules']['elnino'] = true;
|
||||
|
||||
$cfg['Modules']['watchdog'] = true;
|
||||
|
||||
$cfg['Modules']['currencies'] = true;
|
||||
$cfg['Modules']['translations'] = true;
|
||||
$cfg['Modules']['symfony'] = true;
|
||||
|
||||
$cfg['Modules']['margins'] = true;
|
||||
|
||||
// Ceníky dopravy
|
||||
$cfg['Modules']['delivery_pricelist'] = true;
|
||||
|
||||
$cfg['Modules']['pricelists'] = true;
|
||||
|
||||
$cfg['Modules']['indexed_filter'] = true;
|
||||
|
||||
$cfg['insert_products_new'] = true;
|
||||
|
||||
$cfg['Modules']['quantity_discount'] = true;
|
||||
|
||||
$cfg['Modules']['bonus_program'] = true;
|
||||
|
||||
$cfg['Modules']['telfa'] = true;
|
||||
$cfg['Modules']['warehouse'] = true;
|
||||
$cfg['Modules']['stores'] = true;
|
||||
$cfg['Modules']['returns'] = true;
|
||||
$cfg['Modules']['reclamations'] = true;
|
||||
$cfg['Modules']['async_emails'] = true;
|
||||
$cfg['Modules']['heureka_cart'] = [
|
||||
'API_ID' => 'API_ID',
|
||||
'test' => '1',
|
||||
];
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI ADRESY ESHOPU
|
||||
* ======================================================================
|
||||
* full: plna cesta k eshopu s http:// domenou a adresarem
|
||||
* print: plna cesta k eshopu bez http - verze k vytisteni
|
||||
* error: soubor s chybovou hlaskou
|
||||
*/
|
||||
$cfg['Addr']['print'] = 'www.kosmetika-zdravi.kupshop.cz/';
|
||||
$cfg['Addr']['full'] = 'http://'.$cfg['Addr']['print'];
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI FTP CESTY K ESHOPU
|
||||
* ======================================================================
|
||||
* eshop_root: cesta v FTP na serveru
|
||||
*
|
||||
* kdyz se pripoji pomoci FTP uctu na kupshop.cz, tak z rootu
|
||||
* je nasledujici cesta
|
||||
*/
|
||||
$cfg['FTP']['use_ftp'] = false;
|
||||
$cfg['FTP']['eshop_root'] = '/';
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI CEST ESHOPU
|
||||
* ======================================================================
|
||||
*/
|
||||
// ## smarty: motiv sablon tahajici se ze sdilene slozky
|
||||
$cfg['Path']['smarty_tpl']['theme'] = 'kupkolo';
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI JMEN TABULEK, KTERE POUZIVA ESHOP
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['DbTablePrefix'] = '';
|
||||
$cfg['DbTable']['photos-products'] = 'photos_products_relation';
|
||||
$cfg['DbTable']['products-related'] = 'products_related';
|
||||
$cfg['DbTable']['products-favorites'] = 'products_favorites';
|
||||
$cfg['DbTable']['products-sections'] = 'products_in_sections';
|
||||
$cfg['DbTable']['photos_articles'] = 'photos_articles_relation';
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI JAZYKA
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['Lang']['language'] = 'cs';
|
||||
|
||||
$cfg['Order'] = [];
|
||||
// $cfg['Order']['Status'] = array();
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI OBJEDNAVEK
|
||||
* ======================================================================
|
||||
* Status: nastaveni stavu objednavek
|
||||
|
||||
*/
|
||||
$cfg['Order']['Status']['global'][0] = 'nová';
|
||||
$cfg['Order']['Status']['global'][1] = 'přenesena';
|
||||
$cfg['Order']['Status']['global'][2] = 'potvrzena';
|
||||
$cfg['Order']['Status']['global'][3] = 'vyřízena';
|
||||
|
||||
$cfg['Order']['Status']['payed'][0] = 'čeká na zaplacení';
|
||||
$cfg['Order']['Status']['payed'][1] = 'zaplaceno';
|
||||
|
||||
$cfg['Order']['Status']['dispatch'][0] = 'čeká na odeslání';
|
||||
$cfg['Order']['Status']['dispatch'][1] = 'částečně odesláno';
|
||||
$cfg['Order']['Status']['dispatch'][2] = 'odesláno';
|
||||
|
||||
$cfg['Order']['Status']['storno'][0] = 'nestornována';
|
||||
$cfg['Order']['Status']['storno'][1] = 'stornována';
|
||||
|
||||
$cfg['Order']['Status']['attach_invoice'] = [];
|
||||
|
||||
$cfg['Order']['hideCode'] = true;
|
||||
$cfg['Order']['prependProducer'] = true;
|
||||
|
||||
// Nastaveni statu
|
||||
// $cfg['Order']['Countries'] = array('Česká Republika' => 'Česká Republika', 'Slovensko'=>'Slovensko');
|
||||
|
||||
// Pridavat na konec objednanyho produktu jeho kod? Napr: Tretry (velikost:modra, kod:ab12345)
|
||||
// $cfg['Order']['hideCode'] = true;
|
||||
|
||||
// Zakazat mazani objednavky v adminu
|
||||
// $cfg['Order']['disableDelete'] = true;
|
||||
|
||||
// ## vygenerovani cisla objednavky
|
||||
// D - den, M - mesic, Y - rok, #ID - poradova cislovka, * - nahodne cislo
|
||||
// [Y,2][M][D]["-"][#ID,6]
|
||||
$cfg['Order']['number']['pattern'] = '["36"][Y,2][#USER_ID]["0"][#USER_ORDER_INDEX]';
|
||||
|
||||
// Nastaveni flagu objednavek
|
||||
$cfg['Order']['Flags'] = [
|
||||
'R' => [
|
||||
'name' => 'Nedořešené',
|
||||
],
|
||||
'H' => [
|
||||
'name' => 'Heureka',
|
||||
],
|
||||
];
|
||||
|
||||
$cfg['Currencies'] = [
|
||||
'CZK' => [
|
||||
'name' => 'Česká koruna',
|
||||
'symbol' => 'Kč',
|
||||
'price_round' => '100',
|
||||
'price_round_direction' => 'math',
|
||||
'countries' => [
|
||||
'CZ',
|
||||
],
|
||||
],
|
||||
'EUR' => [
|
||||
'name' => 'Euro',
|
||||
'symbol' => '€',
|
||||
'price_round' => '0',
|
||||
'price_round_direction' => 'math',
|
||||
'countries' => [
|
||||
'SK',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/*
|
||||
$cfg['Currencies'] = [
|
||||
'CZK' => ['name' => 'Česká koruna',
|
||||
'symbol' => 'Kč'],
|
||||
'EUR' => ['name' => 'Euro',
|
||||
'symbol' => '€' ]
|
||||
];
|
||||
*/
|
||||
|
||||
$cfg['Factorage'] = [];
|
||||
$cfg['Factorage']['Status'] = [];
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI PROVIZI
|
||||
* ======================================================================
|
||||
* Status: nastaveni stavu provize
|
||||
*/
|
||||
$cfg['Factorage']['Status']['payed'][0] = 'neproplaceno';
|
||||
$cfg['Factorage']['Status']['payed'][1] = 'proplaceno';
|
||||
|
||||
$cfg['Products']['DeliveryTime'] = [];
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI ZBOZI V KATALOGU
|
||||
* ======================================================================
|
||||
* DeliveryTime: nastaveni doby doruceni zbozi
|
||||
*/
|
||||
$cfg['Products']['DeliveryTime']['0'] = 'skladem';
|
||||
$cfg['Products']['DeliveryTime']['-1'] = 'na cestě';
|
||||
$cfg['Products']['DeliveryTime']['-2'] = 'na objednávku';
|
||||
$cfg['Products']['DeliveryTime']['1'] = 'dodáváme do %s dnů';
|
||||
|
||||
// Zasunujici se nabidka filtru - melo by byt true kvuli rychlosti.
|
||||
$cfg['Filter']['Collapsable'] = false;
|
||||
|
||||
// Dynamicky zobrazovat pouze dostupny "flagy" u kategorie
|
||||
$cfg['Filter']['flags'] = ['C', 'R', 'N', 'Z', 'A'];
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI OBRAZKU
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['Photo'] = [
|
||||
'default' => [
|
||||
'crop' => false,
|
||||
'background' => 0xFFFFFF,
|
||||
'watermark' => false,
|
||||
'logo' => false,
|
||||
'png' => false,
|
||||
],
|
||||
'types' => [
|
||||
'product_large' => [
|
||||
'size' => [1024, 768],
|
||||
'crop' => false,
|
||||
'watermark' => true,
|
||||
'logo' => true,
|
||||
],
|
||||
'product_catalog' => [
|
||||
'size' => [220, 165],
|
||||
'png' => true,
|
||||
],
|
||||
'product_detail' => [
|
||||
'size' => [485, 371],
|
||||
],
|
||||
'product_gallery' => [
|
||||
'size' => [188, 118],
|
||||
// 'crop' => true,
|
||||
],
|
||||
'admin' => [
|
||||
'size' => [64, 48],
|
||||
],
|
||||
'section' => [
|
||||
'size' => [80, 80],
|
||||
],
|
||||
'producer' => [
|
||||
'size' => [120, 60],
|
||||
],
|
||||
'payment' => [
|
||||
'size' => [30, 30],
|
||||
],
|
||||
'delivery' => [
|
||||
'size' => [110, 40],
|
||||
],
|
||||
'news' => [
|
||||
'size' => [250, 250],
|
||||
],
|
||||
'top_product' => [
|
||||
'size' => [130, 110],
|
||||
],
|
||||
'news_lg' => [
|
||||
'size' => [385, 250],
|
||||
'crop' => true,
|
||||
],
|
||||
'swatch' => [
|
||||
'size' => [60, 60],
|
||||
'crop' => true,
|
||||
],
|
||||
],
|
||||
'id_to_type' => [
|
||||
0 => 'product_large',
|
||||
1 => 'product_gallery',
|
||||
2 => 'product_catalog',
|
||||
3 => 'product_detail',
|
||||
4 => 'product_gallery',
|
||||
5 => 'admin',
|
||||
6 => 'section',
|
||||
7 => 'producer',
|
||||
8 => 'payment',
|
||||
9 => 'delivery',
|
||||
10 => 'news',
|
||||
11 => 'top_product',
|
||||
12 => 'news_lg',
|
||||
13 => 'swatch',
|
||||
],
|
||||
'placeholder' => '/templates/images/no-img.png',
|
||||
'kind' => [
|
||||
'Y' => 'Hlavní',
|
||||
'N' => 'Vedlejší',
|
||||
'O' => 'Odstín',
|
||||
],
|
||||
];
|
||||
|
||||
$cfg['Menu'] = [];
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI VLASTNICH EDITOVATELNYCH MENU ESHOPU
|
||||
* ======================================================================
|
||||
* aktivni moduly.
|
||||
*
|
||||
* Pro zruseni modulu staci radku zakomentovat pomoci //
|
||||
*/
|
||||
|
||||
$cfg['Menu']['own'][1] = [
|
||||
'name' => 'Patička',
|
||||
'title' => 'Patička',
|
||||
'default' => true,
|
||||
];
|
||||
|
||||
$cfg['Menu']['own'][2] = [
|
||||
'name' => 'Menu uživatel',
|
||||
'title' => 'Menu uživatel',
|
||||
'default' => true,
|
||||
];
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI MENU ESHOPU
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['Menu']['main']['default'] = 'sections';
|
||||
$cfg['Menu']['sections'] = [
|
||||
'show' => true,
|
||||
'collapse' => true,
|
||||
'collapse_settings' => [
|
||||
'max_levels' => 0,
|
||||
],
|
||||
];
|
||||
$cfg['Menu']['producers'] = [
|
||||
'show' => true,
|
||||
'collapse' => false,
|
||||
];
|
||||
$cfg['Menu']['inquiry'] = [
|
||||
'show' => true,
|
||||
];
|
||||
$cfg['Menu']['index_product'] = [
|
||||
'limit' => 9,
|
||||
'photos' => 2,
|
||||
];
|
||||
$cfg['Menu']['random_product'] = [
|
||||
'show' => true,
|
||||
'limit' => 4,
|
||||
'photos' => 1,
|
||||
];
|
||||
$cfg['Menu']['bestseller_product'] = [
|
||||
'show' => true,
|
||||
'limit' => 4,
|
||||
'photos' => 1,
|
||||
];
|
||||
$cfg['Menu']['newest_product'] = [
|
||||
'show' => true,
|
||||
'limit' => 4,
|
||||
'photos' => 1,
|
||||
];
|
||||
$cfg['Menu']['cart_info'] = [
|
||||
'show' => true,
|
||||
];
|
||||
|
||||
$cfg['Menu']['last_visited'] = [
|
||||
'limit' => 6,
|
||||
'photos' => 2,
|
||||
];
|
||||
|
||||
$cfg['Menu']['related'] = [
|
||||
'limit' => 8,
|
||||
'photos' => 2,
|
||||
];
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI ADMINISTRACE ESHOPU
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['Admin']['Login']['User'] = '_KS_ADMIN';
|
||||
$cfg['Admin']['Login']['Password'] = 'ksadmin21';
|
||||
$cfg['Admin']['Login']['Timeout'] = (int) 7200; // 60 = 1 minuta
|
||||
$cfg['Admin']['settings'] = [
|
||||
'email' => 'helpdesk@kupshop.cz',
|
||||
'id' => 0,
|
||||
'privilege' => '',
|
||||
];
|
||||
|
||||
// # NASTAVENI SSL V ADMINISTRACI
|
||||
// zda ma byt v administraci moznost zvolit SSL pripojeni
|
||||
$cfg['Admin']['SSL']['support'] = false;
|
||||
// zda ma byt administrace automaticky presmerovana na SSL
|
||||
$cfg['Admin']['SSL']['automaticRedirection'] = false;
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* NASTAVENI MOD_REWRITE PRO SEO FRIENDLY ODKAZY
|
||||
* ======================================================================
|
||||
*/
|
||||
$cfg['Mod_rewrite'] = true;
|
||||
|
||||
$cfg['Products']['Flags'] = [
|
||||
'N' => ['plural' => 'Novinky', 'singular' => 'Novinka', 'url' => 'novinky', 'short' => 'N', 'order' => -4],
|
||||
'A' => ['plural' => 'Akce', 'singular' => 'Akce', 'url' => 'akce', 'short' => 'A', 'order' => -6],
|
||||
'C' => ['plural' => 'Na cestě', 'singular' => 'Na cestě', 'url' => 'na-ceste', 'short' => 'C', 'order' => -6],
|
||||
'R' => ['plural' => 'Opět skladem', 'singular' => 'Opět skladem', 'url' => 'opet-skladem', 'short' => 'R', 'order' => -6],
|
||||
'T' => ['plural' => 'Testery', 'singular' => 'Tester', 'url' => 'testery', 'short' => 'T', 'order' => -6],
|
||||
'S' => ['plural' => 'Sety', 'singular' => 'Set', 'url' => 'sety', 'short' => 'S', 'order' => -6],
|
||||
'Z' => ['plural' => 'Zlevněno', 'singular' => 'Zlevněno', 'url' => 'zlevneno', 'short' => 'Z', 'order' => -6],
|
||||
'V' => ['plural' => 'Vzorek', 'singular' => 'Vzorek', 'url' => 'vzorky', 'short' => 'V', 'order' => -6],
|
||||
'O' => ['plural' => 'Odstřik', 'singular' => 'Odstřik', 'url' => 'odstrik', 'short' => 'O', 'order' => -6],
|
||||
];
|
||||
|
||||
$cfg['Sections']['Flags'] = [
|
||||
'A' => ['plural' => 'Kategorie s akčním zbožím'],
|
||||
'L' => ['plural' => 'Pro lamy'],
|
||||
];
|
||||
|
||||
$cfg['captcha']['size'] = 40;
|
||||
|
||||
require_once dirname(__FILE__).'/../../../config_db.php';
|
||||
Reference in New Issue
Block a user