first commit
This commit is contained in:
28
modules/ps_eventbus/tests/index.php
Normal file
28
modules/ps_eventbus/tests/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (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:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* 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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (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;
|
||||
28
modules/ps_eventbus/tests/phpstan/index.php
Normal file
28
modules/ps_eventbus/tests/phpstan/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (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:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* 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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (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;
|
||||
32
modules/ps_eventbus/tests/phpstan/phpstan-PS-1.6.neon
Normal file
32
modules/ps_eventbus/tests/phpstan/phpstan-PS-1.6.neon
Normal file
@@ -0,0 +1,32 @@
|
||||
includes:
|
||||
- %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon
|
||||
parameters:
|
||||
checkMissingIterableValueType: false
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
paths:
|
||||
- ../../src
|
||||
- ../../controllers
|
||||
- ../../ps_eventbus.php
|
||||
dynamicConstantNames:
|
||||
- _PS_VERSION_
|
||||
ignoreErrors:
|
||||
- '#Property TabCore::\$name \(string\) does not accept array.#'
|
||||
- '#Parameter \#1 \$value of method ControllerCore::ajaxDie\(\) expects string\|null, string\|false given.#'
|
||||
- '#Parameter \#4 \$ssl of method LinkCore::getModuleLink\(\) expects null, true given.#'
|
||||
- '#Parameter \#6 \$idShop of method LinkCore::getModuleLink\(\) expects null, int given.#'
|
||||
- '#Parameter \#1 \$json of function json_decode expects string, string\|false given.#'
|
||||
- '#Parameter \#2 \$message of method PrestaShop\\Module\\PsEventbus\\WebHook\\Validator::getError\(\) expects string, string\|false given.#'
|
||||
- '#Parameter \#1 \$hook_name of method ModuleCore::registerHook\(\) expects string, array given.#'
|
||||
- '#Access to an undefined property AdminController\|FrontController::\$controller_name.#'
|
||||
- '#Call to static method getAvailable\(\) on an unknown class Theme.#'
|
||||
- '#Call to static method getByDirectory\(\) on an unknown class Theme.#'
|
||||
- '#Call to static method getThemeInfo\(\) on an unknown class Theme.#'
|
||||
- '#Access to an undefined property Context::\$theme.#'
|
||||
- '#Access to an undefined property Shop::\$theme.#'
|
||||
- '#Call to method buildRepository\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Addon\\Theme\\ThemeManagerBuilder.#'
|
||||
- '#Instantiated class PrestaShop\\PrestaShop\\Core\\Addon\\Theme\\ThemeManagerBuilder not found.#'
|
||||
- '#Property Ps_eventbus::\$serviceContainer has unknown class PrestaShop\\ModuleLibServiceContainer\\DependencyInjection\\ServiceContainer as its type.#'
|
||||
- '#Instantiated class PrestaShop\\ModuleLibServiceContainer\\DependencyInjection\\ServiceContainer not found.#'
|
||||
- '#Call to method getService\(\) on an unknown class PrestaShop\\ModuleLibServiceContainer\\DependencyInjection\\ServiceContainer.#'
|
||||
|
||||
level: 7
|
||||
35
modules/ps_eventbus/tests/phpstan/phpstan-PS-1.7.neon
Normal file
35
modules/ps_eventbus/tests/phpstan/phpstan-PS-1.7.neon
Normal file
@@ -0,0 +1,35 @@
|
||||
includes:
|
||||
- %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon
|
||||
parameters:
|
||||
checkMissingIterableValueType: false
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
paths:
|
||||
- ../../src
|
||||
- ../../controllers
|
||||
- ../../ps_eventbus.php
|
||||
dynamicConstantNames:
|
||||
- _PS_VERSION_
|
||||
ignoreErrors:
|
||||
- '#Property TabCore::\$name \(string\) does not accept array.#'
|
||||
- '#Parameter \#1 \$value of method ControllerCore::ajaxDie\(\) expects string\|null, string\|false given.#'
|
||||
- '#Parameter \#4 \$ssl of method LinkCore::getModuleLink\(\) expects null, true given.#'
|
||||
- '#Parameter \#6 \$idShop of method LinkCore::getModuleLink\(\) expects null, int given.#'
|
||||
- '#Parameter \#1 \$json of function json_decode expects string, string\|false given.#'
|
||||
- '#Parameter \#2 \$message of method PrestaShop\\Module\\PsEventbus\\WebHook\\Validator::getError\(\) expects string, string\|false given.#'
|
||||
- '#Parameter \#1 \$hook_name of method ModuleCore::registerHook\(\) expects string, array given.#'
|
||||
- '#Access to an undefined property AdminController\|FrontController::\$controller_name.#'
|
||||
- '#Call to static method getAvailable\(\) on an unknown class Theme.#'
|
||||
- '#Call to static method getByDirectory\(\) on an unknown class Theme.#'
|
||||
- '#Call to static method getThemeInfo\(\) on an unknown class Theme.#'
|
||||
- '#Access to an undefined property Context::\$theme.#'
|
||||
- '#Access to an undefined property Shop::\$theme.#'
|
||||
- '#Call to method buildRepository\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Addon\\Theme\\ThemeManagerBuilder.#'
|
||||
- '#Instantiated class PrestaShop\\PrestaShop\\Core\\Addon\\Theme\\ThemeManagerBuilder not found.#'
|
||||
- '#Class Theme not found.#'
|
||||
- '#Access to property \$id on an unknown class Theme.#'
|
||||
- '#Instantiated class PrestaShop\\ModuleLibServiceContainer\\DependencyInjection\\ServiceContainer not found.#'
|
||||
- '#Call to method getService\(\) on an unknown class PrestaShop\\ModuleLibServiceContainer\\DependencyInjection\\ServiceContainer.#'
|
||||
- '#Cannot access property \$id on Module\|false.#'
|
||||
- '#Class Theme not found.#'
|
||||
|
||||
level: 7
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrestaShop\Module\PsEventbus\Api\EventBusSyncClient;
|
||||
use PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository;
|
||||
use PrestaShop\Module\PsEventbus\Service\ApiAuthorizationService;
|
||||
|
||||
class ApiAuthorizationServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var EventbusSyncRepository
|
||||
*/
|
||||
private $eventbusSyncRepository;
|
||||
/**
|
||||
* @var ApiAuthorizationService
|
||||
*/
|
||||
private $apiAuthorizationService;
|
||||
/**
|
||||
* @var EventBusSyncClient
|
||||
*/
|
||||
private $eventBusSyncClient;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->eventbusSyncRepository = $this->createMock(EventbusSyncRepository::class);
|
||||
$this->eventBusSyncClient = $this->createMock(EventBusSyncClient::class);
|
||||
$this->apiAuthorizationService = new ApiAuthorizationService(
|
||||
$this->eventbusSyncRepository,
|
||||
$this->eventBusSyncClient
|
||||
);
|
||||
}
|
||||
|
||||
public function testAuthorizeCallSucceeds()
|
||||
{
|
||||
$jobId = '12345';
|
||||
|
||||
$this->eventbusSyncRepository
|
||||
->expects($this->at(0))
|
||||
->method('findJobById')
|
||||
->with($jobId)
|
||||
->willReturn(['job_id' => '12345']);
|
||||
$this->eventBusSyncClient->expects($this->at(-1))->method('validateJobId')->willReturn(true);
|
||||
|
||||
$this->assertTrue($this->apiAuthorizationService->authorizeCall($jobId));
|
||||
|
||||
$this->eventbusSyncRepository
|
||||
->expects($this->at(0))
|
||||
->method('findJobById')
|
||||
->with($jobId)
|
||||
->willReturn(false);
|
||||
$this->eventBusSyncClient->expects($this->at(0))->method('validateJobId')->willReturn(['httpCode' => 201]);
|
||||
|
||||
$this->eventbusSyncRepository
|
||||
->expects($this->atLeastOnce())
|
||||
->method('insertJob')
|
||||
->willReturn(true);
|
||||
|
||||
$this->assertTrue($this->apiAuthorizationService->authorizeCall($jobId));
|
||||
}
|
||||
|
||||
public function testAuthorizeCallFails()
|
||||
{
|
||||
$jobId = '12345';
|
||||
|
||||
$this->eventbusSyncRepository
|
||||
->expects($this->at(0))
|
||||
->method('findJobById')
|
||||
->with($jobId)
|
||||
->willReturn(false);
|
||||
|
||||
$this->eventbusSyncRepository
|
||||
->expects($this->atLeastOnce())
|
||||
->method('insertJob')
|
||||
->willReturn(false);
|
||||
|
||||
$this->eventBusSyncClient->method('validateJobId')->willReturn(['httpCode' => 201]);
|
||||
|
||||
$this->assertFalse($this->apiAuthorizationService->authorizeCall($jobId));
|
||||
}
|
||||
}
|
||||
40
modules/ps_eventbus/tests/unit/ArrayFormatterTest.php
Normal file
40
modules/ps_eventbus/tests/unit/ArrayFormatterTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrestaShop\Module\PsEventbus\Formatter\ArrayFormatter;
|
||||
|
||||
class ArrayFormatterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ArrayFormatter
|
||||
*/
|
||||
private $arrayFormatter;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->arrayFormatter = new ArrayFormatter();
|
||||
}
|
||||
|
||||
public function testFormatArray()
|
||||
{
|
||||
$data = [
|
||||
'value1',
|
||||
'value2',
|
||||
];
|
||||
|
||||
$this->assertEquals('value1;value2', $this->arrayFormatter->arrayToString($data));
|
||||
$this->assertEquals('value1:value2', $this->arrayFormatter->arrayToString($data, ':'));
|
||||
}
|
||||
|
||||
public function testFormatValueArrayTest()
|
||||
{
|
||||
$data = [
|
||||
['id' => 1, 'value' => 123],
|
||||
['id' => 2, 'value' => 456],
|
||||
['id' => 3, 'value' => 789],
|
||||
];
|
||||
|
||||
$this->assertEquals('123;456;789', $this->arrayFormatter->formatValueString($data, 'value'));
|
||||
$this->assertEquals('123:456:789', $this->arrayFormatter->formatValueString($data, 'value', ':'));
|
||||
}
|
||||
}
|
||||
29
modules/ps_eventbus/tests/unit/JsonFormatterTest.php
Normal file
29
modules/ps_eventbus/tests/unit/JsonFormatterTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrestaShop\Module\PsEventbus\Formatter\JsonFormatter;
|
||||
|
||||
class JsonFormatterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var JsonFormatter
|
||||
*/
|
||||
private $jsonFormatter;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->jsonFormatter = new JsonFormatter();
|
||||
}
|
||||
|
||||
public function testFormatNewlineJsonString()
|
||||
{
|
||||
$data = [
|
||||
['test' => 'data'],
|
||||
['test2' => 'data2'],
|
||||
];
|
||||
|
||||
$this->assertTrue(is_string($this->jsonFormatter->formatNewlineJsonString($data)));
|
||||
$this->assertRegExp("/\r\n/", $this->jsonFormatter->formatNewlineJsonString($data));
|
||||
}
|
||||
}
|
||||
143
modules/ps_eventbus/tests/unit/ProductDecoratorTest.php
Normal file
143
modules/ps_eventbus/tests/unit/ProductDecoratorTest.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrestaShop\Module\PsEventbus\Decorator\ProductDecorator;
|
||||
use PrestaShop\Module\PsEventbus\Formatter\ArrayFormatter;
|
||||
use PrestaShop\Module\PsEventbus\Repository\CategoryRepository;
|
||||
use PrestaShop\Module\PsEventbus\Repository\LanguageRepository;
|
||||
use PrestaShop\Module\PsEventbus\Repository\ProductRepository;
|
||||
|
||||
class ProductDecoratorTest extends TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testDecorateProducts()
|
||||
{
|
||||
$products = [
|
||||
[
|
||||
'id_product' => '1',
|
||||
'id_attribute' => '3',
|
||||
'name' => 'Hummingbird printed t-shirt',
|
||||
'description' => '<p>SOME HTML</p>',
|
||||
'description_short' => '<p>SOME HTML</p>',
|
||||
'link_rewrite' => 'hummingbird-printed-t-shirt',
|
||||
'iso_code' => 'lt',
|
||||
'default_category' => 'Men',
|
||||
'id_category_default' => '4',
|
||||
'reference' => 'demo_1',
|
||||
'upc' => '',
|
||||
'ean' => '',
|
||||
'isbn' => '',
|
||||
'condition' => 'new',
|
||||
'visibility' => 'both',
|
||||
'active' => true,
|
||||
'quantity' => '300',
|
||||
'manufacturer' => 'Studio Design',
|
||||
'weight' => '10.0',
|
||||
'price_tax_excl' => '23.9',
|
||||
'created_at' => '2020-08-19 08:29:12',
|
||||
'updated_at' => '2020-09-22 10:02:45',
|
||||
'attributes' => 'Dydis:M;Spalva:Balta',
|
||||
'features' => 'Savybė:Trumpos rankovės;Sudėtis:Medvilnė',
|
||||
'images' => '1:1;2:0',
|
||||
'attribute_images' => '1;2;3',
|
||||
'is_default_attribute' => '1',
|
||||
],
|
||||
[
|
||||
'id_product' => '2',
|
||||
'id_attribute' => '0',
|
||||
'name' => 'Hummingbird printed t-shirt',
|
||||
'description' => '<p>SOME HTML</p>',
|
||||
'description_short' => '<p>SOME HTML</p>',
|
||||
'link_rewrite' => 'hummingbird-printed-t-shirt',
|
||||
'iso_code' => 'lt',
|
||||
'default_category' => 'Men',
|
||||
'id_category_default' => '4',
|
||||
'reference' => 'demo_1',
|
||||
'upc' => '',
|
||||
'ean' => '',
|
||||
'isbn' => '',
|
||||
'condition' => 'new',
|
||||
'visibility' => 'both',
|
||||
'active' => true,
|
||||
'quantity' => '300',
|
||||
'manufacturer' => 'Studio Design',
|
||||
'weight' => '10.0',
|
||||
'price_tax_excl' => '23.9',
|
||||
'created_at' => '2020-08-19 08:29:12',
|
||||
'updated_at' => '2020-09-22 10:02:45',
|
||||
'attributes' => 'Dydis:M;Spalva:Balta',
|
||||
'features' => 'Savybė:Trumpos rankovės;Sudėtis:Medvilnė',
|
||||
'images' => '1:1;2:0',
|
||||
'attribute_images' => '1',
|
||||
'is_default_attribute' => '1',
|
||||
],
|
||||
[
|
||||
'id_product' => '2',
|
||||
'id_attribute' => '0',
|
||||
'name' => 'Hummingbird printed t-shirt',
|
||||
'description' => '<p>SOME HTML</p>',
|
||||
'description_short' => '<p>SOME HTML</p>',
|
||||
'link_rewrite' => 'hummingbird-printed-t-shirt',
|
||||
'iso_code' => 'lt',
|
||||
'default_category' => 'Men',
|
||||
'id_category_default' => '4',
|
||||
'reference' => 'demo_1',
|
||||
'upc' => '',
|
||||
'ean' => '',
|
||||
'isbn' => '',
|
||||
'condition' => 'new',
|
||||
'visibility' => 'both',
|
||||
'active' => true,
|
||||
'quantity' => '300',
|
||||
'manufacturer' => 'Studio Design',
|
||||
'weight' => '10.0',
|
||||
'price_tax_excl' => '23.9',
|
||||
'created_at' => '2020-08-19 08:29:12',
|
||||
'updated_at' => '2020-09-22 10:02:45',
|
||||
'attributes' => 'Dydis:M;Spalva:Balta',
|
||||
'features' => 'Savybė:Trumpos rankovės;Sudėtis:Medvilnė',
|
||||
'images' => '1:1;2:0',
|
||||
'attribute_images' => '1',
|
||||
'is_default_attribute' => '1',
|
||||
],
|
||||
];
|
||||
|
||||
$categories = [
|
||||
'category_path' => 'Root > Home > Clothes > Men',
|
||||
'category_id_path' => '1 > 2 > 3 > 4',
|
||||
];
|
||||
|
||||
$contextMock = $this->createMock(Context::class);
|
||||
$linkMock = $this->createMock(Link::class);
|
||||
$linkMock->method('getProductLink')->willReturn('https://test.link/1-0-product.html');
|
||||
$linkMock->method('getImageLink')->willReturn('https://test.link/1-0-product.jpg');
|
||||
|
||||
$shopMock = $this->createMock(Shop::class);
|
||||
$shopMock->id = 1;
|
||||
|
||||
$contextMock->link = $linkMock;
|
||||
$contextMock->shop = $shopMock;
|
||||
|
||||
$languageRepository = $this->createMock(LanguageRepository::class);
|
||||
$languageRepository->method('getLanguageIdByIsoCode')->willReturn(1);
|
||||
$productRepository = $this->createMock(ProductRepository::class);
|
||||
$productRepository->method('getProductImages')->willReturn([]);
|
||||
$productRepository->method('getAttributeImages')->willReturn([]);
|
||||
$categoryRepository = $this->createMock(CategoryRepository::class);
|
||||
$categoryRepository->method('getCategoryPaths')->willReturn($categories);
|
||||
|
||||
$arrayFormatter = new ArrayFormatter();
|
||||
|
||||
$productDecorator = new ProductDecorator($contextMock, $languageRepository, $productRepository, $categoryRepository, $arrayFormatter);
|
||||
$productDecorator->decorateProducts($products, 'en', 1);
|
||||
|
||||
$this->assertInternalType('int', $products[0]['id_product']);
|
||||
$this->assertInternalType('int', $products[0]['id_category_default']);
|
||||
$this->assertInternalType('float', $products[0]['price_tax_excl']);
|
||||
$this->assertInternalType('float', $products[0]['price_tax_incl']);
|
||||
}
|
||||
}
|
||||
65
modules/ps_eventbus/tests/unit/SegmentServiceTest.php
Normal file
65
modules/ps_eventbus/tests/unit/SegmentServiceTest.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrestaShop\Module\PsEventbus\Api\EventBusProxyClient;
|
||||
use PrestaShop\Module\PsEventbus\Formatter\JsonFormatter;
|
||||
use PrestaShop\Module\PsEventbus\Service\ProxyService;
|
||||
|
||||
class ProxyServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ProxyService
|
||||
*/
|
||||
private $segmentService;
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
private $context;
|
||||
/**
|
||||
* @var EventBusProxyClient
|
||||
*/
|
||||
private $eventBusProxyClient;
|
||||
/**
|
||||
* @var JsonFormatter
|
||||
*/
|
||||
private $jsonFormatter;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->context = Context::getContext();
|
||||
$this->eventBusProxyClient = $this->createMock(EventBusProxyClient::class);
|
||||
$this->jsonFormatter = new JsonFormatter();
|
||||
$this->segmentService = new ProxyService($this->eventBusProxyClient, $this->jsonFormatter);
|
||||
}
|
||||
|
||||
public function testValidUpload()
|
||||
{
|
||||
$data = ['important_server_data' => ':)'];
|
||||
$syncId = '12345';
|
||||
$jsonData = $this->jsonFormatter->formatNewlineJsonString($data);
|
||||
|
||||
$this->eventBusProxyClient->method('upload')->willReturn([
|
||||
'status' => 'success',
|
||||
'httpCode' => 201,
|
||||
'body' => 'success',
|
||||
]);
|
||||
|
||||
$startDate = time();
|
||||
$this->assertTrue(is_array($this->segmentService->upload($syncId, $data, $startDate)));
|
||||
$this->assertArrayHasKey('httpCode', $this->segmentService->upload($syncId, $data, $startDate));
|
||||
$this->assertEquals(201, $this->segmentService->upload($syncId, $data, $startDate)['httpCode']);
|
||||
}
|
||||
|
||||
public function testInvalidUpload()
|
||||
{
|
||||
$data = ['important_server_data' => ':)'];
|
||||
$syncId = '12345';
|
||||
$startDate = time();
|
||||
|
||||
$clientException = $this->createMock(ClientException::class);
|
||||
$this->eventBusProxyClient->method('upload')->willThrowException($clientException);
|
||||
$this->assertArrayHasKey('error', $this->segmentService->upload($syncId, $data, $startDate));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PrestaShop\Module\PsEventbus\Formatter\ArrayFormatter;
|
||||
use PrestaShop\Module\PsEventbus\Repository\ConfigurationRepository;
|
||||
use PrestaShop\Module\PsEventbus\Repository\CurrencyRepository;
|
||||
use PrestaShop\Module\PsEventbus\Repository\LanguageRepository;
|
||||
use PrestaShop\Module\PsEventbus\Repository\ServerInformationRepository;
|
||||
use PrestaShop\Module\PsEventbus\Repository\ShopRepository;
|
||||
|
||||
class ServerInformationRepositoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var CurrencyRepository
|
||||
*/
|
||||
private $currencyRepository;
|
||||
/**
|
||||
* @var LanguageRepository
|
||||
*/
|
||||
private $languageRepository;
|
||||
/**
|
||||
* @var ServerInformationRepository
|
||||
*/
|
||||
private $serverInformationRepository;
|
||||
/**
|
||||
* @var ConfigurationRepository
|
||||
*/
|
||||
private $configurationRepository;
|
||||
/**
|
||||
* @var ShopRepository
|
||||
*/
|
||||
private $shopRepository;
|
||||
/**
|
||||
* @var ArrayFormatter
|
||||
*/
|
||||
private $arrayFormatter;
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
private $context;
|
||||
/**
|
||||
* @var Db
|
||||
*/
|
||||
private $db;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->currencyRepository = $this->createMock(CurrencyRepository::class);
|
||||
$this->languageRepository = $this->createMock(LanguageRepository::class);
|
||||
$this->configurationRepository = $this->createMock(ConfigurationRepository::class);
|
||||
$this->shopRepository = $this->createMock(ShopRepository::class);
|
||||
$this->arrayFormatter = $this->createMock(ArrayFormatter::class);
|
||||
$this->context = $this->createMock(Context::class);
|
||||
$link = $this->createMock(Link::class);
|
||||
$this->context->link = $link;
|
||||
$this->db = $this->createMock(Db::class);
|
||||
|
||||
$this->serverInformationRepository = new ServerInformationRepository(
|
||||
$this->context,
|
||||
$this->db,
|
||||
$this->currencyRepository,
|
||||
$this->languageRepository,
|
||||
$this->configurationRepository,
|
||||
$this->shopRepository,
|
||||
$this->arrayFormatter
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetServerInformation()
|
||||
{
|
||||
$this->shopRepository->method('getMultiShopCount')->willReturn(1);
|
||||
$this->currencyRepository->method('getCurrenciesIsoCodes')->willReturn(['EUR', 'USD']);
|
||||
$this->currencyRepository->method('getDefaultCurrencyIsoCode')->willReturn('USD');
|
||||
|
||||
$this->languageRepository->method('getLanguagesIsoCodes')->willReturn(['en', 'fr', 'lt']);
|
||||
$this->languageRepository->method('getDefaultLanguageIsoCode')->willReturn('en');
|
||||
|
||||
$this->configurationRepository->expects($this->at(0))->method('get')->with('PS_REWRITING_SETTINGS')->willReturn(true);
|
||||
$this->configurationRepository->expects($this->at(1))->method('get')->with('PS_CART_FOLLOWING')->willReturn(true);
|
||||
$this->configurationRepository->expects($this->at(2))->method('get')->with('PS_WEIGHT_UNIT')->willReturn('kg');
|
||||
$this->configurationRepository->expects($this->at(3))->method('get')->with('PS_TIMEZONE')->willReturn('GMT/Zulu');
|
||||
$this->configurationRepository->expects($this->at(4))->method('get')->with('PS_ORDER_RETURN')->willReturn('1');
|
||||
$this->configurationRepository->expects($this->at(5))->method('get')->with('PS_ORDER_RETURN_NB_DAYS')->willReturn('1');
|
||||
|
||||
$this->context->link->method('getPageLink')->willReturn('some link');
|
||||
|
||||
$this->assertTrue(is_array($this->serverInformationRepository->getServerInformation()));
|
||||
}
|
||||
}
|
||||
6
modules/ps_eventbus/tests/unit/bootstrap.php
Normal file
6
modules/ps_eventbus/tests/unit/bootstrap.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
$rootDirectory = getenv('_PS_ROOT_DIR_') ?: __DIR__ . '/../../../../';
|
||||
$projectDir = __DIR__ . '/../../';
|
||||
require_once $rootDirectory . 'config/config.inc.php';
|
||||
require_once $projectDir . 'vendor/autoload.php';
|
||||
28
modules/ps_eventbus/tests/unit/index.php
Normal file
28
modules/ps_eventbus/tests/unit/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (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:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* 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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (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;
|
||||
Reference in New Issue
Block a user