2020-09-25 12:17:29 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RetailCrmOrder_v5Test
|
|
|
|
*/
|
2021-09-08 13:00:50 +03:00
|
|
|
class RetailCrmOrder_v5Test extends BitrixTestCase {
|
|
|
|
|
2020-09-25 12:17:29 +03:00
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*/
|
2023-03-15 11:55:04 +03:00
|
|
|
public function setUp(): void
|
2020-09-25 12:17:29 +03:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
|
|
|
|
CModule::IncludeModule('intaro.retailcrm');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $arFields
|
|
|
|
* @param array $arParams
|
|
|
|
* @param string $methodApi
|
|
|
|
* @param array $expected
|
|
|
|
*
|
|
|
|
* @throws \Bitrix\Main\ArgumentException
|
|
|
|
* @throws \Bitrix\Main\ObjectPropertyException
|
|
|
|
* @throws \Bitrix\Main\SystemException
|
|
|
|
* @dataProvider orderSendProvider
|
|
|
|
*/
|
|
|
|
public function testOrderSend($arFields, $arParams, $methodApi, $expected)
|
|
|
|
{
|
2023-12-19 17:13:31 +03:00
|
|
|
RetailcrmConfigProvider::setCustomFieldsStatus('Y');
|
|
|
|
|
2020-09-25 12:17:29 +03:00
|
|
|
self::assertEquals($expected, RetailCrmOrder::orderSend(
|
|
|
|
$arFields,
|
|
|
|
new stdClass(),
|
|
|
|
$arParams,
|
|
|
|
false,
|
|
|
|
null,
|
|
|
|
$methodApi
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2021-09-08 13:00:50 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider orderSendProvider
|
|
|
|
*/
|
|
|
|
public function testOrderSendWitIntegrationPayment(
|
|
|
|
array $arFields,
|
|
|
|
array $arParams,
|
|
|
|
string $methodApi,
|
|
|
|
array $expected
|
|
|
|
): void {
|
|
|
|
RetailcrmConfigProvider::setIntegrationPaymentTypes(['testPayment']);
|
|
|
|
|
|
|
|
$orderSend = RetailCrmOrder::orderSend(
|
|
|
|
$arFields,
|
|
|
|
new stdClass(),
|
|
|
|
$arParams,
|
|
|
|
false,
|
|
|
|
null,
|
|
|
|
$methodApi
|
|
|
|
);
|
|
|
|
|
|
|
|
unset($expected['payments'][0]['paidAt'], $expected['payments'][0]['status']);
|
|
|
|
static::assertEquals($expected['payments'][0], $orderSend['payments'][0]);
|
|
|
|
}
|
|
|
|
|
2022-12-05 16:32:28 +03:00
|
|
|
public function testFieldExists(): void
|
|
|
|
{
|
|
|
|
$order = \Bitrix\Sale\Order::create('s1', 1, 'RUB');
|
2023-06-08 09:33:56 +03:00
|
|
|
$order->setPersonTypeId('bitrixType');
|
2022-12-05 16:32:28 +03:00
|
|
|
$flag = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$order->setField('REASON_CANCELED', 'тестовый заказ');
|
|
|
|
} catch(\Exception $e) {
|
|
|
|
$flag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue($flag, 'Переменной не существует');
|
|
|
|
}
|
|
|
|
|
2021-09-08 13:00:50 +03:00
|
|
|
public function initSystemData(): void
|
|
|
|
{
|
|
|
|
RetailcrmConfigProvider::setOrderTypes(['bitrixType' => 'crmType']);
|
|
|
|
RetailcrmConfigProvider::setContragentTypes(['bitrixType' => 'individual']);
|
|
|
|
RetailcrmConfigProvider::setPaymentStatuses([1 => 'paymentStatus']);
|
|
|
|
RetailcrmConfigProvider::setPaymentTypes([1 => 'testPayment']);
|
|
|
|
RetailcrmConfigProvider::setDeliveryTypes(['test' => 'test']);
|
|
|
|
RetailcrmConfigProvider::setSendPaymentAmount('N');
|
|
|
|
}
|
|
|
|
|
2020-09-25 12:17:29 +03:00
|
|
|
/**
|
|
|
|
* @return array[]
|
|
|
|
*/
|
|
|
|
public function orderSendProvider()
|
|
|
|
{
|
2021-09-08 13:00:50 +03:00
|
|
|
$arFields = $this->getArFields();
|
|
|
|
$this->initSystemData();
|
|
|
|
|
2020-09-25 12:17:29 +03:00
|
|
|
$arParams = [
|
|
|
|
'optionsOrderTypes' => RetailcrmConfigProvider::getOrderTypes(),
|
|
|
|
'optionsPayStatuses' => RetailcrmConfigProvider::getPaymentStatuses(),
|
|
|
|
'optionsContragentType' => RetailcrmConfigProvider::getContragentTypes(),
|
|
|
|
'optionsDelivTypes' => RetailcrmConfigProvider::getDeliveryTypes(),
|
|
|
|
'optionsPayTypes' => RetailcrmConfigProvider::getPaymentTypes(),
|
2023-09-11 09:51:36 +03:00
|
|
|
'optionsOrderProps' => ['bitrixType' => ['fio' => 'FIO']],
|
2023-12-19 17:13:31 +03:00
|
|
|
'optionsPayment' => ['Y' => 'paid'],
|
|
|
|
'customOrderProps' => ['1#TEST_PROP_1' => 'custom_first', '2#TEST_PROP_2' => 'custom_second']
|
2020-09-25 12:17:29 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
return [[
|
|
|
|
'arFields' => $arFields,
|
|
|
|
'arParams' => $arParams,
|
|
|
|
'methodApi' => 'ordersCreate',
|
|
|
|
'expected' => [
|
|
|
|
'number' => $arFields['NUMBER'],
|
2021-09-08 13:00:50 +03:00
|
|
|
'externalId' => (string) $arFields['ID'],
|
2020-09-25 12:17:29 +03:00
|
|
|
'createdAt' => $arFields['DATE_INSERT'],
|
|
|
|
'customer' => ['externalId' => $arFields['USER_ID']],
|
|
|
|
'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']],
|
|
|
|
'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']],
|
|
|
|
'customerComment' => $arFields['USER_DESCRIPTION'],
|
|
|
|
'managerComment' => $arFields['COMMENTS'],
|
|
|
|
'delivery' => [
|
|
|
|
'cost' => $arFields['PRICE_DELIVERY'],
|
2021-09-08 13:00:50 +03:00
|
|
|
'code' => $arFields['DELIVERYS'][0]['id'],
|
|
|
|
'service' => ['code' => $arFields['DELIVERYS'][0]['service']]
|
2020-09-25 12:17:29 +03:00
|
|
|
],
|
|
|
|
'contragent' => [
|
|
|
|
'contragentType' => $arParams['optionsContragentType'][$arFields['PERSON_TYPE_ID']]
|
|
|
|
],
|
|
|
|
'payments' => [[
|
|
|
|
'type' => $arParams['optionsPayTypes'][$arFields['PAYMENTS'][0]['PAY_SYSTEM_ID']],
|
2021-09-08 13:00:50 +03:00
|
|
|
'externalId' => RCrmActions::generatePaymentExternalId($arFields['PAYMENTS'][0]['ID']),
|
|
|
|
'status' => 'paid',
|
|
|
|
'paidAt' => $this->getDateTime()->format('Y-m-d H:i:s')
|
2022-07-20 12:46:32 +03:00
|
|
|
]],
|
2022-12-05 16:32:28 +03:00
|
|
|
'privilegeType' => 'none',
|
2023-09-11 09:51:36 +03:00
|
|
|
'statusComment' => $arFields['REASON_CANCELED'],
|
|
|
|
'firstName' => 'FirstName',
|
2023-12-19 17:13:31 +03:00
|
|
|
'lastName' => 'LastName',
|
|
|
|
'customFields' => ['custom_first' => 'test 1', 'custom_second' => 'test 2']
|
2020-09-25 12:17:29 +03:00
|
|
|
],
|
|
|
|
]];
|
|
|
|
}
|
2023-06-08 09:33:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
*/
|
|
|
|
public function testUploadOrders(): void
|
|
|
|
{
|
|
|
|
$dependencyLoader = Mockery::mock('alias:' . RetailcrmDependencyLoader::class);
|
|
|
|
$dependencyLoader->shouldReceive('loadDependencies')->withAnyArgs()->andReturn(true);
|
|
|
|
|
|
|
|
COption::SetOptionString('intaro.retailcrm', \Intaro\RetailCrm\Component\Constants::CRM_SITES_LIST, serialize([]));
|
|
|
|
|
|
|
|
$rcrmActions = Mockery::mock('alias:' . RCrmActions::class);
|
|
|
|
$rcrmActions->shouldReceive('apiMethod')->withAnyArgs()->andReturn(true);
|
2023-10-13 12:49:09 +03:00
|
|
|
$rcrmActions->shouldReceive('fromJSON')->withAnyArgs()->andReturn('');
|
2023-06-08 09:33:56 +03:00
|
|
|
|
|
|
|
$result = RetailCrmOrder::uploadOrders();
|
|
|
|
|
|
|
|
self::assertTrue($result);
|
|
|
|
}
|
2020-09-25 12:17:29 +03:00
|
|
|
}
|