2021-07-09 13:46:28 +03:00
|
|
|
<?php
|
2022-09-30 17:50:15 +03:00
|
|
|
|
2022-01-10 12:53:00 +03:00
|
|
|
/**
|
2022-09-30 17:50:15 +03:00
|
|
|
* PHP version 7.0
|
2022-01-10 12:53:00 +03:00
|
|
|
*
|
|
|
|
* Class WC_Retailcrm_Uploader_Test - Testing WC_Retailcrm_Uploader.
|
|
|
|
*
|
|
|
|
* @category Integration
|
|
|
|
* @author RetailCRM <integration@retailcrm.ru>
|
|
|
|
* @license http://retailcrm.ru Proprietary
|
|
|
|
* @link http://retailcrm.ru
|
|
|
|
* @see http://help.retailcrm.ru
|
|
|
|
*/
|
2021-07-09 13:46:28 +03:00
|
|
|
class WC_Retailcrm_Uploader_Test extends WC_Retailcrm_Test_Case_Helper
|
|
|
|
{
|
|
|
|
protected $apiMock;
|
|
|
|
protected $responseMock;
|
|
|
|
protected $customer;
|
2021-12-20 11:41:41 +03:00
|
|
|
private $order;
|
2021-07-09 13:46:28 +03:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->responseMock = $this->getMockBuilder('\WC_Retailcrm_Response')
|
|
|
|
->disableOriginalConstructor()
|
2021-12-20 11:41:41 +03:00
|
|
|
->setMethods(array('isSuccessful'))
|
2021-07-09 13:46:28 +03:00
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->setMethods(array(
|
|
|
|
'customersUpload',
|
|
|
|
'customersCreate',
|
|
|
|
'uploadArchiveCustomers',
|
|
|
|
'uploadArchiveOrders',
|
|
|
|
'getCountUsers',
|
2021-12-20 11:41:41 +03:00
|
|
|
'getCountOrders',
|
|
|
|
'customersGet',
|
|
|
|
'customersList',
|
|
|
|
'ordersCreate'
|
2021-07-09 13:46:28 +03:00
|
|
|
))
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
2021-12-20 11:41:41 +03:00
|
|
|
$this->setMockResponse($this->responseMock, 'isSuccessful', true);
|
|
|
|
$this->setMockResponse(
|
|
|
|
$this->apiMock,
|
|
|
|
'customersList',
|
|
|
|
array('success' => true, 'customers' => array(array('externalId' => 1)))
|
|
|
|
);
|
|
|
|
$this->setMockResponse($this->apiMock, 'customersCreate', $this->responseMock);
|
2021-07-09 13:46:28 +03:00
|
|
|
|
|
|
|
$this->customer = new WC_Customer();
|
|
|
|
$this->customer->set_first_name('Tester');
|
|
|
|
$this->customer->set_last_name('Tester');
|
|
|
|
$this->customer->set_email(uniqid(md5(date('Y-m-d H:i:s'))) . '@mail.com');
|
|
|
|
$this->customer->set_billing_email($this->customer->get_email());
|
|
|
|
$this->customer->set_password('password');
|
|
|
|
$this->customer->set_billing_phone('89000000000');
|
|
|
|
$this->customer->set_date_created(date('Y-m-d H:i:s'));
|
|
|
|
$this->customer->save();
|
|
|
|
|
2021-12-20 11:41:41 +03:00
|
|
|
$this->order = WC_Helper_Order::create_order();
|
|
|
|
}
|
2021-07-09 13:46:28 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param retailcrm
|
|
|
|
* @dataProvider dataProviderApiClient
|
|
|
|
*/
|
|
|
|
public function test_customers_upload($retailcrm)
|
|
|
|
{
|
|
|
|
$retailcrm_uploader = $this->getRetailcrmUploader($retailcrm);
|
|
|
|
$data = $retailcrm_uploader->uploadArchiveCustomers(0);
|
|
|
|
|
|
|
|
if ($retailcrm) {
|
|
|
|
$this->assertInternalType('array', $data);
|
|
|
|
$this->assertInternalType('array', $data[0]);
|
|
|
|
$this->assertArrayHasKey('externalId', $data[0]);
|
|
|
|
} else {
|
|
|
|
$this->assertEquals(null, $data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $retailcrm
|
|
|
|
* @dataProvider dataProviderApiClient
|
|
|
|
*/
|
|
|
|
public function test_order_upload($retailcrm)
|
|
|
|
{
|
|
|
|
$retailcrm_uploader = $this->getRetailcrmUploader($retailcrm);
|
|
|
|
$data = $retailcrm_uploader->uploadArchiveOrders(0);
|
|
|
|
|
2021-12-28 13:35:36 +03:00
|
|
|
$this->assertEquals(null, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $retailcrm
|
|
|
|
* @dataProvider dataProviderApiClient
|
|
|
|
*/
|
|
|
|
public function test_upload_selected_orders()
|
|
|
|
{
|
|
|
|
$_GET['order_ids_retailcrm'] = '123, 345, 456';
|
|
|
|
$retailcrm_uploader = $this->getRetailcrmUploader($this->apiMock);
|
|
|
|
$uploadSelectedOrders = $retailcrm_uploader->uploadSelectedOrders();
|
|
|
|
|
|
|
|
$this->assertEquals(null, $uploadSelectedOrders);
|
2021-07-09 13:46:28 +03:00
|
|
|
}
|
|
|
|
|
2021-12-20 11:41:41 +03:00
|
|
|
public function test_get_count_orders_upload()
|
2021-07-09 13:46:28 +03:00
|
|
|
{
|
2021-12-20 11:41:41 +03:00
|
|
|
$retailcrm_uploader = $this->getRetailcrmUploader($this->apiMock);
|
|
|
|
$count_orders = $retailcrm_uploader->getCountOrders();
|
2021-07-09 13:46:28 +03:00
|
|
|
|
2021-12-20 11:41:41 +03:00
|
|
|
$this->assertInternalType('int', $count_orders);
|
2021-07-09 13:46:28 +03:00
|
|
|
}
|
|
|
|
|
2021-12-20 11:41:41 +03:00
|
|
|
public function test_get_count_users_upload()
|
|
|
|
{
|
|
|
|
$retailcrm_uploader = $this->getRetailcrmUploader($this->apiMock);
|
|
|
|
$count_users = $retailcrm_uploader->getCountUsers();
|
|
|
|
|
|
|
|
$this->assertInternalType('int', $count_users);
|
|
|
|
}
|
2021-07-09 13:46:28 +03:00
|
|
|
|
|
|
|
public function dataProviderApiClient()
|
|
|
|
{
|
|
|
|
$this->setUp();
|
|
|
|
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'retailcrm' => $this->apiMock
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'retailcrm' => false
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $retailcrm
|
|
|
|
*
|
|
|
|
* @return WC_Retailcrm_Customers
|
|
|
|
*/
|
|
|
|
private function getRetailcrmUploader($retailcrm)
|
|
|
|
{
|
|
|
|
$customer = new WC_Retailcrm_Customers(
|
|
|
|
$retailcrm,
|
|
|
|
$this->getOptions(),
|
|
|
|
new WC_Retailcrm_Customer_Address()
|
|
|
|
);
|
|
|
|
|
|
|
|
$order = new WC_Retailcrm_Orders(
|
|
|
|
$retailcrm,
|
|
|
|
$this->getOptions(),
|
|
|
|
new WC_Retailcrm_Order_Item($this->getOptions()),
|
2021-12-20 11:41:41 +03:00
|
|
|
new WC_Retailcrm_Order_Address(),
|
|
|
|
new WC_Retailcrm_Customers($retailcrm, $this->getOptions(), new WC_Retailcrm_Customer_Address()),
|
2021-07-09 13:46:28 +03:00
|
|
|
new WC_Retailcrm_Order($this->getOptions()),
|
|
|
|
new WC_Retailcrm_Order_Payment($this->getOptions())
|
|
|
|
);
|
|
|
|
|
|
|
|
return new WC_Retailcrm_Uploader($retailcrm, $order, $customer);
|
|
|
|
}
|
|
|
|
}
|