diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d93306a..567ccb8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2020-09-08 v.5.5.0 +* Добавлена возможность ручной выгрузки заказов в CRM + ## 2020-09-02 v.5.4.6 * Исправлена ошибка установки модуля при отсутствии заказов в Битрикс diff --git a/composer.json b/composer.json index ca61ec47..856ad484 100755 --- a/composer.json +++ b/composer.json @@ -19,6 +19,8 @@ }, "require-dev": { "phpunit/phpunit": "^7", - "vlucas/phpdotenv": "^3.3" + "vlucas/phpdotenv": "^3.3", + "mockery/mockery" : "^1.0", + "fzaninotto/faker" : "^1.7" } } diff --git a/composer.lock b/composer.lock index e7756a0f..30588530 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9dd92e1798bfa1b664589fa3d38dd4da", + "content-hash": "032aa518034a20c6776e550379084efc", "packages": [], "packages-dev": [ { @@ -63,6 +63,168 @@ ], "time": "2019-10-21T16:45:58+00:00" }, + { + "name": "fzaninotto/faker", + "version": "v1.9.1", + "source": { + "type": "git", + "url": "https://github.com/fzaninotto/Faker.git", + "reference": "fc10d778e4b84d5bd315dad194661e091d307c6f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/fc10d778e4b84d5bd315dad194661e091d307c6f", + "reference": "fc10d778e4b84d5bd315dad194661e091d307c6f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "ext-intl": "*", + "phpunit/phpunit": "^4.8.35 || ^5.7", + "squizlabs/php_codesniffer": "^2.9.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Faker\\": "src/Faker/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "François Zaninotto" + } + ], + "description": "Faker is a PHP library that generates fake data for you.", + "keywords": [ + "data", + "faker", + "fixtures" + ], + "time": "2019-12-12T13:22:17+00:00" + }, + { + "name": "hamcrest/hamcrest-php", + "version": "v2.0.1", + "source": { + "type": "git", + "url": "https://github.com/hamcrest/hamcrest-php.git", + "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", + "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", + "shasum": "" + }, + "require": { + "php": "^5.3|^7.0|^8.0" + }, + "replace": { + "cordoval/hamcrest-php": "*", + "davedevelopment/hamcrest-php": "*", + "kodova/hamcrest-php": "*" + }, + "require-dev": { + "phpunit/php-file-iterator": "^1.4 || ^2.0", + "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "autoload": { + "classmap": [ + "hamcrest" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "This is the PHP port of Hamcrest Matchers", + "keywords": [ + "test" + ], + "time": "2020-07-09T08:09:16+00:00" + }, + { + "name": "mockery/mockery", + "version": "1.3.3", + "source": { + "type": "git", + "url": "https://github.com/mockery/mockery.git", + "reference": "60fa2f67f6e4d3634bb4a45ff3171fa52215800d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mockery/mockery/zipball/60fa2f67f6e4d3634bb4a45ff3171fa52215800d", + "reference": "60fa2f67f6e4d3634bb4a45ff3171fa52215800d", + "shasum": "" + }, + "require": { + "hamcrest/hamcrest-php": "^2.0.1", + "lib-pcre": ">=7.0", + "php": ">=5.6.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.10|^6.5|^7.5|^8.5|^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Mockery": "library/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Pádraic Brady", + "email": "padraic.brady@gmail.com", + "homepage": "http://blog.astrumfutura.com" + }, + { + "name": "Dave Marshall", + "email": "dave.marshall@atstsolutions.co.uk", + "homepage": "http://davedevelopment.co.uk" + } + ], + "description": "Mockery is a simple yet flexible PHP mock object framework", + "homepage": "https://github.com/mockery/mockery", + "keywords": [ + "BDD", + "TDD", + "library", + "mock", + "mock objects", + "mockery", + "stub", + "test", + "test double", + "testing" + ], + "time": "2020-08-11T18:10:21+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.9.5", @@ -1541,12 +1703,6 @@ "env", "environment" ], - "funding": [ - { - "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv", - "type": "tidelift" - } - ], "time": "2020-03-12T13:44:00+00:00" }, { @@ -1607,6 +1763,5 @@ "ext-json": "*", "ext-mbstring": "*" }, - "platform-dev": [], - "plugin-api-version": "1.1.0" + "platform-dev": [] } diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index ec6fe3e6..64bcf415 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Исправлена ошибка установки модуля при отсутствии заказов в Битрикс +- Добавлена возможность ручной выгрузки заказов в CRM diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 309a5cc0..c242157b 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,5 +1,5 @@ "5.4.6", - "VERSION_DATE" => "2020-09-02 14:40:00" + "VERSION" => "5.5.0", + "VERSION_DATE" => "2020-09-08 12:10:00" ); diff --git a/intaro.retailcrm/lang/ru/options.php b/intaro.retailcrm/lang/ru/options.php index 7c99b46d..39327d56 100644 --- a/intaro.retailcrm/lang/ru/options.php +++ b/intaro.retailcrm/lang/ru/options.php @@ -68,6 +68,8 @@ $MESS ['MESS_2'] = 'Произошла ошибка сервера, обрати $MESS ['ORDER_TYPES_LIST_CUSTOM'] = 'Внимание! Используется не стандартное соответвие типов заказов.'; $MESS ['ORDER_UPL_START'] = 'Начать выгрузку'; +$MESS ['UPLOAD_ORDERS_OPTIONS'] = 'Ручная выгрузка'; + $MESS ['OTHER_OPTIONS'] = 'Прочие настройки'; $MESS ['ORDERS_OPTIONS'] = 'Настройки заказов'; $MESS ['ORDER_NUMBERS'] = 'Транслировать номера заказов созданных в црм в магазин'; diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 9780b790..99da42f6 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -733,6 +733,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { "TAB" => GetMessage('OTHER_OPTIONS'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_CAPTION') + ), + array( + "DIV" => "edit5", + "TAB" => GetMessage('UPLOAD_ORDERS_OPTIONS'), + "ICON" => '', + "TITLE" => GetMessage('ORDER_UPLOAD'), ) ); $tabControl = new CAdminTabControl("tabControl", $aTabs); @@ -1488,175 +1494,169 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { + + + BeginNextTab(); ?> + + + + + +
+ +
+ + +
+
+
+
+ +
+
+
+
0%
+
+ 0% +
+
+
+
+
+
+ +
+
+
+ Buttons(); ?> End(); ?> - - - - - - -
-
- -
- - - - - - - - - -
-
-
- -
-
-
-
0%
-
- 0% -
-
-
-
-
-
- -
-
-
-
- diff --git a/tests/BitrixTestCase.php b/tests/BitrixTestCase.php new file mode 100644 index 00000000..ae7809af --- /dev/null +++ b/tests/BitrixTestCase.php @@ -0,0 +1,36 @@ +faker = \Faker\Factory::create(); + } + + /** + * этот метод phpUnit вызывает после исполнения текущего теста + * @inheritdoc + */ + public function tearDown() + { + // без этого вызова Mockery не будет работать + \Mockery::close(); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b637362a..5594cf09 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -32,4 +32,7 @@ if (!IsModuleInstalled('intaro.retailcrm')) { RegisterModule('intaro.retailcrm'); } +COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5'); CModule::IncludeModule('intaro.retailcrm'); + +require_once 'BitrixTestCase.php'; diff --git a/tests/classes/general/order/RetailCrmOrderTest.php b/tests/classes/general/order/RetailCrmOrderTest.php new file mode 100644 index 00000000..1b1021ca --- /dev/null +++ b/tests/classes/general/order/RetailCrmOrderTest.php @@ -0,0 +1,172 @@ +retailCrmOrder = \Mockery::mock('RetailCrmOrder'); + COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5'); + CModule::IncludeModule('intaro.retailcrm'); + } + + public function testModuleInstalled() + { + $this->assertTrue(Loader::includeModule("intaro.retailcrm")); + } + + /** + * @param $pSize + * @param $failed + * @param $orderList + * + * @dataProvider getData + */ + public function testUploadOrders($pSize, $failed, $orderList) + { + $this->assertEquals(50, $pSize); + $this->assertFalse($failed); + + if ($orderList) { + $this->assertEquals(3, sizeof($orderList)); + + $this->retailCrmOrder->shouldReceive('uploadOrders') + ->andReturn( + array( + array('id' => 001, 'externalId' => 2), + array('id' => 002, 'externalId' => 3), + array('id' => 003, 'externalId' => 4) + ) + ); + $result = $this->retailCrmOrder->uploadOrders(); + + foreach ($result as $key => $order) { + $this->assertEquals($order["externalId"], $orderList[$key]); + } + } else { + $this->assertFalse($orderList); + } + } + + /** + * @return array + */ + public function getData() + { + return [ + [ + 'pSize' => 50, + 'failed' => false, + 'orderList' => false + ], + [ + 'pSize' => 50, + 'failed' => false, + 'orderList' => array(2,3,4) + ] + ]; + } + + /** + * @param $pack + * @param $method + * @param $keyResponse + * @param $apiMock + * @param $optionsSitesList + * + * @dataProvider getDataUpload + */ + public function testUploadItems($pack, $method, $keyResponse, $apiMock, $optionsSitesList) + { + $responseBody1 = ''; + for ($i = 1; $i < 51; $i++) { + $responseBody1 .= "{\"id\":".$i.",\"externalId\":".$i."},"; + } + + $responseBody1 = substr($responseBody1,0,-1); + $responseBody1 ='{ + "success":true, + "'.$keyResponse.'":['.$responseBody1.'] + }'; + + $responseBody2 ='{ + "success":true, + "uploadedCustomers":[ + {"id":51,"externalId":"51"} + ] + }'; + + $apiMock->shouldReceive($method) + ->andReturn( + new \RetailCrm\Response\ApiResponse( + 200, + $responseBody1 + ), + new \RetailCrm\Response\ApiResponse( + 200, + $responseBody2 + ) + ); + + $test = new RetailCrmOrder(); + $result = $test::uploadItems($pack, $method, $keyResponse, $apiMock, $optionsSitesList); + + $this->assertEquals(sizeof($pack['s1']), sizeof($result)); + } + + /** + * @return mixed + */ + public function getCustomerList() + { + $faker = Faker\Factory::create(); + $customerList = []; + + for ($i = 1; $i < 52; $i++) { + $customerList['s1'][$i]['externalId'] = $i; + $customerList['s1'][$i]['email'] = $faker->email; + $customerList['s1'][$i]['createdAt'] = $faker->date('Y-m-d H:i:s'); + $customerList['s1'][$i]['subscribed'] = ''; + $customerList['s1'][$i]['contragent'] = ['contragentType' => 'individual']; + $customerList['s1'][$i]['firstName'] = $faker->firstName; + $customerList['s1'][$i]['lastName'] = $faker->lastName; + } + + return $customerList; + } + + /** + * @return array + */ + public function getDataUpload() + { + return [ + [ + 'pack' => $this->getCustomerList(), + 'customersUpload', + 'uploadedCustomers', + 'api'=>\Mockery::mock('RetailCrm\ApiClient'), + 'optionsSitesList'=>[] + ], + [ + 'pack'=> [], + 'ordersUpload', + 'uploadedOrders', + 'api'=>\Mockery::mock('RetailCrm\ApiClient'), + 'optionsSitesList'=>[] + ] + ]; + } +}