From 828cd10c911a2d1f079a5ca2ffcaad9be28566ee Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 30 Apr 2018 21:19:00 +1000 Subject: [PATCH] Mark Accent String Tests as incomplete if on a database that is not utf8 --- CRM/Utils/SQL.php | 13 +++++++++++++ tests/phpunit/api/v3/ContactTest.php | 14 +++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CRM/Utils/SQL.php b/CRM/Utils/SQL.php index 5452bffadb..3a90ee05d1 100644 --- a/CRM/Utils/SQL.php +++ b/CRM/Utils/SQL.php @@ -122,4 +122,17 @@ class CRM_Utils_SQL { return TRUE; } + /** + * Is the Database set up to handle acceents. + * @return bool + */ + public static function supportStorageOfAccents() { + $charSetDB = CRM_Core_DAO::executeQuery("SHOW VARIABLES LIKE 'character_set_database'")->fetchAll(); + $charSet = $charSetDB[0]['Value']; + if ($charSet == 'utf8') { + return TRUE; + } + return FALSE; + } + } diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 159775aeea..e7a714b6d6 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -144,19 +144,27 @@ class api_v3_ContactTest extends CiviUnitTestCase { /** * Test for international string acceptance (CRM-10210). + * Requires the databsase to be in utf8. * * @dataProvider getInternationalStrings * * @param string $string * String to be tested. + * @param bool $checkCharSet + * Bool to see if we should check charset. * * @throws \Exception */ - public function testInternationalStrings($string) { + public function testInternationalStrings($string, $checkCharSet = FALSE) { $this->callAPISuccess('Contact', 'create', array_merge( $this->_params, array('first_name' => $string) )); + if ($checkCharSet) { + if (!CRM_Utils_SQL::supportStorageOfAccents()) { + $this->markTestIncomplete('Database is not Charset UTF8 therefore can not store accented strings properly'); + } + } $result = $this->callAPISuccessGetSingle('Contact', array('first_name' => $string)); $this->assertEquals($string, $result['first_name']); @@ -175,8 +183,8 @@ class api_v3_ContactTest extends CiviUnitTestCase { */ public function getInternationalStrings() { $invocations = array(); - $invocations[] = array('Scarabée'); - $invocations[] = array('Iñtërnâtiônàlizætiøn'); + $invocations[] = array('Scarabée', TRUE); + $invocations[] = array('Iñtërnâtiônàlizætiøn', TRUE); $invocations[] = array('これは日本語のテキストです。読めますか'); $invocations[] = array('देखें हिन्दी कैसी नजर आती है। अरे वाह ये तो नजर आती है।'); return $invocations; -- 2.25.1