opencart-module/tests/admin/ModelRetailcrmOrderAdminTest.php

76 lines
2.6 KiB
PHP
Raw Normal View History

2018-06-13 16:13:08 +03:00
<?php
2020-02-19 21:50:16 +03:00
require_once __DIR__ . '/../' . getenv('TEST_SUITE') . '/TestCase.php';
2020-02-19 12:37:03 +03:00
class ModelRetailcrmOrderAdminTest extends TestCase
2018-06-13 16:13:08 +03:00
{
private $orderModel;
private $apiClientMock;
private $settingModel;
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(
'ordersUpload',
'customersList',
'ordersCreate',
2018-08-03 11:54:56 +03:00
'ordersPaymentCreate',
'customersCreate'
2018-06-13 16:13:08 +03:00
))
->getMock();
self::$registry->set(\RetailcrmProxy::class, $this->apiClientMock);
$this->orderModel = $this->loadModel('extension/retailcrm/order');
2018-06-13 16:13:08 +03:00
$this->settingModel = $this->loadModel('setting/setting');
2018-06-13 16:13:08 +03:00
}
public function testUploadToCrm()
{
$saleOrderModel = $this->loadModel('sale/order');
$orders = $saleOrderModel->getOrders();
$fullOrders = array();
foreach ($orders as $order) {
$fullOrder = $saleOrderModel->getOrder($order['order_id']);
$fullOrder['totals'] = $saleOrderModel->getOrderTotals($order['order_id']);
2018-06-13 16:13:08 +03:00
$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);
2018-06-13 16:13:08 +03:00
$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']);
}
}