Commit | Line | Data |
---|---|---|
0ac69d82 ML |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.7 | | |
5 | +--------------------------------------------------------------------+ | |
15a4309a | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
0ac69d82 ML |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * Test class for the option.language API parameter in multilingual. | |
30 | * | |
31 | * @package CiviCRM | |
32 | * @group headless | |
33 | */ | |
34 | class api_v3_MultilingualTest extends CiviUnitTestCase { | |
35 | protected $_apiversion = 3; | |
36 | public $DBResetRequired = FALSE; | |
37 | ||
38 | /** | |
39 | * Sets up the fixture, for example, opens a network connection. | |
40 | * | |
41 | * This method is called before a test is executed. | |
42 | */ | |
43 | protected function setUp() { | |
44 | parent::setUp(); | |
45 | $this->useTransaction(TRUE); | |
46 | } | |
47 | ||
48 | public function tearDown() { | |
49 | CRM_Core_I18n_Schema::makeSinglelingual('en_US'); | |
50 | parent::tearDown(); | |
51 | } | |
52 | ||
53 | public function testOptionLanguage() { | |
3a575348 | 54 | $this->enableMultilingual(); |
0ac69d82 ML |
55 | |
56 | CRM_Core_I18n_Schema::addLocale('fr_CA', 'en_US'); | |
57 | ||
45a47559 | 58 | $this->callAPISuccess('Setting', 'create', array( |
0ac69d82 ML |
59 | 'languageLimit' => array( |
60 | 'en_US', | |
61 | 'fr_CA', | |
62 | ), | |
63 | )); | |
64 | ||
65 | // Take a semi-random OptionGroup and test manually changing its label | |
66 | // in one language, while making sure it stays the same in English. | |
45a47559 | 67 | $group = $this->callAPISuccess('OptionGroup', 'getsingle', array( |
f2cc6a82 | 68 | 'name' => 'contact_edit_options', |
0ac69d82 ML |
69 | )); |
70 | ||
45a47559 | 71 | $english_original = $this->callAPISuccess('OptionValue', 'getsingle', array( |
0ac69d82 | 72 | 'option_group_id' => $group['id'], |
f2cc6a82 | 73 | 'name' => 'IM', |
0ac69d82 ML |
74 | )); |
75 | ||
45a47559 | 76 | $this->callAPISuccess('OptionValue', 'create', array( |
0ac69d82 ML |
77 | 'id' => $english_original['id'], |
78 | 'name' => 'IM', | |
79 | 'label' => 'Messagerie instantanée', | |
80 | 'option.language' => 'fr_CA', | |
81 | )); | |
82 | ||
45a47559 | 83 | $french = $this->callAPISuccess('OptionValue', 'getsingle', array( |
0ac69d82 ML |
84 | 'option_group_id' => $group['id'], |
85 | 'name' => 'IM', | |
86 | 'option.language' => 'fr_CA', | |
87 | )); | |
88 | ||
45a47559 | 89 | $default = $this->callAPISuccess('OptionValue', 'getsingle', array( |
0ac69d82 | 90 | 'option_group_id' => $group['id'], |
f2cc6a82 ML |
91 | 'name' => 'IM', |
92 | 'option.language' => 'en_US', | |
0ac69d82 ML |
93 | )); |
94 | ||
95 | $this->assertEquals($french['label'], 'Messagerie instantanée'); | |
96 | $this->assertEquals($default['label'], $english_original['label']); | |
97 | } | |
98 | ||
3a575348 | 99 | /** |
100 | * CRM-19677: Ensure that entity apis are not affected on Multilingual setup | |
101 | * with check_permissions = TRUE | |
102 | */ | |
103 | public function testAllEntities() { | |
104 | $this->enableMultilingual(); | |
105 | ||
106 | // list of entities which has mandatory attributes | |
107 | $specialEntities = array( | |
108 | 'Attachment' => array('id' => 13), | |
109 | 'CustomValue' => array('entity_id' => 13), | |
110 | 'MailingContact' => array('contact_id' => 13), | |
111 | 'Profile' => array('profile_id' => 13), | |
112 | 'MailingGroup' => array('mailing_id' => 13), | |
113 | ); | |
114 | // deprecated or API.Get is not supported/implemented | |
115 | $skippableEntities = array( | |
116 | 'Logging', | |
117 | 'MailingEventConfirm', | |
118 | 'MailingEventResubscribe', | |
119 | 'MailingEventSubscribe', | |
120 | 'MailingEventUnsubscribe', | |
121 | 'Location', | |
122 | 'Pcp', | |
123 | 'Survey', | |
124 | 'UFField', // throw error for help_post column | |
125 | 'UFGroup', //throw error for title | |
126 | 'User', // need loggedIn user id | |
127 | ); | |
128 | // fetch all entities | |
129 | $entities = $this->callAPISuccess('Entity', 'get', array()); | |
130 | $skippableEntities = array_merge($skippableEntities, $entities['deprecated']); | |
131 | ||
132 | foreach ($entities['values'] as $entity) { | |
133 | $params = array('check_permissions' => 1); | |
134 | if (in_array($entity, $skippableEntities) && $entity != 'MailingGroup') { | |
135 | continue; | |
136 | } | |
137 | if (array_key_exists($entity, $specialEntities)) { | |
138 | $params = array_merge($params, $specialEntities[$entity]); | |
139 | } | |
140 | $this->callAPISuccess($entity, 'get', $params); | |
141 | } | |
142 | } | |
143 | ||
144 | public function enableMultilingual() { | |
145 | $this->callAPISuccess('Setting', 'create', array( | |
146 | 'lcMessages' => 'en_US', | |
147 | 'languageLimit' => array( | |
148 | 'en_US' => 1, | |
149 | ), | |
150 | )); | |
151 | ||
152 | CRM_Core_I18n_Schema::makeMultilingual('en_US'); | |
153 | ||
154 | global $dbLocale; | |
155 | $dbLocale = '_en_US'; | |
156 | } | |
157 | ||
0ac69d82 | 158 | } |