first commit

This commit is contained in:
2024-10-28 22:14:22 +01:00
commit b65352c452
40581 changed files with 5712079 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
<?php
namespace PrestaShop\Module\PsEventbus\Tests\System\Tests\Synchronization;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Provider\CarrierDataProvider;
use PrestaShop\Module\PsEventbus\Provider\CartDataProvider;
use PrestaShop\Module\PsEventbus\Provider\CategoryDataProvider;
use PrestaShop\Module\PsEventbus\Provider\CustomPriceDataProvider;
use PrestaShop\Module\PsEventbus\Provider\CustomProductCarrierDataProvider;
use PrestaShop\Module\PsEventbus\Provider\ModuleDataProvider;
use PrestaShop\Module\PsEventbus\Provider\OrderDataProvider;
use PrestaShop\Module\PsEventbus\Provider\PaginatedApiDataProviderInterface;
use PrestaShop\Module\PsEventbus\Provider\ProductDataProvider;
use PrestaShop\Module\PsEventbus\Service\SynchronizationService;
use PrestaShop\Module\PsEventbus\Tests\System\Tests\BaseTestCase;
use Product;
use Yandex\Allure\Adapter\Annotation\Features;
use Yandex\Allure\Adapter\Annotation\Stories;
use Yandex\Allure\Adapter\Annotation\Title;
use Yandex\Allure\Adapter\Support\StepSupport;
/**
* @Features("synchronization")
* @Stories("full synchronization")
*/
class FullSynchronizationTest extends BaseTestCase
{
use StepSupport;
public function setUp(): void
{
parent::setUp();
$product = new Product(1);
$product->setCarriers([1, 2]);
}
/**
* @Stories("full synchronization")
* @Title("testFullSync")
*/
public function testFullSync()
{
$this->executeStep('apiCarriers', function () {
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(CarrierDataProvider::class);
$this->handle($provider, Config::COLLECTION_CARRIERS);
});
$this->executeStep('apiCarts', function () {
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(CartDataProvider::class);
$this->handle($provider, Config::COLLECTION_CARTS);
});
$this->executeStep('apiCategories', function () {
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(CategoryDataProvider::class);
$this->handle($provider, Config::COLLECTION_CATEGORIES);
});
$this->executeStep('apiModules', function () {
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(ModuleDataProvider::class);
$this->handle($provider, Config::COLLECTION_MODULES);
});
$this->executeStep('apiOrders', function () {
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(OrderDataProvider::class);
$this->handle($provider, Config::COLLECTION_ORDERS);
});
$this->executeStep('apiProducts', function () {
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(ProductDataProvider::class);
$this->handle($provider, Config::COLLECTION_PRODUCTS);
});
$this->executeStep('apiSpecificPrices', function () {
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(CustomPriceDataProvider::class);
$this->handle($provider, Config::COLLECTION_PRODUCTS);
});
$this->executeStep('apiCustomProductCarriers', function () {
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(CustomProductCarrierDataProvider::class);
$this->handle($provider, Config::COLLECTION_CUSTOM_PRODUCT_CARRIERS);
});
}
private function handle(PaginatedApiDataProviderInterface $dataProvider, $type)
{
/** @var SynchronizationService $syncService */
$syncService = $this->container->getService(SynchronizationService::class);
$response = $syncService->handleFullSync(
$dataProvider,
$type,
'test',
'en',
0,
200,
'2021-10-10T10:10:10',
'2021-11-11T11:11:11',
false
);
$this->assertEquals(201, $response['httpCode']);
}
}

View File

@@ -0,0 +1,143 @@
<?php
namespace PrestaShop\Module\PsEventbus\Tests\System\Tests\Synchronization;
use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShop\Module\PsEventbus\Provider\CarrierDataProvider;
use PrestaShop\Module\PsEventbus\Provider\CartDataProvider;
use PrestaShop\Module\PsEventbus\Provider\CategoryDataProvider;
use PrestaShop\Module\PsEventbus\Provider\CustomPriceDataProvider;
use PrestaShop\Module\PsEventbus\Provider\CustomProductCarrierDataProvider;
use PrestaShop\Module\PsEventbus\Provider\ModuleDataProvider;
use PrestaShop\Module\PsEventbus\Provider\OrderDataProvider;
use PrestaShop\Module\PsEventbus\Provider\PaginatedApiDataProviderInterface;
use PrestaShop\Module\PsEventbus\Provider\ProductDataProvider;
use PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository;
use PrestaShop\Module\PsEventbus\Repository\IncrementalSyncRepository;
use PrestaShop\Module\PsEventbus\Service\SynchronizationService;
use PrestaShop\Module\PsEventbus\Tests\System\Tests\BaseTestCase;
use Product;
use Yandex\Allure\Adapter\Annotation\Features;
use Yandex\Allure\Adapter\Annotation\Stories;
use Yandex\Allure\Adapter\Annotation\Title;
use Yandex\Allure\Adapter\Support\StepSupport;
/**
* @Features("synchronization")
* @Stories("incremental synchronization")
*/
class IncrementalSynchronizationTest extends BaseTestCase
{
use StepSupport;
/**
* @var EventbusSyncRepository
*/
private $syncRepository;
public function setUp(): void
{
parent::setUp();
$product = new Product(1);
$product->setCarriers([1, 2]);
/* @var EventbusSyncRepository $syncRepository */
$this->syncRepository = $this->container->getService(EventbusSyncRepository::class);
}
/**
* @Stories("incremental synchronization")
* @Title("testIncrementalSync")
*/
public function testIncrementalSync()
{
/** @var IncrementalSyncRepository $incrementalSyncRepository */
$incrementalSyncRepository = $this->container->getService(IncrementalSyncRepository::class);
$this->executeStep('apiCarriers', function () use ($incrementalSyncRepository) {
$this->syncRepository->insertTypeSync(Config::COLLECTION_CARRIERS, 0, date(DATE_ATOM), 'en');
$incrementalSyncRepository->insertIncrementalObject(1, Config::COLLECTION_CARRIERS, date(DATE_ATOM), 1, 'en');
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(CarrierDataProvider::class);
$this->handle($provider, Config::COLLECTION_CARRIERS);
});
$this->executeStep('apiCarts', function () use ($incrementalSyncRepository) {
$this->syncRepository->insertTypeSync(Config::COLLECTION_CARTS, 0, date(DATE_ATOM), 'en');
$incrementalSyncRepository->insertIncrementalObject(1, Config::COLLECTION_CARTS, date(DATE_ATOM), 1, 'en');
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(CartDataProvider::class);
$this->handle($provider, Config::COLLECTION_CARTS);
});
$this->executeStep('apiCategories', function () use ($incrementalSyncRepository) {
$this->syncRepository->insertTypeSync(Config::COLLECTION_CATEGORIES, 0, date(DATE_ATOM), 'en');
$incrementalSyncRepository->insertIncrementalObject(1, Config::COLLECTION_CATEGORIES, date(DATE_ATOM), 1, 'en');
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(CategoryDataProvider::class);
$this->handle($provider, Config::COLLECTION_CATEGORIES);
});
$this->executeStep('apiModules', function () use ($incrementalSyncRepository) {
$this->syncRepository->insertTypeSync(Config::COLLECTION_MODULES, 0, date(DATE_ATOM), 'en');
$incrementalSyncRepository->insertIncrementalObject(1, Config::COLLECTION_MODULES, date(DATE_ATOM), 1, 'en');
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(ModuleDataProvider::class);
$this->handle($provider, Config::COLLECTION_MODULES, false);
});
$this->executeStep('apiOrders', function () use ($incrementalSyncRepository) {
$this->syncRepository->insertTypeSync(Config::COLLECTION_ORDERS, 0, date(DATE_ATOM), 'en');
$incrementalSyncRepository->insertIncrementalObject(1, Config::COLLECTION_ORDERS, date(DATE_ATOM), 1, 'en');
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(OrderDataProvider::class);
$this->handle($provider, Config::COLLECTION_ORDERS);
});
$this->executeStep('apiProducts', function () use ($incrementalSyncRepository) {
$this->syncRepository->insertTypeSync(Config::COLLECTION_PRODUCTS, 0, date(DATE_ATOM), 'en');
$incrementalSyncRepository->insertIncrementalObject(1, Config::COLLECTION_PRODUCTS, date(DATE_ATOM), 1, 'en');
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(ProductDataProvider::class);
$this->handle($provider, Config::COLLECTION_PRODUCTS);
});
$this->executeStep('apiSpecificPrices', function () use ($incrementalSyncRepository) {
$this->syncRepository->insertTypeSync(Config::COLLECTION_PRODUCTS, 0, date(DATE_ATOM), 'en');
$incrementalSyncRepository->insertIncrementalObject(1, Config::COLLECTION_PRODUCTS, date(DATE_ATOM), 1, 'en');
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(CustomPriceDataProvider::class);
$this->handle($provider, Config::COLLECTION_PRODUCTS);
});
$this->executeStep('apiCustomProductCarriers', function () use ($incrementalSyncRepository) {
$this->syncRepository->insertTypeSync(Config::COLLECTION_CUSTOM_PRODUCT_CARRIERS, 0, date(DATE_ATOM), 'en');
$incrementalSyncRepository->insertIncrementalObject(1, Config::COLLECTION_CUSTOM_PRODUCT_CARRIERS, date(DATE_ATOM), 1, 'en');
/** @var PaginatedApiDataProviderInterface $provider */
$provider = $this->container->getService(CustomProductCarrierDataProvider::class);
$this->handle($provider, Config::COLLECTION_CUSTOM_PRODUCT_CARRIERS);
});
}
private function handle(PaginatedApiDataProviderInterface $dataProvider, $type, $hasRemainingObject = true)
{
/** @var SynchronizationService $syncService */
$syncService = $this->container->getService(SynchronizationService::class);
$response = $syncService->handleIncrementalSync(
$dataProvider,
$type,
'test',
50,
'en',
'2021-10-10T10:10:10',
false
);
if ($hasRemainingObject) {
$this->assertEquals(201, $response['httpCode']);
return;
}
$this->assertEquals(0, $response['total_objects']);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2020 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;