mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-21 20:56:07 +03:00
Tests
This commit is contained in:
parent
3c37df0d9e
commit
6701bc03bb
@ -39,4 +39,4 @@ deploy:
|
||||
on:
|
||||
php: 7.1
|
||||
branch: master
|
||||
condition: "$DEPLOY = true"
|
||||
condition: "$DEPLOY = false"
|
@ -73,10 +73,12 @@ class RoboFile extends \Robo\Tasks
|
||||
$this->taskDeleteDir('www')->run();
|
||||
$this->taskFileSystemStack()
|
||||
->mirror('vendor/opencart/opencart/upload', 'www')
|
||||
->copy('vendor/beyondit/opencart-test-suite/src/upload/system/config/test-config.php', 'www/system/config/test-config.php')
|
||||
->copy('tests/test-config.php', 'www/system/config/test-config.php')
|
||||
->copy('vendor/beyondit/opencart-test-suite/src/upload/system/library/session/test.php', 'www/system/library/session/test.php')
|
||||
->copy('vendor/beyondit/opencart-test-suite/src/upload/admin/controller/startup/test_startup.php','www/admin/controller/startup/test_startup.php')
|
||||
->chmod('www', 0777, 0000, true)
|
||||
->rename('www/config-dist.php', 'www/config.php')
|
||||
->rename('www/admin/config-dist.php', 'www/admin/config.php')
|
||||
->run();
|
||||
|
||||
// Create new database, drop if exists already
|
||||
|
@ -9,6 +9,7 @@
|
||||
"email": "integration@retailcrm.ru"
|
||||
}
|
||||
],
|
||||
"version": "3.1.0-alpha1",
|
||||
"require-dev": {
|
||||
"opencart/opencart" : "3.1.0.0_a1",
|
||||
"vlucas/phpdotenv": "~1.1.0",
|
||||
@ -25,9 +26,11 @@
|
||||
"opencart-dir" : "www"
|
||||
},
|
||||
"scripts" : {
|
||||
"test-library": "bin/phpunit --testsuite library-tests --colors=always",
|
||||
"test-admin": "bin/phpunit --testsuite admin-tests --colors=always",
|
||||
"test-catalog": "bin/phpunit --testsuite catalog-tests --colors=always",
|
||||
"test": [
|
||||
"@test-library",
|
||||
"@test-admin",
|
||||
"@test-catalog"
|
||||
],
|
||||
|
@ -6,7 +6,7 @@
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
processIsolation="true"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
@ -16,8 +16,13 @@
|
||||
<testsuite name="admin-tests">
|
||||
<directory suffix="AdminTest.php">./tests/admin/</directory>
|
||||
</testsuite>
|
||||
<testsuite name="library-tests">
|
||||
<directory suffix="LibraryTest.php">./tests/library/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<env name="OC_ROOT" value="./www/" />
|
||||
<env name="HTTP_SERVER" value="http://localhost:8000/" />
|
||||
<env name="TEST_CONFIG" value="test-config" />
|
||||
</php>
|
||||
</phpunit>
|
@ -540,10 +540,18 @@ class ControllerExtensionModuleRetailcrm extends Controller {
|
||||
|
||||
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/prices.php')) {
|
||||
$this->load->model('extension/retailcrm/custom/prices');
|
||||
$this->model_extension_retailcrm_custom_prices->uploadPrices($products, $this->retailcrm->getApiClient());
|
||||
$this->model_extension_retailcrm_custom_prices->uploadPrices(
|
||||
$products,
|
||||
$this->retailcrm->getApiClient(),
|
||||
$this->retailcrm
|
||||
);
|
||||
} else {
|
||||
$this->load->model('extension/retailcrm/prices');
|
||||
$this->model_extension_retailcrm_prices->uploadPrices($products, $this->retailcrm->getApiClient());
|
||||
$this->model_extension_retailcrm_prices->uploadPrices(
|
||||
$products,
|
||||
$this->retailcrm->getApiClient(),
|
||||
$this->retailcrm
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,137 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ModelExtensionRetailcrmCustomer extends Model {
|
||||
protected $settings;
|
||||
protected $moduleTitle;
|
||||
protected $retailcrmApiClient;
|
||||
|
||||
public function __construct($registry)
|
||||
{
|
||||
parent::__construct($registry);
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
|
||||
$this->moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$this->settings = $this->model_setting_setting->getSetting($this->moduleTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload customers
|
||||
*
|
||||
* @param array $customers
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function uploadToCrm($customers, $retailcrmApiClient)
|
||||
{
|
||||
if ($retailcrmApiClient === false || empty($customers)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customersToCrm = array();
|
||||
|
||||
foreach($customers as $customer) {
|
||||
$customersToCrm[] = $this->process($customer);
|
||||
}
|
||||
|
||||
$chunkedCustomers = array_chunk($customersToCrm, 50);
|
||||
|
||||
foreach($chunkedCustomers as $customersPart) {
|
||||
$retailcrmApiClient->customersUpload($customersPart);
|
||||
}
|
||||
|
||||
return $chunkedCustomers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit customer
|
||||
*
|
||||
* @param array $customer
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function changeInCrm($customer, $retailcrmApiClient)
|
||||
{
|
||||
if ($retailcrmApiClient === false || empty($customer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customerToCrm = $this->process($customer);
|
||||
|
||||
$retailcrmApiClient->customersEdit($customerToCrm);
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create customer
|
||||
*
|
||||
* @param array $customer
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendToCrm($customer, $retailcrmApiClient)
|
||||
{
|
||||
if ($retailcrmApiClient === false || empty($customer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customerToCrm = $this->process($customer);
|
||||
|
||||
$retailcrmApiClient->customersCreate($customerToCrm);
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process customer
|
||||
*
|
||||
* @param array $customer
|
||||
*
|
||||
* @return array $customerToCrm
|
||||
*/
|
||||
private function process($customer)
|
||||
{
|
||||
$customerToCrm = array(
|
||||
'externalId' => $customer['customer_id'],
|
||||
'firstName' => $customer['firstname'],
|
||||
'lastName' => $customer['lastname'],
|
||||
'email' => $customer['email'],
|
||||
'phones' => array(
|
||||
array(
|
||||
'number' => $customer['telephone']
|
||||
)
|
||||
),
|
||||
'createdAt' => $customer['date_added']
|
||||
);
|
||||
|
||||
if (isset($customer['address'])) {
|
||||
$customerToCrm['address'] = array(
|
||||
'index' => $customer['address']['postcode'],
|
||||
'countryIso' => $customer['address']['iso_code_2'],
|
||||
'region' => $customer['address']['zone'],
|
||||
'city' => $customer['address']['city'],
|
||||
'text' => $customer['address']['address_1'] . ' ' . $customer['address']['address_2']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']) && $customer['custom_field']) {
|
||||
$customFields = json_decode($customer['custom_field']);
|
||||
|
||||
foreach ($customFields as $key => $value) {
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']['c_' . $key])) {
|
||||
$customFieldsToCrm[$this->settings[$this->moduleTitle . '_custom_field']['c_' . $key]] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($customFieldsToCrm)) {
|
||||
$customerToCrm['customFields'] = $customFieldsToCrm;
|
||||
}
|
||||
}
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
}
|
@ -98,13 +98,7 @@ class ModelExtensionRetailcrmOrder extends Model
|
||||
*/
|
||||
protected function totalTitles()
|
||||
{
|
||||
if (version_compare(VERSION, '3.0', '<')) {
|
||||
$title = '';
|
||||
} else {
|
||||
$title = 'total_';
|
||||
}
|
||||
|
||||
return $title;
|
||||
return 'total_';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,6 @@
|
||||
class ModelExtensionRetailcrmPrices extends Model
|
||||
{
|
||||
protected $settings;
|
||||
protected $moduleTitle;
|
||||
|
||||
private $options;
|
||||
private $optionValues;
|
||||
@ -13,14 +12,16 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
*
|
||||
* @param array $products
|
||||
* @param \RetailcrmProxy $retailcrm_api_client
|
||||
* @param \Retailcrm\Retailcrm $retailcrm
|
||||
*
|
||||
* @return mixed bool | array
|
||||
*/
|
||||
public function uploadPrices($products, $retailcrm_api_client)
|
||||
public function uploadPrices($products, $retailcrm_api_client, $retailcrm)
|
||||
{
|
||||
$this->load->model('catalog/option');
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$prices = $this->getPrices($products, $retailcrm_api_client);
|
||||
$prices = $this->getPrices($products, $retailcrm_api_client, $retailcrm);
|
||||
|
||||
if ($retailcrm_api_client === false || !$prices) {
|
||||
return false;
|
||||
@ -39,18 +40,19 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
* Get prices
|
||||
*
|
||||
* @param array $products
|
||||
*
|
||||
* @param \RetailcrmProxy $retailcrm_api_client
|
||||
* @param \Retailcrm\Retailcrm $retailcrm
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getPrices($products, $retailcrm_api_client)
|
||||
protected function getPrices($products, $retailcrm_api_client, $retailcrm)
|
||||
{
|
||||
$settings = $this->model_setting_setting->getSetting(\retailcrm\Retailcrm::MODULE);
|
||||
|
||||
$prices = array();
|
||||
$site = $this->getSite($retailcrm_api_client);
|
||||
|
||||
if (!isset($settings[$this->moduleTitle . '_special'])
|
||||
|| $settings[$this->moduleTitle . '_apiversion'] == 'v3'
|
||||
if (!isset($settings[\Retailcrm\Retailcrm::MODULE . '_special'])
|
||||
|| $settings[\Retailcrm\Retailcrm::MODULE . '_apiversion'] == 'v3'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@ -70,7 +72,7 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
}
|
||||
}
|
||||
|
||||
$offers = $this->retailcrm->getOffers($product);
|
||||
$offers = $retailcrm->getOffers($product);
|
||||
|
||||
foreach ($offers as $optionsString => $optionsValues) {
|
||||
$optionsString = explode('_', $optionsString);
|
||||
@ -105,7 +107,7 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
'site' => $site,
|
||||
'prices' => array(
|
||||
array(
|
||||
'code' => $settings[$this->moduleTitle . '_special'],
|
||||
'code' => $settings[\Retailcrm\Retailcrm::MODULE . '_special'],
|
||||
'price' => $productPrice + $optionsValues['price']
|
||||
)
|
||||
)
|
||||
|
@ -2,15 +2,13 @@
|
||||
class ControllerExtensionAnalyticsDaemonCollector extends Controller {
|
||||
public function index() {
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
|
||||
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||
$setting = $settings[$moduleTitle . '_collector'];
|
||||
$settings = $this->model_setting_setting->getSetting(\Retailcrm\Retailcrm::MODULE);
|
||||
$setting = $settings[\Retailcrm\Retailcrm::MODULE . '_collector'];
|
||||
$siteCode = isset($setting['site_key']) ? $setting['site_key'] : '';
|
||||
|
||||
if ($this->customer->isLogged()) $customerId = $this->customer->getID();
|
||||
|
||||
|
||||
$customer = isset($customerId) ? "'customerId': '" . $customerId . "'" : "";
|
||||
$labelPromo = !empty($setting['label_promo']) ? $setting['label_promo'] : null;
|
||||
$labelSend = !empty($setting['label_send']) ? $setting['label_send'] : null;
|
||||
@ -54,7 +52,7 @@ class ControllerExtensionAnalyticsDaemonCollector extends Controller {
|
||||
'period': " . $settings[$moduleTitle . '_collector']['period'] . ",
|
||||
" . $customForm . "
|
||||
});";
|
||||
}
|
||||
}
|
||||
} elseif ($labelPromo != null || $labelSend != null) {
|
||||
$captureForm = "_rc('require', 'capture-form', {
|
||||
" . $customForm . "
|
||||
|
@ -1,104 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ModelExtensionRetailcrmCustomer extends Model {
|
||||
protected $settings;
|
||||
protected $moduleTitle;
|
||||
|
||||
public function __construct($registry)
|
||||
{
|
||||
parent::__construct($registry);
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
|
||||
$this->moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$this->settings = $this->model_setting_setting->getSetting($this->moduleTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create customer
|
||||
*
|
||||
* @param array $customer
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendToCrm($customer, $retailcrmApiClient)
|
||||
{
|
||||
if (empty($customer) || $retailcrmApiClient === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customerToCrm = $this->process($customer);
|
||||
|
||||
$retailcrmApiClient->customersCreate($customerToCrm);
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit customer
|
||||
*
|
||||
* @param array $customer
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function changeInCrm($customer, $retailcrmApiClient)
|
||||
{
|
||||
if (empty($customer) || $retailcrmApiClient === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customerToCrm = $this->process($customer);
|
||||
|
||||
$retailcrmApiClient->customersEdit($customerToCrm);
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process customer
|
||||
*
|
||||
* @param array $customer
|
||||
*
|
||||
* @return array $customerToCrm
|
||||
*/
|
||||
private function process($customer) {
|
||||
$customerToCrm = array(
|
||||
'externalId' => $customer['customer_id'],
|
||||
'firstName' => $customer['firstname'],
|
||||
'lastName' => $customer['lastname'],
|
||||
'email' => $customer['email'],
|
||||
'phones' => array(
|
||||
array(
|
||||
'number' => $customer['telephone']
|
||||
)
|
||||
),
|
||||
'createdAt' => $customer['date_added']
|
||||
);
|
||||
|
||||
if (isset($customer['address'])) {
|
||||
$customerToCrm['address'] = array(
|
||||
'index' => $customer['address']['postcode'],
|
||||
'countryIso' => $customer['address']['iso_code_2'],
|
||||
'region' => $customer['address']['zone'],
|
||||
'city' => $customer['address']['city'],
|
||||
'text' => $customer['address']['address_1'] . ' ' . $customer['address']['address_2']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']) && $customer['custom_field']) {
|
||||
$customFields = json_decode($customer['custom_field']);
|
||||
|
||||
foreach ($customFields as $key => $value) {
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']['c_' . $key])) {
|
||||
$customFieldsToCrm[$this->settings[$this->moduleTitle . '_custom_field']['c_' . $key]] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($customFieldsToCrm)) {
|
||||
$customerToCrm['customFields'] = $customFieldsToCrm;
|
||||
}
|
||||
}
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
}
|
@ -7,6 +7,24 @@ abstract class Base
|
||||
protected $registry;
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* Send to crm
|
||||
*
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function create($retailcrm_api_client);
|
||||
|
||||
/**
|
||||
* Edit in crm
|
||||
*
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function edit($retailcrm_api_client);
|
||||
|
||||
/**
|
||||
* Base constructor.
|
||||
*
|
||||
@ -26,6 +44,13 @@ abstract class Base
|
||||
return $this->registry->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @param $value
|
||||
@ -61,6 +86,60 @@ abstract class Base
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data array
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepare($data)
|
||||
{
|
||||
unset($data);
|
||||
$this->data = Retailcrm::filterRecursive($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload to CRM
|
||||
*
|
||||
* @param $retailcrm_api_client
|
||||
* @param array $data
|
||||
* @param string $method
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function upload($retailcrm_api_client, $data = array(), $method = 'orders')
|
||||
{
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$upload = array();
|
||||
$countOrders = count($data);
|
||||
$countIterations = (int) ($countOrders / 50);
|
||||
|
||||
foreach ($data as $key => $entity) {
|
||||
$this->prepare($entity);
|
||||
$upload[] = $this->data;
|
||||
$this->resetData();
|
||||
|
||||
if ($countIterations > 0) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
||||
if (($countIterations == 0 && count($data) == count($upload))
|
||||
|| count($upload) == 50
|
||||
) {
|
||||
/** @var \RetailcrmApiClient5 $retailcrm_api_client */
|
||||
$retailcrm_api_client->{$method . 'Upload'}($upload);
|
||||
$upload = array();
|
||||
$countIterations--;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $custom_fields
|
||||
* @param array $setting
|
||||
@ -111,78 +190,6 @@ abstract class Base
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data array
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepare($data)
|
||||
{
|
||||
unset($data);
|
||||
Retailcrm::filterRecursive($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send to crm
|
||||
*
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function create($retailcrm_api_client);
|
||||
|
||||
/**
|
||||
* Edit in crm
|
||||
*
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function edit($retailcrm_api_client);
|
||||
|
||||
/**
|
||||
* Upload to CRM
|
||||
*
|
||||
* @param $retailcrm_api_client
|
||||
* @param array $data
|
||||
* @param string $method
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function upload($retailcrm_api_client, $data = array(), $method = 'orders')
|
||||
{
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$upload = array();
|
||||
$countOrders = count($data);
|
||||
$countIterations = (int) ($countOrders / 50);
|
||||
|
||||
foreach ($data as $key => $entity) {
|
||||
$this->prepare($entity);
|
||||
$upload[] = $this->data;
|
||||
$this->resetData();
|
||||
|
||||
if ($countIterations > 0) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
||||
if (($countIterations == 0 && count($data) == count($upload))
|
||||
|| count($upload) == 50
|
||||
) {
|
||||
/** @var \RetailcrmApiClient5 $retailcrm_api_client */
|
||||
$retailcrm_api_client->{$method . 'Upload'}($upload);
|
||||
$upload = array();
|
||||
$countIterations--;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset data on default
|
||||
*/
|
||||
|
@ -7,6 +7,7 @@ class Order extends Base
|
||||
protected $registry;
|
||||
protected $data = array(
|
||||
'number' => 0,
|
||||
'createdAt' => null,
|
||||
'countryIso' => null,
|
||||
'externalId' => 0,
|
||||
'customer' => array(),
|
||||
@ -17,6 +18,7 @@ class Order extends Base
|
||||
'email' => null,
|
||||
'phone' => null,
|
||||
'discountManualAmount' => 0,
|
||||
'customerComment' => null,
|
||||
'items' => array(),
|
||||
'delivery' => array(),
|
||||
'customFields' => array(),
|
||||
@ -141,6 +143,15 @@ class Order extends Base
|
||||
$this->setDataArray($custom_fields, 'customFields');
|
||||
}
|
||||
}
|
||||
|
||||
if ($order['customer_id']) {
|
||||
$this->setDataArray(
|
||||
array(
|
||||
'externalId' => $order['customer_id']
|
||||
),
|
||||
'customer'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
parent::prepare($order);
|
||||
@ -156,6 +167,19 @@ class Order extends Base
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->data['customer']) {
|
||||
$customer = $this->searchCustomer($this->data['phone'], $this->data['email'], $retailcrm_api_client);
|
||||
|
||||
if ($customer) {
|
||||
$this->setDataArray(
|
||||
array(
|
||||
'id' => $customer['id']
|
||||
),
|
||||
'customer'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$response = $retailcrm_api_client->ordersCreate($this->data);
|
||||
|
||||
return $response;
|
||||
@ -171,11 +195,81 @@ class Order extends Base
|
||||
return false;
|
||||
}
|
||||
|
||||
$order_payment = reset($this->data['payments']);
|
||||
unset($this->data['payments']);
|
||||
|
||||
$response = $retailcrm_api_client->ordersEdit($this->data);
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
$this->updatePayment($order_payment, $this->data['externalId'], $retailcrm_api_client);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update payment in CRM
|
||||
*
|
||||
* @param array $order_payment
|
||||
* @param int $order_id
|
||||
* @param \RetailcrmProxy $retailcrm_api_client
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function updatePayment($order_payment, $order_id, $retailcrm_api_client) {
|
||||
$response_order = $retailcrm_api_client->ordersGet($order_id);
|
||||
|
||||
if (!$response_order->isSuccessful()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$order_info = $response_order['order'];
|
||||
|
||||
foreach ($order_info['payments'] as $payment_data) {
|
||||
if (isset($payment_data['externalId']) && $payment_data['externalId'] == $order_id) {
|
||||
$payment = $payment_data;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($payment) && $payment['type'] != $order_payment['type']) {
|
||||
$response = $retailcrm_api_client->ordersPaymentDelete($payment['id']);
|
||||
if ($response->isSuccessful()) {
|
||||
$retailcrm_api_client->ordersPaymentCreate($order_payment);
|
||||
}
|
||||
} elseif (isset($payment) && $payment['type'] == $order_payment['type']) {
|
||||
$retailcrm_api_client->ordersPaymentEdit($order_payment);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $phone
|
||||
* @param $email
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
private function searchCustomer($phone, $email, $retailcrm_api_client) {
|
||||
$customer = array();
|
||||
$response = $retailcrm_api_client->customersList(
|
||||
array(
|
||||
'name' => $phone,
|
||||
'email' => $email
|
||||
),
|
||||
1,
|
||||
100
|
||||
);
|
||||
|
||||
if ($response->isSuccessful() && isset($response['customers'])) {
|
||||
$customers = $response['customers'];
|
||||
if ($customers) {
|
||||
$customer = end($customers);
|
||||
}
|
||||
}
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $shipping_code
|
||||
* @param array $deliveries
|
||||
|
@ -168,6 +168,7 @@ class Retailcrm {
|
||||
$haystack[$key] = trim($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $haystack;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ControllerRetailcrmAdminTest extends OpenCartTest
|
||||
{
|
||||
const MODULE_TITLE = 'retailcrm';
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$query = $this->db->query("SELECT permission from ".DB_PREFIX."user_group WHERE name = 'Administrator'");
|
||||
parent::setUp();
|
||||
|
||||
$query = $this->db->query("SELECT permission from " . DB_PREFIX . "user_group WHERE name = 'Administrator'");
|
||||
$permissions = json_decode($query->row['permission'],true);
|
||||
|
||||
if (!in_array('extension/module/retailcrm',$permissions['access'])) {
|
||||
if (!in_array('extension/module/retailcrm', $permissions['access'])) {
|
||||
$permissions['access'][] = 'extension/module/retailcrm';
|
||||
$this->db->query("UPDATE ".DB_PREFIX."user_group SET permission='".$this->db->escape(json_encode($permissions))."' WHERE name = 'Administrator'");
|
||||
}
|
||||
@ -22,36 +26,15 @@ class ControllerRetailcrmAdminTest extends OpenCartTest
|
||||
public function testIndex()
|
||||
{
|
||||
$this->login('admin', 'admin');
|
||||
|
||||
$response = $this->dispatchAction('extension/module/retailcrm');
|
||||
|
||||
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
||||
}
|
||||
|
||||
public function testIcml()
|
||||
{
|
||||
$this->login('admin', 'admin');
|
||||
|
||||
$response = $this->dispatchAction('extension/module/retailcrm/icml');
|
||||
|
||||
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
||||
$this->dispatchAction('extension/module/retailcrm/icml');
|
||||
$this->assertFileExists(DIR_SYSTEM . '../' . 'retailcrm.xml');
|
||||
}
|
||||
|
||||
public function testInstallCollector()
|
||||
{
|
||||
$this->login('admin', 'admin');
|
||||
|
||||
$response = $this->dispatchAction('extension/module/retailcrm/install_collector');
|
||||
|
||||
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
||||
}
|
||||
|
||||
public function testUnnstallCollector()
|
||||
{
|
||||
$this->login('admin', 'admin');
|
||||
|
||||
$response = $this->dispatchAction('extension/module/retailcrm/uninstall_collector');
|
||||
|
||||
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
||||
}
|
||||
}
|
||||
|
@ -1,187 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ModelRetailcrmOrderAdminTest extends OpenCartTest
|
||||
{
|
||||
private $orderModel;
|
||||
private $apiClientMock;
|
||||
private $settingModel;
|
||||
private $retailcrm;
|
||||
|
||||
const CUSTOMER_ID = 1;
|
||||
const ORDER_WITH_CUST_ID = 1;
|
||||
const ORDER_ID = 2;
|
||||
|
||||
public function setUp()
|
||||
public function testOrderModel()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->orderModel = $this->loadModel('extension/retailcrm/order');
|
||||
|
||||
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array(
|
||||
'ordersUpload',
|
||||
'customersList',
|
||||
'ordersCreate',
|
||||
'ordersPaymentCreate',
|
||||
'customersCreate'
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->settingModel = $this->loadModel('setting/setting');
|
||||
$this->retailcrm = new \retailcrm\retailcrm(self::$registry);
|
||||
|
||||
$this->settingModel->editSetting(
|
||||
$this->retailcrm->getModuleTitle(),
|
||||
array(
|
||||
$this->retailcrm->getModuleTitle() . '_apiversion' => 'v5',
|
||||
$this->retailcrm->getModuleTitle() . '_order_number' => 1,
|
||||
$this->retailcrm->getModuleTitle() . '_status' => array(
|
||||
1 => 'new'
|
||||
),
|
||||
$this->retailcrm->getModuleTitle() . '_delivery' => array(
|
||||
'flat.flat' => 'flat'
|
||||
),
|
||||
$this->retailcrm->getModuleTitle() . '_payment' => array(
|
||||
'cod' => 'cod'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testUploadToCrm()
|
||||
{
|
||||
$saleOrderModel = $this->loadModel('sale/order');
|
||||
$orders = $saleOrderModel->getOrders();
|
||||
$fullOrders = array();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$fullOrder = $saleOrderModel->getOrder($order['order_id']);
|
||||
|
||||
$fullOrder['order_total'] = $saleOrderModel->getOrderTotals($order['order_id']);
|
||||
$fullOrder['products'] = $saleOrderModel->getOrderProducts($order['order_id']);
|
||||
|
||||
foreach($fullOrder['products'] as $key => $product) {
|
||||
$fullOrder['products'][$key]['option'] = $saleOrderModel->getOrderOptions($product['order_id'], $product['order_product_id']);
|
||||
}
|
||||
|
||||
$fullOrders[] = $fullOrder;
|
||||
}
|
||||
|
||||
$chunkedOrders = $this->orderModel->uploadToCrm($fullOrders, $this->apiClientMock);
|
||||
|
||||
$order = $chunkedOrders[0][0];
|
||||
|
||||
$this->assertInternalType('array', $chunkedOrders);
|
||||
$this->assertInternalType('array', $chunkedOrders[0]);
|
||||
$this->assertNotEmpty($chunkedOrders[0]);
|
||||
$this->assertArrayHasKey('externalId', $order);
|
||||
$this->assertArrayHasKey('number', $order);
|
||||
$this->assertArrayHasKey('firstName', $order);
|
||||
$this->assertArrayHasKey('lastName', $order);
|
||||
$this->assertArrayHasKey('email', $order);
|
||||
$this->assertArrayHasKey('phone', $order);
|
||||
$this->assertArrayHasKey('createdAt', $order);
|
||||
$this->assertArrayHasKey('delivery', $order);
|
||||
$this->assertArrayHasKey('status', $order);
|
||||
$this->assertArrayHasKey('items', $order);
|
||||
$this->assertArrayHasKey('payments', $order);
|
||||
$this->assertNotEmpty($order['payments']);
|
||||
}
|
||||
|
||||
public function testUploadWithCustomerTest()
|
||||
{
|
||||
$saleOrderModel = $this->loadModel('sale/order');
|
||||
$order = $saleOrderModel->getOrder(self::ORDER_WITH_CUST_ID);
|
||||
|
||||
$order['totals'] = $saleOrderModel->getOrderTotals($order['order_id']);
|
||||
$order['products'] = $saleOrderModel->getOrderProducts($order['order_id']);
|
||||
|
||||
foreach($order['products'] as $key => $product) {
|
||||
$order['products'][$key]['option'] = $saleOrderModel->getOrderOptions($product['order_id'], $product['order_product_id']);
|
||||
}
|
||||
|
||||
$response = new \RetailcrmApiResponse(
|
||||
201,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'id' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->apiClientMock->expects($this->any())->method('ordersCreate')->willReturn($response);
|
||||
$orderSend = $this->orderModel->uploadOrder($order, $this->apiClientMock);
|
||||
|
||||
$this->assertArrayHasKey('status', $orderSend);
|
||||
$this->assertEquals('new', $orderSend['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderSend);
|
||||
$this->assertArrayHasKey('number', $orderSend);
|
||||
$this->assertArrayHasKey('firstName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderSend);
|
||||
$this->assertEquals('test@mail.ru', $orderSend['email']);
|
||||
$this->assertArrayHasKey('phone', $orderSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderSend['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderSend);
|
||||
$this->assertArrayHasKey('delivery', $orderSend);
|
||||
$this->assertInternalType('array', $orderSend['delivery']);
|
||||
$this->assertEquals('flat', $orderSend['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderSend['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderSend['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderSend['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderSend);
|
||||
$this->assertArrayHasKey('customerComment', $orderSend);
|
||||
$this->assertArrayHasKey('customer', $orderSend);
|
||||
$this->assertArrayHasKey('externalId', $orderSend['customer']);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $orderSend['customer']['externalId']);
|
||||
$this->assertArrayHasKey('payments', $orderSend);
|
||||
$this->assertEquals('cod', $orderSend['payments'][0]['type']);
|
||||
$this->assertNotEmpty($orderSend['payments']);
|
||||
}
|
||||
|
||||
public function testUploadWithoutCustomerTest()
|
||||
{
|
||||
$saleOrderModel = $this->loadModel('sale/order');
|
||||
$order = $saleOrderModel->getOrder(self::ORDER_ID);
|
||||
|
||||
$order['totals'] = $saleOrderModel->getOrderTotals($order['order_id']);
|
||||
$order['products'] = $saleOrderModel->getOrderProducts($order['order_id']);
|
||||
|
||||
foreach($order['products'] as $key => $product) {
|
||||
$order['products'][$key]['option'] = $saleOrderModel->getOrderOptions($product['order_id'], $product['order_product_id']);
|
||||
}
|
||||
|
||||
$response = new \RetailcrmApiResponse(
|
||||
201,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'id' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->apiClientMock->expects($this->any())->method('ordersCreate')->willReturn($response);
|
||||
$orderSend = $this->orderModel->uploadOrder($order, $this->apiClientMock);
|
||||
|
||||
$this->assertArrayHasKey('status', $orderSend);
|
||||
$this->assertArrayHasKey('externalId', $orderSend);
|
||||
$this->assertArrayHasKey('number', $orderSend);
|
||||
$this->assertArrayHasKey('firstName', $orderSend);
|
||||
$this->assertArrayHasKey('lastName', $orderSend);
|
||||
$this->assertArrayHasKey('email', $orderSend);
|
||||
$this->assertArrayHasKey('phone', $orderSend);
|
||||
$this->assertArrayHasKey('createdAt', $orderSend);
|
||||
$this->assertArrayHasKey('delivery', $orderSend);
|
||||
$this->assertArrayHasKey('items', $orderSend);
|
||||
$this->assertContains('#', $orderSend['items'][0]['offer']['externalId']);
|
||||
$this->assertArrayHasKey('payments', $orderSend);
|
||||
$this->assertArrayHasKey('customerComment', $orderSend);
|
||||
$this->assertArrayNotHasKey('customer', $orderSend);
|
||||
$this->assertNotEmpty($orderSend['payments']);
|
||||
$this->assertTrue(true);
|
||||
// todo test
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ModelRetailcrmPricesAdminTest extends OpenCartTest
|
||||
{
|
||||
private $pricesModel;
|
||||
@ -22,22 +24,25 @@ class ModelRetailcrmPricesAdminTest extends OpenCartTest
|
||||
->getMock();
|
||||
|
||||
$this->settingModel = $this->loadModel('setting/setting');
|
||||
$this->retailcrm = new \retailcrm\retailcrm(self::$registry);
|
||||
$this->retailcrm = new \Retailcrm\Retailcrm(self::$registry);
|
||||
|
||||
$this->settingModel->editSetting(
|
||||
$this->retailcrm->getModuleTitle(),
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
array(
|
||||
$this->retailcrm->getModuleTitle() . '_apiversion' => 'v5',
|
||||
$this->retailcrm->getModuleTitle() . '_special' => 'special'
|
||||
\Retailcrm\Retailcrm::MODULE . '_apiversion' => 'v5',
|
||||
\Retailcrm\Retailcrm::MODULE . '_special' => 'special'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testUploadPrices()
|
||||
{
|
||||
$response = new \RetailcrmApiResponse(200, json_encode($this->getSites()));
|
||||
$this->apiClientMock->expects($this->any())->method('sitesList')->willReturn($response);
|
||||
|
||||
$productModel = $this->loadModel('catalog/product');
|
||||
$products = $productModel->getProducts();
|
||||
$prices = $this->pricesModel->uploadPrices($products, $this->apiClientMock);
|
||||
$prices = $this->pricesModel->uploadPrices($products, $this->apiClientMock, $this->retailcrm);
|
||||
$price = $prices[0][0];
|
||||
|
||||
$this->assertInternalType('array', $prices);
|
||||
@ -45,7 +50,20 @@ class ModelRetailcrmPricesAdminTest extends OpenCartTest
|
||||
$this->assertInternalType('array', $price);
|
||||
$this->assertArrayHasKey('externalId', $price);
|
||||
$this->assertArrayHasKey('site', $price);
|
||||
$this->assertEquals('test_site', $price['site']);
|
||||
$this->assertArrayHasKey('prices', $price);
|
||||
$this->assertInternalType('array', $price['prices']);
|
||||
}
|
||||
|
||||
private function getSites()
|
||||
{
|
||||
return array(
|
||||
'success' => true,
|
||||
'sites' => array(
|
||||
array(
|
||||
'code' => 'test_site'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
14
tests/admin/ModelRetailcrmProductsAdminTest.php
Normal file
14
tests/admin/ModelRetailcrmProductsAdminTest.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ModelRetailcrmProductsAdminTest extends OpenCartTest
|
||||
{
|
||||
public function testGetProductOptions()
|
||||
{
|
||||
$model = $this->loadModel('extension/retailcrm/products');
|
||||
$options = $model->getProductOptions(42);
|
||||
|
||||
$this->assertNotEmpty($options);
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ControllerRetailcrmApiCatalogTest extends OpenCartTest
|
||||
{
|
||||
private $apiKey;
|
||||
private $retailcrm;
|
||||
private $username;
|
||||
|
||||
const ORDER_ID = 1;
|
||||
|
||||
@ -14,12 +17,13 @@ class ControllerRetailcrmApiCatalogTest extends OpenCartTest
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api` WHERE api_id = 1");
|
||||
$api = $query->row;
|
||||
$this->apiKey = $api['key'];
|
||||
$this->retailcrm = new \retailcrm\retailcrm(self::$registry);
|
||||
$this->username = $api['username'];
|
||||
$this->retailcrm = new \Retailcrm\Retailcrm(self::$registry);
|
||||
|
||||
$this->setSetting(
|
||||
$this->retailcrm->getModuleTitle(),
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
array(
|
||||
$this->retailcrm->getModuleTitle() . '_country' => array(1),
|
||||
\Retailcrm\Retailcrm::MODULE . '_country' => array(1),
|
||||
)
|
||||
);
|
||||
|
||||
@ -36,6 +40,8 @@ class ControllerRetailcrmApiCatalogTest extends OpenCartTest
|
||||
$this->assertEquals('Not found api key', $data->error);
|
||||
|
||||
$this->request->get['key'] = $this->apiKey;
|
||||
$this->request->get['username'] = $this->username;
|
||||
|
||||
$response = $this->dispatchAction('api/retailcrm/getDeliveryTypes');
|
||||
$data = json_decode($response->getOutput());
|
||||
|
||||
@ -50,6 +56,7 @@ class ControllerRetailcrmApiCatalogTest extends OpenCartTest
|
||||
$this->assertEquals('Not found api key', $data->error);
|
||||
|
||||
$this->request->get['key'] = $this->apiKey;
|
||||
$this->request->get['username'] = $this->username;
|
||||
$response = $this->dispatchAction('api/retailcrm/addOrderHistory');
|
||||
$data = json_decode($response->getOutput());
|
||||
|
||||
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ModelRetailcrmCustomerCatalogTest extends OpenCartTest
|
||||
{
|
||||
private $customerModel;
|
||||
private $apiClientMock;
|
||||
|
||||
const CUSTOMER_ID = 1;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->customerModel = $this->loadModel('extension/retailcrm/customer');
|
||||
|
||||
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array(
|
||||
'customersCreate',
|
||||
'customersEdit'
|
||||
))
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function testSendToCrm()
|
||||
{
|
||||
$customerModel = $this->loadModel('account/customer');
|
||||
$customer = $customerModel->getCustomer(self::CUSTOMER_ID);
|
||||
|
||||
$customerSend = $this->customerModel->sendToCrm($customer, $this->apiClientMock);
|
||||
|
||||
$this->assertArrayHasKey('externalId', $customerSend);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $customerSend['externalId']);
|
||||
$this->assertArrayHasKey('firstName', $customerSend);
|
||||
$this->assertEquals('Test', $customerSend['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $customerSend);
|
||||
$this->assertEquals('Test', $customerSend['lastName']);
|
||||
$this->assertArrayHasKey('email', $customerSend);
|
||||
$this->assertEquals('test@mail.ru', $customerSend['email']);
|
||||
$this->assertArrayHasKey('phones', $customerSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $customerSend['phones'][0]['number']);
|
||||
}
|
||||
|
||||
public function testChangeInCrm()
|
||||
{
|
||||
$customerModel = $this->loadModel('account/customer');
|
||||
$customer = $customerModel->getCustomer(self::CUSTOMER_ID);
|
||||
|
||||
$customerSend = $this->customerModel->changeInCrm($customer, $this->apiClientMock);
|
||||
|
||||
$this->assertArrayHasKey('externalId', $customerSend);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $customerSend['externalId']);
|
||||
$this->assertArrayHasKey('firstName', $customerSend);
|
||||
$this->assertEquals('Test', $customerSend['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $customerSend);
|
||||
$this->assertEquals('Test', $customerSend['lastName']);
|
||||
$this->assertArrayHasKey('email', $customerSend);
|
||||
$this->assertEquals('test@mail.ru', $customerSend['email']);
|
||||
$this->assertArrayHasKey('phones', $customerSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $customerSend['phones'][0]['number']);
|
||||
}
|
||||
}
|
@ -1,192 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ModelRetailcrmOrderCatalogTest extends OpenCartTest
|
||||
{
|
||||
private $orderModel;
|
||||
private $apiClientMock;
|
||||
private $retailcrm;
|
||||
|
||||
const CUSTOMER_ID = 1;
|
||||
const ORDER_WITH_CUST_ID = 1;
|
||||
const ORDER_ID = 2;
|
||||
|
||||
public function setUp()
|
||||
public function testGetOrderStatus()
|
||||
{
|
||||
parent::setUp();
|
||||
$model = $this->loadModel('extension/retailcrm/order');
|
||||
$status_id = $model->getOrderStatusId(1);
|
||||
|
||||
$this->orderModel = $this->loadModel('extension/retailcrm/order');
|
||||
|
||||
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array(
|
||||
'ordersCreate',
|
||||
'ordersEdit',
|
||||
'ordersGet',
|
||||
'ordersPaymentEdit',
|
||||
'customersList'
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->retailcrm = new \retailcrm\retailcrm(self::$registry);
|
||||
|
||||
$this->setSetting(
|
||||
$this->retailcrm->getModuleTitle(),
|
||||
array(
|
||||
$this->retailcrm->getModuleTitle() . '_apiversion' => 'v5',
|
||||
$this->retailcrm->getModuleTitle() . '_order_number' => 1,
|
||||
$this->retailcrm->getModuleTitle() . '_status' => array(
|
||||
1 => 'new'
|
||||
),
|
||||
$this->retailcrm->getModuleTitle() . '_delivery' => array(
|
||||
'flat.flat' => 'flat'
|
||||
),
|
||||
$this->retailcrm->getModuleTitle() . '_payment' => array(
|
||||
'cod' => 'cod'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateOrderWithCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_WITH_CUST_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$orderProcess = $this->orderModel->processOrder($order);
|
||||
$orderSend = $this->orderModel->sendToCrm($orderProcess, $this->apiClientMock);
|
||||
|
||||
$this->assertArrayHasKey('status', $orderSend);
|
||||
$this->assertEquals('new', $orderSend['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderSend);
|
||||
$this->assertArrayHasKey('number', $orderSend);
|
||||
$this->assertArrayHasKey('firstName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderSend);
|
||||
$this->assertEquals('test@mail.ru', $orderSend['email']);
|
||||
$this->assertArrayHasKey('phone', $orderSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderSend['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderSend);
|
||||
$this->assertArrayHasKey('delivery', $orderSend);
|
||||
$this->assertInternalType('array', $orderSend['delivery']);
|
||||
$this->assertEquals('flat', $orderSend['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderSend['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderSend['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderSend['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderSend);
|
||||
$this->assertArrayHasKey('customerComment', $orderSend);
|
||||
$this->assertArrayHasKey('customer', $orderSend);
|
||||
$this->assertArrayHasKey('externalId', $orderSend['customer']);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $orderSend['customer']['externalId']);
|
||||
$this->assertArrayHasKey('payments', $orderSend);
|
||||
$this->assertEquals('cod', $orderSend['payments'][0]['type']);
|
||||
$this->assertNotEmpty($orderSend['payments']);
|
||||
}
|
||||
|
||||
public function testEditOrderWithCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_WITH_CUST_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$orderEditResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'id' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$ordersGetResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'order' => $this->getOrder($order_id)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->apiClientMock->expects($this->any())->method('ordersEdit')->willReturn($orderEditResponse);
|
||||
$this->apiClientMock->expects($this->any())->method('ordersGet')->willReturn($ordersGetResponse);
|
||||
$orderProcess = $this->orderModel->processOrder($order);
|
||||
$orderSend = $this->orderModel->sendToCrm($orderProcess, $this->apiClientMock, false);
|
||||
|
||||
$this->assertArrayHasKey('status', $orderSend);
|
||||
$this->assertEquals('new', $orderSend['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderSend);
|
||||
$this->assertArrayHasKey('number', $orderSend);
|
||||
$this->assertArrayHasKey('firstName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderSend);
|
||||
$this->assertEquals('test@mail.ru', $orderSend['email']);
|
||||
$this->assertArrayHasKey('phone', $orderSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderSend['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderSend);
|
||||
$this->assertArrayHasKey('delivery', $orderSend);
|
||||
$this->assertInternalType('array', $orderSend['delivery']);
|
||||
$this->assertEquals('flat', $orderSend['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderSend['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderSend['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderSend['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderSend);
|
||||
$this->assertArrayHasKey('customerComment', $orderSend);
|
||||
}
|
||||
|
||||
protected function setSetting($code, $data, $store_id = 0) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (substr($key, 0, strlen($code)) == $code) {
|
||||
if (!is_array($value)) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape($value) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape(json_encode($value, true)) . "', serialized = '1'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getOrder($id)
|
||||
{
|
||||
return array(
|
||||
'payments' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'status' => 'not-paid',
|
||||
'type' => 'cod',
|
||||
'externalId' => $id,
|
||||
'amount' => '100'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertNotEmpty($status_id);
|
||||
$this->assertNotNull($status_id);
|
||||
}
|
||||
}
|
||||
|
14
tests/catalog/ModelRetailcrmProductsCatalogTest.php
Normal file
14
tests/catalog/ModelRetailcrmProductsCatalogTest.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ModelRetailcrmProductsCatalogTest extends OpenCartTest
|
||||
{
|
||||
public function testGetProductOptions()
|
||||
{
|
||||
$model = $this->loadModel('extension/retailcrm/products');
|
||||
$options = $model->getProductOptions(42);
|
||||
|
||||
$this->assertNotEmpty($options);
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
class ModelRetailcrmCustomerAdminTest extends OpenCartTest
|
||||
namespace Tests;
|
||||
|
||||
class CustomerRetailcrmLibraryTest extends OpenCartTest
|
||||
{
|
||||
private $customerModel;
|
||||
private $customer;
|
||||
private $apiClientMock;
|
||||
|
||||
const CUSTOMER_ID = 1;
|
||||
@ -11,39 +13,25 @@ class ModelRetailcrmCustomerAdminTest extends OpenCartTest
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->customerModel = $this->loadModel('extension/retailcrm/customer');
|
||||
|
||||
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array(
|
||||
'customersUpload',
|
||||
'customersCreate',
|
||||
'customersEdit'
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$retailcrm = new \Retailcrm\Retailcrm(self::$registry);
|
||||
$this->customer = $retailcrm->createObject(\Retailcrm\Customer::class);
|
||||
}
|
||||
|
||||
public function testUploadToCrm()
|
||||
public function testPrepareCustomer()
|
||||
{
|
||||
$customerModel = $this->loadModel('customer/customer');
|
||||
$customers = $customerModel->getCustomers();
|
||||
|
||||
$customersSend = $this->customerModel->uploadToCrm($customers, $this->apiClientMock);
|
||||
$customer = $customersSend[0][0];
|
||||
|
||||
$this->assertInternalType('array', $customersSend);
|
||||
$this->assertInternalType('array', $customersSend[0]);
|
||||
$this->assertArrayHasKey('externalId', $customer);
|
||||
$this->assertArrayHasKey('firstName', $customer);
|
||||
$this->assertArrayHasKey('lastName', $customer);
|
||||
$this->assertArrayHasKey('email', $customer);
|
||||
}
|
||||
|
||||
public function testChangeInCrm()
|
||||
{
|
||||
$customerModel = $this->loadModel('customer/customer');
|
||||
$customerModel = $this->loadModel('account/customer');
|
||||
$customer = $customerModel->getCustomer(self::CUSTOMER_ID);
|
||||
|
||||
$customerSend = $this->customerModel->changeInCrm($customer, $this->apiClientMock);
|
||||
$this->customer->prepare($customer);
|
||||
$customerSend = $this->customer->getData();
|
||||
|
||||
$this->assertArrayHasKey('externalId', $customerSend);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $customerSend['externalId']);
|
||||
@ -56,4 +44,4 @@ class ModelRetailcrmCustomerAdminTest extends OpenCartTest
|
||||
$this->assertArrayHasKey('phones', $customerSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $customerSend['phones'][0]['number']);
|
||||
}
|
||||
}
|
||||
}
|
306
tests/library/OrderRetailcrmLibraryTest.php
Normal file
306
tests/library/OrderRetailcrmLibraryTest.php
Normal file
@ -0,0 +1,306 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class OrderRetailcrmLibraryTest extends OpenCartTest
|
||||
{
|
||||
private $order;
|
||||
private $apiClientMock;
|
||||
private $retailcrm;
|
||||
|
||||
const CUSTOMER_ID = 1;
|
||||
const ORDER_WITH_CUST_ID = 1;
|
||||
const ORDER_ID = 2;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array(
|
||||
'ordersCreate',
|
||||
'ordersEdit',
|
||||
'ordersGet',
|
||||
'ordersPaymentEdit',
|
||||
'customersList'
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->retailcrm = new \Retailcrm\Retailcrm(self::$registry);
|
||||
|
||||
$this->order = $this->retailcrm->createObject(\Retailcrm\Order::class);
|
||||
|
||||
$this->setSetting(
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
array(
|
||||
\Retailcrm\Retailcrm::MODULE . '_apiversion' => 'v5',
|
||||
\Retailcrm\Retailcrm::MODULE . '_order_number' => 1,
|
||||
\Retailcrm\Retailcrm::MODULE . '_status' => array(
|
||||
1 => 'new'
|
||||
),
|
||||
\Retailcrm\Retailcrm::MODULE . '_delivery' => array(
|
||||
'flat.flat' => 'flat'
|
||||
),
|
||||
\Retailcrm\Retailcrm::MODULE . '_payment' => array(
|
||||
'cod' => 'cod'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrepareCreateOrderWithCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_WITH_CUST_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$this->order->prepare($order);
|
||||
$orderPrepare = $this->order->getData();
|
||||
|
||||
$this->assertArrayHasKey('status', $orderPrepare);
|
||||
$this->assertEquals('new', $orderPrepare['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare);
|
||||
$this->assertArrayHasKey('number', $orderPrepare);
|
||||
$this->assertArrayHasKey('firstName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderPrepare);
|
||||
$this->assertEquals('test@mail.ru', $orderPrepare['email']);
|
||||
$this->assertArrayHasKey('phone', $orderPrepare);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderPrepare['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderPrepare);
|
||||
$this->assertArrayHasKey('delivery', $orderPrepare);
|
||||
$this->assertInternalType('array', $orderPrepare['delivery']);
|
||||
$this->assertEquals('flat', $orderPrepare['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderPrepare['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderPrepare['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderPrepare['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderPrepare);
|
||||
$this->assertArrayHasKey('customer', $orderPrepare);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare['customer']);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $orderPrepare['customer']['externalId']);
|
||||
$this->assertArrayHasKey('payments', $orderPrepare);
|
||||
$this->assertEquals('cod', $orderPrepare['payments'][0]['type']);
|
||||
$this->assertNotEmpty($orderPrepare['payments']);
|
||||
}
|
||||
|
||||
public function testPrepareEditOrderWithCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_WITH_CUST_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$orderEditResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'id' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$ordersGetResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'order' => $this->getOrder($order_id)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->apiClientMock->expects($this->any())->method('ordersEdit')->willReturn($orderEditResponse);
|
||||
$this->apiClientMock->expects($this->any())->method('ordersGet')->willReturn($ordersGetResponse);
|
||||
$this->order->prepare($order);
|
||||
$orderPrepare = $this->order->getData();
|
||||
|
||||
$this->assertArrayHasKey('status', $orderPrepare);
|
||||
$this->assertEquals('new', $orderPrepare['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare);
|
||||
$this->assertArrayHasKey('number', $orderPrepare);
|
||||
$this->assertArrayHasKey('firstName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderPrepare);
|
||||
$this->assertEquals('test@mail.ru', $orderPrepare['email']);
|
||||
$this->assertArrayHasKey('phone', $orderPrepare);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderPrepare['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderPrepare);
|
||||
$this->assertArrayHasKey('delivery', $orderPrepare);
|
||||
$this->assertInternalType('array', $orderPrepare['delivery']);
|
||||
$this->assertEquals('flat', $orderPrepare['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderPrepare['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderPrepare['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderPrepare['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderPrepare);
|
||||
$this->assertArrayHasKey('customer', $orderPrepare);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare['customer']);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $orderPrepare['customer']['externalId']);
|
||||
}
|
||||
|
||||
public function testPrepareCreateOrderWithoutCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$this->order->prepare($order);
|
||||
$orderPrepare = $this->order->getData();
|
||||
|
||||
$this->assertArrayHasKey('status', $orderPrepare);
|
||||
$this->assertEquals('new', $orderPrepare['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare);
|
||||
$this->assertArrayHasKey('number', $orderPrepare);
|
||||
$this->assertArrayHasKey('firstName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderPrepare);
|
||||
$this->assertEquals('test@mail.ru', $orderPrepare['email']);
|
||||
$this->assertArrayHasKey('phone', $orderPrepare);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderPrepare['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderPrepare);
|
||||
$this->assertArrayHasKey('delivery', $orderPrepare);
|
||||
$this->assertInternalType('array', $orderPrepare['delivery']);
|
||||
$this->assertEquals('flat', $orderPrepare['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderPrepare['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderPrepare['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderPrepare['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderPrepare);
|
||||
$this->assertArrayNotHasKey('customer', $orderPrepare);
|
||||
$this->assertArrayHasKey('payments', $orderPrepare);
|
||||
$this->assertEquals('cod', $orderPrepare['payments'][0]['type']);
|
||||
$this->assertNotEmpty($orderPrepare['payments']);
|
||||
}
|
||||
|
||||
public function testPrepareEditOrderWithoutCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$orderEditResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'id' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$ordersGetResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'order' => $this->getOrder($order_id)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->apiClientMock->expects($this->any())->method('ordersEdit')->willReturn($orderEditResponse);
|
||||
$this->apiClientMock->expects($this->any())->method('ordersGet')->willReturn($ordersGetResponse);
|
||||
$this->order->prepare($order);
|
||||
$orderPrepare = $this->order->getData();
|
||||
|
||||
$this->assertArrayHasKey('status', $orderPrepare);
|
||||
$this->assertEquals('new', $orderPrepare['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare);
|
||||
$this->assertArrayHasKey('number', $orderPrepare);
|
||||
$this->assertArrayHasKey('firstName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderPrepare);
|
||||
$this->assertEquals('test@mail.ru', $orderPrepare['email']);
|
||||
$this->assertArrayHasKey('phone', $orderPrepare);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderPrepare['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderPrepare);
|
||||
$this->assertArrayHasKey('delivery', $orderPrepare);
|
||||
$this->assertInternalType('array', $orderPrepare['delivery']);
|
||||
$this->assertEquals('flat', $orderPrepare['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderPrepare['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderPrepare['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderPrepare['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderPrepare);
|
||||
$this->assertArrayNotHasKey('customer', $orderPrepare);
|
||||
}
|
||||
|
||||
protected function setSetting($code, $data, $store_id = 0) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (substr($key, 0, strlen($code)) == $code) {
|
||||
if (!is_array($value)) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape($value) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape(json_encode($value, true)) . "', serialized = '1'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getOrder($id)
|
||||
{
|
||||
return array(
|
||||
'payments' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'status' => 'not-paid',
|
||||
'type' => 'cod',
|
||||
'externalId' => $id,
|
||||
'amount' => '100'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
TRUNCATE TABLE `oc_customer`;
|
||||
INSERT INTO `oc_customer` (`customer_id`, `customer_group_id`, `store_id`, `language_id`, `firstname`, `lastname`, `email`, `telephone`, `fax`, `password`, `salt`, `cart`, `wishlist`, `newsletter`, `address_id`, `custom_field`, `ip`, `status`, `approved`, `safe`, `token`, `code`, `date_added`) VALUES ('1', '1', '0', '1', 'Test', 'Test', 'test@mail.ru', '+7 (000) 000-00-00', '', 'ed3798da75d6cdd695e99e87a60d587a10aa95ff', '51TalnrgH', '', '', '0', '1', '', '172.21.0.1', '1', '1', '0', '', '', '2018-06-07 13:50:08');
|
||||
INSERT INTO `oc_customer` (`customer_id`, `customer_group_id`, `store_id`, `language_id`, `firstname`, `lastname`, `email`, `telephone`, `fax`, `password`, `salt`, `cart`, `wishlist`, `newsletter`, `address_id`, `custom_field`, `ip`, `status`, `safe`, `token`, `code`, `date_added`) VALUES ('1', '1', '0', '1', 'Test', 'Test', 'test@mail.ru', '+7 (000) 000-00-00', '', 'ed3798da75d6cdd695e99e87a60d587a10aa95ff', '51TalnrgH', '', '', '0', '1', '', '172.21.0.1', '1', '0', '', '', '2018-06-07 13:50:08');
|
||||
|
||||
TRUNCATE TABLE `oc_customer_activity`;
|
||||
TRUNCATE TABLE `oc_customer_group`;
|
||||
@ -23,7 +23,6 @@ TRUNCATE TABLE `oc_order`;
|
||||
INSERT INTO `oc_order` (`order_id`, `invoice_no`, `invoice_prefix`, `store_id`, `store_name`, `store_url`, `customer_id`, `customer_group_id`, `firstname`, `lastname`, `email`, `telephone`, `fax`, `custom_field`, `payment_firstname`, `payment_lastname`, `payment_company`, `payment_address_1`, `payment_address_2`, `payment_city`, `payment_postcode`, `payment_country`, `payment_country_id`, `payment_zone`, `payment_zone_id`, `payment_address_format`, `payment_custom_field`, `payment_method`, `payment_code`, `shipping_firstname`, `shipping_lastname`, `shipping_company`, `shipping_address_1`, `shipping_address_2`, `shipping_city`, `shipping_postcode`, `shipping_country`, `shipping_country_id`, `shipping_zone`, `shipping_zone_id`, `shipping_address_format`, `shipping_custom_field`, `shipping_method`, `shipping_code`, `comment`, `total`, `order_status_id`, `affiliate_id`, `commission`, `marketing_id`, `tracking`, `language_id`, `currency_id`, `currency_code`, `currency_value`, `ip`, `forwarded_ip`, `user_agent`, `accept_language`, `date_added`, `date_modified`) VALUES ('1', '0', 'INV-2016-00', '0', 'Opencart', 'http://localhost:8000/', '1', '1', 'Test', 'Test', 'test@mail.ru', '+7 (000) 000-00-00', '', '', 'Test', 'Test', '', 'Address', 'Address 2', 'Test', '111111', 'Russian Federation', '176', 'Rostov-na-Donu', '99', '', '[]', 'Cash on delivery', 'cod', 'Test', 'Test', '', 'Address', 'Address 2', 'Test', '111111', 'Russian Federation', '176', 'Rostov-na-Donu', '99', '', '[]', 'Flat Rate', 'flat.flat', '', '106.0000', '1', '0', '0.0000', '0', '', '1', '1', 'USD', '1.00000000', '172.21.0.1', '', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36', 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7', '2018-06-07 13:51:10', '2018-06-07 13:51:23');
|
||||
INSERT INTO `oc_order` (`order_id`, `invoice_no`, `invoice_prefix`, `store_id`, `store_name`, `store_url`, `customer_id`, `customer_group_id`, `firstname`, `lastname`, `email`, `telephone`, `fax`, `custom_field`, `payment_firstname`, `payment_lastname`, `payment_company`, `payment_address_1`, `payment_address_2`, `payment_city`, `payment_postcode`, `payment_country`, `payment_country_id`, `payment_zone`, `payment_zone_id`, `payment_address_format`, `payment_custom_field`, `payment_method`, `payment_code`, `shipping_firstname`, `shipping_lastname`, `shipping_company`, `shipping_address_1`, `shipping_address_2`, `shipping_city`, `shipping_postcode`, `shipping_country`, `shipping_country_id`, `shipping_zone`, `shipping_zone_id`, `shipping_address_format`, `shipping_custom_field`, `shipping_method`, `shipping_code`, `comment`, `total`, `order_status_id`, `affiliate_id`, `commission`, `marketing_id`, `tracking`, `language_id`, `currency_id`, `currency_code`, `currency_value`, `ip`, `forwarded_ip`, `user_agent`, `accept_language`, `date_added`, `date_modified`) VALUES ('2', '0', 'INV-2016-00', '0', 'Opencart', 'http://localhost:8000/', '0', '1', 'Test', 'Test', 'test@mail.ru', '+7 (000) 000-00-00', '', '[]', 'Test', 'Test', '', 'Address', 'Address 2', 'Test', '111111', 'Russian Federation', '176', 'Rostov-na-Donu', '99', '', '[]', 'Cash on delivery', 'cod', 'Test', 'Test', '', 'Address', 'Address 2', 'Test', '111111', 'Russian Federation', '176', 'Rostov-na-Donu', '99', '', '[]', 'Flat Rate', 'flat.flat', '', '85.0000', '1', '0', '0.0000', '0', '', '1', '1', 'USD', '1.00000000', '172.21.0.1', '', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36', 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7', '2018-06-07 13:53:50', '2018-06-07 13:54:00');
|
||||
|
||||
TRUNCATE TABLE `oc_order_custom_field`;
|
||||
TRUNCATE TABLE `oc_order_history`;
|
||||
INSERT INTO `oc_order_history` (`order_history_id`, `order_id`, `order_status_id`, `notify`, `comment`, `date_added`) VALUES ('19', '2', '1', '0', '', '2018-06-07 13:54:00');
|
||||
INSERT INTO `oc_order_history` (`order_history_id`, `order_id`, `order_status_id`, `notify`, `comment`, `date_added`) VALUES ('18', '1', '1', '0', '', '2018-06-07 13:51:23');
|
||||
|
70
tests/test-config.php
Normal file
70
tests/test-config.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
define('VERSION', '3.1.0.0_a1');
|
||||
|
||||
// Site
|
||||
$_['site_url'] = getenv('HTTP_SERVER');
|
||||
$_['site_ssl'] = false;
|
||||
|
||||
// Database
|
||||
$_['db_autostart'] = true;
|
||||
$_['db_type'] = DB_DRIVER; // mpdo, mssql, mysql, mysqli or postgre
|
||||
$_['db_hostname'] = DB_HOSTNAME;
|
||||
$_['db_username'] = DB_USERNAME;
|
||||
$_['db_password'] = DB_PASSWORD;
|
||||
$_['db_database'] = DB_DATABASE;
|
||||
$_['db_port'] = DB_PORT;
|
||||
|
||||
// Action Events
|
||||
$_['action_event'] = array(
|
||||
'controller/*/before' => array(
|
||||
'event/language/before'
|
||||
),
|
||||
'controller/*/after' => array(
|
||||
'event/language/after'
|
||||
),
|
||||
'view/*/before' => array(
|
||||
500 => 'event/theme/override',
|
||||
998 => 'event/language',
|
||||
1000 => 'event/theme'
|
||||
),
|
||||
'language/*/after' => array(
|
||||
'event/translation'
|
||||
),
|
||||
//'view/*/before' => array(
|
||||
// 1000 => 'event/debug/before'
|
||||
//),
|
||||
'controller/*/after' => array(
|
||||
'event/debug/after'
|
||||
)
|
||||
);
|
||||
|
||||
if (defined('HTTP_CATALOG')) { // is defined iff in catalog
|
||||
|
||||
// Actions
|
||||
$_['action_pre_action'] = array(
|
||||
'startup/startup',
|
||||
'startup/error',
|
||||
'startup/event',
|
||||
'startup/sass',
|
||||
'startup/login',
|
||||
'startup/permission'
|
||||
);
|
||||
} else { // admin
|
||||
// Actions
|
||||
$_['action_pre_action'] = array(
|
||||
'startup/startup',
|
||||
'startup/error',
|
||||
'startup/event',
|
||||
'startup/maintenance',
|
||||
'startup/seo_url'
|
||||
);
|
||||
}
|
||||
|
||||
// Test Settings
|
||||
$_['session_engine'] = 'test';
|
||||
$_['session_autostart'] = false;
|
||||
|
||||
$_['template_engine'] = 'twig';
|
||||
$_['template_directory'] = '';
|
||||
$_['template_cache'] = false;
|
Loading…
Reference in New Issue
Block a user