first commit
This commit is contained in:
403
bundles/KupShop/GTMOldBundle/Tests/GTMEcommerceTest.php
Normal file
403
bundles/KupShop/GTMOldBundle/Tests/GTMEcommerceTest.php
Normal file
@@ -0,0 +1,403 @@
|
||||
<?php
|
||||
|
||||
namespace KupShop\GTMOldBundle\Tests;
|
||||
|
||||
use KupShop\ContentBundle\View\CartView;
|
||||
use KupShop\ContentBundle\View\OrderView;
|
||||
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
||||
use KupShop\GTMOldBundle\Utils\GTMLoader;
|
||||
use KupShop\KupShopBundle\Context\CurrencyContext;
|
||||
use Query\Operator;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class GTMEcommerceTest extends \DatabaseTestCase
|
||||
{
|
||||
use CartTestTrait;
|
||||
use GTMTestHelper;
|
||||
|
||||
public function testCheckout()
|
||||
{
|
||||
$this->prepareCart();
|
||||
$this->insertProduct(10, null, 1);
|
||||
$this->visitStep('summary');
|
||||
$this->cart->max_step = 3;
|
||||
$this->saveCart();
|
||||
|
||||
$cartView = $this->get(CartView::class);
|
||||
$cartView->setRequest(new Request());
|
||||
$cartView->setStepName('user');
|
||||
$cart = $cartView->getBodyVariables();
|
||||
|
||||
/** @var GTMLoader $gtm */
|
||||
$gtm = $this->get(GTMLoader::class);
|
||||
$data = $gtm->getEcommerceData('Checkout', ['body' => $cart]);
|
||||
|
||||
$exp_res = [
|
||||
'event' => 'checkout',
|
||||
'cart' => [],
|
||||
'discounts' => [],
|
||||
'ecommerce' => [
|
||||
'checkout' => [
|
||||
'actionField' => [
|
||||
'step' => 3,
|
||||
],
|
||||
'products' => [
|
||||
[
|
||||
'name' => 'Black and Decker Core EGBL108K aku vrtačka',
|
||||
'id' => '10',
|
||||
'price' => '1609',
|
||||
'brand' => 'Black & Decker',
|
||||
'category' => 'Aku vrtačky',
|
||||
'variant' => '',
|
||||
'quantity' => '1',
|
||||
'dimension14' => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($exp_res, $this->recursivelyChangeType($data));
|
||||
}
|
||||
|
||||
public function testCheckoutWithoutVat()
|
||||
{
|
||||
\Settings::getDefault()->saveValue('analytics', ['google_tag_manager' => ['withoutVAT' => 'Y']]);
|
||||
\Settings::getDefault()->updateValue('analytics', ['google_tag_manager' => ['withoutVAT' => 'Y']]);
|
||||
|
||||
$this->prepareCart();
|
||||
$this->insertProduct(10, null, 1);
|
||||
$this->visitStep('summary');
|
||||
$this->saveCart();
|
||||
|
||||
$cartView = $this->get(CartView::class);
|
||||
$cartView->setRequest(new Request());
|
||||
$cartView->setStepName('user');
|
||||
$cart = $cartView->getBodyVariables();
|
||||
|
||||
/** @var GTMLoader $gtm */
|
||||
$gtm = $this->get(GTMLoader::class);
|
||||
$data = $gtm->getEcommerceData('Checkout', ['body' => $cart]);
|
||||
|
||||
$exp_res = [
|
||||
'event' => 'checkout',
|
||||
'cart' => [],
|
||||
'discounts' => [],
|
||||
'ecommerce' => [
|
||||
'checkout' => [
|
||||
'actionField' => [
|
||||
'step' => 3,
|
||||
],
|
||||
'products' => [
|
||||
[
|
||||
'name' => 'Black and Decker Core EGBL108K aku vrtačka',
|
||||
'id' => '10',
|
||||
'price' => '1399.13',
|
||||
'brand' => 'Black & Decker',
|
||||
'category' => 'Aku vrtačky',
|
||||
'variant' => '',
|
||||
'quantity' => '1',
|
||||
'dimension14' => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($exp_res, $this->recursivelyChangeType($data));
|
||||
}
|
||||
|
||||
public function testPurchase()
|
||||
{
|
||||
$this->prepareCart();
|
||||
$this->insertProduct(10, null, 1);
|
||||
$this->insertProduct(11, 20, 1);
|
||||
$this->cart->max_step = 3;
|
||||
$this->saveCart();
|
||||
|
||||
$this->checkOrderPriceIsSameAsCart();
|
||||
|
||||
$orderView = $this->get(OrderView::class);
|
||||
$orderView->setIDo($this->order->id);
|
||||
$data = $orderView->getBodyVariables();
|
||||
|
||||
$gtm = $this->get(GTMLoader::class);
|
||||
$data = $gtm->getEcommerceData('Purchase', ['body' => $data]);
|
||||
|
||||
$exp_res = [
|
||||
'event' => 'order_success',
|
||||
'ecommerce' => [
|
||||
'purchase' => [
|
||||
'actionField' => [
|
||||
'id' => $this->order->order_no,
|
||||
'affiliation' => 'Osobní odběr - Hotovost',
|
||||
'revenue' => '1709',
|
||||
'tax' => '227',
|
||||
'shipping' => '0',
|
||||
'coupon' => '',
|
||||
],
|
||||
'products' => [
|
||||
[
|
||||
'name' => 'Black and Decker Core EGBL108K aku vrtačka',
|
||||
'id' => '10',
|
||||
'price' => '1609',
|
||||
'brand' => 'Black & Decker',
|
||||
'category' => 'Aku vrtačky',
|
||||
'variant' => '',
|
||||
'quantity' => '1',
|
||||
'id_variation' => '',
|
||||
'id_product' => '10',
|
||||
'ean' => '',
|
||||
],
|
||||
[
|
||||
'name' => 'iPhone wpj',
|
||||
'id' => '11_20',
|
||||
'price' => '100',
|
||||
'brand' => 'wpj',
|
||||
'category' => 'Aku baterie',
|
||||
'variant' => 'Velikost: 41',
|
||||
'quantity' => '1',
|
||||
'id_variation' => '20',
|
||||
'id_product' => '11',
|
||||
'ean' => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'discounts' => [],
|
||||
'transactionPriceWithoutVatAndDelivery' => '1482',
|
||||
'transactionId' => $this->order->order_no,
|
||||
'transactionAffiliation' => 'Demo Kupshop.cz',
|
||||
'transactionCurrency' => 'CZK',
|
||||
'transactionTotal' => '1709',
|
||||
'transactionTax' => '227',
|
||||
'transactionShipping' => '0',
|
||||
'transactionFlags' => [],
|
||||
'transactionProducts' => [
|
||||
['name' => 'Black and Decker Core EGBL108K aku vrtačka',
|
||||
'sku' => '10',
|
||||
'category' => 'Aku vrtačky',
|
||||
'categoryid' => '3',
|
||||
'price' => '1609',
|
||||
'quantity' => '1',
|
||||
],
|
||||
['name' => 'iPhone wpj',
|
||||
'sku' => '11_20',
|
||||
'category' => 'Aku baterie',
|
||||
'categoryid' => '2',
|
||||
'price' => '100',
|
||||
'quantity' => '1',
|
||||
],
|
||||
],
|
||||
'user' => [
|
||||
'name' => 'Wpj',
|
||||
'surname' => 'Wpj',
|
||||
'email' => 'test@wpj.cz',
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($exp_res, $this->recursivelyChangeType($data));
|
||||
}
|
||||
|
||||
public function testPurchaseWithoutVat()
|
||||
{
|
||||
\Settings::getDefault()->saveValue('analytics', ['google_tag_manager' => ['withoutVAT' => 'Y']]);
|
||||
\Settings::getDefault()->updateValue('analytics', ['google_tag_manager' => ['withoutVAT' => 'Y']]);
|
||||
|
||||
$this->prepareCart();
|
||||
$this->insertProduct(10, null, 1);
|
||||
$this->insertProduct(11, 20, 1);
|
||||
$this->visitStep('summary');
|
||||
$this->saveCart();
|
||||
|
||||
$this->checkOrderPriceIsSameAsCart();
|
||||
|
||||
$orderView = $this->get(OrderView::class);
|
||||
$orderView->setIDo($this->order->id);
|
||||
$data = $orderView->getBodyVariables();
|
||||
|
||||
$gtm = $this->get(GTMLoader::class);
|
||||
$data = $gtm->getEcommerceData('Purchase', ['body' => $data]);
|
||||
|
||||
$exp_res = [
|
||||
'transactionPriceWithoutVatAndDelivery' => '1482',
|
||||
'discounts' => [],
|
||||
'transactionId' => $this->order->order_no,
|
||||
'transactionAffiliation' => 'Demo Kupshop.cz',
|
||||
'transactionCurrency' => 'CZK',
|
||||
'transactionTotal' => '1482',
|
||||
'transactionTax' => '227',
|
||||
'transactionShipping' => '0',
|
||||
'transactionFlags' => [],
|
||||
'transactionProducts' => [
|
||||
['name' => 'Black and Decker Core EGBL108K aku vrtačka',
|
||||
'sku' => '10',
|
||||
'category' => 'Aku vrtačky',
|
||||
'categoryid' => '3',
|
||||
'price' => '1399.13',
|
||||
'quantity' => '1',
|
||||
],
|
||||
['name' => 'iPhone wpj',
|
||||
'sku' => '11_20',
|
||||
'category' => 'Aku baterie',
|
||||
'categoryid' => '2',
|
||||
'price' => '82.64',
|
||||
'quantity' => '1',
|
||||
],
|
||||
],
|
||||
'event' => 'order_success',
|
||||
'ecommerce' => [
|
||||
'purchase' => [
|
||||
'actionField' => [
|
||||
'id' => $this->order->order_no,
|
||||
'affiliation' => 'Osobní odběr - Hotovost',
|
||||
'revenue' => '1482',
|
||||
'tax' => '227',
|
||||
'shipping' => '0',
|
||||
'coupon' => '',
|
||||
],
|
||||
'products' => [
|
||||
[
|
||||
'name' => 'Black and Decker Core EGBL108K aku vrtačka',
|
||||
'id' => '10',
|
||||
'price' => '1399.13',
|
||||
'brand' => 'Black & Decker',
|
||||
'category' => 'Aku vrtačky',
|
||||
'variant' => '',
|
||||
'quantity' => '1',
|
||||
'id_variation' => '',
|
||||
'id_product' => '10',
|
||||
'ean' => '',
|
||||
],
|
||||
[
|
||||
'name' => 'iPhone wpj',
|
||||
'id' => '11_20',
|
||||
'price' => '82.64',
|
||||
'brand' => 'wpj',
|
||||
'category' => 'Aku baterie',
|
||||
'variant' => 'Velikost: 41',
|
||||
'quantity' => '1',
|
||||
'id_variation' => '20',
|
||||
'id_product' => '11',
|
||||
'ean' => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'user' => [
|
||||
'name' => 'Wpj',
|
||||
'surname' => 'Wpj',
|
||||
'email' => 'test@wpj.cz',
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($exp_res, $this->recursivelyChangeType($data));
|
||||
}
|
||||
|
||||
public function testConvertedPrices()
|
||||
{
|
||||
\Settings::getDefault()->saveValue('analytics', [
|
||||
'google_tag_manager' => ['withoutVAT' => 'Y',
|
||||
'currency' => 'EUR', ],
|
||||
]);
|
||||
\Settings::getDefault()->updateValue('analytics', [
|
||||
'google_tag_manager' => ['withoutVAT' => 'Y',
|
||||
'currency' => 'EUR', ],
|
||||
]);
|
||||
|
||||
$currencyContext = $this->get(CurrencyContext::class);
|
||||
$currencyContext->activate('CZK');
|
||||
|
||||
sqlQueryBuilder()->update('products')->set('campaign', 'NULL')->where(Operator::inIntArray([11, 10], 'id'))->execute();
|
||||
|
||||
$this->prepareCart();
|
||||
$this->insertProduct(10, null, 1);
|
||||
$this->insertProduct(11, 20, 1);
|
||||
$this->setDeliveryType(2);
|
||||
$this->visitStep('summary');
|
||||
$this->saveCart();
|
||||
|
||||
$this->checkOrderPriceIsSameAsCart();
|
||||
|
||||
$orderView = $this->get(OrderView::class);
|
||||
$orderView->setIDo($this->order->id);
|
||||
$data = $orderView->getBodyVariables();
|
||||
|
||||
$gtm = $this->get(GTMLoader::class);
|
||||
$data = $gtm->getEcommerceData('Purchase', ['body' => $data]);
|
||||
|
||||
$exp_res = [
|
||||
'transactionPriceWithoutVatAndDelivery' => '57',
|
||||
'discounts' => [],
|
||||
'transactionId' => $this->order->order_no,
|
||||
'transactionAffiliation' => 'Demo Kupshop.cz',
|
||||
'transactionCurrency' => 'CZK',
|
||||
'transactionTotal' => '59.2',
|
||||
'transactionTax' => '9.2',
|
||||
'transactionShipping' => '2.7',
|
||||
'transactionFlags' => [],
|
||||
'transactionProducts' => [
|
||||
['name' => 'Black and Decker Core EGBL108K aku vrtačka',
|
||||
'sku' => '10',
|
||||
'category' => 'Aku vrtačky',
|
||||
'categoryid' => '3',
|
||||
'price' => '53.83',
|
||||
'quantity' => '1',
|
||||
],
|
||||
['name' => 'iPhone wpj',
|
||||
'sku' => '11_20',
|
||||
'category' => 'Aku baterie',
|
||||
'categoryid' => '2',
|
||||
'price' => '3.18',
|
||||
'quantity' => '1',
|
||||
],
|
||||
],
|
||||
'event' => 'order_success',
|
||||
'ecommerce' => [
|
||||
'purchase' => [
|
||||
'actionField' => [
|
||||
'id' => $this->order->order_no,
|
||||
'affiliation' => 'Česká pošta - Balík do ruky - Dobirka',
|
||||
'revenue' => '59.2',
|
||||
'tax' => '9.2',
|
||||
'shipping' => '2.7',
|
||||
'coupon' => '',
|
||||
],
|
||||
'products' => [
|
||||
[
|
||||
'name' => 'Black and Decker Core EGBL108K aku vrtačka',
|
||||
'id' => '10',
|
||||
'price' => '53.83',
|
||||
'brand' => 'Black & Decker',
|
||||
'category' => 'Aku vrtačky',
|
||||
'variant' => '',
|
||||
'quantity' => '1',
|
||||
'id_variation' => '',
|
||||
'id_product' => '10',
|
||||
'ean' => '',
|
||||
],
|
||||
[
|
||||
'name' => 'iPhone wpj',
|
||||
'id' => '11_20',
|
||||
'price' => '3.18',
|
||||
'brand' => 'wpj',
|
||||
'category' => 'Aku baterie',
|
||||
'variant' => 'Velikost: 41',
|
||||
'quantity' => '1',
|
||||
'id_variation' => '20',
|
||||
'id_product' => '11',
|
||||
'ean' => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'user' => [
|
||||
'name' => 'Wpj',
|
||||
'surname' => 'Wpj',
|
||||
'email' => 'test@wpj.cz',
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($exp_res, $this->recursivelyChangeType($data));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user