mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03:14 +03:00
Travis tests
This commit is contained in:
parent
6c0993cd03
commit
8f99d55144
48
.travis.yml
Normal file
48
.travis.yml
Normal file
@ -0,0 +1,48 @@
|
||||
language: php
|
||||
|
||||
sudo: false
|
||||
|
||||
php:
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
|
||||
env:
|
||||
global:
|
||||
- DB_USER=root
|
||||
- DB_HOST=localhost
|
||||
- DB_NAME=test_prestashop
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.3
|
||||
dist: precise
|
||||
env: BRANCH=1.6.1.x
|
||||
- php: 5.4
|
||||
env: BRANCH=1.6.1.x
|
||||
- php: 5.5
|
||||
env: BRANCH=1.6.1.x
|
||||
- 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
|
||||
- php: 7.2
|
||||
env: BRANCH=1.6.1.x
|
||||
|
||||
before_script:
|
||||
- bash tests/bin/install.sh
|
||||
|
||||
script:
|
||||
- phpunit -c phpunit.xml.dist
|
||||
|
||||
deploy:
|
||||
skip_cleanup: true
|
||||
provider: script
|
||||
script: make
|
||||
on:
|
||||
php: 7.2
|
||||
branch: master
|
||||
condition: "$DEPLOY = true"
|
14
Makefile
Normal file
14
Makefile
Normal file
@ -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)
|
33
phpunit.xml.dist
Normal file
33
phpunit.xml.dist
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit
|
||||
bootstrap="tests/phpunit/bootstrap.php"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
verbose="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Retailcrm PrestaShop Test Suite">
|
||||
<directory>tests/phpunit</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">retailcrm</directory>
|
||||
<exclude>
|
||||
<directory suffix=".php">retailcrm/translations</directory>
|
||||
<directory suffix=".php">retailcrm/job</directory>
|
||||
<file>bootstrap.php</file>
|
||||
<file>index.php</file>
|
||||
<file>logo.gif</file>
|
||||
<file>logo.png</file>
|
||||
<file>objects.xml</file>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
@ -2,6 +2,9 @@
|
||||
|
||||
class RetailcrmCatalog
|
||||
{
|
||||
public $default_lang;
|
||||
public $default_currency;
|
||||
public $default_country;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
class Service
|
||||
{
|
||||
|
||||
public static function getDate($file)
|
||||
{
|
||||
if (file_exists($file)) {
|
||||
|
@ -20,11 +20,15 @@ require_once(dirname(__FILE__) . '/bootstrap.php');
|
||||
|
||||
class RetailCRM extends Module
|
||||
{
|
||||
public $api = false;
|
||||
|
||||
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 +139,7 @@ class RetailCRM extends Module
|
||||
$this->l('Timezone settings must be identical to both of your crm and shop') .
|
||||
" <a target=\"_blank\" href=\"$address/admin/settings#t-main\">$address/admin/settings#t-main</a>"
|
||||
);
|
||||
|
||||
|
||||
$this->display(__FILE__, 'retailcrm.tpl');
|
||||
|
||||
return $output . $this->displayForm();
|
||||
@ -350,29 +354,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 +392,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 +415,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 +447,8 @@ class RetailCRM extends Module
|
||||
|
||||
$order['customer']['externalId'] = $params['order']->id_customer;
|
||||
$this->api->ordersEdit($order);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
public function hookActionOrderStatusPostUpdate($params)
|
||||
@ -443,7 +456,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 +475,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 +514,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 +539,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 +571,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 +604,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 +621,12 @@ class RetailCRM extends Module
|
||||
'status' => $orderStatus
|
||||
)
|
||||
);
|
||||
|
||||
return $orderStatus;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hookActionPaymentCCAdd($params)
|
||||
@ -620,11 +644,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 +666,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;
|
||||
}
|
||||
|
||||
|
36
tests/bin/install.sh
Normal file
36
tests/bin/install.sh
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ -z $TRAVIS_BUILD_DIR ]; then
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
PRESTASHOP_DIR=$TRAVIS_BUILD_DIR/../PrestaShop
|
||||
|
||||
create_db() {
|
||||
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"
|
||||
}
|
||||
|
||||
clone_prestashop() {
|
||||
cd ..
|
||||
git clone https://github.com/PrestaShop/PrestaShop
|
||||
cd PrestaShop
|
||||
if ! [ -z $BRANCH ]; then
|
||||
git checkout $BRANCH;
|
||||
else
|
||||
composer install;
|
||||
fi
|
||||
}
|
||||
|
||||
install_prestashop() {
|
||||
cd $PRESTASHOP_DIR
|
||||
|
||||
php install-dev/index_cli.php \
|
||||
--domain=example.com \
|
||||
--db_server=$DB_HOST \
|
||||
--db_name=$DB_NAME \
|
||||
--db_user=$DB_USER
|
||||
}
|
||||
|
||||
create_db
|
||||
clone_prestashop
|
||||
install_prestashop
|
25
tests/helpers/RetailcrmTestCase.php
Normal file
25
tests/helpers/RetailcrmTestCase.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
abstract class RetailcrmTestCase extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $contextMock;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
26
tests/helpers/RetailcrmTestHelper.php
Normal file
26
tests/helpers/RetailcrmTestHelper.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
class RetailcrmTestHelper
|
||||
{
|
||||
public static function createOrderPayment($order_reference)
|
||||
{
|
||||
$orderPayment = new OrderPayment();
|
||||
$orderPayment->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();
|
||||
}
|
||||
}
|
40
tests/phpunit/RetailcrmReferencesTest.php
Normal file
40
tests/phpunit/RetailcrmReferencesTest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
class RetailcrmReferencesTest extends RetailcrmTestCase
|
||||
{
|
||||
private $retailcrmReferences;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$apiMock = $this->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);
|
||||
$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);
|
||||
}
|
||||
}
|
281
tests/phpunit/RetailcrmTest.php
Normal file
281
tests/phpunit/RetailcrmTest.php
Normal file
@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
class RetailCRMTest extends RetailcrmTestCase
|
||||
{
|
||||
private $retailcrmModule;
|
||||
private $apiMock;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->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',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
11
tests/phpunit/bootstrap.php
Normal file
11
tests/phpunit/bootstrap.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
require_once dirname(__DIR__) . '../../../PrestaShop/tests/bootstrap.php';
|
||||
require_once dirname(__DIR__) . '../../../PrestaShop/config/config.inc.php';
|
||||
require_once dirname(__DIR__) . '../../../PrestaShop/config/defines_uri.inc.php';
|
||||
require_once dirname(__DIR__) . '../../retailcrm/bootstrap.php';
|
||||
require_once dirname(__DIR__) . '/helpers/RetailcrmTestCase.php';
|
||||
require_once dirname(__DIR__) . '/helpers/RetailcrmTestHelper.php';
|
||||
|
||||
$module = new RetailCRM();
|
||||
$module->install();
|
Loading…
x
Reference in New Issue
Block a user