1
0
mirror of synced 2025-02-21 09:23:14 +03:00

Improvement of tests for history

This commit is contained in:
Dima Uryvskiy 2022-04-18 18:01:57 +03:00 committed by GitHub
parent c1e913d063
commit 5838dde9eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 112 additions and 80 deletions

View File

@ -401,12 +401,29 @@ if (!class_exists('WC_Retailcrm_History')) :
$billingAddress = $order['contact']['address'];
// @codeCoverageIgnoreStart
// TODO: There is a task to analyze the work set billing address in WC order
$wcOrder->set_billing_state(self::arrayValue($billingAddress, 'region'));
$wcOrder->set_billing_postcode(self::arrayValue($billingAddress, 'index'));
$wcOrder->set_billing_country(self::arrayValue($billingAddress, 'country'));
$wcOrder->set_billing_city(self::arrayValue($billingAddress, 'city'));
$wcOrder->set_billing_address_1(self::arrayValue($billingAddress, 'text'));
if (isset($billingAddress['country'])) {
$wcOrder->set_billing_country($billingAddress['country']);
}
if (isset($billingAddress['region'])) {
$wcOrder->set_billing_state($billingAddress['region']);
}
if (isset($billingAddress['index'])) {
$wcOrder->set_billing_postcode($billingAddress['index']);
}
if (isset($billingAddress['city'])) {
$wcOrder->set_billing_city($billingAddress['city']);
}
if (isset($billingAddress['street'])) {
$wcOrder->set_shipping_address_1($billingAddress['street']);
}
if (isset($billingAddress['building'])) {
$wcOrder->set_shipping_address_2($billingAddress['building']);
}
// @codeCoverageIgnoreEnd
}
}
@ -495,6 +512,10 @@ if (!class_exists('WC_Retailcrm_History')) :
$wcOrder->set_shipping_state($shippingAddress['region']);
}
if (isset($shippingAddress['index'])) {
$wcOrder->set_shipping_postcode($shippingAddress['index']);
}
if (isset($shippingAddress['city'])) {
$wcOrder->set_shipping_city($shippingAddress['city']);
}
@ -721,31 +742,31 @@ if (!class_exists('WC_Retailcrm_History')) :
$companyName = $customer['mainCompany']['name'];
}
$addressShipping = array(
'first_name' => isset($order['firstName']) ? $order['firstName'] : '',
'last_name' => isset($order['lastName']) ? $order['lastName'] : '',
$addressShipping = [
'first_name' => $order['firstName'] ?? '',
'last_name' => $order['lastName'] ?? '',
'company' => '',
'address_1' => isset($order['delivery']['address']['text']) ? $order['delivery']['address']['text'] : '',
'address_1' => $order['delivery']['address']['text'] ?? '',
'address_2' => '',
'city' => isset($order['delivery']['address']['city']) ? $order['delivery']['address']['city'] : '',
'state' => isset($order['delivery']['address']['region']) ? $order['delivery']['address']['region'] : '',
'postcode' => isset($order['delivery']['address']['index']) ? $order['delivery']['address']['index'] : '',
'country' => isset($order['delivery']['address']['countryIso']) ? $order['delivery']['address']['countryIso'] : ''
);
'city' => $order['delivery']['address']['city'] ?? '',
'state' => $order['delivery']['address']['region'] ?? '',
'postcode' => $order['delivery']['address']['index'] ?? '',
'country' => $order['delivery']['address']['countryIso'] ?? ''
];
$addressBilling = array(
'first_name' => isset($contactOrCustomer['firstName']) ? $contactOrCustomer['firstName'] : '',
'last_name' => isset($contactOrCustomer['lastName']) ? $contactOrCustomer['lastName'] : '',
$addressBilling = [
'first_name' => $contactOrCustomer['firstName'] ?? '',
'last_name' => $contactOrCustomer['lastName'] ?? '',
'company' => $companyName,
'email' => isset($contactOrCustomer['email']) ? $contactOrCustomer['email'] : '',
'phone' => isset($contactOrCustomer['phones'][0]['number']) ? $contactOrCustomer['phones'][0]['number'] : '',
'address_1' => isset($billingAddress['text']) ? $billingAddress['text'] : '',
'email' => $contactOrCustomer['email'] ?? '',
'phone' => $contactOrCustomer['phones'][0]['number'] ?? '',
'address_1' => $billingAddress['text'] ?? '',
'address_2' => '',
'city' => isset($billingAddress['city']) ? $billingAddress['city'] : '',
'state' => isset($billingAddress['region']) ? $billingAddress['region'] : '',
'postcode' => isset($billingAddress['index']) ? $billingAddress['index'] : '',
'country' => isset($billingAddress['countryIso']) ? $billingAddress['countryIso'] : ''
);
'city' => $billingAddress['city'] ?? '',
'state' => $billingAddress['region'] ?? '',
'postcode' => $billingAddress['index'] ?? '',
'country' => $billingAddress['countryIso'] ?? ''
];
if (isset($order['payments']) && $order['payments']) {
$payment = WC_Payment_Gateways::instance();

View File

@ -55,7 +55,6 @@ class DataHistoryRetailCrm
'totalSumm' => 0,
'averageSumm' => 0,
'ordersCount' => 0,
'customFields' => [],
'personalDiscount' => 0,
'cumulativeDiscount' => 0,
'address' => [
@ -64,11 +63,12 @@ class DataHistoryRetailCrm
'countryIso' => 'ES',
'region' => 'Region',
'city' => 'City',
'text' => 'street Test 777',
'text' => 'Street',
],
'customFields' => ['crm_customer' => 'test_customer'],
'segments' => [],
'firstName' => 'Test_Name',
'lastName' => 'Test',
'lastName' => 'Test_LastName',
'email' => 'mail_test@mail.es',
'phones' => [ '0' => [ 'number' => '+79184563200' ] ],
'birthday' => '2021-10-01'
@ -116,17 +116,18 @@ class DataHistoryRetailCrm
'prepaySum' => 0,
'purchaseSumm' => 50,
'markDatetime' => '2018-01-01 00:00:00',
'firstName' => 'Test',
'lastName' => 'Test',
'firstName' => 'Test_Name',
'lastName' => 'Test_LastName',
'phone' => '80000000000',
'call' => false,
'expired' => false,
'customFields' => ['crm_order' => 'test_order'],
'customer' => [
'type' => 'customer',
'segments' => [],
'id' => 1,
'firstName' => 'Test',
'lastName' => 'Test',
'firstName' => 'Test_Name',
'lastName' => 'Test_LastName',
'email' => 'email@test.ru',
'phones' => [
[
@ -137,11 +138,11 @@ class DataHistoryRetailCrm
]
],
'address' => [
'index' => '111111',
'countryIso' => 'RU',
'region' => 'Test region',
'city' => 'Test',
'text' => 'Test text address'
'index' => 123456,
'countryIso' => 'ES',
'region' => 'Region',
'city' => 'City',
'text' => 'Street'
],
'createdAt' => '2018-01-01 00:00:00',
'managerId' => 1,
@ -158,20 +159,17 @@ class DataHistoryRetailCrm
'averageSumm' => 15387.25,
'ordersCount' => 4,
'costSumm' => 101,
'customFields' => [
'custom' => 'test'
]
],
'contragent' => [],
'delivery' => [
'cost' => 0,
'netCost' => 0,
'address' => [
'index' => '111111',
'countryIso' => 'RU',
'region' => 'Test region',
'city' => 'Test',
'text' => 'Test text address'
'index' => 123456,
'countryIso' => 'ES',
'region' => 'Region',
'city' => 'City',
'text' => 'Street'
]
],
'site' => 'test-com',
@ -217,7 +215,6 @@ class DataHistoryRetailCrm
'height' => 0,
'shipmentStore' => 'main',
'shipped' => false,
'customFields' => [],
'uploadedToExternalStoreSystem' => false
]
]
@ -263,8 +260,8 @@ class DataHistoryRetailCrm
'prepaySum' => 0,
'purchaseSumm' => 50,
'markDatetime' => '2018-01-01 00:00:00',
'firstName' => 'Test',
'lastName' => 'Test',
'firstName' => 'Test_Name',
'lastName' => 'Test_LastName',
'phone' => '80000000000',
'call' => false,
'expired' => false,
@ -272,8 +269,8 @@ class DataHistoryRetailCrm
'type' => 'customer',
'segments' => [],
'id' => 1,
'firstName' => 'Test',
'lastName' => 'Test',
'firstName' => 'Test_Name',
'lastName' => 'Test_LastName',
'email' => 'email@test.ru',
'phones' => [
[
@ -284,11 +281,11 @@ class DataHistoryRetailCrm
]
],
'address' => [
'index' => '111111',
'countryIso' => 'RU',
'region' => 'Test region',
'city' => 'Test',
'text' => 'Test text address'
'index' => 123456,
'countryIso' => 'ES',
'region' => 'Region',
'city' => 'City',
'text' => 'Street'
],
'createdAt' => '2018-01-01 00:00:00',
'managerId' => 1,
@ -305,20 +302,17 @@ class DataHistoryRetailCrm
'averageSumm' => 15387.25,
'ordersCount' => 4,
'costSumm' => 101,
'customFields' => [
'custom' => 'test'
]
],
'contragent' => [],
'delivery' => [
'cost' => 0,
'netCost' => 0,
'address' => [
'index' => '111111',
'countryIso' => 'RU',
'region' => 'Test region',
'city' => 'Test',
'text' => 'Test text address'
'index' => 123456,
'countryIso' => 'ES',
'region' => 'Region',
'city' => 'City',
'text' => 'Street'
]
],
'site' => 'test-com',
@ -385,7 +379,6 @@ class DataHistoryRetailCrm
'height' => 0,
'shipmentStore' => 'main',
'shipped' => false,
'customFields' => [],
'uploadedToExternalStoreSystem' => false
]
],
@ -712,7 +705,6 @@ class DataHistoryRetailCrm
'averageSumm' => 9412,
'ordersCount' => 1,
'costSumm' => 0,
'customFields' => [],
'personalDiscount' => 0,
'cumulativeDiscount' => 0,
'address' => [
@ -745,7 +737,6 @@ class DataHistoryRetailCrm
'averageSumm' => 9412,
'ordersCount' => 1,
'costSumm' => 0,
'customFields' => [],
'personalDiscount' => 0,
'cumulativeDiscount' => 0,
'address' => [

View File

@ -59,8 +59,8 @@ class WC_Retailcrm_Test_Case_Helper extends WC_Unit_Test_Case
'update_number' => 'yes',
'debug_mode' => 'yes',
'debug-info' => '',
'order-meta-data-retailcrm' => json_encode(['woo_order' => 'woo_order_test']),
'customer-meta-data-retailcrm' => json_encode(['woo_customer' => 'woo_customer_test']),
'order-meta-data-retailcrm' => json_encode(['woo_order' => 'crm_order']),
'customer-meta-data-retailcrm' => json_encode(['woo_customer' => 'crm_customer']),
];
update_option(WC_Retailcrm_Base::$option_key, $options);

View File

@ -113,7 +113,7 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertNotEmpty($customer['email']);
$this->assertEquals($customer['firstName'], $this->customer->get_first_name());
$this->assertEquals($customer['email'], $this->customer->get_email());
$this->assertEquals($customer['customFields']['woo_customer_test'], 'test_custom_fields');
$this->assertEquals($customer['customFields']['crm_customer'], 'test_custom_fields');
} else {
$this->assertEquals(null, $id);
$this->assertEquals([], $customer);
@ -146,7 +146,7 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertNotEmpty($customer['email']);
$this->assertEquals($customer['firstName'], $this->customer->get_first_name());
$this->assertEquals($customer['email'], $this->customer->get_email());
$this->assertEquals($customer['customFields']['woo_customer_test'], 'test_custom_fields');
$this->assertEquals($customer['customFields']['crm_customer'], 'test_custom_fields');
} else {
$this->assertEquals(null, $id);
$this->assertEquals([], $customer);
@ -196,7 +196,7 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertNotEmpty($customer['createdAt']);
$this->assertNotEmpty($customer['firstName']);
$this->assertNotEmpty($customer['email']);
$this->assertEquals($customer['customFields']['woo_customer_test'], 'test_custom_fields');
$this->assertEquals($customer['customFields']['crm_customer'], 'test_custom_fields');
} else {
$this->assertEquals(null, $wcCustomer);
$this->assertEquals([], $customer);
@ -225,7 +225,7 @@ class WC_Retailcrm_Customers_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertNotEmpty($customer['createdAt']);
$this->assertNotEmpty($customer['firstName']);
$this->assertNotEmpty($customer['email']);
$this->assertEquals($customer['customFields']['woo_customer_test'], 'test_custom_fields');
$this->assertEquals($customer['customFields']['crm_customer'], 'test_custom_fields');
} else {
$this->assertEquals(null, $wcCustomer);
$this->assertEquals([], $customer);

View File

@ -40,7 +40,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
$retailcrm_history = new WC_Retailcrm_History($this->apiMock);
$retailcrm_history->getHistory();
$orders = wc_get_orders(array('numberposts' => -1));
$orders = wc_get_orders(['numberposts' => -1]);
$wcOrder = end($orders);
if (!$wcOrder) {
@ -58,9 +58,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
if (is_object($order_added_item)) {
$this->assertEquals($product->get_id(), $order_added_item->get_product()->get_id());
}
$this->assertNotEmpty($wcOrder->get_date_created());
$this->assertEquals("2018-01-01 00:00:00", $order['history'][0]['createdAt']);
$this->assertNotEmpty($shipping_address['first_name']);
$this->assertNotEmpty($shipping_address['last_name']);
$this->assertNotEmpty($shipping_address['postcode']);
@ -68,6 +66,15 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertNotEmpty($shipping_address['country']);
$this->assertNotEmpty($shipping_address['state']);
$this->assertEquals('Test_Name', $shipping_address['first_name']);
$this->assertEquals('Test_LastName', $shipping_address['last_name']);
$this->assertEquals('City', $shipping_address['city']);
$this->assertEquals('Region', $shipping_address['state']);
$this->assertEquals('ES', $shipping_address['country']);
$this->assertEquals(123456, $shipping_address['postcode']);
$this->assertEquals('Street', $shipping_address['address_1']);
if (isset($billing_address['phone'])) {
$this->assertNotEmpty($billing_address['phone']);
}
@ -83,6 +90,14 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertNotEmpty($billing_address['country']);
$this->assertNotEmpty($billing_address['state']);
$this->assertEquals('Test_Name', $billing_address['first_name']);
$this->assertEquals('Test_LastName', $billing_address['last_name']);
$this->assertEquals('City', $billing_address['city']);
$this->assertEquals('Region', $billing_address['state']);
$this->assertEquals('ES', $billing_address['country']);
$this->assertEquals(123456, $billing_address['postcode']);
$this->assertEquals('Street', $billing_address['address_1']);
if ($wcOrder->get_payment_method()) {
$this->assertEquals('payment4', $options[$wcOrder->get_payment_method()]);
}
@ -144,7 +159,6 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
}
$this->assertNotEmpty($order_added->get_date_created());
$this->assertEquals("2018-01-01 00:00:00", $order['history'][0]['createdAt']);
$this->assertNotEmpty($shipping_address['first_name']);
$this->assertNotEmpty($shipping_address['last_name']);
$this->assertNotEmpty($shipping_address['postcode']);
@ -223,7 +237,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertEquals('tester001@example.com', $order_updated->get_billing_email());
//Check order note
$notes = wc_get_order_notes(array('limit' => 100, 'order_id' => $order->get_id()));
$notes = wc_get_order_notes(['limit' => 100, 'order_id' => $order->get_id()]);
foreach ($notes as $note) {
if ($note->content === 'managerComment') {
@ -287,6 +301,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertEquals('Test_Name', $wcCustomer->get_first_name());
$this->assertEquals('City', $wcCustomer->get_billing_city());
$this->assertEquals(123456, $wcCustomer->get_billing_postcode());
$this->assertEquals('test_customer', $wcCustomer->get_meta('woo_customer'));
}
public function test_history_switch_customer_tests()
@ -731,7 +746,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
{
$mock = $this->getMockBuilder('\WC_Retailcrm_Response_Helper')
->disableOriginalConstructor()
->setMethods(array('isSuccessful'))
->setMethods(['isSuccessful'])
->getMock();
$mock->expects($this->any())

View File

@ -110,6 +110,7 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertArrayHasKey('type', $orderData['payments'][0]);
$this->assertArrayHasKey('externalId', $orderData['payments'][0]);
$this->assertEquals('payment1', $orderData['payments'][0]['type']);
$this->assertEquals($orderData['customFields']['crm_order'], 'test_custom_fields');
} else {
$this->assertEquals(null, $order);
}
@ -185,6 +186,7 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertArrayHasKey('name', $orderData['company']);
$this->assertEquals(777, $orderData['company']['id']);
$this->assertEquals($this->order->get_billing_company(), $orderData['company']['name']);
$this->assertEquals($orderData['customFields']['crm_order'], 'test_custom_fields');
} else {
$this->assertEquals(null, $order);
}
@ -239,7 +241,8 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertEquals('US', $orderData['countryIso']);
$this->assertEquals(0, $orderData['discountManualAmount']);
$this->assertEquals(0, $orderData['discountManualPercent']);
$this->assertEquals($orderData['customFields']['crm_order'], 'test_custom_fields');
if (mb_strlen($orderData['delivery']['address']['index']) === 6) {
$this->assertEquals('123456', $orderData['delivery']['address']['index']);
} else {
@ -502,6 +505,8 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
}
$this->order->save();
update_post_meta($this->order->get_id(), 'woo_order', 'test_custom_fields');
}
private function getResponseData($externalId)