3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Test class for the option.language API parameter in multilingual.
34 class api_v3_MultilingualTest
extends CiviUnitTestCase
{
35 protected $_apiversion = 3;
36 public $DBResetRequired = FALSE;
39 * Sets up the fixture, for example, opens a network connection.
41 * This method is called before a test is executed.
43 protected function setUp() {
45 $this->useTransaction(TRUE);
48 public function tearDown() {
49 CRM_Core_I18n_Schema
::makeSinglelingual('en_US');
54 * @dataProvider versionThreeAndFour
56 public function testOptionLanguage($version) {
57 $this->enableMultilingual();
58 $this->_apiversion
= $version;
60 CRM_Core_I18n_Schema
::addLocale('fr_CA', 'en_US');
62 $this->callAPISuccess('Setting', 'create', [
69 // Take a semi-random OptionGroup and test manually changing its label
70 // in one language, while making sure it stays the same in English.
71 $group = $this->callAPISuccess('OptionGroup', 'getsingle', [
72 'name' => 'contact_edit_options',
75 $english_original = $this->callAPISuccess('OptionValue', 'getsingle', [
76 'option_group_id' => $group['id'],
80 $this->callAPISuccess('OptionValue', 'create', [
81 'id' => $english_original['id'],
83 'label' => 'Messagerie instantanée',
84 'option.language' => 'fr_CA',
87 $french = $this->callAPISuccess('OptionValue', 'getsingle', [
88 'option_group_id' => $group['id'],
90 'options' => ['language' => 'fr_CA'],
93 // Ensure that after language is changed in previous call it will go back to the default.
94 $default = $this->callAPISuccess('OptionValue', 'getsingle', [
95 'option_group_id' => $group['id'],
99 $this->assertEquals($french['label'], 'Messagerie instantanée');
100 $this->assertEquals($default['label'], $english_original['label']);
104 * CRM-19677: Ensure that entity apis are not affected on Multilingual setup
105 * with check_permissions = TRUE
107 public function testAllEntities() {
108 $this->enableMultilingual();
110 // list of entities which has mandatory attributes
112 'Attachment' => ['id' => 13],
113 'CustomValue' => ['entity_id' => 13],
114 'MailingContact' => ['contact_id' => 13],
115 'Profile' => ['profile_id' => 13],
116 'MailingGroup' => ['mailing_id' => 13],
118 // deprecated or API.Get is not supported/implemented
119 $skippableEntities = [
121 'MailingEventConfirm',
122 'MailingEventResubscribe',
123 'MailingEventSubscribe',
124 'MailingEventUnsubscribe',
128 // throw error for help_post column
130 //throw error for title
132 // need loggedIn user id
135 // fetch all entities
136 $entities = $this->callAPISuccess('Entity', 'get', []);
137 $skippableEntities = array_merge($skippableEntities, $entities['deprecated']);
139 foreach ($entities['values'] as $entity) {
140 $params = ['check_permissions' => 1];
141 if (in_array($entity, $skippableEntities) && $entity != 'MailingGroup') {
144 if (array_key_exists($entity, $specialEntities)) {
145 $params = array_merge($params, $specialEntities[$entity]);
147 $this->callAPISuccess($entity, 'get', $params);