Update Unit test styling to cover the future coder version
[civicrm-core.git] / tests / phpunit / api / v3 / MultilingualTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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() {
54 $this->enableMultilingual();
55
56 CRM_Core_I18n_Schema::addLocale('fr_CA', 'en_US');
57
58 $this->callAPISuccess('Setting', 'create', array(
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.
67 $group = $this->callAPISuccess('OptionGroup', 'getsingle', array(
68 'name' => 'contact_edit_options',
69 ));
70
71 $english_original = $this->callAPISuccess('OptionValue', 'getsingle', array(
72 'option_group_id' => $group['id'],
73 'name' => 'IM',
74 ));
75
76 $this->callAPISuccess('OptionValue', 'create', array(
77 'id' => $english_original['id'],
78 'name' => 'IM',
79 'label' => 'Messagerie instantanée',
80 'option.language' => 'fr_CA',
81 ));
82
83 $french = $this->callAPISuccess('OptionValue', 'getsingle', array(
84 'option_group_id' => $group['id'],
85 'name' => 'IM',
86 'option.language' => 'fr_CA',
87 ));
88
89 $default = $this->callAPISuccess('OptionValue', 'getsingle', array(
90 'option_group_id' => $group['id'],
91 'name' => 'IM',
92 'option.language' => 'en_US',
93 ));
94
95 $this->assertEquals($french['label'], 'Messagerie instantanée');
96 $this->assertEquals($default['label'], $english_original['label']);
97 }
98
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 // throw error for help_post column
125 'UFField',
126 //throw error for title
127 'UFGroup',
128 // need loggedIn user id
129 'User',
130 );
131 // fetch all entities
132 $entities = $this->callAPISuccess('Entity', 'get', array());
133 $skippableEntities = array_merge($skippableEntities, $entities['deprecated']);
134
135 foreach ($entities['values'] as $entity) {
136 $params = array('check_permissions' => 1);
137 if (in_array($entity, $skippableEntities) && $entity != 'MailingGroup') {
138 continue;
139 }
140 if (array_key_exists($entity, $specialEntities)) {
141 $params = array_merge($params, $specialEntities[$entity]);
142 }
143 $this->callAPISuccess($entity, 'get', $params);
144 }
145 }
146
147 }