Merge pull request #11735 from mukeshcompucorp/CRM-21814-add-proper-container-to...
[civicrm-core.git] / tests / phpunit / api / v3 / MultilingualTest.php
index 5b2a4d86baddb0b4f3fd0cbe9dc2c0ced8722277..7d92691854014867619c117f0d50bf2007c107a0 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2016                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -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';
+  }
+
 }