From 231e26f81e25d1114b4e92a8143be9880ebd3a14 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Wed, 23 Nov 2016 05:13:25 +0530 Subject: [PATCH] CRM-19677: Mailings fail in Multilingual post 4.7.13 --- CRM/Core/DAO/AllCoreTables.php | 5 ++ tests/phpunit/api/v3/MultilingualTest.php | 71 +++++++++++++++++++---- 2 files changed, 65 insertions(+), 11 deletions(-) diff --git a/CRM/Core/DAO/AllCoreTables.php b/CRM/Core/DAO/AllCoreTables.php index 2fced2a763..0ce9bb94fa 100644 --- a/CRM/Core/DAO/AllCoreTables.php +++ b/CRM/Core/DAO/AllCoreTables.php @@ -141,6 +141,11 @@ class CRM_Core_DAO_AllCoreTables { } public static function getClassForTable($tableName) { + //CRM-19677: on multilingual setup, trim locale from $tableName to fetch class name + if (CRM_Core_I18n::isMultilingual()) { + global $dbLocale; + $tableName = str_replace($dbLocale, '', $tableName); + } return CRM_Utils_Array::value($tableName, self::tables()); } diff --git a/tests/phpunit/api/v3/MultilingualTest.php b/tests/phpunit/api/v3/MultilingualTest.php index 5b2a4d86ba..6318c811a5 100644 --- a/tests/phpunit/api/v3/MultilingualTest.php +++ b/tests/phpunit/api/v3/MultilingualTest.php @@ -51,17 +51,7 @@ class api_v3_MultilingualTest extends CiviUnitTestCase { } public function testOptionLanguage() { - $this->callAPISuccess('Setting', 'create', array( - 'lcMessages' => 'en_US', - 'languageLimit' => array( - 'en_US' => 1, - ), - )); - - CRM_Core_I18n_Schema::makeMultilingual('en_US'); - - global $dbLocale; - $dbLocale = '_en_US'; + $this->enableMultilingual(); CRM_Core_I18n_Schema::addLocale('fr_CA', 'en_US'); @@ -106,4 +96,63 @@ class api_v3_MultilingualTest extends CiviUnitTestCase { $this->assertEquals($default['label'], $english_original['label']); } + /** + * CRM-19677: Ensure that entity apis are not affected on Multilingual setup + * with check_permissions = TRUE + */ + public function testAllEntities() { + $this->enableMultilingual(); + + // list of entities which has mandatory attributes + $specialEntities = array( + 'Attachment' => array('id' => 13), + 'CustomValue' => array('entity_id' => 13), + 'MailingContact' => array('contact_id' => 13), + 'Profile' => array('profile_id' => 13), + 'MailingGroup' => array('mailing_id' => 13), + ); + // deprecated or API.Get is not supported/implemented + $skippableEntities = array( + 'Logging', + 'MailingEventConfirm', + 'MailingEventResubscribe', + 'MailingEventSubscribe', + 'MailingEventUnsubscribe', + 'Location', + 'Pcp', + 'Survey', + 'UFField', // throw error for help_post column + 'UFGroup', //throw error for title + 'User', // need loggedIn user id + ); + // fetch all entities + $entities = $this->callAPISuccess('Entity', 'get', array()); + $skippableEntities = array_merge($skippableEntities, $entities['deprecated']); + + foreach ($entities['values'] as $entity) { + $params = array('check_permissions' => 1); + if (in_array($entity, $skippableEntities) && $entity != 'MailingGroup') { + continue; + } + if (array_key_exists($entity, $specialEntities)) { + $params = array_merge($params, $specialEntities[$entity]); + } + $this->callAPISuccess($entity, 'get', $params); + } + } + + public function enableMultilingual() { + $this->callAPISuccess('Setting', 'create', array( + 'lcMessages' => 'en_US', + 'languageLimit' => array( + 'en_US' => 1, + ), + )); + + CRM_Core_I18n_Schema::makeMultilingual('en_US'); + + global $dbLocale; + $dbLocale = '_en_US'; + } + } -- 2.25.1