From fa6c068a5c396931a68b4e9b223d8ef8330d324c Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Wed, 5 Jun 2024 15:02:05 +0200 Subject: [PATCH 01/24] ECP-81:[WIP] unit tests in prestashop module --- tests/Unit/.phpunit.result.cache | 1 + tests/Unit/Fixture.php | 143 ++++++++++++++++++ tests/Unit/bootstrap.php | 45 ++++++ .../classes/models/LengowConnectorTest.php | 63 ++++++++ .../classes/models/LengowExceptionTest.php | 34 +++++ tests/Unit/phpunit.xml | 19 +++ 6 files changed, 305 insertions(+) create mode 100644 tests/Unit/.phpunit.result.cache create mode 100644 tests/Unit/Fixture.php create mode 100644 tests/Unit/bootstrap.php create mode 100644 tests/Unit/classes/models/LengowConnectorTest.php create mode 100644 tests/Unit/classes/models/LengowExceptionTest.php create mode 100644 tests/Unit/phpunit.xml diff --git a/tests/Unit/.phpunit.result.cache b/tests/Unit/.phpunit.result.cache new file mode 100644 index 00000000..6988d818 --- /dev/null +++ b/tests/Unit/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":4,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":4},"times":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":0.012,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":0.017,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExceptionTest::testClassInstantiation":0}} \ No newline at end of file diff --git a/tests/Unit/Fixture.php b/tests/Unit/Fixture.php new file mode 100644 index 00000000..a86dcaf6 --- /dev/null +++ b/tests/Unit/Fixture.php @@ -0,0 +1,143 @@ + + * @copyright 2017 Lengow SAS + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + +namespace Lengow\Connector\Test\Unit; + +use Exception; + +class Fixture extends \PHPUnit\Framework\TestCase +{ + /** + * Call protected/private method of a class. + * + * @param object &$object Instantiated object that we will run method on + * @param string $methodName Method name to call + * @param array $parameters Array of parameters to pass into method + * + * @return mixed Method return + */ + public function invokeMethod(&$object, $methodName, $parameters = []) + { + try { + $reflection = new \ReflectionClass(get_class($object)); + $method = $reflection->getMethod($methodName); + $method->setAccessible(true); + return $method->invokeArgs($object, $parameters); + } catch (Exception $e) { + return false; + } + } + + /** + * Return value of a private property using ReflectionClass + * + * @param object &$object Instantiated object that we will run method on. + * @param string $propertyName Class property + * + * @return mixed + */ + public function getPrivatePropertyValue(&$object, $propertyName = '_data') + { + try { + $reflection = new \ReflectionClass(get_class($object)); + $property = $reflection->getProperty($propertyName); + $property->setAccessible(true); + return $property->getValue($object); + } catch (Exception $e) { + return false; + } + } + + /** + * Set value of a private property using ReflectionClass + * + * @param object &$object Instantiated object that we will run method on. + * @param array $propertyNames Class properties + * @param array $propertyValues Class value properties + */ + public function setPrivatePropertyValue($object, $propertyNames, $propertyValues, $orignalObject = null) + { + $ii = 0; + try { + if (!is_null($orignalObject)) { + $reflection = new \ReflectionClass(get_class($orignalObject)); + } else { + $reflection = new \ReflectionClass(get_class($object)); + } + + } catch (Exception $e) { + $reflection = false; + } + if ($reflection) { + foreach ($propertyNames as $propertyName) { + try { + $property = $reflection->getProperty($propertyName); + $property->setAccessible(true); + $property->setValue($object, $propertyValues[$ii]); + $ii++; + } catch (Exception $e) { + continue; + } + } + } + } + + + + /** + * Get a fake class for mock function + */ + public function getFakeClass() + { + return $this->getMockBuilder('FakeClass')->getMock(); + } + + /** + * Mock specific function + * + * @param object &$object Instantiated object that we will run method on + * @param array $methodNames Method names to call + * @param array $returns Array of parameters to return + * @param array $constructArgs Args for constructor + * + * @return mixed Method return + */ + public function mockFunctions($object, $methodNames, $returns, $constructArgs = []) + { + $ii = 0; + if (!empty($constructArgs)) { + $mockFunction = $this->getMockBuilder(get_class($object)) + ->setMethods($methodNames) + ->setConstructorArgs($constructArgs) + ->getMock(); + } else { + + $mockFunction = $this->getMockBuilder(get_class($object)) + ->setMethods($methodNames) + ->disableOriginalConstructor() + ->getMock(); + } + + foreach ($methodNames as $methodName) { + $mockFunction->expects($this->any())->method($methodName)->will($this->returnValue($returns[$ii])); + $ii++; + } + return $mockFunction; + } +} \ No newline at end of file diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php new file mode 100644 index 00000000..d99f7c13 --- /dev/null +++ b/tests/Unit/bootstrap.php @@ -0,0 +1,45 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + */ + +//php7.4 -d date.timezone=UTC ./vendor/phpunit/phpunit/phpunit -c modules/lengow/tests/Unit/phpunit.xml modules/lengow/tests/Unit +define('_PS_IN_TEST_', true); +define('_PS_ROOT_DIR_', __DIR__ . '/../../../..'); +define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/tests/Resources/modules/'); +require_once __DIR__ . '/../../../../config/defines.inc.php'; +//require_once __DIR__ . '/../../../../config/config.inc.php'; +require_once _PS_CONFIG_DIR_ . 'autoload.php'; +require_once __DIR__.'/../../vendor/autoload.php'; +require_once __DIR__.'/./Fixture.php'; + +if (!defined('PHPUNIT_COMPOSER_INSTALL')) { + define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../vendor/autoload.php'); +} + +define('_NEW_COOKIE_KEY_', PhpEncryption::createNewRandomKey()); + +if (!defined('__PS_BASE_URI__')) { + define('__PS_BASE_URI__', ''); +} diff --git a/tests/Unit/classes/models/LengowConnectorTest.php b/tests/Unit/classes/models/LengowConnectorTest.php new file mode 100644 index 00000000..45dc728b --- /dev/null +++ b/tests/Unit/classes/models/LengowConnectorTest.php @@ -0,0 +1,63 @@ +connector = new LengowConnector('12345678','123456789'); + + } + + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowConnector::class, + $this->connector, + '[Test Class Instantiation] Check class instantiation' + ); + } + + /** + * @covers LengowConnector::format + */ + public function testFormat() + { + $fixture = new Fixture(); + $this->assertEquals( + ['id' => 1, 'name' => 'A green door', 'price' => '12.5', 'tags' => ['home', 'green']], + $fixture->invokeMethod( + $this->connector, + 'format', + ['{"id": 1,"name": "A green door","price": 12.50,"tags": ["home", "green"]}', 'json'] + ), + '[Test Format] Check json format' + ); + + $this->assertEquals( + 'simple,plop,/1233;variable', + $fixture->invokeMethod($this->connector, "format", ['simple,plop,/1233;variable', 'stream']), + '[Test Format] Check no specific format format' + ); + } + +} \ No newline at end of file diff --git a/tests/Unit/classes/models/LengowExceptionTest.php b/tests/Unit/classes/models/LengowExceptionTest.php new file mode 100644 index 00000000..b8fcf12a --- /dev/null +++ b/tests/Unit/classes/models/LengowExceptionTest.php @@ -0,0 +1,34 @@ +exception = new LengowException('Hello world'); + } + + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowException::class, + $this->exception, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/phpunit.xml b/tests/Unit/phpunit.xml new file mode 100644 index 00000000..3df9a810 --- /dev/null +++ b/tests/Unit/phpunit.xml @@ -0,0 +1,19 @@ + + + + + + + . + + + + + ../../src + ../../classes + ../../controllers + + + From c0ac00ab04c7121828e702473fd70c107cfa8291 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Thu, 6 Jun 2024 09:41:24 +0200 Subject: [PATCH 02/24] ECP-81:[WIP] unit tests in prestashop module --- tests/Unit/.phpunit.result.cache | 2 +- tests/Unit/bootstrap.php | 10 +++-- .../classes/models/LengowConnectorTest.php | 18 ++++----- .../classes/models/LengowExceptionTest.php | 6 +-- .../Unit/classes/models/LengowExportTest.php | 17 ++++++++ tests/Unit/classes/models/LengowFileTest.php | 39 +++++++++++++++++++ tests/Unit/classes/models/LengowLogTest.php | 38 ++++++++++++++++++ 7 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 tests/Unit/classes/models/LengowExportTest.php create mode 100644 tests/Unit/classes/models/LengowFileTest.php create mode 100644 tests/Unit/classes/models/LengowLogTest.php diff --git a/tests/Unit/.phpunit.result.cache b/tests/Unit/.phpunit.result.cache index 6988d818..6aa72427 100644 --- a/tests/Unit/.phpunit.result.cache +++ b/tests/Unit/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":4,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":4},"times":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":0.012,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":0.017,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExceptionTest::testClassInstantiation":0}} \ No newline at end of file +{"version":1,"defects":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":4,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":5,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":4},"times":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":0.012,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":0.017,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExceptionTest::testClassInstantiation":0,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":0.002,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":0.001}} \ No newline at end of file diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index d99f7c13..e8f37f0b 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -25,11 +25,10 @@ */ //php7.4 -d date.timezone=UTC ./vendor/phpunit/phpunit/phpunit -c modules/lengow/tests/Unit/phpunit.xml modules/lengow/tests/Unit -define('_PS_IN_TEST_', true); +define('_PS_IN_TEST_', false); define('_PS_ROOT_DIR_', __DIR__ . '/../../../..'); -define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/tests/Resources/modules/'); +define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/modules/'); require_once __DIR__ . '/../../../../config/defines.inc.php'; -//require_once __DIR__ . '/../../../../config/config.inc.php'; require_once _PS_CONFIG_DIR_ . 'autoload.php'; require_once __DIR__.'/../../vendor/autoload.php'; require_once __DIR__.'/./Fixture.php'; @@ -38,8 +37,11 @@ define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../vendor/autoload.php'); } -define('_NEW_COOKIE_KEY_', PhpEncryption::createNewRandomKey()); +if (!defined('_NEW_COOKIE_KEY_')) { + define('_NEW_COOKIE_KEY_', PhpEncryption::createNewRandomKey()); +} if (!defined('__PS_BASE_URI__')) { define('__PS_BASE_URI__', ''); } + diff --git a/tests/Unit/classes/models/LengowConnectorTest.php b/tests/Unit/classes/models/LengowConnectorTest.php index 45dc728b..b43b61a7 100644 --- a/tests/Unit/classes/models/LengowConnectorTest.php +++ b/tests/Unit/classes/models/LengowConnectorTest.php @@ -5,29 +5,28 @@ use Lengow\Connector\Test\Unit\Fixture; use PHPUnit\Framework\TestCase; use LengowConnector; -use LengowConfiguration; + class LengowConnectorTest extends TestCase { - - /** * * @var LengowConnector */ protected $connector; - /** - * Sets up the fixture, for example, open a network connection. - * This method is called before a test is executed. + * Setup * + * @return void */ - public function setUp() : void + public function setUp(): void { $this->connector = new LengowConnector('12345678','123456789'); - } + /** + * test class + */ public function testClassInstantiation() { $this->assertInstanceOf( @@ -37,7 +36,7 @@ public function testClassInstantiation() ); } - /** + /** * @covers LengowConnector::format */ public function testFormat() @@ -59,5 +58,4 @@ public function testFormat() '[Test Format] Check no specific format format' ); } - } \ No newline at end of file diff --git a/tests/Unit/classes/models/LengowExceptionTest.php b/tests/Unit/classes/models/LengowExceptionTest.php index b8fcf12a..8beb713f 100644 --- a/tests/Unit/classes/models/LengowExceptionTest.php +++ b/tests/Unit/classes/models/LengowExceptionTest.php @@ -13,11 +13,11 @@ class LengowExceptionTest extends TestCase protected $exception; /** - * Sets up the fixture, for example, open a network connection. - * This method is called before a test is executed. + * setup * + * @return void */ - public function setUp() : void + public function setUp(): void { $this->exception = new LengowException('Hello world'); diff --git a/tests/Unit/classes/models/LengowExportTest.php b/tests/Unit/classes/models/LengowExportTest.php new file mode 100644 index 00000000..87acc655 --- /dev/null +++ b/tests/Unit/classes/models/LengowExportTest.php @@ -0,0 +1,17 @@ +file = new LengowFile(LengowMain::FOLDER_LOG,'unit-test-log.txt'); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowFile::class, + $this->file, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowLogTest.php b/tests/Unit/classes/models/LengowLogTest.php new file mode 100644 index 00000000..e1ccaeb8 --- /dev/null +++ b/tests/Unit/classes/models/LengowLogTest.php @@ -0,0 +1,38 @@ +log = new LengowLog(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowLog::class, + $this->log, + '[Test Class Instantiation] Check class instantiation' + ); + } +} From 88df30e5f807fca8eeb0362de01465295835c54c Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Thu, 6 Jun 2024 11:44:33 +0200 Subject: [PATCH 03/24] ECP-81:[WIP] unit tests in prestashop module --- tests/Unit/.phpunit.result.cache | 2 +- tests/Unit/bootstrap.php | 4 +- .../Unit/classes/models/LengowActionTest.php | 39 ++++++++++++++++++ .../Unit/classes/models/LengowAddressTest.php | 39 ++++++++++++++++++ .../Unit/classes/models/LengowBackupTest.php | 39 ++++++++++++++++++ .../Unit/classes/models/LengowCarrierTest.php | 39 ++++++++++++++++++ tests/Unit/classes/models/LengowCartTest.php | 39 ++++++++++++++++++ .../Unit/classes/models/LengowCatalogTest.php | 39 ++++++++++++++++++ .../models/LengowConfigurationFormTest.php | 39 ++++++++++++++++++ .../models/LengowConfigurationTest.php | 39 ++++++++++++++++++ .../Unit/classes/models/LengowCountryTest.php | 39 ++++++++++++++++++ .../classes/models/LengowTranslationTest.php | 41 +++++++++++++++++++ 12 files changed, 395 insertions(+), 3 deletions(-) create mode 100644 tests/Unit/classes/models/LengowActionTest.php create mode 100644 tests/Unit/classes/models/LengowAddressTest.php create mode 100644 tests/Unit/classes/models/LengowBackupTest.php create mode 100644 tests/Unit/classes/models/LengowCarrierTest.php create mode 100644 tests/Unit/classes/models/LengowCartTest.php create mode 100644 tests/Unit/classes/models/LengowCatalogTest.php create mode 100644 tests/Unit/classes/models/LengowConfigurationFormTest.php create mode 100644 tests/Unit/classes/models/LengowConfigurationTest.php create mode 100644 tests/Unit/classes/models/LengowCountryTest.php create mode 100644 tests/Unit/classes/models/LengowTranslationTest.php diff --git a/tests/Unit/.phpunit.result.cache b/tests/Unit/.phpunit.result.cache index 6aa72427..7957865d 100644 --- a/tests/Unit/.phpunit.result.cache +++ b/tests/Unit/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":4,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":5,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":4},"times":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":0.012,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":0.017,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExceptionTest::testClassInstantiation":0,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":0.002,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":0.001}} \ No newline at end of file +{"version":1,"defects":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":4,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":5,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowTranslationTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowAddressTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCarrierTest::testClassInstantiation":4},"times":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":0.012,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":0.017,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testFormat":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExceptionTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowTranslationTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowAddressTest::testClassInstantiation":0.007,"Lengow\\Connector\\Test\\Unit\\Model\\LengowActionTest::testClassInstantiation":0.009,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCarrierTest::testClassInstantiation":0.009,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCartTest::testClassInstantiation":0.01,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCatalogTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowBackupTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConfigurationTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConfigurationFormTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCountryTest::testClassInstantiation":0.004}} \ No newline at end of file diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index e8f37f0b..042ac97e 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -25,11 +25,12 @@ */ //php7.4 -d date.timezone=UTC ./vendor/phpunit/phpunit/phpunit -c modules/lengow/tests/Unit/phpunit.xml modules/lengow/tests/Unit -define('_PS_IN_TEST_', false); +//define('_PS_IN_TEST_', true); define('_PS_ROOT_DIR_', __DIR__ . '/../../../..'); define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/modules/'); require_once __DIR__ . '/../../../../config/defines.inc.php'; require_once _PS_CONFIG_DIR_ . 'autoload.php'; +require_once _PS_CONFIG_DIR_ . 'config.inc.php'; require_once __DIR__.'/../../vendor/autoload.php'; require_once __DIR__.'/./Fixture.php'; @@ -44,4 +45,3 @@ if (!defined('__PS_BASE_URI__')) { define('__PS_BASE_URI__', ''); } - diff --git a/tests/Unit/classes/models/LengowActionTest.php b/tests/Unit/classes/models/LengowActionTest.php new file mode 100644 index 00000000..4bd114c9 --- /dev/null +++ b/tests/Unit/classes/models/LengowActionTest.php @@ -0,0 +1,39 @@ +action = new LengowAction(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowAction::class, + $this->action, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowAddressTest.php b/tests/Unit/classes/models/LengowAddressTest.php new file mode 100644 index 00000000..ef0883d8 --- /dev/null +++ b/tests/Unit/classes/models/LengowAddressTest.php @@ -0,0 +1,39 @@ +address = new LengowAddress(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowAddress::class, + $this->address, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowBackupTest.php b/tests/Unit/classes/models/LengowBackupTest.php new file mode 100644 index 00000000..baa87c21 --- /dev/null +++ b/tests/Unit/classes/models/LengowBackupTest.php @@ -0,0 +1,39 @@ +backup = new LengowBackup(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowBackup::class, + $this->backup, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowCarrierTest.php b/tests/Unit/classes/models/LengowCarrierTest.php new file mode 100644 index 00000000..9784a908 --- /dev/null +++ b/tests/Unit/classes/models/LengowCarrierTest.php @@ -0,0 +1,39 @@ +carrier = new LengowCarrier(1,1); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowCarrier::class, + $this->carrier, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowCartTest.php b/tests/Unit/classes/models/LengowCartTest.php new file mode 100644 index 00000000..ccbe6bd3 --- /dev/null +++ b/tests/Unit/classes/models/LengowCartTest.php @@ -0,0 +1,39 @@ +cart = new LengowCart(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowCart::class, + $this->cart, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowCatalogTest.php b/tests/Unit/classes/models/LengowCatalogTest.php new file mode 100644 index 00000000..7cfb7395 --- /dev/null +++ b/tests/Unit/classes/models/LengowCatalogTest.php @@ -0,0 +1,39 @@ +catalog = new LengowCatalog(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowCatalog::class, + $this->catalog, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowConfigurationFormTest.php b/tests/Unit/classes/models/LengowConfigurationFormTest.php new file mode 100644 index 00000000..d1381fb0 --- /dev/null +++ b/tests/Unit/classes/models/LengowConfigurationFormTest.php @@ -0,0 +1,39 @@ +form = new LengowConfigurationForm([]); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowConfigurationForm::class, + $this->form, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowConfigurationTest.php b/tests/Unit/classes/models/LengowConfigurationTest.php new file mode 100644 index 00000000..80cf3849 --- /dev/null +++ b/tests/Unit/classes/models/LengowConfigurationTest.php @@ -0,0 +1,39 @@ +config = new LengowConfiguration(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowConfiguration::class, + $this->config, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowCountryTest.php b/tests/Unit/classes/models/LengowCountryTest.php new file mode 100644 index 00000000..b116b1ee --- /dev/null +++ b/tests/Unit/classes/models/LengowCountryTest.php @@ -0,0 +1,39 @@ +country = new LengowCountry(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowCountry::class, + $this->country, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowTranslationTest.php b/tests/Unit/classes/models/LengowTranslationTest.php new file mode 100644 index 00000000..39652655 --- /dev/null +++ b/tests/Unit/classes/models/LengowTranslationTest.php @@ -0,0 +1,41 @@ +translate = new LengowTranslation('fr'); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowTranslation::class, + $this->translate, + '[Test Class Instantiation] Check class instantiation' + ); + } +} From c31e3429138b89f4a575833fb1f3c0fc8f2a231c Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Thu, 6 Jun 2024 14:30:42 +0200 Subject: [PATCH 04/24] ECP-81:[WIP] unit tests in prestashop module --- tests/Unit/.phpunit.result.cache | 2 +- tests/Unit/bootstrap.php | 3 ++ .../classes/models/LengowCustomerTest.php | 39 ++++++++++++++++ .../Unit/classes/models/LengowExportTest.php | 44 ++++++++++++++----- tests/Unit/classes/models/LengowFeedTest.php | 39 ++++++++++++++++ .../Unit/classes/models/LengowGenderTest.php | 39 ++++++++++++++++ tests/Unit/classes/models/LengowHookTest.php | 41 +++++++++++++++++ tests/Unit/phpunit.xml | 1 + 8 files changed, 196 insertions(+), 12 deletions(-) create mode 100644 tests/Unit/classes/models/LengowCustomerTest.php create mode 100644 tests/Unit/classes/models/LengowFeedTest.php create mode 100644 tests/Unit/classes/models/LengowGenderTest.php create mode 100644 tests/Unit/classes/models/LengowHookTest.php diff --git a/tests/Unit/.phpunit.result.cache b/tests/Unit/.phpunit.result.cache index 7957865d..e4a5d955 100644 --- a/tests/Unit/.phpunit.result.cache +++ b/tests/Unit/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":4,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":5,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowTranslationTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowAddressTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCarrierTest::testClassInstantiation":4},"times":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":0.012,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":0.017,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testFormat":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExceptionTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowTranslationTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowAddressTest::testClassInstantiation":0.007,"Lengow\\Connector\\Test\\Unit\\Model\\LengowActionTest::testClassInstantiation":0.009,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCarrierTest::testClassInstantiation":0.009,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCartTest::testClassInstantiation":0.01,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCatalogTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowBackupTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConfigurationTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConfigurationFormTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCountryTest::testClassInstantiation":0.004}} \ No newline at end of file +{"version":1,"defects":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":4,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":5,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowTranslationTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowAddressTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCarrierTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCustomerTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFeedTest::testClassInstantiation":4},"times":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":0.012,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":0.017,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testFormat":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExceptionTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":0.009,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowTranslationTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowAddressTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowActionTest::testClassInstantiation":0.008,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCarrierTest::testClassInstantiation":0.008,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCartTest::testClassInstantiation":0.014,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCatalogTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowBackupTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConfigurationTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConfigurationFormTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCountryTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCustomerTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFeedTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowGenderTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowHookTest::testClassInstantiation":0.861}} \ No newline at end of file diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index 042ac97e..2e1e35ea 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -45,3 +45,6 @@ if (!defined('__PS_BASE_URI__')) { define('__PS_BASE_URI__', ''); } + + + diff --git a/tests/Unit/classes/models/LengowCustomerTest.php b/tests/Unit/classes/models/LengowCustomerTest.php new file mode 100644 index 00000000..49880aec --- /dev/null +++ b/tests/Unit/classes/models/LengowCustomerTest.php @@ -0,0 +1,39 @@ +customer = new LengowCustomer(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowCustomer::class, + $this->customer, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowExportTest.php b/tests/Unit/classes/models/LengowExportTest.php index 87acc655..db3f7f66 100644 --- a/tests/Unit/classes/models/LengowExportTest.php +++ b/tests/Unit/classes/models/LengowExportTest.php @@ -1,17 +1,39 @@ export = new LengowExport([]); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowExport::class, + $this->export, + '[Test Class Instantiation] Check class instantiation' + ); + } } diff --git a/tests/Unit/classes/models/LengowFeedTest.php b/tests/Unit/classes/models/LengowFeedTest.php new file mode 100644 index 00000000..889ca9a2 --- /dev/null +++ b/tests/Unit/classes/models/LengowFeedTest.php @@ -0,0 +1,39 @@ +feed = new LengowFeed(false, LengowFeed::FORMAT_CSV, false); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowFeed::class, + $this->feed, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowGenderTest.php b/tests/Unit/classes/models/LengowGenderTest.php new file mode 100644 index 00000000..27afe835 --- /dev/null +++ b/tests/Unit/classes/models/LengowGenderTest.php @@ -0,0 +1,39 @@ +gender = new LengowGender(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowGender::class, + $this->gender, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowHookTest.php b/tests/Unit/classes/models/LengowHookTest.php new file mode 100644 index 00000000..f30f3570 --- /dev/null +++ b/tests/Unit/classes/models/LengowHookTest.php @@ -0,0 +1,41 @@ +hook = new LengowHook($module); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowHook::class, + $this->hook, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/phpunit.xml b/tests/Unit/phpunit.xml index 3df9a810..e7d6aa61 100644 --- a/tests/Unit/phpunit.xml +++ b/tests/Unit/phpunit.xml @@ -3,6 +3,7 @@ backupGlobals="true"> + From de274e71b2c121ab65979d34a65f2c895e590d83 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Thu, 6 Jun 2024 16:19:54 +0200 Subject: [PATCH 05/24] ECP-81:[WIP] unit tests in prestashop module --- classes/models/LengowMarketplace.php | 9 +- classes/models/LengowTranslation.php | 18 +- .../classes/models/LengowMarketplaceTest.php | 2230 +++++++++++++++++ 3 files changed, 2253 insertions(+), 4 deletions(-) create mode 100644 tests/Unit/classes/models/LengowMarketplaceTest.php diff --git a/classes/models/LengowMarketplace.php b/classes/models/LengowMarketplace.php index e53a7b6c..1eefe589 100644 --- a/classes/models/LengowMarketplace.php +++ b/classes/models/LengowMarketplace.php @@ -114,13 +114,17 @@ class LengowMarketplace * Construct a new Marketplace instance with marketplace API * * @param string $name name of the marketplace + * @param string $marketplacesData the json data * * @throws LengowException marketplace not present */ - public function __construct($name) + public function __construct($name, $marketplacesData = '') { - self::loadApiMarketplace(); + $this->name = (string) Tools::strtolower($name); + if (!empty($marketplacesData)) { + self::$marketplaces = json_decode($marketplacesData); + } if (!isset(self::$marketplaces->{$this->name})) { self::loadApiMarketplace(true); } @@ -792,3 +796,4 @@ public function hasReturnTrackingNumber(): bool return in_array(LengowAction::ARG_RETURN_TRACKING_NUMBER, $arguments); } } + diff --git a/classes/models/LengowTranslation.php b/classes/models/LengowTranslation.php index 3d5636f2..c4aecc78 100755 --- a/classes/models/LengowTranslation.php +++ b/classes/models/LengowTranslation.php @@ -54,10 +54,13 @@ class LengowTranslation /** * Construct + * + * @param string $isoCode */ - public function __construct() + public function __construct($isoCode = '') { - $this->isoCode = Context::getContext()->language->iso_code; + + $this->isoCode = !empty($isoCode) ? $isoCode : $this->getCurrentIsoCode(); } /** @@ -147,4 +150,15 @@ public function loadFile($isoCode, $filename = null) return !empty($translation); } + + /** + * Returns current language is code + * + * @return string + */ + protected function getCurrentIsoCode() + { + return Context::getContext()->language->iso_code; + } } + diff --git a/tests/Unit/classes/models/LengowMarketplaceTest.php b/tests/Unit/classes/models/LengowMarketplaceTest.php new file mode 100644 index 00000000..5ed4b660 --- /dev/null +++ b/tests/Unit/classes/models/LengowMarketplaceTest.php @@ -0,0 +1,2230 @@ +marketplace = new LengowMarketplace( + 'amazon_fr', + $this->getMarketplacesMock() + ); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowMarketplace::class, + $this->marketplace, + '[Test Class Instantiation] Check class instantiation' + ); + } + + /** + * @return string + */ + protected function getMarketplacesMock() + { + return '{ + "amazon_fr": { + "logo": null, + "name": "Amazon FR", + "orders": { + "status": { + "new": ["Pending", "PendingAvailability"], + "shipped": ["Shipped", "InvoiceUnconfirmed"], + "canceled": ["Canceled"], + "refunded": ["Refunded"], + "waiting_shipment": ["PartiallyShipped", "Unfulfillable", "Unshipped"] + }, + "actions": { + "ship": { + "args": ["carrier", "shipping_method"], + "status": ["waiting_shipment"], + "optional_args": ["carrier_name", "line", "shipping_date", "tracking_number"], + "args_description": { + "line": { + "type": "line_number", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "carrier": { + "type": "list", + "depends_on": null, + "valid_values": { + "4PX": { + "label": "4PX" + }, + "A-1": { + "label": "A-1" + }, + "ABF": { + "label": "ABF" + }, + "ATS": { + "label": "ATS" + }, + "BJS": { + "label": "BJS" + }, + "BRT": { + "label": "BRT" + }, + "CDC": { + "label": "CDC" + }, + "DHL": { + "label": "DHL" + }, + "DPD": { + "label": "DPD" + }, + "DSV": { + "label": "DSV" + }, + "EUB": { + "label": "EUB" + }, + "GLS": { + "label": "GLS" + }, + "GO!": { + "label": "GO!" + }, + "MRW": { + "label": "MRW" + }, + "OSM": { + "label": "OSM" + }, + "R+L": { + "label": "R+L" + }, + "SDA": { + "label": "SDA" + }, + "SFC": { + "label": "SFC" + }, + "TNT": { + "label": "TNT" + }, + "UPS": { + "label": "UPS" + }, + "VIR": { + "label": "VIR" + }, + "XDP": { + "label": "XDP" + }, + "YDH": { + "label": "YDH" + }, + "CEVA": { + "label": "CEVA" + }, + "DTDC": { + "label": "DTDC" + }, + "ECMS": { + "label": "ECMS" + }, + "Gati": { + "label": "Gati" + }, + "JCEX": { + "label": "JCEX" + }, + "Otro": { + "label": "Otro" + }, + "Saia": { + "label": "Saia" + }, + "Seur": { + "label": "Seur" + }, + "USPS": { + "label": "USPS" + }, + "Arkas": { + "label": "Arkas" + }, + "DHLPL": { + "label": "DHLPL" + }, + "Estes": { + "label": "Estes" + }, + "FedEx": { + "label": "FedEx" + }, + "Nacex": { + "label": "Nacex" + }, + "Pilot": { + "label": "Pilot" + }, + "Rieck": { + "label": "Rieck" + }, + "Seino": { + "label": "Seino" + }, + "TIPSA": { + "label": "TIPSA" + }, + "TNTIT": { + "label": "TNTIT" + }, + "UPSMI": { + "label": "UPSMI" + }, + "VNLIN": { + "label": "VNLIN" + }, + "WINIT": { + "label": "WINIT" + }, + "Yodel": { + "label": "Yodel" + }, + "ALLJOY": { + "label": "ALLJOY" + }, + "Aramex": { + "label": "Aramex" + }, + "Asgard": { + "label": "Asgard" + }, + "Assett": { + "label": "Assett" + }, + "Balnak": { + "label": "Balnak" + }, + "Bombax": { + "label": "Bombax" + }, + "Conway": { + "label": "Conway" + }, + "Dotzot": { + "label": "Dotzot" + }, + "Energo": { + "label": "Energo" + }, + "InPost": { + "label": "InPost" + }, + "NITTSU": { + "label": "NITTSU" + }, + "Nexive": { + "label": "Nexive" + }, + "OnTrac": { + "label": "OnTrac" + }, + "Rhenus": { + "label": "Rhenus" + }, + "Rivigo": { + "label": "Rivigo" + }, + "SAGAWA": { + "label": "SAGAWA" + }, + "SENDLE": { + "label": "SENDLE" + }, + "Sendle": { + "label": "Sendle" + }, + "Spoton": { + "label": "Spoton" + }, + "Target": { + "label": "Target" + }, + "YAMATO": { + "label": "YAMATO" + }, + "YANWEN": { + "label": "YANWEN" + }, + "geodis": { + "label": "geodis" + }, + "AT POST": { + "label": "AT POST" + }, + "Asendia": { + "label": "Asendia" + }, + "Correos": { + "label": "Correos" + }, + "DACHSER": { + "label": "DACHSER" + }, + "Fastway": { + "label": "Fastway" + }, + "HS code": { + "label": "HS code" + }, + "Heppner": { + "label": "Heppner" + }, + "Milkman": { + "label": "Milkman" + }, + "Panther": { + "label": "Panther" + }, + "Post NL": { + "label": "Post NL" + }, + "Qxpress": { + "label": "Qxpress" + }, + "Speedex": { + "label": "Speedex" + }, + "Trackon": { + "label": "Trackon" + }, + "iParcel": { + "label": "iParcel" + }, + "Arrow XL": { + "label": "Arrow XL" + }, + "Best Buy": { + "label": "Best Buy" + }, + "BlueDart": { + "label": "BlueDart" + }, + "Correios": { + "label": "Correios" + }, + "Endopack": { + "label": "Endopack" + }, + "Envialia": { + "label": "Envialia" + }, + "Estafeta": { + "label": "Estafeta" + }, + "FEDEX_JP": { + "label": "FEDEX_JP" + }, + "Kargokar": { + "label": "Kargokar" + }, + "La Poste": { + "label": "La Poste" + }, + "Landmark": { + "label": "Landmark" + }, + "Ninjavan": { + "label": "Ninjavan" + }, + "PostNord": { + "label": "PostNord" + }, + "QExpress": { + "label": "QExpress" + }, + "Tourline": { + "label": "Tourline" + }, + "Whizzard": { + "label": "Whizzard" + }, + "AFL\/Fedex": { + "label": "AFL\/Fedex" + }, + "CELERITAS": { + "label": "CELERITAS" + }, + "Cititrans": { + "label": "Cititrans" + }, + "City Link": { + "label": "City Link" + }, + "Coliposte": { + "label": "Coliposte" + }, + "Colissimo": { + "label": "Colissimo" + }, + "DHL Kargo": { + "label": "DHL Kargo" + }, + "DHL-Paket": { + "label": "DHL-Paket" + }, + "Delhivery": { + "label": "Delhivery" + }, + "DirectLog": { + "label": "DirectLog" + }, + "Lasership": { + "label": "Lasership" + }, + "MNG Kargo": { + "label": "MNG Kargo" + }, + "PTT Kargo": { + "label": "PTT Kargo" + }, + "PUROLATOR": { + "label": "PUROLATOR" + }, + "Parcelnet": { + "label": "Parcelnet" + }, + "Smartmail": { + "label": "Smartmail" + }, + "TNT Kargo": { + "label": "TNT Kargo" + }, + "Tuffnells": { + "label": "Tuffnells" + }, + "AAA Cooper": { + "label": "AAA Cooper" + }, + "Aras Kargo": { + "label": "Aras Kargo" + }, + "Bo\u011fazi\u00e7i": { + "label": "Bo\u011fazi\u00e7i" + }, + "CTTExpress": { + "label": "CTTExpress" + }, + "Cart2India": { + "label": "Cart2India" + }, + "China Post": { + "label": "China Post" + }, + "Chronopost": { + "label": "Chronopost" + }, + "DX Freight": { + "label": "DX Freight" + }, + "First Mile": { + "label": "First Mile" + }, + "India Post": { + "label": "India Post" + }, + "JP_EXPRESS": { + "label": "JP_EXPRESS" + }, + "Japan Post": { + "label": "Japan Post" + }, + "Newgistics": { + "label": "Newgistics" + }, + "Roadrunner": { + "label": "Roadrunner" + }, + "Royal Mail": { + "label": "Royal Mail" + }, + "SF Express": { + "label": "SF Express" + }, + "Safexpress": { + "label": "Safexpress" + }, + "ShipGlobal": { + "label": "ShipGlobal" + }, + "Spring GDS": { + "label": "Spring GDS" + }, + "Streamlite": { + "label": "Streamlite" + }, + "TransFolha": { + "label": "TransFolha" + }, + "Xpressbees": { + "label": "Xpressbees" + }, + "AUSSIE_POST": { + "label": "AUSSIE_POST" + }, + "COLIS PRIVE": { + "label": "COLIS PRIVE" + }, + "Canada Post": { + "label": "Canada Post" + }, + "Colis Prive": { + "label": "Colis Prive" + }, + "DB Schenker": { + "label": "DB Schenker" + }, + "DHL Express": { + "label": "DHL Express" + }, + "DHL Freight": { + "label": "DHL Freight" + }, + "Fillo Kargo": { + "label": "Fillo Kargo" + }, + "GEL Express": { + "label": "GEL Express" + }, + "Metro Kargo": { + "label": "Metro Kargo" + }, + "Parcelforce": { + "label": "Parcelforce" + }, + "Polish Post": { + "label": "Polish Post" + }, + "Raben Group": { + "label": "Raben Group" + }, + "STO Express": { + "label": "STO Express" + }, + "Selem Kargo": { + "label": "Selem Kargo" + }, + "ShipEconomy": { + "label": "ShipEconomy" + }, + "UPS Freight": { + "label": "UPS Freight" + }, + "WanbExpress": { + "label": "WanbExpress" + }, + "XPO Freight": { + "label": "XPO Freight" + }, + "YTO Express": { + "label": "YTO Express" + }, + "Yun Express": { + "label": "Yun Express" + }, + "ZTO Express": { + "label": "ZTO Express" + }, + "Best Express": { + "label": "Best Express" + }, + "Blue Package": { + "label": "Blue Package" + }, + "Ecom Express": { + "label": "Ecom Express" + }, + "First Flight": { + "label": "First Flight" + }, + "IDS Netzwerk": { + "label": "IDS Netzwerk" + }, + "Kuehne+Nagel": { + "label": "Kuehne+Nagel" + }, + "Old Dominion": { + "label": "Old Dominion" + }, + "Professional": { + "label": "Professional" + }, + "Ship Delight": { + "label": "Ship Delight" + }, + "S\u00fcrat Kargo": { + "label": "S\u00fcrat Kargo" + }, + "Ceva Lojistik": { + "label": "Ceva Lojistik" + }, + "DHL eCommerce": { + "label": "DHL eCommerce" + }, + "Deutsche Post": { + "label": "Deutsche Post" + }, + "Emirates Post": { + "label": "Emirates Post" + }, + "Fedex Freight": { + "label": "Fedex Freight" + }, + "Geopost Kargo": { + "label": "Geopost Kargo" + }, + "Hongkong Post": { + "label": "Hongkong Post" + }, + "ICC Worldwide": { + "label": "ICC Worldwide" + }, + "Narpost Kargo": { + "label": "Narpost Kargo" + }, + "NipponExpress": { + "label": "NipponExpress" + }, + "Pilot Freight": { + "label": "Pilot Freight" + }, + "SagawaExpress": { + "label": "SagawaExpress" + }, + "Self Delivery": { + "label": "Self Delivery" + }, + "Total Express": { + "label": "Total Express" + }, + "Urban Express": { + "label": "Urban Express" + }, + "Yunda Express": { + "label": "Yunda Express" + }, + "Australia Post": { + "label": "Australia Post" + }, + "Chrono Express": { + "label": "Chrono Express" + }, + "CouriersPlease": { + "label": "CouriersPlease" + }, + "Home Logistics": { + "label": "Home Logistics" + }, + "Horoz Lojistik": { + "label": "Horoz Lojistik" + }, + "Poste Italiane": { + "label": "Poste Italiane" + }, + "Ship Global US": { + "label": "Ship Global US" + }, + "Singapore Post": { + "label": "Singapore Post" + }, + "Tezel Lojistik": { + "label": "Tezel Lojistik" + }, + "Yellow Freight": { + "label": "Yellow Freight" + }, + "Yurti\u00e7i Kargo": { + "label": "Yurti\u00e7i Kargo" + }, + "Amazon Shipping": { + "label": "Amazon Shipping" + }, + "Correos Express": { + "label": "Correos Express" + }, + "Couriers Please": { + "label": "Couriers Please" + }, + "DHL Global Mail": { + "label": "DHL Global Mail" + }, + "FedEx SmartPost": { + "label": "FedEx SmartPost" + }, + "OneWorldExpress": { + "label": "OneWorldExpress" + }, + "YamatoTransport": { + "label": "YamatoTransport" + }, + "Digital Delivery": { + "label": "Digital Delivery" + }, + "Geodis Calberson": { + "label": "Geodis Calberson" + }, + "Hunter Logistics": { + "label": "Hunter Logistics" + }, + "Overnite Express": { + "label": "Overnite Express" + }, + "Shunfeng Express": { + "label": "Shunfeng Express" + }, + "DHL Home Delivery": { + "label": "DHL Home Delivery" + }, + "First Flight China": { + "label": "First Flight China" + }, + "StarTrack-ArticleID": { + "label": "StarTrack-ArticleID" + }, + "Toll Global Express": { + "label": "Toll Global Express" + }, + "Watkins and Shepard": { + "label": "Watkins and Shepard" + }, + "SEINO TRANSPORTATION": { + "label": "SEINO TRANSPORTATION" + }, + "Shree Maruti Courier": { + "label": "Shree Maruti Courier" + }, + "UPS Mail Innovations": { + "label": "UPS Mail Innovations" + }, + "StarTrack-Consignment": { + "label": "StarTrack-Consignment" + }, + "Hermes Logistik Gruppe": { + "label": "Hermes Logistik Gruppe" + }, + "Shree Tirupati Courier": { + "label": "Shree Tirupati Courier" + }, + "AustraliaPost-ArticleId": { + "label": "AustraliaPost-ArticleId" + }, + "Beijing Quanfeng Express": { + "label": "Beijing Quanfeng Express" + }, + "AustraliaPost-Consignment": { + "label": "AustraliaPost-Consignment" + }, + "The Professional Couriers": { + "label": "The Professional Couriers" + }, + "Hermes Einrichtungsservice": { + "label": "Hermes Einrichtungsservice" + }, + "South Eastern Freight Lines": { + "label": "South Eastern Freight Lines" + } + }, + "default_value": "", + "accept_free_values": true + }, + "carrier_name": { + "type": "string", + "depends_on": { + "operation": "allOf", + "conditions": [{ + "value": "Other", + "function": "equals", + "key_path": { + "path": "carrier", + "root": "action_data" + } + }] + }, + "valid_values": {}, + "default_value": "", + "accept_free_values": true + }, + "shipping_date": { + "type": "date", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "shipping_method": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "tracking_number": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + } + } + }, + "cancel": { + "args": [], + "status": ["new", "waiting_shipment"], + "optional_args": ["line", "reason"], + "args_description": { + "line": { + "type": "line_number", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "reason": { + "type": "list", + "depends_on": null, + "valid_values": { + "NoInventory": { + "label": "No inventory" + }, + "BuyerCanceled": { + "label": "Buyer canceled" + }, + "CustomerReturn": { + "label": "Customer return" + }, + "CustomerExchange": { + "label": "Customer exchange" + }, + "GeneralAdjustment": { + "label": "General adjustment" + }, + "CarrierCreditDecision": { + "label": "Carrier credit decision" + }, + "CarrierCoverageFailure": { + "label": "Carrier coverage failure" + }, + "MerchandiseNotReceived": { + "label": "Merchandise not received" + }, + "ShippingAddressUndeliverable": { + "label": "Shipping address undeliverable" + }, + "RiskAssessmentInformationNotValid": { + "label": "Risk assessment information not valid" + } + }, + "default_value": null, + "accept_free_values": false + } + } + }, + "refund": { + "args": ["line", "reason"], + "status": ["shipped"], + "optional_args": ["refund_price", "refund_shipping_price", "refund_shipping_taxes", "refund_taxes"], + "args_description": { + "line": { + "type": "line_number", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "reason": { + "type": "list", + "depends_on": null, + "valid_values": { + "Other": { + "label": "Other" + }, + "Exchange": { + "label": "Exchange" + }, + "PriceError": { + "label": "Price Error" + }, + "NoInventory": { + "label": "No inventory" + }, + "CouldNotShip": { + "label": "Could not ship" + }, + "CustomerReturn": { + "label": "Customer return" + }, + "GeneralAdjustment": { + "label": "General adjustment" + }, + "ProductOutofStock": { + "label": "Product out of stock" + }, + "TransactionRecord": { + "label": "Transaction record" + }, + "CarrierCreditDecision": { + "label": "Carrier credit decision" + }, + "CarrierCoverageFailure": { + "label": "Carrier coverage failure" + }, + "CustomerAddressIncorrect": { + "label": "Customer address incorrect" + }, + "RiskAssessmentInformationNotValid": { + "label": "Risk assessment information not valid" + } + }, + "default_value": "ProductOutofStock", + "accept_free_values": false + }, + "refund_price": { + "type": "price", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "refund_taxes": { + "type": "price", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "refund_shipping_price": { + "type": "price", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "refund_shipping_taxes": { + "type": "price", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + } + } + }, + "buy_shipment_label": { + "args": ["carrier_pickup", "currency_code", "declared_value", "delivery_experience", "from_address_city", "from_address_country_code", "from_address_line", "from_address_mail", "from_address_name", "from_address_phone", "from_address_postal_code", "package_dimension_height", "package_dimension_length", "package_dimension_unit", "package_dimension_width", "shipping_date", "shipping_service_id", "weight", "weight_unit"], + "status": [], + "optional_args": ["carrier", "delivery_date", "from_address_state_province", "line", "tracking_number"], + "args_description": { + "line": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "weight": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "carrier": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "weight_unit": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "currency_code": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "delivery_date": { + "type": "date", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "shipping_date": { + "type": "date", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "carrier_pickup": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "declared_value": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "tracking_number": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_city": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_line": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_mail": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_name": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_phone": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "delivery_experience": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "shipping_service_id": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "package_dimension_unit": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "package_dimension_width": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_postal_code": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "package_dimension_height": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "package_dimension_length": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_country_code": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_state_province": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + } + } + }, + "set_eligible_shipping_methods": { + "args": ["carrier_pickup", "currency_code", "declared_value", "delivery_experience", "from_address_city", "from_address_country_code", "from_address_line", "from_address_mail", "from_address_name", "from_address_phone", "from_address_postal_code", "package_dimension_height", "package_dimension_length", "package_dimension_unit", "package_dimension_width", "shipping_date", "weight", "weight_unit"], + "status": [], + "optional_args": ["delivery_date", "from_address_state_province", "line"], + "args_description": { + "line": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "weight": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "weight_unit": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "currency_code": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "delivery_date": { + "type": "date", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "shipping_date": { + "type": "date", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "carrier_pickup": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "declared_value": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_city": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_line": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_mail": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_name": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_phone": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "delivery_experience": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "package_dimension_unit": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "package_dimension_width": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_postal_code": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "package_dimension_height": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "package_dimension_length": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_country_code": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + }, + "from_address_state_province": { + "type": "string", + "depends_on": null, + "valid_values": {}, + "default_value": null, + "accept_free_values": true + } + } + } + }, + "carriers": { + "4PX": { + "label": "4PX", + "lengow_code": null + }, + "A-1": { + "label": "A-1", + "lengow_code": null + }, + "ABF": { + "label": "ABF", + "lengow_code": null + }, + "ATS": { + "label": "ATS", + "lengow_code": null + }, + "BJS": { + "label": "BJS", + "lengow_code": null + }, + "BRT": { + "label": "BRT", + "lengow_code": null + }, + "CDC": { + "label": "CDC", + "lengow_code": null + }, + "DHL": { + "label": "DHL", + "lengow_code": null + }, + "DPD": { + "label": "DPD", + "lengow_code": null + }, + "DSV": { + "label": "DSV", + "lengow_code": null + }, + "EUB": { + "label": "EUB", + "lengow_code": null + }, + "GLS": { + "label": "GLS", + "lengow_code": null + }, + "GO!": { + "label": "GO!", + "lengow_code": null + }, + "MRW": { + "label": "MRW", + "lengow_code": null + }, + "OSM": { + "label": "OSM", + "lengow_code": null + }, + "R+L": { + "label": "R+L", + "lengow_code": null + }, + "SDA": { + "label": "SDA", + "lengow_code": null + }, + "SFC": { + "label": "SFC", + "lengow_code": null + }, + "TNT": { + "label": "TNT", + "lengow_code": null + }, + "UPS": { + "label": "UPS", + "lengow_code": null + }, + "VIR": { + "label": "VIR", + "lengow_code": null + }, + "XDP": { + "label": "XDP", + "lengow_code": null + }, + "YDH": { + "label": "YDH", + "lengow_code": null + }, + "CEVA": { + "label": "CEVA", + "lengow_code": null + }, + "DTDC": { + "label": "DTDC", + "lengow_code": null + }, + "ECMS": { + "label": "ECMS", + "lengow_code": null + }, + "Gati": { + "label": "Gati", + "lengow_code": null + }, + "JCEX": { + "label": "JCEX", + "lengow_code": null + }, + "Otro": { + "label": "Otro", + "lengow_code": null + }, + "Saia": { + "label": "Saia", + "lengow_code": null + }, + "Seur": { + "label": "Seur", + "lengow_code": null + }, + "USPS": { + "label": "USPS", + "lengow_code": null + }, + "Arkas": { + "label": "Arkas", + "lengow_code": null + }, + "DHLPL": { + "label": "DHLPL", + "lengow_code": null + }, + "Estes": { + "label": "Estes", + "lengow_code": null + }, + "FedEx": { + "label": "FedEx", + "lengow_code": null + }, + "Nacex": { + "label": "Nacex", + "lengow_code": null + }, + "Pilot": { + "label": "Pilot", + "lengow_code": null + }, + "Rieck": { + "label": "Rieck", + "lengow_code": null + }, + "Seino": { + "label": "Seino", + "lengow_code": null + }, + "TIPSA": { + "label": "TIPSA", + "lengow_code": null + }, + "TNTIT": { + "label": "TNTIT", + "lengow_code": null + }, + "UPSMI": { + "label": "UPSMI", + "lengow_code": null + }, + "VNLIN": { + "label": "VNLIN", + "lengow_code": null + }, + "WINIT": { + "label": "WINIT", + "lengow_code": null + }, + "Yodel": { + "label": "Yodel", + "lengow_code": null + }, + "ALLJOY": { + "label": "ALLJOY", + "lengow_code": null + }, + "Aramex": { + "label": "Aramex", + "lengow_code": null + }, + "Asgard": { + "label": "Asgard", + "lengow_code": null + }, + "Assett": { + "label": "Assett", + "lengow_code": null + }, + "Balnak": { + "label": "Balnak", + "lengow_code": null + }, + "Bombax": { + "label": "Bombax", + "lengow_code": null + }, + "Conway": { + "label": "Conway", + "lengow_code": null + }, + "Dotzot": { + "label": "Dotzot", + "lengow_code": null + }, + "Energo": { + "label": "Energo", + "lengow_code": null + }, + "InPost": { + "label": "InPost", + "lengow_code": null + }, + "NITTSU": { + "label": "NITTSU", + "lengow_code": null + }, + "Nexive": { + "label": "Nexive", + "lengow_code": null + }, + "OnTrac": { + "label": "OnTrac", + "lengow_code": null + }, + "Rhenus": { + "label": "Rhenus", + "lengow_code": null + }, + "Rivigo": { + "label": "Rivigo", + "lengow_code": null + }, + "SAGAWA": { + "label": "SAGAWA", + "lengow_code": null + }, + "SENDLE": { + "label": "SENDLE", + "lengow_code": null + }, + "Sendle": { + "label": "Sendle", + "lengow_code": null + }, + "Spoton": { + "label": "Spoton", + "lengow_code": null + }, + "Target": { + "label": "Target", + "lengow_code": null + }, + "YAMATO": { + "label": "YAMATO", + "lengow_code": null + }, + "YANWEN": { + "label": "YANWEN", + "lengow_code": null + }, + "geodis": { + "label": "geodis", + "lengow_code": null + }, + "AT POST": { + "label": "AT POST", + "lengow_code": null + }, + "Asendia": { + "label": "Asendia", + "lengow_code": null + }, + "Correos": { + "label": "Correos", + "lengow_code": null + }, + "DACHSER": { + "label": "DACHSER", + "lengow_code": null + }, + "Fastway": { + "label": "Fastway", + "lengow_code": null + }, + "HS code": { + "label": "HS code", + "lengow_code": null + }, + "Heppner": { + "label": "Heppner", + "lengow_code": null + }, + "Milkman": { + "label": "Milkman", + "lengow_code": null + }, + "Panther": { + "label": "Panther", + "lengow_code": null + }, + "Post NL": { + "label": "Post NL", + "lengow_code": null + }, + "Qxpress": { + "label": "Qxpress", + "lengow_code": null + }, + "Speedex": { + "label": "Speedex", + "lengow_code": null + }, + "Trackon": { + "label": "Trackon", + "lengow_code": null + }, + "iParcel": { + "label": "iParcel", + "lengow_code": null + }, + "Arrow XL": { + "label": "Arrow XL", + "lengow_code": null + }, + "Best Buy": { + "label": "Best Buy", + "lengow_code": null + }, + "BlueDart": { + "label": "BlueDart", + "lengow_code": null + }, + "Correios": { + "label": "Correios", + "lengow_code": null + }, + "Endopack": { + "label": "Endopack", + "lengow_code": null + }, + "Envialia": { + "label": "Envialia", + "lengow_code": null + }, + "Estafeta": { + "label": "Estafeta", + "lengow_code": null + }, + "FEDEX_JP": { + "label": "FEDEX_JP", + "lengow_code": null + }, + "Kargokar": { + "label": "Kargokar", + "lengow_code": null + }, + "La Poste": { + "label": "La Poste", + "lengow_code": null + }, + "Landmark": { + "label": "Landmark", + "lengow_code": null + }, + "Ninjavan": { + "label": "Ninjavan", + "lengow_code": null + }, + "PostNord": { + "label": "PostNord", + "lengow_code": null + }, + "QExpress": { + "label": "QExpress", + "lengow_code": null + }, + "Tourline": { + "label": "Tourline", + "lengow_code": null + }, + "Whizzard": { + "label": "Whizzard", + "lengow_code": null + }, + "AFL\/Fedex": { + "label": "AFL\/Fedex", + "lengow_code": null + }, + "CELERITAS": { + "label": "CELERITAS", + "lengow_code": null + }, + "Cititrans": { + "label": "Cititrans", + "lengow_code": null + }, + "City Link": { + "label": "City Link", + "lengow_code": null + }, + "Coliposte": { + "label": "Coliposte", + "lengow_code": null + }, + "Colissimo": { + "label": "Colissimo", + "lengow_code": null + }, + "DHL Kargo": { + "label": "DHL Kargo", + "lengow_code": null + }, + "DHL-Paket": { + "label": "DHL-Paket", + "lengow_code": null + }, + "Delhivery": { + "label": "Delhivery", + "lengow_code": null + }, + "DirectLog": { + "label": "DirectLog", + "lengow_code": null + }, + "Lasership": { + "label": "Lasership", + "lengow_code": null + }, + "MNG Kargo": { + "label": "MNG Kargo", + "lengow_code": null + }, + "PTT Kargo": { + "label": "PTT Kargo", + "lengow_code": null + }, + "PUROLATOR": { + "label": "PUROLATOR", + "lengow_code": null + }, + "Parcelnet": { + "label": "Parcelnet", + "lengow_code": null + }, + "Smartmail": { + "label": "Smartmail", + "lengow_code": null + }, + "TNT Kargo": { + "label": "TNT Kargo", + "lengow_code": null + }, + "Tuffnells": { + "label": "Tuffnells", + "lengow_code": null + }, + "AAA Cooper": { + "label": "AAA Cooper", + "lengow_code": null + }, + "Aras Kargo": { + "label": "Aras Kargo", + "lengow_code": null + }, + "Bo\u011fazi\u00e7i": { + "label": "Bo\u011fazi\u00e7i", + "lengow_code": null + }, + "CTTExpress": { + "label": "CTTExpress", + "lengow_code": null + }, + "Cart2India": { + "label": "Cart2India", + "lengow_code": null + }, + "China Post": { + "label": "China Post", + "lengow_code": null + }, + "Chronopost": { + "label": "Chronopost", + "lengow_code": null + }, + "DX Freight": { + "label": "DX Freight", + "lengow_code": null + }, + "First Mile": { + "label": "First Mile", + "lengow_code": null + }, + "India Post": { + "label": "India Post", + "lengow_code": null + }, + "JP_EXPRESS": { + "label": "JP_EXPRESS", + "lengow_code": null + }, + "Japan Post": { + "label": "Japan Post", + "lengow_code": null + }, + "Newgistics": { + "label": "Newgistics", + "lengow_code": null + }, + "Roadrunner": { + "label": "Roadrunner", + "lengow_code": null + }, + "Royal Mail": { + "label": "Royal Mail", + "lengow_code": null + }, + "SF Express": { + "label": "SF Express", + "lengow_code": null + }, + "Safexpress": { + "label": "Safexpress", + "lengow_code": null + }, + "ShipGlobal": { + "label": "ShipGlobal", + "lengow_code": null + }, + "Spring GDS": { + "label": "Spring GDS", + "lengow_code": null + }, + "Streamlite": { + "label": "Streamlite", + "lengow_code": null + }, + "TransFolha": { + "label": "TransFolha", + "lengow_code": null + }, + "Xpressbees": { + "label": "Xpressbees", + "lengow_code": null + }, + "AUSSIE_POST": { + "label": "AUSSIE_POST", + "lengow_code": null + }, + "COLIS PRIVE": { + "label": "COLIS PRIVE", + "lengow_code": null + }, + "Canada Post": { + "label": "Canada Post", + "lengow_code": null + }, + "Colis Prive": { + "label": "Colis Prive", + "lengow_code": null + }, + "DB Schenker": { + "label": "DB Schenker", + "lengow_code": null + }, + "DHL Express": { + "label": "DHL Express", + "lengow_code": null + }, + "DHL Freight": { + "label": "DHL Freight", + "lengow_code": null + }, + "Fillo Kargo": { + "label": "Fillo Kargo", + "lengow_code": null + }, + "GEL Express": { + "label": "GEL Express", + "lengow_code": null + }, + "Metro Kargo": { + "label": "Metro Kargo", + "lengow_code": null + }, + "Parcelforce": { + "label": "Parcelforce", + "lengow_code": null + }, + "Polish Post": { + "label": "Polish Post", + "lengow_code": null + }, + "Raben Group": { + "label": "Raben Group", + "lengow_code": null + }, + "STO Express": { + "label": "STO Express", + "lengow_code": null + }, + "Selem Kargo": { + "label": "Selem Kargo", + "lengow_code": null + }, + "ShipEconomy": { + "label": "ShipEconomy", + "lengow_code": null + }, + "UPS Freight": { + "label": "UPS Freight", + "lengow_code": null + }, + "WanbExpress": { + "label": "WanbExpress", + "lengow_code": null + }, + "XPO Freight": { + "label": "XPO Freight", + "lengow_code": null + }, + "YTO Express": { + "label": "YTO Express", + "lengow_code": null + }, + "Yun Express": { + "label": "Yun Express", + "lengow_code": null + }, + "ZTO Express": { + "label": "ZTO Express", + "lengow_code": null + }, + "Best Express": { + "label": "Best Express", + "lengow_code": null + }, + "Blue Package": { + "label": "Blue Package", + "lengow_code": null + }, + "Ecom Express": { + "label": "Ecom Express", + "lengow_code": null + }, + "First Flight": { + "label": "First Flight", + "lengow_code": null + }, + "IDS Netzwerk": { + "label": "IDS Netzwerk", + "lengow_code": null + }, + "Kuehne+Nagel": { + "label": "Kuehne+Nagel", + "lengow_code": null + }, + "Old Dominion": { + "label": "Old Dominion", + "lengow_code": null + }, + "Professional": { + "label": "Professional", + "lengow_code": null + }, + "Ship Delight": { + "label": "Ship Delight", + "lengow_code": null + }, + "S\u00fcrat Kargo": { + "label": "S\u00fcrat Kargo", + "lengow_code": null + }, + "Ceva Lojistik": { + "label": "Ceva Lojistik", + "lengow_code": null + }, + "DHL eCommerce": { + "label": "DHL eCommerce", + "lengow_code": null + }, + "Deutsche Post": { + "label": "Deutsche Post", + "lengow_code": null + }, + "Emirates Post": { + "label": "Emirates Post", + "lengow_code": null + }, + "Fedex Freight": { + "label": "Fedex Freight", + "lengow_code": null + }, + "Geopost Kargo": { + "label": "Geopost Kargo", + "lengow_code": null + }, + "Hongkong Post": { + "label": "Hongkong Post", + "lengow_code": null + }, + "ICC Worldwide": { + "label": "ICC Worldwide", + "lengow_code": null + }, + "Narpost Kargo": { + "label": "Narpost Kargo", + "lengow_code": null + }, + "NipponExpress": { + "label": "NipponExpress", + "lengow_code": null + }, + "Pilot Freight": { + "label": "Pilot Freight", + "lengow_code": null + }, + "SagawaExpress": { + "label": "SagawaExpress", + "lengow_code": null + }, + "Self Delivery": { + "label": "Self Delivery", + "lengow_code": null + }, + "Total Express": { + "label": "Total Express", + "lengow_code": null + }, + "Urban Express": { + "label": "Urban Express", + "lengow_code": null + }, + "Yunda Express": { + "label": "Yunda Express", + "lengow_code": null + }, + "Australia Post": { + "label": "Australia Post", + "lengow_code": null + }, + "Chrono Express": { + "label": "Chrono Express", + "lengow_code": null + }, + "CouriersPlease": { + "label": "CouriersPlease", + "lengow_code": null + }, + "Home Logistics": { + "label": "Home Logistics", + "lengow_code": null + }, + "Horoz Lojistik": { + "label": "Horoz Lojistik", + "lengow_code": null + }, + "Poste Italiane": { + "label": "Poste Italiane", + "lengow_code": null + }, + "Ship Global US": { + "label": "Ship Global US", + "lengow_code": null + }, + "Singapore Post": { + "label": "Singapore Post", + "lengow_code": null + }, + "Tezel Lojistik": { + "label": "Tezel Lojistik", + "lengow_code": null + }, + "Yellow Freight": { + "label": "Yellow Freight", + "lengow_code": null + }, + "Yurti\u00e7i Kargo": { + "label": "Yurti\u00e7i Kargo", + "lengow_code": null + }, + "Amazon Shipping": { + "label": "Amazon Shipping", + "lengow_code": null + }, + "Correos Express": { + "label": "Correos Express", + "lengow_code": null + }, + "Couriers Please": { + "label": "Couriers Please", + "lengow_code": null + }, + "DHL Global Mail": { + "label": "DHL Global Mail", + "lengow_code": null + }, + "FedEx SmartPost": { + "label": "FedEx SmartPost", + "lengow_code": null + }, + "OneWorldExpress": { + "label": "OneWorldExpress", + "lengow_code": null + }, + "YamatoTransport": { + "label": "YamatoTransport", + "lengow_code": null + }, + "Digital Delivery": { + "label": "Digital Delivery", + "lengow_code": null + }, + "Geodis Calberson": { + "label": "Geodis Calberson", + "lengow_code": null + }, + "Hunter Logistics": { + "label": "Hunter Logistics", + "lengow_code": null + }, + "Overnite Express": { + "label": "Overnite Express", + "lengow_code": null + }, + "Shunfeng Express": { + "label": "Shunfeng Express", + "lengow_code": null + }, + "DHL Home Delivery": { + "label": "DHL Home Delivery", + "lengow_code": null + }, + "First Flight China": { + "label": "First Flight China", + "lengow_code": null + }, + "StarTrack-ArticleID": { + "label": "StarTrack-ArticleID", + "lengow_code": null + }, + "Toll Global Express": { + "label": "Toll Global Express", + "lengow_code": null + }, + "Watkins and Shepard": { + "label": "Watkins and Shepard", + "lengow_code": null + }, + "SEINO TRANSPORTATION": { + "label": "SEINO TRANSPORTATION", + "lengow_code": null + }, + "Shree Maruti Courier": { + "label": "Shree Maruti Courier", + "lengow_code": null + }, + "UPS Mail Innovations": { + "label": "UPS Mail Innovations", + "lengow_code": null + }, + "StarTrack-Consignment": { + "label": "StarTrack-Consignment", + "lengow_code": null + }, + "Hermes Logistik Gruppe": { + "label": "Hermes Logistik Gruppe", + "lengow_code": null + }, + "Shree Tirupati Courier": { + "label": "Shree Tirupati Courier", + "lengow_code": null + }, + "AustraliaPost-ArticleId": { + "label": "AustraliaPost-ArticleId", + "lengow_code": null + }, + "Beijing Quanfeng Express": { + "label": "Beijing Quanfeng Express", + "lengow_code": null + }, + "AustraliaPost-Consignment": { + "label": "AustraliaPost-Consignment", + "lengow_code": null + }, + "The Professional Couriers": { + "label": "The Professional Couriers", + "lengow_code": null + }, + "Hermes Einrichtungsservice": { + "label": "Hermes Einrichtungsservice", + "lengow_code": null + }, + "South Eastern Freight Lines": { + "label": "South Eastern Freight Lines", + "lengow_code": null + } + }, + "shipping_methods": { + "NextDay": { + "label": "NextDay", + "lengow_code": "nextday" + }, + "SameDay": { + "label": "SameDay", + "lengow_code": "sameday" + }, + "Priority": { + "label": "Priority", + "lengow_code": null + }, + "Standard": { + "label": "Standard", + "lengow_code": "standard" + }, + "Expedited": { + "label": "Expedited", + "lengow_code": "expedited" + }, + "Scheduled": { + "label": "Scheduled", + "lengow_code": "scheduled" + }, + "SecondDay": { + "label": "SecondDay", + "lengow_code": "secondday" + }, + "FreeEconomy": { + "label": "FreeEconomy", + "lengow_code": "freeeconomy" + }, + "BuyerTaxInfo": { + "label": "BuyerTaxInfo", + "lengow_code": "buyertaxinfo" + } + } + }, + "country": "FRA", + "package": "sp_amazon.mp.fr", + "homepage": "http:\/\/www.amazon.com\/", + "description": "A generalist marketplace, Amazon is designed for all sellers seeking to reach a wide audience whether locally or internationally. Appear in Amazon\'s search results thanks to a well-structured feed, create detailed and attractive pages and win the buy box. \r\nAmazon offers you a broad range of associated services such as \u201cFulfilled by Amazon\u201d, which allows you to delegate the management of your stock and the dispatching of your products to the ecommerce giant. \r\n\r\nChoose your feed:\r\n- The Amazon feed to create and publish your product catalogue for products that are not yet sold on the marketplace.\r\n- The Listing Loader feed to attach your products to existing product sheets.\r\n\r\nStart selling on the world\u2019s leading ecommerce site!", + "legacy_code": "amazon", + "country_iso_a2": "FR" + } + }'; + } +} From 62965f1a77a56e62b38b7f835d1af1b3f0214a0b Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Thu, 6 Jun 2024 17:11:06 +0200 Subject: [PATCH 06/24] ECP-81:[WIP] unit tests in prestashop module --- .../Unit/classes/models/LengowMethodTest.php | 38 +++++++++++++++++++ .../classes/models/LengowNameParserTest.php | 38 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tests/Unit/classes/models/LengowMethodTest.php create mode 100644 tests/Unit/classes/models/LengowNameParserTest.php diff --git a/tests/Unit/classes/models/LengowMethodTest.php b/tests/Unit/classes/models/LengowMethodTest.php new file mode 100644 index 00000000..da9af164 --- /dev/null +++ b/tests/Unit/classes/models/LengowMethodTest.php @@ -0,0 +1,38 @@ +method = new LengowMethod(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowMethod::class, + $this->method, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowNameParserTest.php b/tests/Unit/classes/models/LengowNameParserTest.php new file mode 100644 index 00000000..9262345d --- /dev/null +++ b/tests/Unit/classes/models/LengowNameParserTest.php @@ -0,0 +1,38 @@ +nameParser = new LengowNameParser(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowNameParser::class, + $this->nameParser, + '[Test Class Instantiation] Check class instantiation' + ); + } +} From 4989c09e076dda4c2af6ee3baba543c79acd177c Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Thu, 6 Jun 2024 17:12:24 +0200 Subject: [PATCH 07/24] ECP-81:[WIP] unit tests in prestashop module --- tests/Unit/classes/models/LengowTranslationTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Unit/classes/models/LengowTranslationTest.php b/tests/Unit/classes/models/LengowTranslationTest.php index 39652655..69a7dd77 100644 --- a/tests/Unit/classes/models/LengowTranslationTest.php +++ b/tests/Unit/classes/models/LengowTranslationTest.php @@ -15,8 +15,6 @@ class LengowTranslationTest extends TestCase */ protected $translate; - //protected $translateClass = 'LengowTranslation'; - /** * setup * @@ -24,7 +22,7 @@ class LengowTranslationTest extends TestCase */ public function setup(): void { - $this->translate = new LengowTranslation('fr'); + $this->translate = new LengowTranslation('en'); } /** From b9da7b0763a160baeeb9c449f3458f628f6686a7 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Thu, 6 Jun 2024 17:16:41 +0200 Subject: [PATCH 08/24] ECP-81:[WIP] unit tests in prestashop module --- tests/Unit/classes/models/LengowOrderTest.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/Unit/classes/models/LengowOrderTest.php diff --git a/tests/Unit/classes/models/LengowOrderTest.php b/tests/Unit/classes/models/LengowOrderTest.php new file mode 100644 index 00000000..9caa6508 --- /dev/null +++ b/tests/Unit/classes/models/LengowOrderTest.php @@ -0,0 +1,38 @@ +order = new LengowOrder(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowOrder::class, + $this->order, + '[Test Class Instantiation] Check class instantiation' + ); + } +} From e7d798199883074bae798b82f5301c636d261ccc Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Thu, 6 Jun 2024 17:17:54 +0200 Subject: [PATCH 09/24] ECP-81:[WIP] unit tests in prestashop module --- tests/Unit/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index 2e1e35ea..8bd237cb 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -25,7 +25,7 @@ */ //php7.4 -d date.timezone=UTC ./vendor/phpunit/phpunit/phpunit -c modules/lengow/tests/Unit/phpunit.xml modules/lengow/tests/Unit -//define('_PS_IN_TEST_', true); +//define('_PS_IN_TEST_', true) need a database named test_._DB_NAME_; define('_PS_ROOT_DIR_', __DIR__ . '/../../../..'); define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/modules/'); require_once __DIR__ . '/../../../../config/defines.inc.php'; From 94637e1a7952ff57adfcd765ab17dde5e206a379 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Thu, 6 Jun 2024 17:20:25 +0200 Subject: [PATCH 10/24] ECP-81:[WIP] unit tests in prestashop module --- tests/Unit/classes/index.php | 29 +++++++++++++++++++++++++++++ tests/Unit/classes/models/index.php | 29 +++++++++++++++++++++++++++++ tests/Unit/index.php | 29 +++++++++++++++++++++++++++++ tests/index.php | 29 +++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 tests/Unit/classes/index.php create mode 100644 tests/Unit/classes/models/index.php create mode 100644 tests/Unit/index.php create mode 100644 tests/index.php diff --git a/tests/Unit/classes/index.php b/tests/Unit/classes/index.php new file mode 100644 index 00000000..ebf17e2b --- /dev/null +++ b/tests/Unit/classes/index.php @@ -0,0 +1,29 @@ + + * @copyright 2017 Lengow SAS + * @license http://www.apache.org/licenses/LICENSE-2.0 + */ +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; diff --git a/tests/Unit/classes/models/index.php b/tests/Unit/classes/models/index.php new file mode 100644 index 00000000..ebf17e2b --- /dev/null +++ b/tests/Unit/classes/models/index.php @@ -0,0 +1,29 @@ + + * @copyright 2017 Lengow SAS + * @license http://www.apache.org/licenses/LICENSE-2.0 + */ +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; diff --git a/tests/Unit/index.php b/tests/Unit/index.php new file mode 100644 index 00000000..ebf17e2b --- /dev/null +++ b/tests/Unit/index.php @@ -0,0 +1,29 @@ + + * @copyright 2017 Lengow SAS + * @license http://www.apache.org/licenses/LICENSE-2.0 + */ +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; diff --git a/tests/index.php b/tests/index.php new file mode 100644 index 00000000..ebf17e2b --- /dev/null +++ b/tests/index.php @@ -0,0 +1,29 @@ + + * @copyright 2017 Lengow SAS + * @license http://www.apache.org/licenses/LICENSE-2.0 + */ +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; From b802134788be5788c649244788bda573a8b5f97e Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Thu, 6 Jun 2024 17:28:16 +0200 Subject: [PATCH 11/24] ECP-81:[WIP] unit tests in prestashop module --- .../classes/models/LengowOrderCarrierTest.php | 38 +++++++++++++++++++ .../classes/models/LengowOrderDetailTest.php | 38 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tests/Unit/classes/models/LengowOrderCarrierTest.php create mode 100644 tests/Unit/classes/models/LengowOrderDetailTest.php diff --git a/tests/Unit/classes/models/LengowOrderCarrierTest.php b/tests/Unit/classes/models/LengowOrderCarrierTest.php new file mode 100644 index 00000000..1eb2ba86 --- /dev/null +++ b/tests/Unit/classes/models/LengowOrderCarrierTest.php @@ -0,0 +1,38 @@ +orderCarrier = new LengowOrderCarrier(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowOrderCarrier::class, + $this->orderCarrier, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowOrderDetailTest.php b/tests/Unit/classes/models/LengowOrderDetailTest.php new file mode 100644 index 00000000..1c9cfe01 --- /dev/null +++ b/tests/Unit/classes/models/LengowOrderDetailTest.php @@ -0,0 +1,38 @@ +orderDetail = new LengowOrderDetail(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + LengowOrderDetail::class, + $this->orderDetail, + '[Test Class Instantiation] Check class instantiation' + ); + } +} From 47992a3e041ce720a861f6743462deca11995c44 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Thu, 6 Jun 2024 17:33:37 +0200 Subject: [PATCH 12/24] ECP-81:[WIP] unit tests in prestashop module --- tests/Unit/Fixture.php | 30 ++++++++----------- tests/Unit/bootstrap.php | 11 +++---- .../Unit/classes/models/LengowActionTest.php | 10 ++----- .../Unit/classes/models/LengowAddressTest.php | 10 ++----- .../Unit/classes/models/LengowBackupTest.php | 10 ++----- .../Unit/classes/models/LengowCarrierTest.php | 10 ++----- tests/Unit/classes/models/LengowCartTest.php | 10 ++----- .../Unit/classes/models/LengowCatalogTest.php | 10 ++----- .../models/LengowConfigurationFormTest.php | 10 ++----- .../models/LengowConfigurationTest.php | 10 ++----- .../classes/models/LengowConnectorTest.php | 14 ++++----- .../Unit/classes/models/LengowCountryTest.php | 10 ++----- .../classes/models/LengowCustomerTest.php | 10 ++----- .../classes/models/LengowExceptionTest.php | 6 ++-- .../Unit/classes/models/LengowExportTest.php | 10 ++----- tests/Unit/classes/models/LengowFeedTest.php | 10 ++----- tests/Unit/classes/models/LengowFileTest.php | 10 ++----- .../Unit/classes/models/LengowGenderTest.php | 10 ++----- tests/Unit/classes/models/LengowHookTest.php | 13 +++----- tests/Unit/classes/models/LengowLogTest.php | 9 ++---- .../classes/models/LengowMarketplaceTest.php | 9 ++---- .../Unit/classes/models/LengowMethodTest.php | 9 ++---- .../classes/models/LengowNameParserTest.php | 9 ++---- .../classes/models/LengowOrderCarrierTest.php | 9 ++---- .../classes/models/LengowOrderDetailTest.php | 9 ++---- tests/Unit/classes/models/LengowOrderTest.php | 9 ++---- .../classes/models/LengowTranslationTest.php | 10 ++----- 27 files changed, 95 insertions(+), 192 deletions(-) diff --git a/tests/Unit/Fixture.php b/tests/Unit/Fixture.php index a86dcaf6..89167761 100644 --- a/tests/Unit/Fixture.php +++ b/tests/Unit/Fixture.php @@ -10,8 +10,7 @@ * http://opensource.org/licenses/osl-3.0.php * * @category Lengow - * @package Lengow_Connector - * @subpackage Test + * * @author Team module * @copyright 2017 Lengow SAS * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) @@ -19,8 +18,6 @@ namespace Lengow\Connector\Test\Unit; -use Exception; - class Fixture extends \PHPUnit\Framework\TestCase { /** @@ -38,8 +35,9 @@ public function invokeMethod(&$object, $methodName, $parameters = []) $reflection = new \ReflectionClass(get_class($object)); $method = $reflection->getMethod($methodName); $method->setAccessible(true); + return $method->invokeArgs($object, $parameters); - } catch (Exception $e) { + } catch (\Exception $e) { return false; } } @@ -47,7 +45,7 @@ public function invokeMethod(&$object, $methodName, $parameters = []) /** * Return value of a private property using ReflectionClass * - * @param object &$object Instantiated object that we will run method on. + * @param object &$object Instantiated object that we will run method on * @param string $propertyName Class property * * @return mixed @@ -58,8 +56,9 @@ public function getPrivatePropertyValue(&$object, $propertyName = '_data') $reflection = new \ReflectionClass(get_class($object)); $property = $reflection->getProperty($propertyName); $property->setAccessible(true); + return $property->getValue($object); - } catch (Exception $e) { + } catch (\Exception $e) { return false; } } @@ -67,7 +66,7 @@ public function getPrivatePropertyValue(&$object, $propertyName = '_data') /** * Set value of a private property using ReflectionClass * - * @param object &$object Instantiated object that we will run method on. + * @param object &$object Instantiated object that we will run method on * @param array $propertyNames Class properties * @param array $propertyValues Class value properties */ @@ -80,8 +79,7 @@ public function setPrivatePropertyValue($object, $propertyNames, $propertyValues } else { $reflection = new \ReflectionClass(get_class($object)); } - - } catch (Exception $e) { + } catch (\Exception $e) { $reflection = false; } if ($reflection) { @@ -90,16 +88,14 @@ public function setPrivatePropertyValue($object, $propertyNames, $propertyValues $property = $reflection->getProperty($propertyName); $property->setAccessible(true); $property->setValue($object, $propertyValues[$ii]); - $ii++; - } catch (Exception $e) { + ++$ii; + } catch (\Exception $e) { continue; } } } } - - /** * Get a fake class for mock function */ @@ -127,7 +123,6 @@ public function mockFunctions($object, $methodNames, $returns, $constructArgs = ->setConstructorArgs($constructArgs) ->getMock(); } else { - $mockFunction = $this->getMockBuilder(get_class($object)) ->setMethods($methodNames) ->disableOriginalConstructor() @@ -136,8 +131,9 @@ public function mockFunctions($object, $methodNames, $returns, $constructArgs = foreach ($methodNames as $methodName) { $mockFunction->expects($this->any())->method($methodName)->will($this->returnValue($returns[$ii])); - $ii++; + ++$ii; } + return $mockFunction; } -} \ No newline at end of file +} diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index 8bd237cb..59d9ce09 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -24,15 +24,15 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ -//php7.4 -d date.timezone=UTC ./vendor/phpunit/phpunit/phpunit -c modules/lengow/tests/Unit/phpunit.xml modules/lengow/tests/Unit -//define('_PS_IN_TEST_', true) need a database named test_._DB_NAME_; +// php7.4 -d date.timezone=UTC ./vendor/phpunit/phpunit/phpunit -c modules/lengow/tests/Unit/phpunit.xml modules/lengow/tests/Unit +// define('_PS_IN_TEST_', true) need a database named test_._DB_NAME_; define('_PS_ROOT_DIR_', __DIR__ . '/../../../..'); define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/modules/'); require_once __DIR__ . '/../../../../config/defines.inc.php'; require_once _PS_CONFIG_DIR_ . 'autoload.php'; require_once _PS_CONFIG_DIR_ . 'config.inc.php'; -require_once __DIR__.'/../../vendor/autoload.php'; -require_once __DIR__.'/./Fixture.php'; +require_once __DIR__ . '/../../vendor/autoload.php'; +require_once __DIR__ . '/./Fixture.php'; if (!defined('PHPUNIT_COMPOSER_INSTALL')) { define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../vendor/autoload.php'); @@ -45,6 +45,3 @@ if (!defined('__PS_BASE_URI__')) { define('__PS_BASE_URI__', ''); } - - - diff --git a/tests/Unit/classes/models/LengowActionTest.php b/tests/Unit/classes/models/LengowActionTest.php index 4bd114c9..badabb7d 100644 --- a/tests/Unit/classes/models/LengowActionTest.php +++ b/tests/Unit/classes/models/LengowActionTest.php @@ -1,17 +1,13 @@ action = new LengowAction(); + $this->action = new \LengowAction(); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowAction::class, + \LengowAction::class, $this->action, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowAddressTest.php b/tests/Unit/classes/models/LengowAddressTest.php index ef0883d8..a67e87fb 100644 --- a/tests/Unit/classes/models/LengowAddressTest.php +++ b/tests/Unit/classes/models/LengowAddressTest.php @@ -1,17 +1,13 @@ address = new LengowAddress(); + $this->address = new \LengowAddress(); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowAddress::class, + \LengowAddress::class, $this->address, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowBackupTest.php b/tests/Unit/classes/models/LengowBackupTest.php index baa87c21..7b22facc 100644 --- a/tests/Unit/classes/models/LengowBackupTest.php +++ b/tests/Unit/classes/models/LengowBackupTest.php @@ -1,17 +1,13 @@ backup = new LengowBackup(); + $this->backup = new \LengowBackup(); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowBackup::class, + \LengowBackup::class, $this->backup, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowCarrierTest.php b/tests/Unit/classes/models/LengowCarrierTest.php index 9784a908..0492612a 100644 --- a/tests/Unit/classes/models/LengowCarrierTest.php +++ b/tests/Unit/classes/models/LengowCarrierTest.php @@ -1,17 +1,13 @@ carrier = new LengowCarrier(1,1); + $this->carrier = new \LengowCarrier(1, 1); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowCarrier::class, + \LengowCarrier::class, $this->carrier, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowCartTest.php b/tests/Unit/classes/models/LengowCartTest.php index ccbe6bd3..a7f432d3 100644 --- a/tests/Unit/classes/models/LengowCartTest.php +++ b/tests/Unit/classes/models/LengowCartTest.php @@ -1,17 +1,13 @@ cart = new LengowCart(); + $this->cart = new \LengowCart(); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowCart::class, + \LengowCart::class, $this->cart, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowCatalogTest.php b/tests/Unit/classes/models/LengowCatalogTest.php index 7cfb7395..cf6f27bd 100644 --- a/tests/Unit/classes/models/LengowCatalogTest.php +++ b/tests/Unit/classes/models/LengowCatalogTest.php @@ -1,17 +1,13 @@ catalog = new LengowCatalog(); + $this->catalog = new \LengowCatalog(); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowCatalog::class, + \LengowCatalog::class, $this->catalog, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowConfigurationFormTest.php b/tests/Unit/classes/models/LengowConfigurationFormTest.php index d1381fb0..51ef7da5 100644 --- a/tests/Unit/classes/models/LengowConfigurationFormTest.php +++ b/tests/Unit/classes/models/LengowConfigurationFormTest.php @@ -1,17 +1,13 @@ form = new LengowConfigurationForm([]); + $this->form = new \LengowConfigurationForm([]); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowConfigurationForm::class, + \LengowConfigurationForm::class, $this->form, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowConfigurationTest.php b/tests/Unit/classes/models/LengowConfigurationTest.php index 80cf3849..b36d0726 100644 --- a/tests/Unit/classes/models/LengowConfigurationTest.php +++ b/tests/Unit/classes/models/LengowConfigurationTest.php @@ -1,17 +1,13 @@ config = new LengowConfiguration(); + $this->config = new \LengowConfiguration(); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowConfiguration::class, + \LengowConfiguration::class, $this->config, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowConnectorTest.php b/tests/Unit/classes/models/LengowConnectorTest.php index b43b61a7..77926b9f 100644 --- a/tests/Unit/classes/models/LengowConnectorTest.php +++ b/tests/Unit/classes/models/LengowConnectorTest.php @@ -4,13 +4,11 @@ use Lengow\Connector\Test\Unit\Fixture; use PHPUnit\Framework\TestCase; -use LengowConnector; class LengowConnectorTest extends TestCase { /** - * - * @var LengowConnector + * @var \LengowConnector */ protected $connector; @@ -21,7 +19,7 @@ class LengowConnectorTest extends TestCase */ public function setUp(): void { - $this->connector = new LengowConnector('12345678','123456789'); + $this->connector = new \LengowConnector('12345678', '123456789'); } /** @@ -30,14 +28,14 @@ public function setUp(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowConnector::class, + \LengowConnector::class, $this->connector, '[Test Class Instantiation] Check class instantiation' ); } /** - * @covers LengowConnector::format + * @covers \LengowConnector::format */ public function testFormat() { @@ -54,8 +52,8 @@ public function testFormat() $this->assertEquals( 'simple,plop,/1233;variable', - $fixture->invokeMethod($this->connector, "format", ['simple,plop,/1233;variable', 'stream']), + $fixture->invokeMethod($this->connector, 'format', ['simple,plop,/1233;variable', 'stream']), '[Test Format] Check no specific format format' ); } -} \ No newline at end of file +} diff --git a/tests/Unit/classes/models/LengowCountryTest.php b/tests/Unit/classes/models/LengowCountryTest.php index b116b1ee..c35ea49b 100644 --- a/tests/Unit/classes/models/LengowCountryTest.php +++ b/tests/Unit/classes/models/LengowCountryTest.php @@ -1,17 +1,13 @@ country = new LengowCountry(); + $this->country = new \LengowCountry(); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowCountry::class, + \LengowCountry::class, $this->country, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowCustomerTest.php b/tests/Unit/classes/models/LengowCustomerTest.php index 49880aec..9ae47a7e 100644 --- a/tests/Unit/classes/models/LengowCustomerTest.php +++ b/tests/Unit/classes/models/LengowCustomerTest.php @@ -1,17 +1,13 @@ customer = new LengowCustomer(); + $this->customer = new \LengowCustomer(); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowCustomer::class, + \LengowCustomer::class, $this->customer, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowExceptionTest.php b/tests/Unit/classes/models/LengowExceptionTest.php index 8beb713f..2ed9769b 100644 --- a/tests/Unit/classes/models/LengowExceptionTest.php +++ b/tests/Unit/classes/models/LengowExceptionTest.php @@ -3,7 +3,6 @@ namespace Lengow\Connector\Test\Unit\Model; use PHPUnit\Framework\TestCase; -use LengowException; class LengowExceptionTest extends TestCase { @@ -19,14 +18,13 @@ class LengowExceptionTest extends TestCase */ public function setUp(): void { - - $this->exception = new LengowException('Hello world'); + $this->exception = new \LengowException('Hello world'); } public function testClassInstantiation() { $this->assertInstanceOf( - LengowException::class, + \LengowException::class, $this->exception, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowExportTest.php b/tests/Unit/classes/models/LengowExportTest.php index db3f7f66..543ed6c5 100644 --- a/tests/Unit/classes/models/LengowExportTest.php +++ b/tests/Unit/classes/models/LengowExportTest.php @@ -1,17 +1,13 @@ export = new LengowExport([]); + $this->export = new \LengowExport([]); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowExport::class, + \LengowExport::class, $this->export, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowFeedTest.php b/tests/Unit/classes/models/LengowFeedTest.php index 889ca9a2..66d11d68 100644 --- a/tests/Unit/classes/models/LengowFeedTest.php +++ b/tests/Unit/classes/models/LengowFeedTest.php @@ -1,17 +1,13 @@ feed = new LengowFeed(false, LengowFeed::FORMAT_CSV, false); + $this->feed = new \LengowFeed(false, \LengowFeed::FORMAT_CSV, false); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowFeed::class, + \LengowFeed::class, $this->feed, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowFileTest.php b/tests/Unit/classes/models/LengowFileTest.php index 246a3066..f65af9e3 100644 --- a/tests/Unit/classes/models/LengowFileTest.php +++ b/tests/Unit/classes/models/LengowFileTest.php @@ -1,17 +1,13 @@ file = new LengowFile(LengowMain::FOLDER_LOG,'unit-test-log.txt'); + $this->file = new \LengowFile(\LengowMain::FOLDER_LOG, 'unit-test-log.txt'); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowFile::class, + \LengowFile::class, $this->file, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowGenderTest.php b/tests/Unit/classes/models/LengowGenderTest.php index 27afe835..6fbc90f7 100644 --- a/tests/Unit/classes/models/LengowGenderTest.php +++ b/tests/Unit/classes/models/LengowGenderTest.php @@ -1,17 +1,13 @@ gender = new LengowGender(); + $this->gender = new \LengowGender(); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowGender::class, + \LengowGender::class, $this->gender, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowHookTest.php b/tests/Unit/classes/models/LengowHookTest.php index f30f3570..efc5c072 100644 --- a/tests/Unit/classes/models/LengowHookTest.php +++ b/tests/Unit/classes/models/LengowHookTest.php @@ -1,18 +1,13 @@ hook = new LengowHook($module); + $module = new \Lengow(); + $this->hook = new \LengowHook($module); } /** @@ -33,7 +28,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowHook::class, + \LengowHook::class, $this->hook, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowLogTest.php b/tests/Unit/classes/models/LengowLogTest.php index e1ccaeb8..ea459a90 100644 --- a/tests/Unit/classes/models/LengowLogTest.php +++ b/tests/Unit/classes/models/LengowLogTest.php @@ -1,16 +1,13 @@ log = new LengowLog(); + $this->log = new \LengowLog(); } /** @@ -30,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowLog::class, + \LengowLog::class, $this->log, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowMarketplaceTest.php b/tests/Unit/classes/models/LengowMarketplaceTest.php index 5ed4b660..6b842872 100644 --- a/tests/Unit/classes/models/LengowMarketplaceTest.php +++ b/tests/Unit/classes/models/LengowMarketplaceTest.php @@ -1,16 +1,13 @@ marketplace = new LengowMarketplace( + $this->marketplace = new \LengowMarketplace( 'amazon_fr', $this->getMarketplacesMock() ); @@ -33,7 +30,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowMarketplace::class, + \LengowMarketplace::class, $this->marketplace, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowMethodTest.php b/tests/Unit/classes/models/LengowMethodTest.php index da9af164..9b23ff58 100644 --- a/tests/Unit/classes/models/LengowMethodTest.php +++ b/tests/Unit/classes/models/LengowMethodTest.php @@ -1,16 +1,13 @@ method = new LengowMethod(); + $this->method = new \LengowMethod(); } /** @@ -30,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowMethod::class, + \LengowMethod::class, $this->method, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowNameParserTest.php b/tests/Unit/classes/models/LengowNameParserTest.php index 9262345d..fce3d4e8 100644 --- a/tests/Unit/classes/models/LengowNameParserTest.php +++ b/tests/Unit/classes/models/LengowNameParserTest.php @@ -1,16 +1,13 @@ nameParser = new LengowNameParser(); + $this->nameParser = new \LengowNameParser(); } /** @@ -30,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowNameParser::class, + \LengowNameParser::class, $this->nameParser, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowOrderCarrierTest.php b/tests/Unit/classes/models/LengowOrderCarrierTest.php index 1eb2ba86..85b11a43 100644 --- a/tests/Unit/classes/models/LengowOrderCarrierTest.php +++ b/tests/Unit/classes/models/LengowOrderCarrierTest.php @@ -1,16 +1,13 @@ orderCarrier = new LengowOrderCarrier(); + $this->orderCarrier = new \LengowOrderCarrier(); } /** @@ -30,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowOrderCarrier::class, + \LengowOrderCarrier::class, $this->orderCarrier, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowOrderDetailTest.php b/tests/Unit/classes/models/LengowOrderDetailTest.php index 1c9cfe01..b6e5885e 100644 --- a/tests/Unit/classes/models/LengowOrderDetailTest.php +++ b/tests/Unit/classes/models/LengowOrderDetailTest.php @@ -1,16 +1,13 @@ orderDetail = new LengowOrderDetail(); + $this->orderDetail = new \LengowOrderDetail(); } /** @@ -30,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowOrderDetail::class, + \LengowOrderDetail::class, $this->orderDetail, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowOrderTest.php b/tests/Unit/classes/models/LengowOrderTest.php index 9caa6508..a299b3d0 100644 --- a/tests/Unit/classes/models/LengowOrderTest.php +++ b/tests/Unit/classes/models/LengowOrderTest.php @@ -1,16 +1,13 @@ order = new LengowOrder(); + $this->order = new \LengowOrder(); } /** @@ -30,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowOrder::class, + \LengowOrder::class, $this->order, '[Test Class Instantiation] Check class instantiation' ); diff --git a/tests/Unit/classes/models/LengowTranslationTest.php b/tests/Unit/classes/models/LengowTranslationTest.php index 69a7dd77..2d32e5b0 100644 --- a/tests/Unit/classes/models/LengowTranslationTest.php +++ b/tests/Unit/classes/models/LengowTranslationTest.php @@ -1,17 +1,13 @@ translate = new LengowTranslation('en'); + $this->translate = new \LengowTranslation('en'); } /** @@ -31,7 +27,7 @@ public function setup(): void public function testClassInstantiation() { $this->assertInstanceOf( - LengowTranslation::class, + \LengowTranslation::class, $this->translate, '[Test Class Instantiation] Check class instantiation' ); From 2382d6726ae0b11bf77e9981ad7eadd210e6c67a Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Fri, 7 Jun 2024 10:53:36 +0200 Subject: [PATCH 13/24] ECP-81:[WIP] unit tests in prestashop module --- classes/models/LengowMarketplace.php | 2 - classes/models/LengowTranslation.php | 2 - tests/Unit/.phpunit.result.cache | 2 +- tests/Unit/bootstrap.php | 4 +- .../classes/models/LengowImportOrderTest.php | 53 +++++++++++++++++++ .../Unit/classes/models/LengowImportTest.php | 35 ++++++++++++ .../Unit/classes/models/LengowInstallTest.php | 36 +++++++++++++ tests/Unit/classes/models/LengowLinkTest.php | 35 ++++++++++++ tests/Unit/classes/models/LengowListTest.php | 44 +++++++++++++++ tests/Unit/classes/models/LengowMainTest.php | 35 ++++++++++++ .../classes/models/LengowOrderErrorTest.php | 35 ++++++++++++ .../classes/models/LengowOrderLIneTest.php | 35 ++++++++++++ .../models/LengowPaymentModuleTest.php | 35 ++++++++++++ .../Unit/classes/models/LengowProductTest.php | 35 ++++++++++++ tests/Unit/classes/models/LengowShopTest.php | 35 ++++++++++++ tests/Unit/classes/models/LengowSyncTest.php | 35 ++++++++++++ .../models/LengowToolboxElementTest.php | 35 ++++++++++++ .../Unit/classes/models/LengowToolboxTest.php | 35 ++++++++++++ 18 files changed, 522 insertions(+), 6 deletions(-) create mode 100644 tests/Unit/classes/models/LengowImportOrderTest.php create mode 100644 tests/Unit/classes/models/LengowImportTest.php create mode 100644 tests/Unit/classes/models/LengowInstallTest.php create mode 100644 tests/Unit/classes/models/LengowLinkTest.php create mode 100644 tests/Unit/classes/models/LengowListTest.php create mode 100644 tests/Unit/classes/models/LengowMainTest.php create mode 100644 tests/Unit/classes/models/LengowOrderErrorTest.php create mode 100644 tests/Unit/classes/models/LengowOrderLIneTest.php create mode 100644 tests/Unit/classes/models/LengowPaymentModuleTest.php create mode 100644 tests/Unit/classes/models/LengowProductTest.php create mode 100644 tests/Unit/classes/models/LengowShopTest.php create mode 100644 tests/Unit/classes/models/LengowSyncTest.php create mode 100644 tests/Unit/classes/models/LengowToolboxElementTest.php create mode 100644 tests/Unit/classes/models/LengowToolboxTest.php diff --git a/classes/models/LengowMarketplace.php b/classes/models/LengowMarketplace.php index 1eefe589..100c9fad 100644 --- a/classes/models/LengowMarketplace.php +++ b/classes/models/LengowMarketplace.php @@ -120,7 +120,6 @@ class LengowMarketplace */ public function __construct($name, $marketplacesData = '') { - $this->name = (string) Tools::strtolower($name); if (!empty($marketplacesData)) { self::$marketplaces = json_decode($marketplacesData); @@ -796,4 +795,3 @@ public function hasReturnTrackingNumber(): bool return in_array(LengowAction::ARG_RETURN_TRACKING_NUMBER, $arguments); } } - diff --git a/classes/models/LengowTranslation.php b/classes/models/LengowTranslation.php index c4aecc78..abf386b5 100755 --- a/classes/models/LengowTranslation.php +++ b/classes/models/LengowTranslation.php @@ -59,7 +59,6 @@ class LengowTranslation */ public function __construct($isoCode = '') { - $this->isoCode = !empty($isoCode) ? $isoCode : $this->getCurrentIsoCode(); } @@ -161,4 +160,3 @@ protected function getCurrentIsoCode() return Context::getContext()->language->iso_code; } } - diff --git a/tests/Unit/.phpunit.result.cache b/tests/Unit/.phpunit.result.cache index e4a5d955..a32dbf9b 100644 --- a/tests/Unit/.phpunit.result.cache +++ b/tests/Unit/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":4,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":5,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowTranslationTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowAddressTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCarrierTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCustomerTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFeedTest::testClassInstantiation":4},"times":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":0.012,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":0.017,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testFormat":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExceptionTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":0.009,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowTranslationTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowAddressTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowActionTest::testClassInstantiation":0.008,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCarrierTest::testClassInstantiation":0.008,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCartTest::testClassInstantiation":0.014,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCatalogTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowBackupTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConfigurationTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConfigurationFormTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCountryTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCustomerTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFeedTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowGenderTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowHookTest::testClassInstantiation":0.861}} \ No newline at end of file +{"version":1,"defects":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":4,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":5,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowTranslationTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowAddressTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCarrierTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCustomerTest::testClassInstantiation":3,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFeedTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowImportOrderTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowInstallTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowListTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowMarketplaceTest::testClassInstantiation":4,"Lengow\\Connector\\Test\\Unit\\Model\\LengowToolboxElementTest::testClassInstantiation":3},"times":{"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testClassInstantiation":0.012,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testFormat":0.001,"Lengow\\Connector\\Test\\Unit\\Model\\ConnectorTest::testConnect":0.017,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConnectorTest::testFormat":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExceptionTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowExportTest::testClassInstantiation":0.009,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLogTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFileTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowTranslationTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowAddressTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowActionTest::testClassInstantiation":0.008,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCarrierTest::testClassInstantiation":0.007,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCartTest::testClassInstantiation":0.009,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCatalogTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowBackupTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConfigurationTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowConfigurationFormTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCountryTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowCustomerTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowFeedTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowGenderTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowHookTest::testClassInstantiation":0.027,"Lengow\\Connector\\Test\\Unit\\Model\\LengowImportTest::testClassInstantiation":0.007,"Lengow\\Connector\\Test\\Unit\\Model\\LengowImportOrderTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowInstallTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowLinkTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowMainTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowListTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowMarketplaceTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowMethodTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowNameParserTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowOrderTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowOrderCarrierTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowOrderDetailTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowOrderErrorTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowOrderLineTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowPaymentModuleTest::testClassInstantiation":0.007,"Lengow\\Connector\\Test\\Unit\\Model\\LengowProductTest::testClassInstantiation":0.019,"Lengow\\Connector\\Test\\Unit\\Model\\LengowShopTest::testClassInstantiation":0.006,"Lengow\\Connector\\Test\\Unit\\Model\\LengowSyncTest::testClassInstantiation":0.004,"Lengow\\Connector\\Test\\Unit\\Model\\LengowToolboxTest::testClassInstantiation":0.005,"Lengow\\Connector\\Test\\Unit\\Model\\LengowToolboxElementTest::testClassInstantiation":0.004}} \ No newline at end of file diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index 59d9ce09..83b1ee39 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -25,7 +25,7 @@ */ // php7.4 -d date.timezone=UTC ./vendor/phpunit/phpunit/phpunit -c modules/lengow/tests/Unit/phpunit.xml modules/lengow/tests/Unit -// define('_PS_IN_TEST_', true) need a database named test_._DB_NAME_; +define('_PS_IN_TEST_', true); define('_PS_ROOT_DIR_', __DIR__ . '/../../../..'); define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/modules/'); require_once __DIR__ . '/../../../../config/defines.inc.php'; @@ -45,3 +45,5 @@ if (!defined('__PS_BASE_URI__')) { define('__PS_BASE_URI__', ''); } + + diff --git a/tests/Unit/classes/models/LengowImportOrderTest.php b/tests/Unit/classes/models/LengowImportOrderTest.php new file mode 100644 index 00000000..a1de8799 --- /dev/null +++ b/tests/Unit/classes/models/LengowImportOrderTest.php @@ -0,0 +1,53 @@ +importOrder = new \LengowImportOrder( + [ + \LengowImportOrder::PARAM_CONTEXT => $context, + \LengowImportOrder::PARAM_SHOP_ID => $context->shop->id, + \LengowImportOrder::PARAM_SHOP_GROUP_ID => $context->shop->id_shop_group, + \LengowImportOrder::PARAM_LANG_ID => $context->language->id, + \LengowImportOrder::PARAM_FORCE_SYNC => false, + \LengowImportOrder::PARAM_FORCE_PRODUCT => false, + \LengowImportOrder::PARAM_DEBUG_MODE => false, + \LengowImportOrder::PARAM_LOG_OUTPUT => false, + \LengowImportOrder::PARAM_MARKETPLACE_SKU => '', + \LengowImportOrder::PARAM_DELIVERY_ADDRESS_ID => '', + \LengowImportOrder::PARAM_ORDER_DATA => '', + \LengowImportOrder::PARAM_PACKAGE_DATA => '', + \LengowImportOrder::PARAM_FIRST_PACKAGE => '', + \LengowImportOrder::PARAM_IMPORT_ONE_ORDER => false, + ] + ); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowImportOrder::class, + $this->importOrder, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowImportTest.php b/tests/Unit/classes/models/LengowImportTest.php new file mode 100644 index 00000000..228a3f27 --- /dev/null +++ b/tests/Unit/classes/models/LengowImportTest.php @@ -0,0 +1,35 @@ +import = new \LengowImport([]); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowImport::class, + $this->import, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowInstallTest.php b/tests/Unit/classes/models/LengowInstallTest.php new file mode 100644 index 00000000..215e0e3c --- /dev/null +++ b/tests/Unit/classes/models/LengowInstallTest.php @@ -0,0 +1,36 @@ +install = new \LengowInstall($module); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowInstall::class, + $this->install, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowLinkTest.php b/tests/Unit/classes/models/LengowLinkTest.php new file mode 100644 index 00000000..71e72d86 --- /dev/null +++ b/tests/Unit/classes/models/LengowLinkTest.php @@ -0,0 +1,35 @@ +link = new \LengowLink(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowLink::class, + $this->link, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowListTest.php b/tests/Unit/classes/models/LengowListTest.php new file mode 100644 index 00000000..f5815441 --- /dev/null +++ b/tests/Unit/classes/models/LengowListTest.php @@ -0,0 +1,44 @@ +list = new \LengowList( + [ + 'id' => 1, + 'fields_list' => '', + 'selection' => '', + 'identifier' => '', + 'controller' => '', + 'sql' => '', + ] + ); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowList::class, + $this->list, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowMainTest.php b/tests/Unit/classes/models/LengowMainTest.php new file mode 100644 index 00000000..1b986bc4 --- /dev/null +++ b/tests/Unit/classes/models/LengowMainTest.php @@ -0,0 +1,35 @@ +main = new \LengowMain(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowMain::class, + $this->main, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowOrderErrorTest.php b/tests/Unit/classes/models/LengowOrderErrorTest.php new file mode 100644 index 00000000..8d51556b --- /dev/null +++ b/tests/Unit/classes/models/LengowOrderErrorTest.php @@ -0,0 +1,35 @@ +orderError = new \LengowOrderError(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowOrderError::class, + $this->orderError, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowOrderLIneTest.php b/tests/Unit/classes/models/LengowOrderLIneTest.php new file mode 100644 index 00000000..94bad098 --- /dev/null +++ b/tests/Unit/classes/models/LengowOrderLIneTest.php @@ -0,0 +1,35 @@ +orderLine = new \LengowOrderLine(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowOrderLine::class, + $this->orderLine, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowPaymentModuleTest.php b/tests/Unit/classes/models/LengowPaymentModuleTest.php new file mode 100644 index 00000000..efe358bf --- /dev/null +++ b/tests/Unit/classes/models/LengowPaymentModuleTest.php @@ -0,0 +1,35 @@ +paymentModule = new \LengowPaymentModule(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowPaymentModule::class, + $this->paymentModule, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowProductTest.php b/tests/Unit/classes/models/LengowProductTest.php new file mode 100644 index 00000000..d614ca4b --- /dev/null +++ b/tests/Unit/classes/models/LengowProductTest.php @@ -0,0 +1,35 @@ +product = new \LengowProduct(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowProduct::class, + $this->product, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowShopTest.php b/tests/Unit/classes/models/LengowShopTest.php new file mode 100644 index 00000000..768189a2 --- /dev/null +++ b/tests/Unit/classes/models/LengowShopTest.php @@ -0,0 +1,35 @@ +shop = new \LengowShop(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowShop::class, + $this->shop, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowSyncTest.php b/tests/Unit/classes/models/LengowSyncTest.php new file mode 100644 index 00000000..30c5380c --- /dev/null +++ b/tests/Unit/classes/models/LengowSyncTest.php @@ -0,0 +1,35 @@ +sync = new \LengowSync(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowSync::class, + $this->sync, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowToolboxElementTest.php b/tests/Unit/classes/models/LengowToolboxElementTest.php new file mode 100644 index 00000000..669829a4 --- /dev/null +++ b/tests/Unit/classes/models/LengowToolboxElementTest.php @@ -0,0 +1,35 @@ +toolboxElement = new \LengowToolboxElement(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowToolboxElement::class, + $this->toolboxElement, + '[Test Class Instantiation] Check class instantiation' + ); + } +} diff --git a/tests/Unit/classes/models/LengowToolboxTest.php b/tests/Unit/classes/models/LengowToolboxTest.php new file mode 100644 index 00000000..2dcc7717 --- /dev/null +++ b/tests/Unit/classes/models/LengowToolboxTest.php @@ -0,0 +1,35 @@ +toolbox = new \LengowToolbox(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowToolbox::class, + $this->toolbox, + '[Test Class Instantiation] Check class instantiation' + ); + } +} From 8d22002197a090ff0486ac5cc3fa71879a59c8de Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Fri, 7 Jun 2024 12:22:42 +0200 Subject: [PATCH 14/24] ECP-81:[WIP] unit tests in prestashop module --- .../Unit/classes/models/LengowActionTest.php | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/tests/Unit/classes/models/LengowActionTest.php b/tests/Unit/classes/models/LengowActionTest.php index badabb7d..dcf211ae 100644 --- a/tests/Unit/classes/models/LengowActionTest.php +++ b/tests/Unit/classes/models/LengowActionTest.php @@ -32,4 +32,97 @@ public function testClassInstantiation() '[Test Class Instantiation] Check class instantiation' ); } + /** + * @covers \LengowAction::load + */ + public function testLoad() + { + $rowMock = [ + \LengowAction::FIELD_ID => 1, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 1, + \LengowAction::FIELD_ACTION_TYPE => 'ship', + \LengowAction::FIELD_RETRY => 0, + \LengowAction::FIELD_PARAMETERS => [], + \LengowAction::FIELD_STATE => 1, + \LengowAction::FIELD_CREATED_AT => '1970-01-01 00:00:00', + \LengowAction::FIELD_UPDATED_AT => '1970-01-01 00:00:00' + ]; + $this->action->load($rowMock); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ID], + $this->action->id, + '[Test LengowAction] load id' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ACTION_ID], + $this->action->actionId, + '[Test LengowAction] load action_id' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ORDER_ID], + $this->action->idOrder, + '[Test LengowAction] load order_id' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_RETRY], + $this->action->retry, + '[Test LengowAction] load retry' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_CREATED_AT], + $this->action->createdAt, + '[Test LengowAction] load created_at' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_UPDATED_AT], + $this->action->updatedAt, + '[Test LengowAction] load updated_at' + ); + } + + /** + * @covers \LengowAction::findByActionId + */ + public function testFindByActionId() + { + $id = -1; + + $this->assertFalse( + $this->action->findByActionId($id), + '[Test LengowAction] findByActionId -1' + ); + + $rowMock = [ + \LengowAction::FIELD_ID => 123, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 456, + \LengowAction::FIELD_ACTION_TYPE => 'ship', + \LengowAction::FIELD_RETRY => 0, + \LengowAction::FIELD_PARAMETERS => [], + \LengowAction::FIELD_STATE => 1, + \LengowAction::FIELD_CREATED_AT => '1970-01-01 00:00:00', + \LengowAction::FIELD_UPDATED_AT => '1970-01-01 00:00:00' + ]; + + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('getRow') + ->willReturn($rowMock); + \Db::setInstanceForTesting($dbMock); + $result = $this->action->findByActionId($rowMock[\LengowAction::FIELD_ID]); + $this->assertTrue($result, '[Test LengowAction] findByActionId 123'); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ACTION_ID], + $this->action->actionId, + '[Test LengowAction] findByActionId action_id' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ID], + $this->action->id, + '[Test LengowAction] findByActionId id' + ); + \Db::deleteTestingInstance(); + } } From 824236dd4817142092ed7a9580692dc3413a9622 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Fri, 7 Jun 2024 15:04:44 +0200 Subject: [PATCH 15/24] ECP-81:[WIP] unit tests in prestashop module --- .../Unit/classes/models/LengowActionTest.php | 183 ++++++++++++++++-- 1 file changed, 171 insertions(+), 12 deletions(-) diff --git a/tests/Unit/classes/models/LengowActionTest.php b/tests/Unit/classes/models/LengowActionTest.php index dcf211ae..2cf023f3 100644 --- a/tests/Unit/classes/models/LengowActionTest.php +++ b/tests/Unit/classes/models/LengowActionTest.php @@ -11,6 +11,12 @@ class LengowActionTest extends TestCase */ protected $action; + /** + * + * @var string $testName + */ + protected $testName; + /** * setup * @@ -19,6 +25,7 @@ class LengowActionTest extends TestCase public function setup(): void { $this->action = new \LengowAction(); + $this->testName = '[Test '.\LengowAction::class.'] '; } /** @@ -29,7 +36,7 @@ public function testClassInstantiation() $this->assertInstanceOf( \LengowAction::class, $this->action, - '[Test Class Instantiation] Check class instantiation' + $this->testName.__METHOD__.' Check class instantiation' ); } /** @@ -52,32 +59,32 @@ public function testLoad() $this->assertEquals( $rowMock[\LengowAction::FIELD_ID], $this->action->id, - '[Test LengowAction] load id' + $this->testName.__METHOD__.' load id' ); $this->assertEquals( $rowMock[\LengowAction::FIELD_ACTION_ID], $this->action->actionId, - '[Test LengowAction] load action_id' + $this->testName.__METHOD__.' load action_id' ); $this->assertEquals( $rowMock[\LengowAction::FIELD_ORDER_ID], $this->action->idOrder, - '[Test LengowAction] load order_id' + $this->testName.__METHOD__.' load order_id' ); $this->assertEquals( $rowMock[\LengowAction::FIELD_RETRY], $this->action->retry, - '[Test LengowAction] load retry' + $this->testName.__METHOD__.' load retry' ); $this->assertEquals( $rowMock[\LengowAction::FIELD_CREATED_AT], $this->action->createdAt, - '[Test LengowAction] load created_at' + $this->testName.__METHOD__.' load created_at' ); $this->assertEquals( $rowMock[\LengowAction::FIELD_UPDATED_AT], $this->action->updatedAt, - '[Test LengowAction] load updated_at' + $this->testName.__METHOD__.' load updated_at' ); } @@ -87,10 +94,9 @@ public function testLoad() public function testFindByActionId() { $id = -1; - $this->assertFalse( $this->action->findByActionId($id), - '[Test LengowAction] findByActionId -1' + $this->testName.__METHOD__.' false' ); $rowMock = [ @@ -112,16 +118,169 @@ public function testFindByActionId() ->willReturn($rowMock); \Db::setInstanceForTesting($dbMock); $result = $this->action->findByActionId($rowMock[\LengowAction::FIELD_ID]); - $this->assertTrue($result, '[Test LengowAction] findByActionId 123'); + $this->assertTrue($result, $this->testName.__METHOD__.' findByActionId 123'); $this->assertEquals( $rowMock[\LengowAction::FIELD_ACTION_ID], $this->action->actionId, - '[Test LengowAction] findByActionId action_id' + $this->testName.__METHOD__.' findByActionId action_id' ); $this->assertEquals( $rowMock[\LengowAction::FIELD_ID], $this->action->id, - '[Test LengowAction] findByActionId id' + $this->testName.__METHOD__.' findByActionId id' + ); + \Db::deleteTestingInstance(); + } + + /** + * @covers \LengowAction::getActionByActionId + */ + public function testGetActionByActionId() + { + $resultFalse = \LengowAction::getActionByActionId(-1); + $this->assertFalse($resultFalse, $this->testName.__METHOD__.' false'); + $rowMock = [ + \LengowAction::FIELD_ID => 123, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 456, + \LengowAction::FIELD_ACTION_TYPE => 'ship', + \LengowAction::FIELD_RETRY => 0, + \LengowAction::FIELD_PARAMETERS => [], + \LengowAction::FIELD_STATE => 1, + \LengowAction::FIELD_CREATED_AT => '1970-01-01 00:00:00', + \LengowAction::FIELD_UPDATED_AT => '1970-01-01 00:00:00' + ]; + + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('getRow') + ->willReturn($rowMock); + \Db::setInstanceForTesting($dbMock); + $result = \LengowAction::getActionByActionId($rowMock[\LengowAction::FIELD_ACTION_ID]); + + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ID], + $result, + $this->testName.__METHOD__.' action_id' + ); + \Db::deleteTestingInstance(); + } + + /** + * @covers \LengowAction::getActionsByOrderId + */ + public function testGetActionsByOrderId() + { + $resultFalse = \LengowAction::getActionsByOrderId(-1); + $this->assertFalse($resultFalse, $this->testName.__METHOD__.' false'); + $rowMock = [ + \LengowAction::FIELD_ID => 123, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 456, + \LengowAction::FIELD_ACTION_TYPE => 'ship', + \LengowAction::FIELD_RETRY => 0, + \LengowAction::FIELD_PARAMETERS => [], + \LengowAction::FIELD_STATE => 1, + \LengowAction::FIELD_CREATED_AT => '1970-01-01 00:00:00', + \LengowAction::FIELD_UPDATED_AT => '1970-01-01 00:00:00' + ]; + $actionMock = clone $this->action; + $actionMock->load($rowMock); + $actionsWaited = [$actionMock]; + + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('executeS')->willReturn([$rowMock]); + \Db::setInstanceForTesting($dbMock); + $result = \LengowAction::getActionsByOrderId($rowMock[\LengowAction::FIELD_ORDER_ID]); + $this->assertEquals( + $actionsWaited, + $result, + $this->testName.__METHOD__.' actions array found' + ); + \Db::deleteTestingInstance(); + } + + /** + * @covers \LengowAction::getActiveActions + */ + public function testGetActiveActions() + { + + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('executeS')->willReturn([]); + \Db::setInstanceForTesting($dbMock); + $resultFalse = \LengowAction::getActiveActions(); + $this->assertFalse($resultFalse, $this->testName.__METHOD__.' false'); + + $rowMock = [ + \LengowAction::FIELD_ID => 123, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 456, + \LengowAction::FIELD_ACTION_TYPE => 'ship', + \LengowAction::FIELD_RETRY => 0, + \LengowAction::FIELD_PARAMETERS => [], + \LengowAction::FIELD_STATE => 1, + \LengowAction::FIELD_CREATED_AT => '1970-01-01 00:00:00', + \LengowAction::FIELD_UPDATED_AT => '1970-01-01 00:00:00' + ]; + $dbMock2 = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock2->method('executeS')->willReturn([$rowMock]); + \Db::setInstanceForTesting($dbMock2); + + $resultArray = \LengowAction::getActiveActions(false); + + $this->assertEquals( + [$rowMock], + $resultArray, + $this->testName.__METHOD__.' active actions array' + ); + $actionMock = clone $this->action; + $actionMock->load($rowMock); + $actionsWaited = [$actionMock]; + $resultLoad = \LengowAction::getActiveActions(true); + $this->assertEquals( + $actionsWaited, + $resultLoad, + $this->testName.__METHOD__.' active actions load' + ); + \Db::deleteTestingInstance(); + } + + /** + * @covers \LengowAction::getLastOrderActionType + */ + public function testGetLastOrderActionType() + { + $resultFalse = \LengowAction::getLastOrderActionType(-1); + $this->assertFalse($resultFalse, $this->testName.__METHOD__.' false'); + $rowMock = [ + \LengowAction::FIELD_ID => 123, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 456, + \LengowAction::FIELD_ACTION_TYPE => 'cancel', + \LengowAction::FIELD_RETRY => 0, + \LengowAction::FIELD_PARAMETERS => [], + \LengowAction::FIELD_STATE => 1, + \LengowAction::FIELD_CREATED_AT => '1970-01-01 00:00:00', + \LengowAction::FIELD_UPDATED_AT => '1970-01-01 00:00:00' + ]; + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('executeS')->willReturn([$rowMock]); + \Db::setInstanceForTesting($dbMock); + $resultLast = \LengowAction::getLastOrderActionType($rowMock[\LengowAction::FIELD_ORDER_ID]); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ACTION_TYPE], + $resultLast, + $this->testName.__METHOD__.' last action' ); \Db::deleteTestingInstance(); } From f7385d532ced6ebbbf56489817b7a6867720f73f Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Fri, 7 Jun 2024 16:56:41 +0200 Subject: [PATCH 16/24] ECP-81:[WIP] unit tests in prestashop module --- classes/models/LengowAction.php | 8 +- classes/models/LengowConnector.php | 112 ++++++++++++++++-- .../Unit/classes/models/LengowActionTest.php | 67 +++++++++++ 3 files changed, 178 insertions(+), 9 deletions(-) diff --git a/classes/models/LengowAction.php b/classes/models/LengowAction.php index 8fe2ab3e..2ccafacc 100644 --- a/classes/models/LengowAction.php +++ b/classes/models/LengowAction.php @@ -200,6 +200,7 @@ public static function getActionByActionId($actionId) public static function getActionsByOrderId($idOrder, $onlyActive = false, $actionType = null, $load = true) { try { + $sqlOnlyActive = $onlyActive ? ' AND state = ' . self::STATE_NEW : ''; $sqlType = $actionType === null ? '' : ' AND action_type = "' . pSQL($actionType) . '"'; $rows = Db::getInstance()->executeS( @@ -326,7 +327,12 @@ public static function canSendAction($params, $lengowOrder) unset($getParams[$param]); } } - $result = LengowConnector::queryApi(LengowConnector::GET, LengowConnector::API_ORDER_ACTION, $getParams); + + $result = LengowConnector::getInstance()->requestApi( + LengowConnector::GET, + LengowConnector::API_ORDER_ACTION, + $getParams + ); if (isset($result->error, $result->error->message)) { throw new LengowException($result->error->message); } diff --git a/classes/models/LengowConnector.php b/classes/models/LengowConnector.php index c5611bbd..b146b756 100755 --- a/classes/models/LengowConnector.php +++ b/classes/models/LengowConnector.php @@ -155,6 +155,9 @@ class LengowConnector self::API_PLUGIN, ]; + /** @var array List of LengowConnector instances */ + protected static $instance = []; + /** * Make a new Lengow API Connector. * @@ -167,6 +170,57 @@ public function __construct($accessToken, $secret) $this->secret = $secret; } + /** + * Returns a LengowConnector instance + * + * @param string $accessToken + * @param string $secret + * + * @return bool|\LengowConnector + */ + public static function getInstance($accessToken = '', $secret = '') + { + if (isset(self::$instance[0]) + && self::$instance[0] instanceof LengowConnector) { + return self::$instance[0]; + } + list($accountIdFound, $accessTokenFound, $secretFound) = LengowConfiguration::getAccessIds(); + + if (empty($accessTokenFound) + || empty($secretFound) + || empty($accountIdFound)) { + return false; + } + + if ($accessToken && $secret) { + $connector = new LengowConnector($accessToken, $secret); + } else { + $connector = new LengowConnector($accessTokenFound, $secretFound); + } + + self::$instance[0] = $connector; + + return $connector; + } + + /** + * Will set the instance for testing + * + * @param LengowConnect $testConnector + */ + public static function setInstanceForTesting($testConnector) + { + self::$instance[0] = $testConnector; + } + + /** + * Will reset $intance array + */ + public static function disableTestingInstance() + { + self::$instance = []; + } + /** * Check API Authentication * @@ -179,11 +233,8 @@ public static function isValidAuth($logOutput = false) if (!LengowToolbox::isCurlActivated()) { return false; } - list($accountId, $accessToken, $secret) = LengowConfiguration::getAccessIds(); - if ($accountId === null) { - return false; - } - $connector = new LengowConnector($accessToken, $secret); + + $connector = self::getInstance(); try { $connector->connect(false, $logOutput); } catch (LengowException $e) { @@ -225,7 +276,7 @@ public static function queryApi($type, $api, $args = [], $body = '', $logOutput if ($accountId === null && $authorizationRequired) { return false; } - $connector = new LengowConnector($accessToken, $secret); + $connector = self::getInstance($accessToken, $secret); $type = (string) Tools::strtolower($type); $args = $authorizationRequired ? array_merge([LengowImport::ARG_ACCOUNT_ID => $accountId], $args) @@ -259,7 +310,7 @@ public static function queryApi($type, $api, $args = [], $body = '', $logOutput */ public static function getAccountIdByCredentials($accessToken, $secret, $logOutput = false) { - $connector = new LengowConnector($accessToken, $secret); + $connector = self::getInstance($accessToken, $secret); try { $data = $connector->callAction( self::API_ACCESS_TOKEN, @@ -388,6 +439,51 @@ public function patch($api, $args = [], $format = self::FORMAT_JSON, $body = '', return $this->call($api, $args, self::PATCH, $format, $body, $logOutput); } + /** + * Get result for a request to Api + * + * @param string $type request type (GET / POST / PUT / PATCH) + * @param string $api request api + * @param array $args request params + * @param string $body body data for request + * @param bool $logOutput see log or not + * + * @return array|false + */ + public function requestApi($type, $api, $args = [], $body = '', $logOutput = false) + { + if (!in_array($type, [self::GET, self::POST, self::PUT, self::PATCH])) { + return false; + } + try { + $authorizationRequired = !in_array($api, self::$apiWithoutAuthorizations, true); + list($accountId) = LengowConfiguration::getAccessIds(); + if ($accountId === null && $authorizationRequired) { + return false; + } + + $type = (string) Tools::strtolower($type); + $args = $authorizationRequired + ? array_merge([LengowImport::ARG_ACCOUNT_ID => $accountId], $args) + : $args; + $results = $this->$type($api, $args, self::FORMAT_STREAM, $body, $logOutput); + } catch (LengowException $e) { + $message = LengowMain::decodeLogMessage($e->getMessage(), LengowTranslation::DEFAULT_ISO_CODE); + $error = LengowMain::setLogMessage( + 'log.connector.error_api', + [ + 'error_code' => $e->getCode(), + 'error_message' => $message, + ] + ); + LengowMain::log(LengowLog::CODE_CONNECTOR, $error, $logOutput); + + return false; + } + + return json_decode($results); + } + /** * The API method * @@ -442,7 +538,7 @@ private function call($api, $args, $type, $format, $body, $logOutput) * * @throws LengowException */ - private function callAction($api, $args, $type, $format, $body, $logOutput) + protected function callAction($api, $args, $type, $format, $body, $logOutput) { $result = $this->makeRequest($type, $api, $args, $this->token, $body, $logOutput); diff --git a/tests/Unit/classes/models/LengowActionTest.php b/tests/Unit/classes/models/LengowActionTest.php index 2cf023f3..0e85b758 100644 --- a/tests/Unit/classes/models/LengowActionTest.php +++ b/tests/Unit/classes/models/LengowActionTest.php @@ -284,4 +284,71 @@ public function testGetLastOrderActionType() ); \Db::deleteTestingInstance(); } + + /** + * @covers \LengowAction::find + */ + public function testFind() + { + $this->assertFalse( + $this->action->find(-1), + $this->testName.__METHOD__.' false' + ); + $rowMock = [ + \LengowAction::FIELD_ID => 123, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 456, + \LengowAction::FIELD_ACTION_TYPE => 'ship', + \LengowAction::FIELD_RETRY => 0, + \LengowAction::FIELD_PARAMETERS => [], + \LengowAction::FIELD_STATE => 1, + \LengowAction::FIELD_CREATED_AT => '1970-01-01 00:00:00', + \LengowAction::FIELD_UPDATED_AT => '1970-01-01 00:00:00' + ]; + + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('getRow')->willReturn($rowMock); + \Db::setInstanceForTesting($dbMock); + $result = $this->action->find($rowMock[\LengowAction::FIELD_ID]); + $this->assertTrue($result, $this->testName.__METHOD__.' true'); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ACTION_ID], + $this->action->actionId, + $this->testName.__METHOD__.' action_id' + ); + \Db::deleteTestingInstance(); + } + + /** + * @covers \LengowAction::canSendAction + */ + public function testCanSendAction() + { + $mockParams = [ + \LengowAction::ARG_CARRIER => 'DHL', + \LengowAction::ARG_CARRIER_NAME => 'DHL', + \LengowAction::ARG_SHIPPING_METHOD => 'DHL', + \LengowAction::ARG_ACTION_TYPE => 'ship' + ]; + $lengowConnectorMock = $this->getMockBuilder(\LengowConnector::class) + ->disableOriginalConstructor() + ->getMock(); + $lengowConnectorMock->method('requestApi') + ->willReturn(json_decode('{"count":0}')); + \LengowConnector::setInstanceForTesting($lengowConnectorMock); + $lengowOrder = new \LengowOrder(); + $result = \LengowAction::canSendAction($mockParams, $lengowOrder); + $this->assertTrue($result, $this->testName.__METHOD__.' true'); + $lengowConnectorMock2 = $this->getMockBuilder(\LengowConnector::class) + ->disableOriginalConstructor() + ->getMock(); + $lengowConnectorMock2->method('requestApi') + ->willReturn(json_decode('{"count":1, "results":[{"id":1}]}')); + \LengowConnector::setInstanceForTesting($lengowConnectorMock2); + $result2 = \LengowAction::canSendAction($mockParams, $lengowOrder); + $this->assertFalse($result2, $this->testName.__METHOD__.' false'); + \LengowConnector::disableTestingInstance(); + } } From 1d58e97efc5b3cce5abc57e129b263c2d98b06b0 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Fri, 7 Jun 2024 17:09:18 +0200 Subject: [PATCH 17/24] ECP-81:[WIP] unit tests in prestashop module --- classes/controllers/LengowHomeController.php | 2 +- classes/models/LengowAction.php | 4 ++-- classes/models/LengowCatalog.php | 6 +++--- classes/models/LengowOrder.php | 2 +- classes/models/LengowSync.php | 10 +++++----- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/classes/controllers/LengowHomeController.php b/classes/controllers/LengowHomeController.php index 606a1145..4e644519 100755 --- a/classes/controllers/LengowHomeController.php +++ b/classes/controllers/LengowHomeController.php @@ -165,7 +165,7 @@ private function connectCms() $cmsConnected = LengowSync::syncCatalog(true); if (!$cmsConnected) { $syncData = json_encode(LengowSync::getSyncData()); - $result = LengowConnector::queryApi(LengowConnector::POST, LengowConnector::API_CMS, [], $syncData); + $result = LengowConnector::getInstance()->requestApi(LengowConnector::POST, LengowConnector::API_CMS, [], $syncData); if (isset($result->common_account)) { $cmsConnected = true; $messageKey = 'log.connection.cms_creation_success'; diff --git a/classes/models/LengowAction.php b/classes/models/LengowAction.php index 2ccafacc..42357f16 100644 --- a/classes/models/LengowAction.php +++ b/classes/models/LengowAction.php @@ -381,7 +381,7 @@ public static function canSendAction($params, $lengowOrder) public static function sendAction($params, $lengowOrder) { if (!LengowConfiguration::debugModeIsActive()) { - $result = LengowConnector::queryApi(LengowConnector::POST, LengowConnector::API_ORDER_ACTION, $params); + $result = LengowConnector::getInstance()->requestApi(LengowConnector::POST, LengowConnector::API_ORDER_ACTION, $params); if (isset($result->id)) { self::createAction( [ @@ -590,7 +590,7 @@ public static function checkFinishAction($logOutput = false) $logOutput ); do { - $results = LengowConnector::queryApi( + $results = LengowConnector::getInstance()->requestApi( LengowConnector::GET, LengowConnector::API_ORDER_ACTION, [ diff --git a/classes/models/LengowCatalog.php b/classes/models/LengowCatalog.php index 8e5132e6..733a1515 100644 --- a/classes/models/LengowCatalog.php +++ b/classes/models/LengowCatalog.php @@ -33,7 +33,7 @@ class LengowCatalog */ public static function hasCatalogNotLinked() { - $lengowCatalogs = LengowConnector::queryApi(LengowConnector::GET, LengowConnector::API_CMS_CATALOG); + $lengowCatalogs = LengowConnector::getInstance()->requestApi(LengowConnector::GET, LengowConnector::API_CMS_CATALOG); if (!$lengowCatalogs) { return false; } @@ -56,7 +56,7 @@ public static function hasCatalogNotLinked() public static function getCatalogList() { $catalogList = []; - $lengowCatalogs = LengowConnector::queryApi(LengowConnector::GET, LengowConnector::API_CMS_CATALOG); + $lengowCatalogs = LengowConnector::getInstance()->requestApi(LengowConnector::GET, LengowConnector::API_CMS_CATALOG); if (!$lengowCatalogs) { return $catalogList; } @@ -132,7 +132,7 @@ public static function linkCatalogs(array $catalogsByShops) ); } if ($hasCatalogToLink) { - $result = LengowConnector::queryApi( + $result = LengowConnector::getInstance()->requestApi( LengowConnector::POST, LengowConnector::API_CMS_MAPPING, [], diff --git a/classes/models/LengowOrder.php b/classes/models/LengowOrder.php index 754904ed..4032d907 100644 --- a/classes/models/LengowOrder.php +++ b/classes/models/LengowOrder.php @@ -1161,7 +1161,7 @@ public function callAction($action) public function getOrderLineByApi() { $orderLines = []; - $results = LengowConnector::queryApi( + $results = LengowConnector::getInstance()->requestApi( LengowConnector::GET, LengowConnector::API_ORDER, [ diff --git a/classes/models/LengowSync.php b/classes/models/LengowSync.php index 36217c2e..7afea5a5 100755 --- a/classes/models/LengowSync.php +++ b/classes/models/LengowSync.php @@ -163,7 +163,7 @@ public static function syncCatalog($force = false, $logOutput = false) return $success; } } - $result = LengowConnector::queryApi(LengowConnector::GET, LengowConnector::API_CMS, [], '', $logOutput); + $result = LengowConnector::getInstance()->requestApi(LengowConnector::GET, LengowConnector::API_CMS, [], '', $logOutput); if (isset($result->cms)) { $cmsToken = LengowMain::getToken(); foreach ($result->cms as $cms) { @@ -276,7 +276,7 @@ public static function setCmsOption($force = false, $logOutput = false) } } $options = json_encode(self::getOptionData()); - LengowConnector::queryApi(LengowConnector::PUT, LengowConnector::API_CMS, [], $options, $logOutput); + LengowConnector::getInstance()->requestApi(LengowConnector::PUT, LengowConnector::API_CMS, [], $options, $logOutput); LengowConfiguration::updateGlobalValue(LengowConfiguration::LAST_UPDATE_OPTION_CMS, time()); return true; @@ -301,7 +301,7 @@ public static function getStatusAccount($force = false, $logOutput = false) ); } } - $result = LengowConnector::queryApi(LengowConnector::GET, LengowConnector::API_PLAN, [], '', $logOutput); + $result = LengowConnector::getInstance()->requestApi(LengowConnector::GET, LengowConnector::API_PLAN, [], '', $logOutput); if (isset($result->isFreeTrial)) { $status = [ 'type' => $result->isFreeTrial ? 'free_trial' : '', @@ -352,7 +352,7 @@ public static function getMarketplaces($force = false, $logOutput = false) } } // recovering data with the API - $result = LengowConnector::queryApi( + $result = LengowConnector::getInstance()->requestApi( LengowConnector::GET, LengowConnector::API_MARKETPLACE, [], @@ -414,7 +414,7 @@ public static function getPluginData($force = false, $logOutput = false) return json_decode(LengowConfiguration::getGlobalValue(LengowConfiguration::PLUGIN_DATA), true); } } - $plugins = LengowConnector::queryApi( + $plugins = LengowConnector::getInstance()->requestApi( LengowConnector::GET, LengowConnector::API_PLUGIN, [], From f621e1b6b363526972cc6023b3ea0c0df8283df8 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Mon, 10 Jun 2024 11:17:39 +0200 Subject: [PATCH 18/24] ECP-81:[WIP] unit tests in prestashop module --- classes/models/LengowConnector.php | 22 ++--- .../Unit/classes/models/LengowActionTest.php | 90 ++++++++++++++++++- 2 files changed, 100 insertions(+), 12 deletions(-) diff --git a/classes/models/LengowConnector.php b/classes/models/LengowConnector.php index b146b756..db698013 100755 --- a/classes/models/LengowConnector.php +++ b/classes/models/LengowConnector.php @@ -155,8 +155,8 @@ class LengowConnector self::API_PLUGIN, ]; - /** @var array List of LengowConnector instances */ - protected static $instance = []; + /** @var LengowConnector|null instance */ + protected static $instance; /** * Make a new Lengow API Connector. @@ -176,20 +176,20 @@ public function __construct($accessToken, $secret) * @param string $accessToken * @param string $secret * - * @return bool|\LengowConnector + * @return null|\LengowConnector */ public static function getInstance($accessToken = '', $secret = '') { - if (isset(self::$instance[0]) - && self::$instance[0] instanceof LengowConnector) { - return self::$instance[0]; + if (!empty(self::$instance) + && self::$instance instanceof LengowConnector) { + return self::$instance; } list($accountIdFound, $accessTokenFound, $secretFound) = LengowConfiguration::getAccessIds(); if (empty($accessTokenFound) || empty($secretFound) || empty($accountIdFound)) { - return false; + return null; } if ($accessToken && $secret) { @@ -198,7 +198,7 @@ public static function getInstance($accessToken = '', $secret = '') $connector = new LengowConnector($accessTokenFound, $secretFound); } - self::$instance[0] = $connector; + self::$instance = $connector; return $connector; } @@ -206,11 +206,11 @@ public static function getInstance($accessToken = '', $secret = '') /** * Will set the instance for testing * - * @param LengowConnect $testConnector + * @param LengowConnector $testConnector */ public static function setInstanceForTesting($testConnector) { - self::$instance[0] = $testConnector; + self::$instance = $testConnector; } /** @@ -218,7 +218,7 @@ public static function setInstanceForTesting($testConnector) */ public static function disableTestingInstance() { - self::$instance = []; + self::$instance = null; } /** diff --git a/tests/Unit/classes/models/LengowActionTest.php b/tests/Unit/classes/models/LengowActionTest.php index 0e85b758..62b6fc39 100644 --- a/tests/Unit/classes/models/LengowActionTest.php +++ b/tests/Unit/classes/models/LengowActionTest.php @@ -321,7 +321,7 @@ public function testFind() \Db::deleteTestingInstance(); } - /** + /** * @covers \LengowAction::canSendAction */ public function testCanSendAction() @@ -351,4 +351,92 @@ public function testCanSendAction() $this->assertFalse($result2, $this->testName.__METHOD__.' false'); \LengowConnector::disableTestingInstance(); } + + /** + * @covers \LengowAction::createAction() + */ + public function testCreateAction() + { + $mockParams = [ + \LengowAction::ARG_CARRIER => 'DHL', + \LengowAction::ARG_CARRIER_NAME => 'DHL', + \LengowAction::ARG_SHIPPING_METHOD => 'DHL', + \LengowAction::ARG_ACTION_TYPE => 'ship' + ]; + + $mockToSend = [ + \LengowAction::FIELD_PARAMETERS => $mockParams, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 1, + \LengowAction::FIELD_ACTION_TYPE => 'ship', + 'marketplace_sku' => 'amazon_fr-123456' + ]; + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('insert')->willReturn(true); + \Db::setInstanceForTesting($dbMock); + $result = \LengowAction::createAction($mockToSend); + $this->assertTrue($result, $this->testName.__METHOD__.' true'); + + $dbMock2 = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock2->method('insert') + ->willThrowException(new \PrestaShopDatabaseException('plop')); + \Db::setInstanceForTesting($dbMock2); + $resultFalse = \LengowAction::createAction($mockToSend); + $this->assertFalse($resultFalse, $this->testName.__METHOD__.' false'); + \Db::deleteTestingInstance(); + } + + /** + * covers \LengowAction::updateAction + */ + public function testUpdateAction() + { + $mockParams = [ + \LengowAction::ARG_CARRIER => 'DHL', + \LengowAction::ARG_CARRIER_NAME => 'DHL', + \LengowAction::ARG_SHIPPING_METHOD => 'DHL', + \LengowAction::ARG_ACTION_TYPE => 'ship' + ]; + $mockToSend = [ + \LengowAction::FIELD_PARAMETERS => $mockParams, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 1, + \LengowAction::FIELD_ACTION_TYPE => 'ship', + 'marketplace_sku' => 'amazon_fr-123456' + ]; + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('getRow')->willReturn([]); + \Db::setInstanceForTesting($dbMock); + $resultFalse = \LengowAction::updateAction($mockToSend); + $this->assertFalse($resultFalse, $this->testName.__METHOD__.' false'); + $dbMock2 = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock2->method('getRow')->willReturn( + [ + \LengowAction::FIELD_ID => 1, + \LengowAction::FIELD_RETRY => false, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 1, + \LengowAction::FIELD_ACTION_TYPE => 'ship', + \LengowAction::FIELD_PARAMETERS => $mockParams, + \LengowAction::FIELD_STATE => 'new', + \LengowAction::FIELD_CREATED_AT => date('Y-m-d H:i:s'), + \LengowAction::FIELD_UPDATED_AT => date('Y-m-d H:i:s') + ] + ); + $dbMock2->method('update')->willReturn(true); + \Db::setInstanceForTesting($dbMock2); + $result = \LengowAction::updateAction($mockToSend); + $this->assertTrue($result, $this->testName.__METHOD__.' true'); + \Db::deleteTestingInstance(); + } + + } From a8b0c88c3d59d0516ef3ea118025464375388475 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Mon, 10 Jun 2024 11:59:50 +0200 Subject: [PATCH 19/24] ECP-81:[WIP] unit tests in prestashop module --- classes/models/LengowConnector.php | 24 ++++++++++++++---------- classes/models/LengowLog.php | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/classes/models/LengowConnector.php b/classes/models/LengowConnector.php index db698013..4108db96 100755 --- a/classes/models/LengowConnector.php +++ b/classes/models/LengowConnector.php @@ -184,18 +184,12 @@ public static function getInstance($accessToken = '', $secret = '') && self::$instance instanceof LengowConnector) { return self::$instance; } - list($accountIdFound, $accessTokenFound, $secretFound) = LengowConfiguration::getAccessIds(); + list($accountIdConfig, $accessTokenConfig, $secretConfig) = LengowConfiguration::getAccessIds(); - if (empty($accessTokenFound) - || empty($secretFound) - || empty($accountIdFound)) { - return null; - } - - if ($accessToken && $secret) { - $connector = new LengowConnector($accessToken, $secret); + if ($accountIdConfig) { + $connector = new LengowConnector($accessTokenConfig, $secretConfig); } else { - $connector = new LengowConnector($accessTokenFound, $secretFound); + $connector = new LengowConnector($accessToken, $secret); } self::$instance = $connector; @@ -235,7 +229,11 @@ public static function isValidAuth($logOutput = false) } $connector = self::getInstance(); + if (is_null($connector)) { + return false; + } try { + $connector->connect(false, $logOutput); } catch (LengowException $e) { $message = LengowMain::decodeLogMessage($e->getMessage(), LengowTranslation::DEFAULT_ISO_CODE); @@ -277,6 +275,9 @@ public static function queryApi($type, $api, $args = [], $body = '', $logOutput return false; } $connector = self::getInstance($accessToken, $secret); + if (is_null($connector)) { + return false; + } $type = (string) Tools::strtolower($type); $args = $authorizationRequired ? array_merge([LengowImport::ARG_ACCOUNT_ID => $accountId], $args) @@ -311,6 +312,9 @@ public static function queryApi($type, $api, $args = [], $body = '', $logOutput public static function getAccountIdByCredentials($accessToken, $secret, $logOutput = false) { $connector = self::getInstance($accessToken, $secret); + if (is_null($connector)) { + return null; + } try { $data = $connector->callAction( self::API_ACCESS_TOKEN, diff --git a/classes/models/LengowLog.php b/classes/models/LengowLog.php index ad932808..4b41f36f 100755 --- a/classes/models/LengowLog.php +++ b/classes/models/LengowLog.php @@ -99,7 +99,7 @@ public static function getPaths() } foreach ($files as $file) { preg_match('/^logs-([0-9]{4}-[0-9]{2}-[0-9]{2})\.txt$/', $file->fileName, $match); - $date = $match[1]; + $date = isset($match[1]) ? $match[1] : ''; $logs[] = [ self::LOG_DATE => $date, self::LOG_LINK => LengowMain::getToolboxUrl() From f9cbf068981c5e5b83ef72f73e3f0a330374c4d6 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Mon, 10 Jun 2024 16:31:19 +0200 Subject: [PATCH 20/24] ECP-81:[WIP] unit tests in prestashop module --- .../Unit/classes/models/LengowActionTest.php | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/Unit/classes/models/LengowActionTest.php b/tests/Unit/classes/models/LengowActionTest.php index 62b6fc39..df779ace 100644 --- a/tests/Unit/classes/models/LengowActionTest.php +++ b/tests/Unit/classes/models/LengowActionTest.php @@ -438,5 +438,79 @@ public function testUpdateAction() \Db::deleteTestingInstance(); } + /** + * @covers \LengowAction::finishAction + */ + public function testFinishAction() + { + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('update')->willReturn(false); + \Db::setInstanceForTesting($dbMock); + $resultFalse = \LengowAction::finishAction(1); + $this->assertFalse($resultFalse, $this->testName.__METHOD__.' false'); + $dbMock->method('update')->willReturn(true); + \Db::setInstanceForTesting($dbMock); + $result = \LengowAction::finishAction(2); + $this->assertFalse($result, $this->testName.__METHOD__.' true'); + \Db::deleteTestingInstance(); + } + + /** + * @covers \LengowAction::finishAllAction + */ + public function testFinishAllAction() + { + $rowMock = [ + \LengowAction::FIELD_ID => 123, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 456, + \LengowAction::FIELD_ACTION_TYPE => 'ship', + \LengowAction::FIELD_RETRY => 0, + \LengowAction::FIELD_PARAMETERS => [], + \LengowAction::FIELD_STATE => 1, + \LengowAction::FIELD_CREATED_AT => '1970-01-01 00:00:00', + \LengowAction::FIELD_UPDATED_AT => '1970-01-01 00:00:00' + ]; + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('update')->willReturn(true); + $dbMock->method('executeS')->willReturn([]); + \Db::setInstanceForTesting($dbMock); + $resultFalse = \LengowAction::finishAllActions(1); + $this->assertFalse($resultFalse, $this->testName.__METHOD__.' false'); + $dbMock->method('executeS')->willReturn([$rowMock]); + \Db::setInstanceForTesting($dbMock); + $result = \LengowAction::finishAllActions(2); + $this->assertFalse($result, $this->testName.__METHOD__.' true'); + \Db::deleteTestingInstance(); + } + + /** + * @covers \LengowAction::getIntervalTime + */ + public function testGetIntervalTime() + { + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dateLast = new \DateTime('now', new \DateTimeZone('Europe/Paris')); + $dateLast->sub(new \DateInterval("PT1H")); + + $configMock = [ + 'name' => \LengowConfiguration::LAST_UPDATE_ACTION_SYNCHRONIZATION, + 'value'=> $dateLast->getTimestamp(), + 'id_lang' => 0 + ]; + $dbMock->method('executeS')->willReturn([$configMock]); + \Db::setInstanceForTesting($dbMock); + $result = \LengowAction::getIntervalTime(); + $waited = \LengowAction::MAX_INTERVAL_TIME; + $this->assertEquals($waited, $result, $this->testName.__METHOD__.' 1 hour'); + \Db::deleteTestingInstance(); + } + } From 663263e418140d58ed403d503ca37c608079f705 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Mon, 10 Jun 2024 16:51:42 +0200 Subject: [PATCH 21/24] ECP-81:[WIP] unit tests in prestashop module --- .../Unit/classes/models/LengowActionTest.php | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/Unit/classes/models/LengowActionTest.php b/tests/Unit/classes/models/LengowActionTest.php index df779ace..35679816 100644 --- a/tests/Unit/classes/models/LengowActionTest.php +++ b/tests/Unit/classes/models/LengowActionTest.php @@ -512,5 +512,37 @@ public function testGetIntervalTime() \Db::deleteTestingInstance(); } - + /** + * @covers \LengowAction::getOldActions + */ + public function testGetOldActions() + { + $rowMock = [ + \LengowAction::FIELD_ID => 123, + \LengowAction::FIELD_ORDER_ID => 1, + \LengowAction::FIELD_ACTION_ID => 456, + \LengowAction::FIELD_ACTION_TYPE => 'ship', + \LengowAction::FIELD_RETRY => 0, + \LengowAction::FIELD_PARAMETERS => [], + \LengowAction::FIELD_STATE => 1, + \LengowAction::FIELD_CREATED_AT => '1970-01-01 00:00:00', + \LengowAction::FIELD_UPDATED_AT => '1970-01-01 00:00:00' + ]; + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('executeS') + ->willThrowException(new \PrestaShopDatabaseException('plop')); + \Db::setInstanceForTesting($dbMock); + $resultFalse = \LengowAction::getOldActions(); + $this->assertFalse($resultFalse, $this->testName.__METHOD__.' false'); + $dbMock2 = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock2->method('executeS')->willReturn([$rowMock]); + \Db::setInstanceForTesting($dbMock2); + $resultArray = \LengowAction::getOldActions(); + $this->assertEquals([$rowMock], $resultArray, $this->testName.__METHOD__.' array'); + \Db::deleteTestingInstance(); + } } From aa1c508dc57136d7d8ea1644e36e2ccf7fb126e3 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Mon, 10 Jun 2024 17:08:15 +0200 Subject: [PATCH 22/24] ECP-81:[WIP] unit tests in prestashop module --- tests/Unit/classes/models/LengowActionTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Unit/classes/models/LengowActionTest.php b/tests/Unit/classes/models/LengowActionTest.php index 35679816..e911465b 100644 --- a/tests/Unit/classes/models/LengowActionTest.php +++ b/tests/Unit/classes/models/LengowActionTest.php @@ -458,7 +458,7 @@ public function testFinishAction() } /** - * @covers \LengowAction::finishAllAction + * @covers \LengowAction::finishAllActions */ public function testFinishAllAction() { @@ -545,4 +545,5 @@ public function testGetOldActions() $this->assertEquals([$rowMock], $resultArray, $this->testName.__METHOD__.' array'); \Db::deleteTestingInstance(); } + } From 7aa22c79caeba0064715de8d81afeb244f84e805 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Tue, 11 Jun 2024 10:39:34 +0200 Subject: [PATCH 23/24] ECP-81:[WIP] unit tests in prestashop module --- .../Unit/classes/models/LengowAddressTest.php | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/tests/Unit/classes/models/LengowAddressTest.php b/tests/Unit/classes/models/LengowAddressTest.php index a67e87fb..c78f4973 100644 --- a/tests/Unit/classes/models/LengowAddressTest.php +++ b/tests/Unit/classes/models/LengowAddressTest.php @@ -11,6 +11,13 @@ class LengowAddressTest extends TestCase */ protected $address; + /** + * + * @var string $testName + */ + protected $testName; + + /** * setup * @@ -19,6 +26,7 @@ class LengowAddressTest extends TestCase public function setup(): void { $this->address = new \LengowAddress(); + $this->testName = '[Test '.\LengowAddress::class.'] '; } /** @@ -32,4 +40,99 @@ public function testClassInstantiation() '[Test Class Instantiation] Check class instantiation' ); } + + /** + * @covers \LengowAddress::getByAlias + */ + public function testGetByAlias() + { + $rowMock = [ + 'alias' => 'test', + 'id_address' => 1, + 'id_country' => 1, + 'id_cusotmer' => 1, + 'firstname' => 'John', + 'lastname' => 'Doe', + 'address1' => '10 RUE DES LILAS', + 'postcode' => '75002', + 'city' => 'PARIS' + + ]; + + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('getRow')->willReturn($rowMock); + \Db::setInstanceForTesting($dbMock); + $result = \LengowAddress::getByAlias('test'); + $this->assertIsObject($result, $this->testName.__METHOD__.' object'); + $this->assertEquals( + $rowMock['alias'], + $result->alias, + $this->testName.__METHOD__.' alias' + ); + $this->assertEquals( + $rowMock['address1'], + $result->address1, + $this->testName.__METHOD__.' address1' + ); + $this->assertEquals( + $rowMock['firstname'], + $result->firstname, + $this->testName.__METHOD__.' firstname' + ); + $dbMock2 = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock2->method('getRow')->willReturn([]); + \Db::setInstanceForTesting($dbMock2); + $resultFalse = \LengowAddress::getByAlias('test'); + $this->assertFalse($resultFalse, $this->testName.__METHOD__.' false'); + \Db::deleteTestingInstance(); + } + + /** + * @covers \LengowAddress::getByHash + */ + public function testGetByHash() + { + $rowMock = [ + 'alias' => '098f6bcd4621d373cade4e832627b4f6', + 'id_address' => 1, + 'id_country' => 1, + 'id_cusotmer' => 1, + 'firstname' => 'John', + 'lastname' => 'Doe', + 'address1' => '10 RUE DES LILAS', + 'postcode' => '75002', + 'city' => 'PARIS' + + ]; + + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('getRow')->willReturn($rowMock); + \Db::setInstanceForTesting($dbMock); + $resultHash = \LengowAddress::getByHash('test'); + $this->assertIsObject($resultHash, $this->testName.__METHOD__.' object'); + $this->assertEquals( + $rowMock['address1'], + $resultHash->address1, + $this->testName.__METHOD__.' address1' + ); + $this->assertEquals( + $rowMock['firstname'], + $resultHash->firstname, + $this->testName.__METHOD__.' firstname' + ); + $dbMock2 = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock2->method('getRow')->willReturn([]); + \Db::setInstanceForTesting($dbMock2); + $resultFalse = \LengowAddress::getByHash('test'); + $this->assertFalse($resultFalse, $this->testName.__METHOD__.' false'); + \Db::deleteTestingInstance(); + } } From c72f46ce741861c12d5b3e38c603edac7691b5e5 Mon Sep 17 00:00:00 2001 From: "alexis.hermanns" Date: Tue, 11 Jun 2024 16:27:11 +0200 Subject: [PATCH 24/24] ECP-81: unit test for LengowOrderDetail in progress --- tests/Unit/bootstrap.php | 2 +- .../classes/models/LengowOrderDetailTest.php | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index 83b1ee39..7a02c92b 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -24,7 +24,7 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ -// php7.4 -d date.timezone=UTC ./vendor/phpunit/phpunit/phpunit -c modules/lengow/tests/Unit/phpunit.xml modules/lengow/tests/Unit +// php7.4 -d date.timezone=Europe/Paris ./vendor/phpunit/phpunit/phpunit -c modules/lengow/tests/Unit/phpunit.xml modules/lengow/tests/Unit define('_PS_IN_TEST_', true); define('_PS_ROOT_DIR_', __DIR__ . '/../../../..'); define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/modules/'); diff --git a/tests/Unit/classes/models/LengowOrderDetailTest.php b/tests/Unit/classes/models/LengowOrderDetailTest.php index b6e5885e..a4ac2429 100644 --- a/tests/Unit/classes/models/LengowOrderDetailTest.php +++ b/tests/Unit/classes/models/LengowOrderDetailTest.php @@ -11,6 +11,12 @@ class LengowOrderDetailTest extends TestCase */ protected $orderDetail; + /** + * + * @var string $testName + */ + protected $testName; + /** * setup * @@ -19,6 +25,7 @@ class LengowOrderDetailTest extends TestCase public function setup(): void { $this->orderDetail = new \LengowOrderDetail(); + $this->testName = '[Test '. \LengowOrderDetail::class.'] '; } /** @@ -32,4 +39,29 @@ public function testClassInstantiation() '[Test Class Instantiation] Check class instantiation' ); } + + /** + * @covers \LengowOrderDetail::findByOrderIdProductId + */ + public function testFindByOrderIdProductId() + { + + $rowMock = [ + 'id_order_detail' => 1 + ]; + $dbMock = $this->getMockBuilder(\Db::class) + ->disableOriginalConstructor() + ->getMock(); + $dbMock->method('getRow') + ->willReturn($rowMock); + $dbMock->method('getValue')->willReturn(1); + \Db::setInstanceForTesting($dbMock); + $result1 = \LengowOrderDetail::findByOrderIdProductId(1, 1); + $this->assertEquals( + $rowMock['id_order_detail'], + $result1, + $this->testName.__METHOD__.' id_order_detail' + ); + \Db::deleteTestingInstance(); + } }