From a83e8a28c95986d1fdf56f66a190091dec66b9e9 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 16 Oct 2016 12:44:04 +1100 Subject: [PATCH] CRM-19463 Proper fix to get E2E tests passing ensure that arrays are utf-8 encoded --- CRM/Utils/Array.php | 12 ++++++++++++ CRM/Utils/SoapServer.php | 27 ++++++++++++++++++--------- tests/phpunit/E2E/Extern/SoapTest.php | 4 ++-- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/CRM/Utils/Array.php b/CRM/Utils/Array.php index 64d7c14410..75b5b4c354 100644 --- a/CRM/Utils/Array.php +++ b/CRM/Utils/Array.php @@ -1076,4 +1076,16 @@ class CRM_Utils_Array { return $input; } + public static function encode_items($array) { + foreach ($array as $key => $value) { + if (is_array($value)) { + $array[$key] = self::encode_items($value); + } + else { + $array[$key] = mb_convert_encoding($value, 'Windows-1252', 'UTF-8'); + } + } + return $array; + } + } diff --git a/CRM/Utils/SoapServer.php b/CRM/Utils/SoapServer.php index 0aaa56e677..95fe15d942 100644 --- a/CRM/Utils/SoapServer.php +++ b/CRM/Utils/SoapServer.php @@ -157,7 +157,8 @@ class CRM_Utils_SoapServer { 'body' => $body, 'version' => 3, ); - return civicrm_api('Mailing', 'event_bounce', $params); + $result = civicrm_api('Mailing', 'event_bounce', $params); + return CRM_Utils_Array::encode_items($result); } /** @@ -181,7 +182,8 @@ class CRM_Utils_SoapServer { 'hash' => $hash, 'version' => 3, ); - return civicrm_api('MailingGroup', 'event_unsubscribe', $params); + $result = civicrm_api('MailingGroup', 'event_unsubscribe', $params); + return CRM_Utils_Array::encode_items($result); } /** @@ -203,7 +205,8 @@ class CRM_Utils_SoapServer { 'hash' => $hash, 'version' => 3, ); - return civicrm_api('MailingGroup', 'event_domain_unsubscribe', $params); + $result = civicrm_api('MailingGroup', 'event_domain_unsubscribe', $params); + return CRM_Utils_Array::encode_items($result); } /** @@ -225,7 +228,8 @@ class CRM_Utils_SoapServer { 'hash' => $hash, 'version' => 3, ); - return civicrm_api('MailingGroup', 'event_resubscribe', $params); + $result = civicrm_api('MailingGroup', 'event_resubscribe', $params); + return CRM_Utils_Array::encode_items($result); } /** @@ -244,7 +248,8 @@ class CRM_Utils_SoapServer { 'group_id' => $group, 'version' => 3, ); - return civicrm_api('MailingGroup', 'event_subscribe', $params); + $result = civicrm_api('MailingGroup', 'event_subscribe', $params); + return CRM_Utils_Array::encode_items($result); } /** @@ -266,7 +271,8 @@ class CRM_Utils_SoapServer { 'hash' => $hash, 'version' => 3, ); - return civicrm_api('Mailing', 'event_confirm', $params); + $result = civicrm_api('Mailing', 'event_confirm', $params); + return CRM_Utils_Array::encode_items($result); } /** @@ -295,7 +301,8 @@ class CRM_Utils_SoapServer { 'time_stamp' => date('YmdHis'), 'version' => 3, ); - return civicrm_api('Mailing', 'event_reply', $params); + $result = civicrm_api('Mailing', 'event_reply', $params); + return CRM_Utils_Array::encode_items($result); } /** @@ -317,7 +324,8 @@ class CRM_Utils_SoapServer { 'email' => $email, 'version' => 3, ); - return civicrm_api('Mailing', 'event_forward', $params); + $result = civicrm_api('Mailing', 'event_forward', $params); + return CRM_Utils_Array::encode_items($result); } /** @@ -330,7 +338,8 @@ class CRM_Utils_SoapServer { public function get_contact($key, $params) { $this->verify($key); $params['version'] = 3; - return json_encode(civicrm_api('contact', 'get', $params)); + $result = civicrm_api('contact', 'get', $params); + return CRM_Utils_Array::encode_items($result); } } diff --git a/tests/phpunit/E2E/Extern/SoapTest.php b/tests/phpunit/E2E/Extern/SoapTest.php index e98a39653d..3abc49e88f 100644 --- a/tests/phpunit/E2E/Extern/SoapTest.php +++ b/tests/phpunit/E2E/Extern/SoapTest.php @@ -77,10 +77,10 @@ class E2E_Extern_SoapTest extends CiviEndToEndTestCase { public function testGetContact() { $client = $this->createClient(); $key = $client->authenticate($this->adminUser, $this->adminPass); - $contacts = json_decode($client->get_contact($key, array( + $contacts = $client->get_contact($key, array( 'contact_id' => 101, 'return.display_name' => 1, - )), TRUE); + )); $this->assertEquals($contacts['is_error'], 0); $this->assertEquals($contacts['count'], 1); $this->assertEquals($contacts['values'][101]['contact_id'], 101); -- 2.25.1