Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
CustomFieldDataUtilTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  public static $activateDefaultLanguages = true;
40 
41  public static function setUpBeforeClass()
42  {
43  parent::setUpBeforeClass();
44  SecurityTestHelper::createSuperAdmin();
45  }
46 
47  public function testSetAndGetTranslatedLabels()
48  {
49  $this->assertEquals('en', Yii::app()->language);
50  $values = array(
51  'Item 1',
52  'Item 2',
53  'Item 3',
54  );
55  $labels = array(
56  'fr' => array('Item 1 fr',
57  'Item 2 fr',
58  'Item 3 fr'),
59  );
60  $customFieldData = CustomFieldData::getByName('Items');
61  $customFieldData->serializedData = serialize($values);
62  $customFieldData->serializedLabels = serialize($labels);
63  $this->assertTrue($customFieldData->save());
64  $id = $customFieldData->id;
65  $customFieldData->forget();
66  unset($customFieldData);
67 
68  $customFieldData = CustomFieldData::getById($id);
69  $dataAndLabels = CustomFieldDataUtil::
71  $compareData = array('Item 1' => 'Item 1', 'Item 2' => 'Item 2', 'Item 3' => 'Item 3');
72  $this->assertEquals($compareData, $dataAndLabels);
73 
74  $dataAndLabels = CustomFieldDataUtil::
76  $compareData = array('Item 1' => 'Item 1 fr', 'Item 2' => 'Item 2 fr', 'Item 3' => 'Item 3 fr');
77  $this->assertEquals($compareData, $dataAndLabels);
78 
79  $dataAndLabels = CustomFieldDataUtil::
81  $compareData = array('Item 1' => 'Item 1', 'Item 2' => 'Item 2', 'Item 3' => 'Item 3');
82  $this->assertEquals($compareData, $dataAndLabels);
83  }
84 
85  public function testSetAndGetEmptyValueWhichShouldUtilizeFallBack()
86  {
87  $this->assertEquals('en', Yii::app()->language);
88  $values = array(
89  'Item 1',
90  'Item 2',
91  'Item 3',
92  );
93  $labels = array(
94  'fr' => array('Item 1 fr',
95  '',
96  'Item 3 fr'),
97  );
98  $customFieldData = CustomFieldData::getByName('Items2');
99  $customFieldData->serializedData = serialize($values);
100  $customFieldData->serializedLabels = serialize($labels);
101  $this->assertTrue($customFieldData->save());
102  $id = $customFieldData->id;
103  $customFieldData->forget();
104  unset($customFieldData);
105 
106  $customFieldData = CustomFieldData::getById($id);
107  $dataAndLabels = CustomFieldDataUtil::
109  $compareData = array('Item 1' => 'Item 1', 'Item 2' => 'Item 2', 'Item 3' => 'Item 3');
110  $this->assertEquals($compareData, $dataAndLabels);
111 
112  $dataAndLabels = CustomFieldDataUtil::
114  $compareData = array('Item 1' => 'Item 1 fr', 'Item 2' => 'Item 2', 'Item 3' => 'Item 3 fr');
115  $this->assertEquals($compareData, $dataAndLabels);
116  }
117 
118  public function testGetTranslatedLabelByValue()
119  {
120  $this->assertEquals('en', Yii::app()->language);
121  $values = array(
122  'Item 1',
123  'Item 2',
124  'Item 3',
125  );
126  $labels = array(
127  'fr' => array('Item 1 fr',
128  '',
129  'Item 3 fr'),
130  );
131  $customFieldData = CustomFieldData::getByName('Items2');
132  $customFieldData->serializedData = serialize($values);
133  $customFieldData->serializedLabels = serialize($labels);
134  $this->assertTrue($customFieldData->save());
135  $id = $customFieldData->id;
136  $customFieldData->forget();
137  unset($customFieldData);
138 
139  $customFieldData = CustomFieldData::getById($id);
140  $value = CustomFieldDataUtil::getTranslatedLabelByValue($customFieldData, 'Item 1', 'en');
141  $this->assertEquals('Item 1', $value);
142  $value = CustomFieldDataUtil::getTranslatedLabelByValue($customFieldData, 'Item 1', 'fr');
143  $this->assertEquals('Item 1 fr', $value);
144  }
145  }
146 ?>
static getDataIndexedByDataAndTranslatedLabelsByLanguage(CustomFieldData $customFieldData, $language)
static getByName($name, $shouldCache=true)
static getById($id, $modelClassName=null)
Generated on Tue Jul 7 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.