diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..c160e2b
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,34 @@
+language: php
+
+sudo: false
+
+php:
+ - 5.6
+ - 7.0
+ - 7.1
+ - 7.2
+
+matrix:
+ include:
+ - php: 5.6
+ env: BRANCH=1.6.1.x
+ - php: 7.0
+ env: BRANCH=1.6.1.x
+ - php: 7.1
+ env: BRANCH=1.6.1.x
+
+before_script:
+ - bash tests/bin/clone_prestashop.sh
+ - bash tests/bin/before_script.sh
+
+script:
+ - bash tests/bin/script.sh
+
+deploy:
+ skip_cleanup: true
+ provider: script
+ script: make
+ on:
+ php: 7.2
+ branch: master
+ condition: "$DEPLOY = true"
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d6c7ae8
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+FILE = $(TRAVIS_BUILD_DIR)/VERSION
+VERSION = `cat $(FILE)`
+ARCHIVE_NAME = '/tmp/prestashop-'$(VERSION)'.zip'
+
+all: build_archive send_to_ftp delete_archive
+
+build_archive:
+ zip -r $(ARCHIVE_NAME) ./retailcrm/*
+
+send_to_ftp:
+ curl -T $(ARCHIVE_NAME) -u $(FTP_USER):$(FTP_PASSWORD) ftp://$(FTP_HOST)
+
+delete_archive:
+ rm -f $(ARCHIVE_NAME)
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..fae692e
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+2.2.1
\ No newline at end of file
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..c76fd75
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,33 @@
+
+
+
+
+ tests/phpunit
+
+
+
+
+ retailcrm
+
+ retailcrm/translations
+ retailcrm/job
+ bootstrap.php
+ index.php
+ logo.gif
+ logo.png
+ objects.xml
+
+
+
+
\ No newline at end of file
diff --git a/retailcrm/lib/RetailcrmCatalog.php b/retailcrm/lib/RetailcrmCatalog.php
index 2414979..691bd1b 100644
--- a/retailcrm/lib/RetailcrmCatalog.php
+++ b/retailcrm/lib/RetailcrmCatalog.php
@@ -2,6 +2,9 @@
class RetailcrmCatalog
{
+ public $default_lang;
+ public $default_currency;
+ public $default_country;
public function __construct()
{
diff --git a/retailcrm/lib/RetailcrmReferences.php b/retailcrm/lib/RetailcrmReferences.php
index 4bba661..c5a3957 100644
--- a/retailcrm/lib/RetailcrmReferences.php
+++ b/retailcrm/lib/RetailcrmReferences.php
@@ -2,6 +2,11 @@
class RetailcrmReferences
{
+ public $default_lang;
+ public $carriers;
+ public $payment_modules = array();
+
+ private $api;
public function __construct($client)
{
@@ -158,7 +163,7 @@ class RetailcrmReferences
return $paymentDeliveryTypes;
}
- public function getSystemPaymentModules()
+ public function getSystemPaymentModules($active = true)
{
$shop_id = Context::getContext()->shop->id;
@@ -189,7 +194,7 @@ class RetailcrmReferences
$module->group = null;
}
- if ($module->active != 0) {
+ if ($module->active != 0 || $active === false) {
$this->payment_modules[] = array(
'id' => $module->id,
'code' => $module->name,
@@ -270,4 +275,60 @@ class RetailcrmReferences
return $crmPaymentTypes;
}
+ public function getStores()
+ {
+ $storesShop = $this->getShopStores();
+ $retailcrmStores = $this->getApiStores();
+
+ foreach ($storesShop as $key => $storeShop) {
+ $stores[] = array(
+ 'type' => 'select',
+ 'name' => 'RETAILCRM_STORES['. $key .']',
+ 'label' => $storeShop,
+ 'options' => array(
+ 'query' => $retailcrmStores,
+ 'id' => 'id_option',
+ 'name' => 'name'
+ )
+ );
+ }
+
+ return $stores;
+ }
+
+ protected function getShopStores()
+ {
+ $stores = array();
+ $warehouses = Warehouse::getWarehouses();
+
+ foreach ($warehouses as $warehouse) {
+ $arrayName = explode('-', $warehouse['name']);
+ $warehouseName = trim($arrayName[1]);
+ $stores[$warehouse['id_warehouse']] = $warehouseName;
+ }
+
+ return $stores;
+ }
+
+ protected function getApiStores()
+ {
+ $crmStores = array();
+ $response = $this->api->storesList();
+
+ if ($response) {
+ $crmStores[] = array(
+ 'id_option' => '',
+ 'name' => ''
+ );
+
+ foreach ($response->stores as $store) {
+ $crmStores[] = array(
+ 'id_option' => $store['code'],
+ 'name' => $store['name']
+ );
+ }
+ }
+
+ return $crmStores;
+ }
}
diff --git a/retailcrm/lib/RetailcrmService.php b/retailcrm/lib/RetailcrmService.php
index 9a94694..86df68d 100644
--- a/retailcrm/lib/RetailcrmService.php
+++ b/retailcrm/lib/RetailcrmService.php
@@ -2,7 +2,6 @@
class Service
{
-
public static function getDate($file)
{
if (file_exists($file)) {
diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php
index 96c97b0..3e2ec69 100644
--- a/retailcrm/retailcrm.php
+++ b/retailcrm/retailcrm.php
@@ -20,11 +20,25 @@ require_once(dirname(__FILE__) . '/bootstrap.php');
class RetailCRM extends Module
{
+ public $api = false;
+ public $default_lang;
+ public $default_currency;
+ public $default_country;
+ public $apiUrl;
+ public $apiKey;
+ public $apiVersion;
+ public $psVersion;
+ public $log;
+ public $confirmUninstall;
+ public $reference;
+
+ private $use_new_hooks = true;
+
public function __construct()
{
$this->name = 'retailcrm';
$this->tab = 'export';
- $this->version = '2.2.0';
+ $this->version = '2.2.1';
$this->author = 'Retail Driver LCC';
$this->displayName = $this->l('RetailCRM');
$this->description = $this->l('Integration module for RetailCRM');
@@ -135,7 +149,7 @@ class RetailCRM extends Module
$this->l('Timezone settings must be identical to both of your crm and shop') .
" $address/admin/settings#t-main"
);
-
+
$this->display(__FILE__, 'retailcrm.tpl');
return $output . $this->displayForm();
@@ -350,29 +364,35 @@ class RetailCRM extends Module
public function hookActionCustomerAccountAdd($params)
{
- $this->api->customersCreate(
- array(
- 'externalId' => $params['newCustomer']->id,
- 'firstName' => $params['newCustomer']->firstname,
- 'lastName' => $params['newCustomer']->lastname,
- 'email' => $params['newCustomer']->email,
- 'createdAt' => $params['newCustomer']->date_add
- )
+ $customer = $params['newCustomer'];
+ $customerSend = array(
+ 'externalId' => $customer->id,
+ 'firstName' => $customer->firstname,
+ 'lastName' => $customer->lastname,
+ 'email' => $customer->email,
+ 'createdAt' => $customer->date_add
);
+
+ $this->api->customersCreate($customerSend);
+
+ return $customerSend;
}
// this hook added in 1.7
public function hookActionCustomerAccountUpdate($params)
{
- $this->api->customersEdit(
- array(
- 'externalId' => $params['customer']->id,
- 'firstName' => $params['customer']->firstname,
- 'lastName' => $params['customer']->lastname,
- 'email' => $params['customer']->email,
- 'birthday' => $params['customer']->birthday
- )
+ $customer = $params['customer'];
+ $customerSend = array(
+ 'externalId' => $customer->id,
+ 'firstName' => $customer->firstname,
+ 'lastName' => $customer->lastname,
+ 'email' => $customer->email,
+ 'birthday' => $customer->birthday
);
+
+ $this->api->customersEdit($customerSend);
+
+ return $customerSend;
}
public function hookNewOrder($params)
@@ -382,19 +402,20 @@ class RetailCRM extends Module
public function hookActionPaymentConfirmation($params)
{
- $this->api->ordersEdit(
- array(
- 'externalId' => $params['id_order'],
- 'paymentStatus' => 'paid'
- )
- );
+ if ($this->apiVersion == 4) {
+ $this->api->ordersEdit(
+ array(
+ 'externalId' => $params['id_order'],
+ 'paymentStatus' => 'paid'
+ )
+ );
+ }
return $this->hookActionOrderStatusPostUpdate($params);
}
public function hookActionOrderEdited($params)
{
- $apiVersion = Configuration::get('RETAILCRM_API_VERSION');
$order = array(
'externalId' => $params['order']->id,
'firstName' => $params['customer']->firstname,
@@ -404,7 +425,7 @@ class RetailCRM extends Module
'delivery' => array('cost' => $params['order']->total_shipping)
);
- if ($apiVersion != 5) {
+ if ($this->apiVersion != 5) {
$order['discount'] = $params['order']->total_discounts;
} else {
$order['discountManualAmount'] = $params['order']->total_discounts;
@@ -436,6 +457,8 @@ class RetailCRM extends Module
$order['customer']['externalId'] = $params['order']->id_customer;
$this->api->ordersEdit($order);
+
+ return $order;
}
public function hookActionOrderStatusPostUpdate($params)
@@ -443,7 +466,6 @@ class RetailCRM extends Module
$delivery = json_decode(Configuration::get('RETAILCRM_API_DELIVERY'), true);
$payment = json_decode(Configuration::get('RETAILCRM_API_PAYMENT'), true);
$status = json_decode(Configuration::get('RETAILCRM_API_STATUS'), true);
- $apiVersion = Configuration::get('RETAILCRM_API_VERSION');
if (isset($params['orderStatus'])) {
$customer = array(
@@ -463,13 +485,13 @@ class RetailCRM extends Module
'delivery' => array('cost' => $params['order']->total_shipping)
);
- if ($apiVersion != 5) {
+ if ($this->apiVersion != 5) {
$order['discount'] = $params['order']->total_discounts;
} else {
$order['discountManualAmount'] = $params['order']->total_discounts;
}
- $cart = new Cart($params['cart']->id);
+ $cart = $params['cart'];
$addressCollection = $cart->getAddressCollection();
$address = array_shift($addressCollection);
@@ -502,7 +524,7 @@ class RetailCRM extends Module
$customer['phones'][] = array('number' => $phone);
$order['phone'] = $phone;
}
-
+
foreach ($cart->getProducts() as $item) {
if (isset($item['id_product_attribute']) && $item['id_product_attribute'] > 0) {
$productId = $item['id_product'] . '#' . $item['id_product_attribute'];
@@ -527,16 +549,21 @@ class RetailCRM extends Module
}
}
- $order['items'][] = array(
+ $orderItem = array(
'initialPrice' => !empty($item['rate'])
? $item['price'] + ($item['price'] * $item['rate'] / 100)
: $item['price'],
'quantity' => $item['quantity'],
'offer' => array('externalId' => $productId),
- 'productName' => $item['name'],
- 'properties' => $arProp
+ 'productName' => $item['name']
);
+ if (isset($arProp)) {
+ $orderItem['properties'] = $arProp;
+ }
+
+ $order['items'][] = $orderItem;
+
unset($arAttr);
unset($count);
unset($arProp);
@@ -554,20 +581,20 @@ class RetailCRM extends Module
$paymentCode = $params['order']->payment;
}
- if ($apiVersion != 5) {
+ if ($this->apiVersion != 5) {
if (array_key_exists($paymentCode, $payment) && !empty($payment[$paymentCode])) {
$order['paymentType'] = $payment[$paymentCode];
}
} else {
- $payment = array(
+ $paymentSend = array(
'externalId' => $params['order']->id .'#'. $params['order']->reference,
'amount' => $params['order']->total_paid,
'type' => $payment[$paymentCode] ? $payment[$paymentCode] : ''
);
}
- if (isset($payment)) {
- $order['payments'][] = $payment;
+ if (isset($paymentSend)) {
+ $order['payments'][] = $paymentSend;
}
$statusCode = $params['orderStatus']->id;
@@ -587,6 +614,9 @@ class RetailCRM extends Module
$order['customer']['externalId'] = $customer['externalId'];
$this->api->ordersCreate($order);
+
+ return $order;
+
} elseif (isset($params['newOrderStatus'])) {
$statusCode = $params['newOrderStatus']->id;
@@ -601,8 +631,12 @@ class RetailCRM extends Module
'status' => $orderStatus
)
);
+
+ return $orderStatus;
}
}
+
+ return false;
}
public function hookActionPaymentCCAdd($params)
@@ -620,11 +654,12 @@ class RetailCRM extends Module
if (array_key_exists($payCode, $paymentCRM) && !empty($paymentCRM[$payCode])) {
$payment = $paymentCRM[$payCode];
}
-
+
$response = $this->api->ordersGet($order_id);
if ($response !== false) {
$orderCRM = $response['order'];
+
if ($orderCRM && $orderCRM['payments']) {
foreach ($orderCRM['payments'] as $orderPayment) {
if ($orderPayment['type'] == $payment) {
@@ -641,27 +676,31 @@ class RetailCRM extends Module
if (isset($updatePayment)) {
$this->api->ordersPaymentEdit($updatePayment);
+
+ return $updatePayment;
} else {
- $this->api->ordersPaymentCreate(
- array(
- 'externalId' => $params['paymentCC']->id,
- 'amount' => $params['paymentCC']->amount,
- 'paidAt' => $params['paymentCC']->date_add,
- 'type' => $payment,
- 'status' => 'paid',
- 'order' => array(
- 'externalId' => $order_id,
- ),
- )
+ $createPayment = array(
+ 'externalId' => $params['paymentCC']->id,
+ 'amount' => $params['paymentCC']->amount,
+ 'paidAt' => $params['paymentCC']->date_add,
+ 'type' => $payment,
+ 'status' => 'paid',
+ 'order' => array(
+ 'externalId' => $order_id,
+ ),
);
+
+ $this->api->ordersPaymentCreate($createPayment);
+
+ return $createPayment;
}
- return true;
+
+ return false;
}
private function validateCrmAddress($address)
{
if (preg_match("/https:\/\/(.*).retailcrm.ru/", $address) === 1) {
-
return true;
}
diff --git a/tests/bin/before_script.sh b/tests/bin/before_script.sh
new file mode 100644
index 0000000..3fe6e86
--- /dev/null
+++ b/tests/bin/before_script.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+if [ -z $TRAVIS_BUILD_DIR ]; then
+ exit 0;
+fi
+
+PRESTASHOP_DIR=$TRAVIS_BUILD_DIR/../PrestaShop
+
+cd $PRESTASHOP_DIR
+
+if [ -z $BRANCH ]; then
+ cp tests/parameters.yml.travis app/config/parameters.yml
+ bash travis-scripts/install-prestashop
+else
+ bash travis-scripts/install-prestashop.sh
+fi
diff --git a/tests/bin/clone_prestashop.sh b/tests/bin/clone_prestashop.sh
new file mode 100644
index 0000000..fde2403
--- /dev/null
+++ b/tests/bin/clone_prestashop.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+if [ -z $TRAVIS_BUILD_DIR ]; then
+ exit 0;
+fi
+
+PRESTASHOP_DIR=$TRAVIS_BUILD_DIR/../PrestaShop
+
+cd ..
+git clone https://github.com/PrestaShop/PrestaShop
+cd PrestaShop
+
+if ! [ -z $BRANCH ]; then
+ git checkout $BRANCH;
+ cd tests
+ composer install
+else
+ composer install --prefer-dist --no-interaction --no-progress
+fi
diff --git a/tests/bin/script.sh b/tests/bin/script.sh
new file mode 100644
index 0000000..a104a9e
--- /dev/null
+++ b/tests/bin/script.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+if [ -z $TRAVIS_BUILD_DIR ]; then
+ exit 0;
+fi
+
+PRESTASHOP_DIR=$TRAVIS_BUILD_DIR/../PrestaShop
+
+if ! [ -z $BRANCH ]; then
+ phpunit
+else
+ cd $PRESTASHOP_DIR
+ composer run-script create-test-db --timeout=0
+ php ../PrestaShop/vendor/bin/phpunit -c $TRAVIS_BUILD_DIR/phpunit.xml.dist
+fi
diff --git a/tests/helpers/RetailcrmTestCase.php b/tests/helpers/RetailcrmTestCase.php
new file mode 100644
index 0000000..10a33e6
--- /dev/null
+++ b/tests/helpers/RetailcrmTestCase.php
@@ -0,0 +1,27 @@
+')) {
+ $contextMocker = new \Tests\Unit\ContextMocker();
+ $this->contextMock = $contextMocker->mockContext();
+ }
+ }
+
+ protected function setConfig()
+ {
+ $delivery = json_encode(array('delivery' => 'delivery'));
+ $status = json_encode(array('status' => 'status', 'new' => 'new', 'completed'=> 'completed'));
+ $payment = json_encode(array('ps_checkpayment' => 'ps_checkpayment', 'bankwire' => 'bankwire', 'cheque' => 'cheque'));
+
+ Configuration::updateValue('RETAILCRM_API_DELIVERY', $delivery);
+ Configuration::updateValue('RETAILCRM_API_STATUS', $status);
+ Configuration::updateValue('RETAILCRM_API_PAYMENT', $payment);
+ }
+}
diff --git a/tests/helpers/RetailcrmTestHelper.php b/tests/helpers/RetailcrmTestHelper.php
new file mode 100644
index 0000000..58e2172
--- /dev/null
+++ b/tests/helpers/RetailcrmTestHelper.php
@@ -0,0 +1,26 @@
+order_reference = $order_reference;
+ $orderPayment->id_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT');
+ $orderPayment->conversion_rate = 1.000000;
+ $orderPayment->amount = 100;
+ $orderPayment->payment_method = 'Bank wire';
+ $orderPayment->date_add = date('Y-m-d H:i:s');
+
+ $orderPayment->save();
+
+ return $orderPayment;
+ }
+
+ public static function deleteOrderPayment($id)
+ {
+ $orderPayment = new OrderPayment($id);
+
+ return $orderPayment->delete();
+ }
+}
diff --git a/tests/phpunit/RetailcrmReferencesTest.php b/tests/phpunit/RetailcrmReferencesTest.php
new file mode 100644
index 0000000..64acd5c
--- /dev/null
+++ b/tests/phpunit/RetailcrmReferencesTest.php
@@ -0,0 +1,43 @@
+createMock('RetailcrmProxy');
+ $this->retailcrmReferences = new RetailcrmReferences($apiMock);
+ $this->retailcrmReferences->getSystemPaymentModules(false);
+ }
+
+ public function testCarriers()
+ {
+ $this->assertInternalType('array', $this->retailcrmReferences->carriers);
+ $this->assertNotEmpty($this->retailcrmReferences->carriers);
+ $this->assertArrayHasKey('name', $this->retailcrmReferences->carriers[0]);
+ $this->assertArrayHasKey('id_carrier', $this->retailcrmReferences->carriers[0]);
+ }
+
+ public function testGetSystemPaymentModules()
+ {
+ $this->assertInternalType('array', $this->retailcrmReferences->payment_modules);
+
+ if (version_compare(_PS_VERSION_, '1.7', '>')) {
+ $this->assertNotEmpty($this->retailcrmReferences->payment_modules);
+ $this->assertArrayHasKey('name', $this->retailcrmReferences->payment_modules[0]);
+ $this->assertArrayHasKey('code', $this->retailcrmReferences->payment_modules[0]);
+ $this->assertArrayHasKey('id', $this->retailcrmReferences->payment_modules[0]);
+ }
+ }
+
+ public function testGetStatuses()
+ {
+ $statuses = $this->retailcrmReferences->getStatuses();
+
+ $this->assertInternalType('array', $statuses);
+ $this->assertNotEmpty($statuses);
+ }
+}
diff --git a/tests/phpunit/RetailcrmTest.php b/tests/phpunit/RetailcrmTest.php
new file mode 100644
index 0000000..8bd3dba
--- /dev/null
+++ b/tests/phpunit/RetailcrmTest.php
@@ -0,0 +1,281 @@
+setConfig();
+
+ $this->apiMock = $this->getMockBuilder('RetailcrmProxy')
+ ->disableOriginalConstructor()
+ ->setMethods(
+ array(
+ 'customersCreate',
+ 'customersEdit',
+ 'customersGet',
+ 'ordersCreate',
+ 'ordersEdit',
+ 'ordersGet',
+ 'ordersPaymentEdit',
+ 'ordersPaymentCreate'
+ )
+ )
+ ->getMock();
+
+ $this->retailcrmModule = new RetailCRM();
+ $this->retailcrmModule->api = $this->apiMock;
+ }
+
+ public function testHookActionCustomerAccountAdd()
+ {
+ $newCustomer = new Customer(1);
+ $params = array('newCustomer' => $newCustomer);
+ $customer = $this->retailcrmModule->hookActionCustomerAccountAdd($params);
+
+ $this->assertNotEmpty($customer);
+ $this->assertArrayHasKey('externalId', $customer);
+ $this->assertArrayHasKey('firstName', $customer);
+ $this->assertArrayHasKey('lastName', $customer);
+ $this->assertArrayHasKey('email', $customer);
+ $this->assertArrayHasKey('createdAt', $customer);
+ }
+
+ public function testHookActionCustomerAccountUpdate()
+ {
+ $customer = new Customer(1);
+ $params = array('customer' => $customer);
+ $customer = $this->retailcrmModule->hookActionCustomerAccountUpdate($params);
+
+ $this->assertNotEmpty($customer);
+ $this->assertArrayHasKey('externalId', $customer);
+ $this->assertArrayHasKey('firstName', $customer);
+ $this->assertArrayHasKey('lastName', $customer);
+ $this->assertArrayHasKey('email', $customer);
+ $this->assertArrayHasKey('birthday', $customer);
+ }
+
+ public function testHookActionOrderEdited()
+ {
+ $order = new Order(1);
+ $customer = new Customer($order->id_customer);
+ $params = array('order' => $order, 'customer' => $customer);
+
+ $orderSend = $this->retailcrmModule->hookActionOrderEdited($params);
+
+ $this->assertNotNull($orderSend);
+ $this->assertArrayHasKey('externalId', $orderSend);
+ $this->assertArrayHasKey('firstName', $orderSend);
+ $this->assertArrayHasKey('lastName', $orderSend);
+ $this->assertArrayHasKey('email', $orderSend);
+ $this->assertArrayHasKey('delivery', $orderSend);
+ $this->assertArrayHasKey('items', $orderSend);
+ }
+
+ /**
+ * @param $newOrder
+ * @param $apiVersion
+ * @dataProvider dataProvider
+ */
+ public function testHookActionOrderStatusPostUpdate($newOrder, $apiVersion)
+ {
+ $this->retailcrmModule->apiVersion = $apiVersion;
+ $order = new Order(1);
+ $customer = new Customer($order->id_customer);
+ $cart = $this->createMock('Cart');
+ $cart->expects($this->any())->method('getProducts')->willReturn($this->getProducts());
+ $cart->expects($this->any())->method('getAddressCollection')->willReturn($this->getAddressCollection());
+ $status = new StdClass();
+
+ if ($newOrder === false) {
+ $status->id = 'completed';
+
+ $params = array(
+ 'newOrderStatus' => $status,
+ 'id_order' => $order->id
+ );
+ } else {
+ $status->id = 'new';
+
+ $params = array(
+ 'orderStatus' => $status,
+ 'customer' => $customer,
+ 'order' => $order,
+ 'cart' => $cart,
+ );
+ }
+
+ $result = $this->retailcrmModule->hookActionOrderStatusPostUpdate($params);
+
+ if ($newOrder === false) {
+ $this->assertEquals('completed', $result);
+ } else {
+ $this->assertArrayHasKey('status', $result);
+ $this->assertArrayHasKey('externalId', $result);
+ $this->assertArrayHasKey('firstName', $result);
+ $this->assertArrayHasKey('lastName', $result);
+ $this->assertArrayHasKey('email', $result);
+ $this->assertArrayHasKey('delivery', $result);
+ $this->assertArrayHasKey('items', $result);
+ $this->assertArrayHasKey('customer', $result);
+ $this->assertArrayHasKey('externalId', $result['customer']);
+
+ if ($apiVersion == 5) {
+ $this->assertArrayHasKey('payments', $result);
+ $this->assertInternalType('array', $result['payments']);
+ } else {
+ $this->assertArrayHasKey('paymentType', $result);
+ }
+ }
+ }
+
+ /**
+ * @param $ordersGet
+ * @dataProvider ordersGetDataProvider
+ */
+ public function testHookActionPaymentCCAdd($ordersGet)
+ {
+ $order = new Order(1);
+
+ $orderPayment = RetailcrmTestHelper::createOrderPayment($order->reference);
+ $cart = new Cart($order->id_cart);
+
+ $params = array(
+ 'paymentCC' => $orderPayment,
+ 'cart' => $cart
+ );
+
+ $referenceMock = $this->createMock('RetailcrmReferences');
+ $referenceMock->expects($this->once())->method('getSystemPaymentModules')->willReturn($this->getSystemPaymentModules());
+ $this->retailcrmModule->reference = $referenceMock;
+ $this->apiMock->expects($this->any())->method('ordersGet')->willReturn($ordersGet);
+
+ $result = $this->retailcrmModule->hookActionPaymentCCAdd($params);
+
+ $this->assertInternalType('array', $result);
+ $this->assertArrayHasKey('type', $result);
+ $this->assertArrayHasKey('amount', $result);
+
+ RetailcrmTestHelper::deleteOrderPayment($orderPayment->id);
+ }
+
+ /**
+ * @return array
+ */
+ public function dataProvider()
+ {
+ return array(
+ array(
+ 'newOrder' => true,
+ 'apiVersion' => 4
+ ),
+ array(
+ 'newOrder' => false,
+ 'apiVersion' => 4
+ ),
+ array(
+ 'newOrder' => true,
+ 'apiVersion' => 5
+ ),
+ array(
+ 'newOrder' => false,
+ 'apiVersion' => 5
+ )
+ );
+ }
+
+ /**
+ * @return array
+ */
+ public function ordersGetDataProvider()
+ {
+ return array(
+ array(
+ 'ordersGet' => array(
+ 'success' => true,
+ 'order' => array(
+ 'payments' => array(
+ array(
+ 'type' => 'bankwire'
+ )
+ ),
+ 'totalSumm' => 1500
+ )
+ )
+ ),
+ array(
+ 'ordersGet' => array(
+ 'success' => true,
+ 'order' => array(
+ 'payments' => array(
+ array(
+ 'type' => 'cheque'
+ )
+ ),
+ 'totalSumm' => 1500
+ )
+ )
+ )
+ );
+ }
+
+ /**
+ * @return array
+ */
+ private function getProducts()
+ {
+ return array(
+ array(
+ 'id_product_attribute' => 1,
+ 'id_product' => 1,
+ 'attributes' => '',
+ 'rate' => 1,
+ 'price' => 100,
+ 'name' => 'Test product 1',
+ 'quantity' => 2
+ ),
+ array(
+ 'id_product_attribute' => 1,
+ 'id_product' => 2,
+ 'attributes' => '',
+ 'rate' => 1,
+ 'price' => 100,
+ 'name' => 'Test product 2',
+ 'quantity' => 1
+ )
+ );
+ }
+
+ /**
+ * @return array
+ */
+ private function getAddressCollection()
+ {
+ $address = new Address(1);
+
+ return array($address);
+ }
+
+ /**
+ * @return array
+ */
+ private function getSystemPaymentModules()
+ {
+ return array (
+ array (
+ 'id' => '3',
+ 'code' => 'bankwire',
+ 'name' => 'Bank wire',
+ ),
+ array (
+ 'id' => '30',
+ 'code' => 'cheque',
+ 'name' => 'Payment by check',
+ )
+ );
+ }
+}
diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php
new file mode 100644
index 0000000..8cf5da5
--- /dev/null
+++ b/tests/phpunit/bootstrap.php
@@ -0,0 +1,12 @@
+install();