1
0
Fork 0
mirror of synced 2025-04-11 05:00:55 +00:00

Add tests

This commit is contained in:
Uryvskiy Dima 2023-12-12 12:03:33 +03:00
parent d5898bab9b
commit 1b2fb50059
7 changed files with 72 additions and 23 deletions

View file

@ -15,6 +15,7 @@ use Bitrix\Sale\EventActions;
use Bitrix\Sale\Internals\OrderTable;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Installer\InstallerTrait;
use Intaro\RetailCrm\Service\CurrencyService;
use Intaro\RetailCrm\Service\OrderLoyaltyDataService;
use Intaro\RetailCrm\Vendor\Symfony\Component\Process\PhpExecutableFinder;
use RetailCrm\ApiClient;
@ -391,14 +392,13 @@ class intaro_retailcrm extends CModule
}
foreach ($arResult['arSites'] as $bitrixSite) {
$LID = $bitrixSite['LID'];
$LID = $bitrixSite['LID'] ?? null;
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
if (
isset($arResult['sitesList'][$siteCode[$LID]])
&& $arResult['arCurrencySites'][$LID] !== $arResult['sitesList'][$siteCode[$LID]]['currency'])
{
$arResult['errCode'] = 'ERR_CURRENCY_SITES';
}
$crmCurrency = $arResult['sitesList'][$siteCode]['currency'] ?? null;
$crmSite = $arResult['sitesList'][$siteCode]['name'] ?? null;
$arResult['errCode'] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency, $LID, $crmSite);
}
if (count($arResult['arSites']) != count($siteCode)) {
@ -1476,13 +1476,14 @@ class intaro_retailcrm extends CModule
}
if (!isset($res['errCode']) && count($bitrixSites) === 1 ) {
$LID = $bitrixSites[0]['LID'];
$LID = $bitrixSites[0]['LID'] ?? null;
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
$crmSite = reset($result->sites);
$crmSiteData = reset($arResult['sitesList']);
$crmSiteName = $crmSiteData['name'] ?? null;
$crmCurrency = $crmSiteData['currency'] ?? null;
if ($currencySites[$LID] !== $crmSite['currency']) {
$res['errCode'] = 'ERR_CURRENCY_SITES';
}
$res['errCode'] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency, $LID, $crmSiteName);
}
if (!isset($res)) {

View file

@ -15,7 +15,8 @@ $MESS ['ERR_COUNT_SITES'] = 'Введенный вами API Ключ относ
Измените настройки доступа для API ключа, он должен работать только с одним магазином в CRM';
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
//$MESS ['URL_NOT_FOUND'] = 'В настройках одного или нескольких сайтов не заполнено поле "URL сервера".';
$MESS ['ERR_CMS_CURRENCY'] = 'Не удалось получить валюту сайта Bitrix';
$MESS ['ERR_CRM_CURRENCY'] = 'Не удалось получить валюту магазина CRM';
$MESS ['INFO_1'] = 'Введите адрес экземпляра RetailCRM (например, https://demo.retailcrm.ru) и API-ключ.';
$MESS ['INFO_2'] = 'API-ключ можно сгенерировать при регистрации магазина в RetailCRM (Администрирование > Интеграция).';
$MESS ['INFO_3'] = 'Код сайта в 1С-Битрикс должен совпадать с кодом сайта в RetailCRM (Администрирование > Магазины).';

View file

@ -11,4 +11,6 @@ $MESS ['ERR_FIELDS_API_HOST'] = 'Неверно заполнены поля.';
$MESS ['INFO_1'] = 'Задайте соответствия между Вашими магазинами в 1С-Битрикс и RetailCRM.';
$MESS ['INFO_2'] = 'У всех Ваших магазинов в RetailCRM должен быть общий API-ключ!';
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
$MESS ['ERR_CMS_CURRENCY'] = 'Не удалось получить валюту сайта Bitrix';
$MESS ['ERR_CRM_CURRENCY'] = 'Не удалось получить валюту магазина CRM';

View file

@ -31,6 +31,8 @@ $MESS ['ERR_COUNT_SITES'] = 'Введенный вами API Ключ относ
Измените настройки доступа для API ключа, он должен работать только с одним магазином в CRM';
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
$MESS ['ERR_CMS_CURRENCY'] = 'Не удалось получить валюту сайта Bitrix';
$MESS ['ERR_CRM_CURRENCY'] = 'Не удалось получить валюту магазина CRM';
$MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Сохранить настройки';
$MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Сохранить';

View file

@ -0,0 +1,22 @@
<?php
namespace Intaro\RetailCrm\Service;
class CurrencyService
{
public static function validateCurrency($cmsCurrency, $crmCurrency, $cmsSite = null, $crmSite = null)
{
$errorMessage = '';
if ($cmsCurrency === null) {
$errorMessage = GetMessage('ERR_CMS_CURRENCY') . ' (' . $cmsSite . ')';
} elseif ($crmCurrency === null) {
$errorMessage = GetMessage('ERR_CRM_CURRENCY') . ' (' . $crmSite . ')';
} elseif ($cmsCurrency !== $crmCurrency) {
$errorMessage = GetMessage('ERR_CURRENCY_SITES') . ' (' . $crmSite . ')';
}
return $errorMessage;
}
}

View file

@ -13,9 +13,10 @@ use Intaro\RetailCrm\Component\Constants;
use Intaro\RetailCrm\Component\Handlers\EventsHandlers;
use Intaro\RetailCrm\Repository\AgreementRepository;
use Intaro\RetailCrm\Repository\TemplateRepository;
use Intaro\RetailCrm\Service\CurrencyService;
use Intaro\RetailCrm\Service\OrderLoyaltyDataService;
use Intaro\RetailCrm\Service\Utils as RetailcrmUtils;
use RetailCrm\Exception\CurlException;
use \Intaro\RetailCrm\Service\Utils as RetailcrmUtils;
IncludeModuleLangFile(__FILE__);
$mid = 'intaro.retailcrm';
@ -1090,18 +1091,21 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
continue;
}
if ($arResult['arCurrencySites'][$LID] !== $arResult['sitesList'][$crmCode]['currency']) {
$errorsText[] = GetMessage('ERR_CURRENCY_SITES') . ' (' . $arResult['sitesList'][$crmCode]['name'] . ')';
}
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
$crmCurrency = $arResult['sitesList'][$crmCode]['currency'] ?? null;
$crmSite = $arResult['sitesList'][$crmCode]['name'] ?? null;
$errorsText[] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency, $LID, $crmSite);
}
} else {
$LID = $arResult['arSites'][0]['LID'];
$LID = $arResult['arSites'][0]['LID'] ?? null;
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
$crmSite = reset($arResult['sitesList']);
$crmSiteData = reset($arResult['sitesList']);
$crmSiteName = $crmSiteData['name'] ?? null;
$crmCurrency = $crmSiteData['currency'] ?? null;
if ($arResult['arCurrencySites'][$LID] !== $crmSite['currency']) {
$errorsText[] = GetMessage('ERR_CURRENCY_SITES') . ' (' . $crmSite['name'] . ')';
}
$errorsText[] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency, $LID, $crmSiteName);
}
}

View file

@ -0,0 +1,17 @@
<?php
use Intaro\RetailCrm\Service\CurrencyService;
class CurrencyServiceTest extends BitrixTestCase
{
public function setUp(): void
{
parent::setUp();
}
public function testValidateCurrency()
{
self::assertNotEquals('', CurrencyService::validateCurrency('RUB', 'USD'));
self::assertNotEquals('', CurrencyService::validateCurrency('USD', 'RUB'));
self::assertEquals('', CurrencyService::validateCurrency('RUB', 'RUB'));
}
}