3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test class for the option.language API parameter in multilingual.
18 class api_v3_MultilingualTest
extends CiviUnitTestCase
{
19 protected $_apiversion = 3;
20 public $DBResetRequired = FALSE;
23 * Sets up the fixture, for example, opens a network connection.
25 * This method is called before a test is executed.
27 protected function setUp() {
29 $this->useTransaction(TRUE);
32 public function tearDown() {
33 CRM_Core_I18n_Schema
::makeSinglelingual('en_US');
38 * @dataProvider versionThreeAndFour
40 public function testOptionLanguage($version) {
41 $this->enableMultilingual();
42 $this->_apiversion
= $version;
44 CRM_Core_I18n_Schema
::addLocale('fr_CA', 'en_US');
46 $this->callAPISuccess('Setting', 'create', [
53 // Take a semi-random OptionGroup and test manually changing its label
54 // in one language, while making sure it stays the same in English.
55 $group = $this->callAPISuccess('OptionGroup', 'getsingle', [
56 'name' => 'contact_edit_options',
59 $english_original = $this->callAPISuccess('OptionValue', 'getsingle', [
60 'option_group_id' => $group['id'],
64 $this->callAPISuccess('OptionValue', 'create', [
65 'id' => $english_original['id'],
67 'label' => 'Messagerie instantanée',
68 'option.language' => 'fr_CA',
71 $french = $this->callAPISuccess('OptionValue', 'getsingle', [
72 'option_group_id' => $group['id'],
74 'options' => ['language' => 'fr_CA'],
77 // Ensure that after language is changed in previous call it will go back to the default.
78 $default = $this->callAPISuccess('OptionValue', 'getsingle', [
79 'option_group_id' => $group['id'],
83 $this->assertEquals($french['label'], 'Messagerie instantanée');
84 $this->assertEquals($default['label'], $english_original['label']);
88 * CRM-19677: Ensure that entity apis are not affected on Multilingual setup
89 * with check_permissions = TRUE
91 public function testAllEntities() {
92 $this->enableMultilingual();
94 // list of entities which has mandatory attributes
96 'Attachment' => ['id' => 13],
97 'CustomValue' => ['entity_id' => 13],
98 'MailingContact' => ['contact_id' => 13],
99 'Profile' => ['profile_id' => 13],
100 'MailingGroup' => ['mailing_id' => 13],
102 // deprecated or API.Get is not supported/implemented
103 $skippableEntities = [
105 'MailingEventConfirm',
106 'MailingEventResubscribe',
107 'MailingEventSubscribe',
108 'MailingEventUnsubscribe',
112 // throw error for help_post column
114 //throw error for title
116 // need loggedIn user id
119 // fetch all entities
120 $entities = $this->callAPISuccess('Entity', 'get', []);
121 $skippableEntities = array_merge($skippableEntities, $entities['deprecated']);
123 foreach ($entities['values'] as $entity) {
124 $params = ['check_permissions' => 1];
125 if (in_array($entity, $skippableEntities) && $entity != 'MailingGroup') {
128 if (array_key_exists($entity, $specialEntities)) {
129 $params = array_merge($params, $specialEntities[$entity]);
131 $this->callAPISuccess($entity, 'get', $params);