193 lines
6.0 KiB
PHP
193 lines
6.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\GTMBundle\Tests;
|
|
|
|
use KupShop\CatalogBundle\ProductList\ProductListBanners;
|
|
use KupShop\CatalogBundle\View\CategoryView;
|
|
use KupShop\ContentBundle\Util\SliderUtil;
|
|
use KupShop\DevelopmentBundle\Util\Tests\RequestSessionTrait;
|
|
use KupShop\GTMBundle\Utils\GTMLoader;
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
|
|
class GTMPromotionsTest extends \DatabaseTestCase
|
|
{
|
|
use GTMTestHelper;
|
|
use RequestSessionTrait;
|
|
|
|
/**
|
|
* @dataProvider provideGTMFrontendData
|
|
*/
|
|
public function testFilter(string $type, array $data, string|array $result): void
|
|
{
|
|
$this->insertSQL('sliders_in_sections', ['id_section' => 1, 'position' => 'main', 'id_slider' => 1]);
|
|
$this->prepareRequestStackSession();
|
|
$banners = $this->get(ProductListBanners::class);
|
|
$requestStack = $this->get(RequestStack::class);
|
|
$request = $requestStack->getMainRequest();
|
|
|
|
$request->server->set('REQUEST_URI', '/');
|
|
$request->cookies->set('userlogin', '123');
|
|
$request->cookies->set('PHPSESSID', '12356');
|
|
|
|
$homeView = $this->get(CategoryView::class);
|
|
$homeView->setCategoryId(1);
|
|
|
|
if ($data !== []) {
|
|
$banners->setStepSize(3)
|
|
->setCount(1)
|
|
->setSliderId(1)
|
|
->setSeedFromFilterParams(new \FilterParams())
|
|
->attach($homeView->productList, new \Pager(1, 1));
|
|
}
|
|
|
|
$homeView->getResponse();
|
|
$gtm = $this->get(GTMLoader::class);
|
|
$data = $gtm->getData($homeView);
|
|
$sliderUtil = $this->get(SliderUtil::class);
|
|
$data['slider'] = $sliderUtil->get(1);
|
|
|
|
$data = $gtm->getEcommerceData($type, $data, $homeView);
|
|
$this->assertEquals(
|
|
$result,
|
|
$this->recursivelyChangeType($data)
|
|
);
|
|
}
|
|
|
|
public function provideGTMFrontendData(): \Generator
|
|
{
|
|
yield 'Default position' => [
|
|
'type' => 'PromotionImpression',
|
|
'data' => [
|
|
'position' => 1,
|
|
],
|
|
'result' => [
|
|
'event' => 'promotionView',
|
|
'_clear' => true,
|
|
'promotions' => [
|
|
0 => [
|
|
'id' => 1,
|
|
'name' => 'Banner 1',
|
|
'creative' => 'Úvod',
|
|
'position' => 1,
|
|
'positionCatalog' => 2,
|
|
],
|
|
[
|
|
'id' => 2,
|
|
'name' => 'Banner 2',
|
|
'creative' => 'Úvod',
|
|
'position' => 2,
|
|
'positionCatalog' => 2,
|
|
],
|
|
],
|
|
],
|
|
];
|
|
|
|
yield 'Out of default position' => [
|
|
'type' => 'PromotionImpression',
|
|
'data' => [
|
|
'position' => 2,
|
|
],
|
|
'result' => [
|
|
'event' => 'promotionView',
|
|
'_clear' => true,
|
|
'promotions' => [
|
|
0 => [
|
|
'id' => 1,
|
|
'name' => 'Banner 1',
|
|
'creative' => 'Úvod',
|
|
'position' => 1,
|
|
'positionCatalog' => 2,
|
|
],
|
|
[
|
|
'id' => 2,
|
|
'name' => 'Banner 2',
|
|
'creative' => 'Úvod',
|
|
'position' => 2,
|
|
'positionCatalog' => 2,
|
|
],
|
|
],
|
|
],
|
|
];
|
|
|
|
yield 'Two banners' => [
|
|
'type' => 'PromotionImpression',
|
|
'data' => [
|
|
'position' => 2,
|
|
],
|
|
'result' => [
|
|
'event' => 'promotionView',
|
|
'_clear' => true,
|
|
'promotions' => [
|
|
0 => [
|
|
'id' => 1,
|
|
'name' => 'Banner 1',
|
|
'creative' => 'Úvod',
|
|
'position' => 1,
|
|
'positionCatalog' => 2,
|
|
],
|
|
[
|
|
'id' => 2,
|
|
'name' => 'Banner 2',
|
|
'creative' => 'Úvod',
|
|
'position' => 2,
|
|
'positionCatalog' => 2,
|
|
],
|
|
],
|
|
],
|
|
];
|
|
|
|
yield 'No banner' => [
|
|
'type' => 'PromotionImpression',
|
|
'data' => [],
|
|
'result' => [
|
|
'event' => 'promotionView',
|
|
'_clear' => true,
|
|
'promotions' => [
|
|
0 => [
|
|
'id' => 1,
|
|
'name' => 'Banner 1',
|
|
'creative' => 'Úvod',
|
|
'position' => 1,
|
|
],
|
|
[
|
|
'id' => 2,
|
|
'name' => 'Banner 2',
|
|
'creative' => 'Úvod',
|
|
'position' => 2,
|
|
],
|
|
],
|
|
],
|
|
];
|
|
|
|
yield 'click!' => [
|
|
'type' => 'PromotionClick',
|
|
'data' => [
|
|
'position' => 1,
|
|
'positionCatalog' => 3,
|
|
],
|
|
'result' => [
|
|
'event' => 'promotionClick',
|
|
'_clear' => true,
|
|
'promotions' => [
|
|
0 => [
|
|
'id' => 1,
|
|
'name' => 'Banner 1',
|
|
'creative' => 'Úvod',
|
|
'position' => 1,
|
|
'positionCatalog' => 2,
|
|
],
|
|
[
|
|
'id' => 2,
|
|
'name' => 'Banner 2',
|
|
'creative' => 'Úvod',
|
|
'position' => 2,
|
|
'positionCatalog' => 2,
|
|
],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
}
|