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 8fe2ab3e..42357f16 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); } @@ -375,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( [ @@ -584,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/LengowConnector.php b/classes/models/LengowConnector.php index c5611bbd..4108db96 100755 --- a/classes/models/LengowConnector.php +++ b/classes/models/LengowConnector.php @@ -155,6 +155,9 @@ class LengowConnector self::API_PLUGIN, ]; + /** @var LengowConnector|null instance */ + protected static $instance; + /** * Make a new Lengow API Connector. * @@ -167,6 +170,51 @@ public function __construct($accessToken, $secret) $this->secret = $secret; } + /** + * Returns a LengowConnector instance + * + * @param string $accessToken + * @param string $secret + * + * @return null|\LengowConnector + */ + public static function getInstance($accessToken = '', $secret = '') + { + if (!empty(self::$instance) + && self::$instance instanceof LengowConnector) { + return self::$instance; + } + list($accountIdConfig, $accessTokenConfig, $secretConfig) = LengowConfiguration::getAccessIds(); + + if ($accountIdConfig) { + $connector = new LengowConnector($accessTokenConfig, $secretConfig); + } else { + $connector = new LengowConnector($accessToken, $secret); + } + + self::$instance = $connector; + + return $connector; + } + + /** + * Will set the instance for testing + * + * @param LengowConnector $testConnector + */ + public static function setInstanceForTesting($testConnector) + { + self::$instance = $testConnector; + } + + /** + * Will reset $intance array + */ + public static function disableTestingInstance() + { + self::$instance = null; + } + /** * Check API Authentication * @@ -179,12 +227,13 @@ public static function isValidAuth($logOutput = false) if (!LengowToolbox::isCurlActivated()) { return false; } - list($accountId, $accessToken, $secret) = LengowConfiguration::getAccessIds(); - if ($accountId === null) { + + $connector = self::getInstance(); + if (is_null($connector)) { return false; } - $connector = new LengowConnector($accessToken, $secret); try { + $connector->connect(false, $logOutput); } catch (LengowException $e) { $message = LengowMain::decodeLogMessage($e->getMessage(), LengowTranslation::DEFAULT_ISO_CODE); @@ -225,7 +274,10 @@ 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); + if (is_null($connector)) { + return false; + } $type = (string) Tools::strtolower($type); $args = $authorizationRequired ? array_merge([LengowImport::ARG_ACCOUNT_ID => $accountId], $args) @@ -259,7 +311,10 @@ 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); + if (is_null($connector)) { + return null; + } try { $data = $connector->callAction( self::API_ACCESS_TOKEN, @@ -388,6 +443,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 +542,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/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() diff --git a/classes/models/LengowMarketplace.php b/classes/models/LengowMarketplace.php index e53a7b6c..100c9fad 100644 --- a/classes/models/LengowMarketplace.php +++ b/classes/models/LengowMarketplace.php @@ -114,13 +114,16 @@ 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); } 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, [], diff --git a/classes/models/LengowTranslation.php b/classes/models/LengowTranslation.php index 3d5636f2..abf386b5 100755 --- a/classes/models/LengowTranslation.php +++ b/classes/models/LengowTranslation.php @@ -54,10 +54,12 @@ 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 +149,14 @@ 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/.phpunit.result.cache b/tests/Unit/.phpunit.result.cache new file mode 100644 index 00000000..a32dbf9b --- /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,"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/Fixture.php b/tests/Unit/Fixture.php new file mode 100644 index 00000000..89167761 --- /dev/null +++ b/tests/Unit/Fixture.php @@ -0,0 +1,139 @@ + + * @copyright 2017 Lengow SAS + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + +namespace Lengow\Connector\Test\Unit; + +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; + } +} diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php new file mode 100644 index 00000000..7a02c92b --- /dev/null +++ b/tests/Unit/bootstrap.php @@ -0,0 +1,49 @@ + + * @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=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/'); +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'; + +if (!defined('PHPUNIT_COMPOSER_INSTALL')) { + define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../vendor/autoload.php'); +} + +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/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/LengowActionTest.php b/tests/Unit/classes/models/LengowActionTest.php new file mode 100644 index 00000000..e911465b --- /dev/null +++ b/tests/Unit/classes/models/LengowActionTest.php @@ -0,0 +1,549 @@ +action = new \LengowAction(); + $this->testName = '[Test '.\LengowAction::class.'] '; + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowAction::class, + $this->action, + $this->testName.__METHOD__.' 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, + $this->testName.__METHOD__.' load id' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ACTION_ID], + $this->action->actionId, + $this->testName.__METHOD__.' load action_id' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ORDER_ID], + $this->action->idOrder, + $this->testName.__METHOD__.' load order_id' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_RETRY], + $this->action->retry, + $this->testName.__METHOD__.' load retry' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_CREATED_AT], + $this->action->createdAt, + $this->testName.__METHOD__.' load created_at' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_UPDATED_AT], + $this->action->updatedAt, + $this->testName.__METHOD__.' load updated_at' + ); + } + + /** + * @covers \LengowAction::findByActionId + */ + public function testFindByActionId() + { + $id = -1; + $this->assertFalse( + $this->action->findByActionId($id), + $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->findByActionId($rowMock[\LengowAction::FIELD_ID]); + $this->assertTrue($result, $this->testName.__METHOD__.' findByActionId 123'); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ACTION_ID], + $this->action->actionId, + $this->testName.__METHOD__.' findByActionId action_id' + ); + $this->assertEquals( + $rowMock[\LengowAction::FIELD_ID], + $this->action->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(); + } + + /** + * @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(); + } + + /** + * @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(); + } + + /** + * @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::finishAllActions + */ + 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(); + } + + /** + * @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(); + } + +} diff --git a/tests/Unit/classes/models/LengowAddressTest.php b/tests/Unit/classes/models/LengowAddressTest.php new file mode 100644 index 00000000..c78f4973 --- /dev/null +++ b/tests/Unit/classes/models/LengowAddressTest.php @@ -0,0 +1,138 @@ +address = new \LengowAddress(); + $this->testName = '[Test '.\LengowAddress::class.'] '; + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowAddress::class, + $this->address, + '[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(); + } +} diff --git a/tests/Unit/classes/models/LengowBackupTest.php b/tests/Unit/classes/models/LengowBackupTest.php new file mode 100644 index 00000000..7b22facc --- /dev/null +++ b/tests/Unit/classes/models/LengowBackupTest.php @@ -0,0 +1,35 @@ +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..0492612a --- /dev/null +++ b/tests/Unit/classes/models/LengowCarrierTest.php @@ -0,0 +1,35 @@ +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..a7f432d3 --- /dev/null +++ b/tests/Unit/classes/models/LengowCartTest.php @@ -0,0 +1,35 @@ +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..cf6f27bd --- /dev/null +++ b/tests/Unit/classes/models/LengowCatalogTest.php @@ -0,0 +1,35 @@ +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..51ef7da5 --- /dev/null +++ b/tests/Unit/classes/models/LengowConfigurationFormTest.php @@ -0,0 +1,35 @@ +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..b36d0726 --- /dev/null +++ b/tests/Unit/classes/models/LengowConfigurationTest.php @@ -0,0 +1,35 @@ +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/LengowConnectorTest.php b/tests/Unit/classes/models/LengowConnectorTest.php new file mode 100644 index 00000000..77926b9f --- /dev/null +++ b/tests/Unit/classes/models/LengowConnectorTest.php @@ -0,0 +1,59 @@ +connector = new \LengowConnector('12345678', '123456789'); + } + + /** + * test class + */ + 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' + ); + } +} diff --git a/tests/Unit/classes/models/LengowCountryTest.php b/tests/Unit/classes/models/LengowCountryTest.php new file mode 100644 index 00000000..c35ea49b --- /dev/null +++ b/tests/Unit/classes/models/LengowCountryTest.php @@ -0,0 +1,35 @@ +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/LengowCustomerTest.php b/tests/Unit/classes/models/LengowCustomerTest.php new file mode 100644 index 00000000..9ae47a7e --- /dev/null +++ b/tests/Unit/classes/models/LengowCustomerTest.php @@ -0,0 +1,35 @@ +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/LengowExceptionTest.php b/tests/Unit/classes/models/LengowExceptionTest.php new file mode 100644 index 00000000..2ed9769b --- /dev/null +++ b/tests/Unit/classes/models/LengowExceptionTest.php @@ -0,0 +1,32 @@ +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/classes/models/LengowExportTest.php b/tests/Unit/classes/models/LengowExportTest.php new file mode 100644 index 00000000..543ed6c5 --- /dev/null +++ b/tests/Unit/classes/models/LengowExportTest.php @@ -0,0 +1,35 @@ +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..66d11d68 --- /dev/null +++ b/tests/Unit/classes/models/LengowFeedTest.php @@ -0,0 +1,35 @@ +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/LengowFileTest.php b/tests/Unit/classes/models/LengowFileTest.php new file mode 100644 index 00000000..f65af9e3 --- /dev/null +++ b/tests/Unit/classes/models/LengowFileTest.php @@ -0,0 +1,35 @@ +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/LengowGenderTest.php b/tests/Unit/classes/models/LengowGenderTest.php new file mode 100644 index 00000000..6fbc90f7 --- /dev/null +++ b/tests/Unit/classes/models/LengowGenderTest.php @@ -0,0 +1,35 @@ +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..efc5c072 --- /dev/null +++ b/tests/Unit/classes/models/LengowHookTest.php @@ -0,0 +1,36 @@ +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/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/LengowLogTest.php b/tests/Unit/classes/models/LengowLogTest.php new file mode 100644 index 00000000..ea459a90 --- /dev/null +++ b/tests/Unit/classes/models/LengowLogTest.php @@ -0,0 +1,35 @@ +log = new \LengowLog(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowLog::class, + $this->log, + '[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/LengowMarketplaceTest.php b/tests/Unit/classes/models/LengowMarketplaceTest.php new file mode 100644 index 00000000..6b842872 --- /dev/null +++ b/tests/Unit/classes/models/LengowMarketplaceTest.php @@ -0,0 +1,2227 @@ +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" + } + }'; + } +} diff --git a/tests/Unit/classes/models/LengowMethodTest.php b/tests/Unit/classes/models/LengowMethodTest.php new file mode 100644 index 00000000..9b23ff58 --- /dev/null +++ b/tests/Unit/classes/models/LengowMethodTest.php @@ -0,0 +1,35 @@ +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..fce3d4e8 --- /dev/null +++ b/tests/Unit/classes/models/LengowNameParserTest.php @@ -0,0 +1,35 @@ +nameParser = new \LengowNameParser(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \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 new file mode 100644 index 00000000..85b11a43 --- /dev/null +++ b/tests/Unit/classes/models/LengowOrderCarrierTest.php @@ -0,0 +1,35 @@ +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..a4ac2429 --- /dev/null +++ b/tests/Unit/classes/models/LengowOrderDetailTest.php @@ -0,0 +1,67 @@ +orderDetail = new \LengowOrderDetail(); + $this->testName = '[Test '. \LengowOrderDetail::class.'] '; + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowOrderDetail::class, + $this->orderDetail, + '[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(); + } +} 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/LengowOrderTest.php b/tests/Unit/classes/models/LengowOrderTest.php new file mode 100644 index 00000000..a299b3d0 --- /dev/null +++ b/tests/Unit/classes/models/LengowOrderTest.php @@ -0,0 +1,35 @@ +order = new \LengowOrder(); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowOrder::class, + $this->order, + '[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' + ); + } +} diff --git a/tests/Unit/classes/models/LengowTranslationTest.php b/tests/Unit/classes/models/LengowTranslationTest.php new file mode 100644 index 00000000..2d32e5b0 --- /dev/null +++ b/tests/Unit/classes/models/LengowTranslationTest.php @@ -0,0 +1,35 @@ +translate = new \LengowTranslation('en'); + } + + /** + * test class + */ + public function testClassInstantiation() + { + $this->assertInstanceOf( + \LengowTranslation::class, + $this->translate, + '[Test Class Instantiation] Check class instantiation' + ); + } +} 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/Unit/phpunit.xml b/tests/Unit/phpunit.xml new file mode 100644 index 00000000..e7d6aa61 --- /dev/null +++ b/tests/Unit/phpunit.xml @@ -0,0 +1,20 @@ + + + + + + + + . + + + + + ../../src + ../../classes + ../../controllers + + + 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;