From fd6ad9f64ab3dfd3076611dd833252dd41c404c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=9A=D1=83=D0=B7?= =?UTF-8?q?=D0=BD=D0=B5=D1=86=D0=BE=D0=B2?= Date: Tue, 28 Feb 2023 17:43:16 +0300 Subject: [PATCH] Fixed error for empty address and added test for the function --- src/include/class-wc-retailcrm-history.php | 5 ++--- tests/test-wc-retailcrm-history.php | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/include/class-wc-retailcrm-history.php b/src/include/class-wc-retailcrm-history.php index 767dfcb..655a3f8 100644 --- a/src/include/class-wc-retailcrm-history.php +++ b/src/include/class-wc-retailcrm-history.php @@ -1006,15 +1006,14 @@ if (!class_exists('WC_Retailcrm_History')) : /** * Returns data for address_1 and address_2(if exist data for this field) for WC order. * - * @param string $addressLine + * @param string $addressLine|null * * @return mixed */ - private function getAddressLines(string $addressLine) + public function getAddressLines(?string $addressLine = '') { if (strpos($addressLine, WC_Retailcrm_Abstracts_Address::ADDRESS_LINE_DIVIDER) !== false) { $addressLines = explode(WC_Retailcrm_Abstracts_Address::ADDRESS_LINE_DIVIDER, $addressLine); - return ['address_1' => $addressLines[0], 'address_2' => $addressLines[1]]; } diff --git a/tests/test-wc-retailcrm-history.php b/tests/test-wc-retailcrm-history.php index 89da0ab..48603bb 100644 --- a/tests/test-wc-retailcrm-history.php +++ b/tests/test-wc-retailcrm-history.php @@ -57,6 +57,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper if (is_object($orderItem)) { $this->assertEquals($product->get_id(), $orderItem->get_product()->get_id()); + $this->assertEquals($product->get_id(), $orderItem->get_product()->get_id()); } $this->assertNotEmpty($wcOrder->get_date_created()); @@ -734,7 +735,23 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper $this->assertEmpty($order->get_customer_id()); } - /** + public function test_get_address_lines() + { + $retailcrm_history = new \WC_Retailcrm_History(); + $this->assertEquals('', $retailcrm_history->getAddressLines()); + + $this->assertEquals('Test', $retailcrm_history->getAddressLines('Test')); + + $this->assertEquals( + [ + 'address_1' => 'Test', + 'address_2' => 'Test 2' + ], + $retailcrm_history->getAddressLines('Test || Test 2') + ); + } + + /** * Mock ordersGet response. * * @param bool $isSuccessful