Merge pull request #9139 from GinkgoFJG/CRM-19425
[civicrm-core.git] / tests / phpunit / api / v3 / MultilingualTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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->callAPISuccess('Setting', 'create', array(
55 'lcMessages' => 'en_US',
56 'languageLimit' => array(
57 'en_US' => 1,
58 ),
59 ));
60
61 CRM_Core_I18n_Schema::makeMultilingual('en_US');
62
63 global $dbLocale;
64 $dbLocale = '_en_US';
65
66 CRM_Core_I18n_Schema::addLocale('fr_CA', 'en_US');
67
68 $this->callAPISuccess('Setting', 'create', array(
69 'languageLimit' => array(
70 'en_US',
71 'fr_CA',
72 ),
73 ));
74
75 // Take a semi-random OptionGroup and test manually changing its label
76 // in one language, while making sure it stays the same in English.
77 $group = $this->callAPISuccess('OptionGroup', 'getsingle', array(
78 'name' => 'contact_edit_options',
79 ));
80
81 $english_original = $this->callAPISuccess('OptionValue', 'getsingle', array(
82 'option_group_id' => $group['id'],
83 'name' => 'IM',
84 ));
85
86 $this->callAPISuccess('OptionValue', 'create', array(
87 'id' => $english_original['id'],
88 'name' => 'IM',
89 'label' => 'Messagerie instantanée',
90 'option.language' => 'fr_CA',
91 ));
92
93 $french = $this->callAPISuccess('OptionValue', 'getsingle', array(
94 'option_group_id' => $group['id'],
95 'name' => 'IM',
96 'option.language' => 'fr_CA',
97 ));
98
99 $default = $this->callAPISuccess('OptionValue', 'getsingle', array(
100 'option_group_id' => $group['id'],
101 'name' => 'IM',
102 'option.language' => 'en_US',
103 ));
104
105 $this->assertEquals($french['label'], 'Messagerie instantanée');
106 $this->assertEquals($default['label'], $english_original['label']);
107 }
108
109 }