1
0
mirror of synced 2025-01-19 09:21:43 +03:00
woocommerce-module/tests/test-wc-retailcrm-customers.php

156 lines
5.0 KiB
PHP
Raw Normal View History

<?php
class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper
{
protected $apiMock;
protected $responseMock;
protected $customer;
public function setUp()
{
$this->responseMock = $this->getMockBuilder('\WC_Retailcrm_Response')
->disableOriginalConstructor()
->setMethods(array(
'isSuccessful'
))
->getMock();
$this->apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy')
->disableOriginalConstructor()
->setMethods(array(
'ordersGet',
'ordersCreate',
'ordersEdit',
'customersGet',
'customersCreate',
'customersEdit'
))
->getMock();
2019-01-17 15:58:13 +03:00
$this->responseMock->expects($this->any())
->method('isSuccessful')
->willReturn(true);
$this->apiMock->expects($this->any())
->method('customersCreate')
->willReturn($this->responseMock);
$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');
2020-04-13 16:09:44 +03:00
$this->customer->set_billing_email($this->customer->get_email());
$this->customer->set_password('password');
$this->customer->set_billing_phone('89000000000');
2020-11-19 18:02:04 +03:00
$this->customer->set_date_created(date('Y-m-d H:i:s'));
$this->customer->save();
}
/**
* @param retailcrm
* @dataProvider dataProviderApiClient
*/
public function test_wc_customer_get($retailcrm)
{
$wc_customer = new WC_Customer($this->customer->get_id());
2019-03-20 15:51:31 +03:00
$retailcrm_customer = $this->getRetailcrmCustomer($retailcrm);
$this->assertEquals($wc_customer, $retailcrm_customer->wcCustomerGet($this->customer->get_id()));
}
/**
* @param $retailcrm
* @dataProvider dataProviderApiClient
*/
public function test_create_customer($retailcrm)
{
2019-03-20 15:51:31 +03:00
$retailcrm_customer = $this->getRetailcrmCustomer($retailcrm);
2019-01-17 15:58:13 +03:00
$id = $retailcrm_customer->createCustomer($this->customer->get_id());
$customer_send = $retailcrm_customer->getCustomer();
if ($retailcrm) {
$this->assertArrayHasKey('firstName', $customer_send);
$this->assertArrayHasKey('createdAt', $customer_send);
$this->assertArrayHasKey('email', $customer_send);
$this->assertNotEmpty($customer_send['externalId']);
2020-11-19 18:02:04 +03:00
$this->assertNotEmpty($customer_send['createdAt']);
$this->assertNotEmpty($customer_send['firstName']);
$this->assertNotEmpty($customer_send['email']);
} else {
2019-01-17 15:58:13 +03:00
$this->assertEquals(null, $id);
$this->assertEquals(array(), $customer_send);
}
}
/**
* @param $retailcrm
* @dataProvider dataProviderApiClient
*/
public function test_update_customer($retailcrm)
{
2019-03-20 15:51:31 +03:00
$retailcrm_customer = $this->getRetailcrmCustomer($retailcrm);
$customer = $retailcrm_customer->updateCustomer($this->customer->get_id());
$customer_send = $retailcrm_customer->getCustomer();
if ($retailcrm) {
$this->assertArrayHasKey('externalId', $customer_send);
$this->assertArrayHasKey('firstName', $customer_send);
$this->assertArrayHasKey('createdAt', $customer_send);
$this->assertArrayHasKey('email', $customer_send);
$this->assertNotEmpty($customer_send['externalId']);
2020-11-19 18:02:04 +03:00
$this->assertNotEmpty($customer_send['createdAt']);
$this->assertNotEmpty($customer_send['firstName']);
$this->assertNotEmpty($customer_send['email']);
$this->assertInstanceOf('WC_Customer', $customer);
} else {
$this->assertEquals(null, $customer);
$this->assertEquals(array(), $customer_send);
}
}
/**
* @param $retailcrm
*
* @dataProvider dataProviderApiClient
* @throws \Exception
*/
public function test_create_customer_empty_response($retailcrm)
{
$this->responseMock = null;
$this->apiMock = null;
$retailcrm_customer = $this->getRetailcrmCustomer($retailcrm);
$id = $retailcrm_customer->createCustomer($this->customer->get_id());
$this->assertEquals(null, $id);
}
public function dataProviderApiClient()
{
$this->setUp();
return array(
array(
'retailcrm' => $this->apiMock
),
array(
'retailcrm' => false
)
);
}
2019-03-20 15:51:31 +03:00
/**
* @param $retailcrm
*
* @return WC_Retailcrm_Customers
*/
private function getRetailcrmCustomer($retailcrm)
{
return new WC_Retailcrm_Customers(
$retailcrm,
$this->getOptions(),
new WC_Retailcrm_Customer_Address()
);
}
}