Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
CustomFieldTest.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 
37  class CustomFieldTest extends BaseTest
38  {
39  public function testSaveAndLoadCustomFieldData()
40  {
41  $values = array(
42  'Item 1',
43  'Item 2',
44  'Item 3',
45  );
46  $labels = array(
47  'fr' => 'Item 1 fr',
48  'fr' => 'Item 2 fr',
49  'fr' => 'Item 3 fr',
50  );
51  $customFieldData = CustomFieldData::getByName('Items');
52  $customFieldData->serializedData = serialize($values);
53  $customFieldData->serializedLabels = serialize($labels);
54  $this->assertTrue($customFieldData->save());
55  $id = $customFieldData->id;
56  unset($customFieldData);
57 
58  $customFieldData = CustomFieldData::getById($id);
59  $loadedValues = unserialize($customFieldData->serializedData);
60  $loadedLabels = unserialize($customFieldData->serializedLabels);
61  $this->assertEquals('Items', $customFieldData->name);
62  $this->assertNull ( $customFieldData->defaultValue);
63  $this->assertEquals($values, $loadedValues);
64  $this->assertEquals($labels, $loadedLabels);
65 
66  $customFieldData->defaultValue = $values[2];
67  $this->assertTrue($customFieldData->save());
68  unset($customFieldData);
69  $customFieldData = CustomFieldData::getById($id);
70  $this->assertEquals('Items', $customFieldData->name);
71  $this->assertEquals('Item 3', $customFieldData->defaultValue);
72  $this->assertEquals($values, $loadedValues);
73  }
74 
78  public function testCustomField()
79  {
80  $customFieldData = CustomFieldData::getByName('Items');
81  $customField = new CustomField();
82  $customField->value = $customFieldData->defaultValue;
83  $customField->data = $customFieldData;
84  $this->assertTrue($customField->save());
85 
86  $values = unserialize($customField->data->serializedData);
87  $customField->value = $values[0];
88  $this->assertTrue($customFieldData->save());
89  unset($customFieldData);
90 
91  $customFieldData = CustomFieldData::getByName('Items');
92  $this->assertEquals('Item 1', $customField->value);
93  }
94 
99  {
100  $values = array(
101  'Automotive',
102  'Adult Entertainment',
103  'Financial Services',
104  'Mercenaries & Armaments',
105  );
106  $industryFieldData = CustomFieldData::getByName('Industries');
107  $industryFieldData->defaultValue = $values[1];
108  $industryFieldData->serializedData = serialize($values);
109  $this->assertTrue($industryFieldData->save());
110 
111  $model = new TestCustomFieldsModel();
112  $this->assertEquals($values[1], $model->industry->value);
113  $this->assertTrue($model->validate());
114 
115  $_FAKEPOST = array(
116  'industry' => array(
117  'value' => $values[2],
118  ),
119  );
120 
121  $model->setAttributes($_FAKEPOST);
122  $this->assertEquals($values[2], $model->industry->value);
123  }
124 
129  {
130  $values = array(
131  'A',
132  'B',
133  'C',
134  );
135  $customFieldData = CustomFieldData::getByName('updateItems');
136  $customFieldData->serializedData = serialize($values);
137  $this->assertTrue($customFieldData->save());
138  $id = $customFieldData->id;
139 
140  $customField = new CustomField();
141  $customField->value = 'A';
142  $customField->data = $customFieldData;
143  $this->assertTrue($customField->save());
144 
145  $customField = new CustomField();
146  $customField->value = 'B';
147  $customField->data = $customFieldData;
148  $this->assertTrue($customField->save());
149 
150  $customField = new CustomField();
151  $customField->value = 'C';
152  $customField->data = $customFieldData;
153  $this->assertTrue($customField->save());
154 
155  $customField = new CustomField();
156  $customField->value = 'C';
157  $customField->data = $customFieldData;
158  $this->assertTrue($customField->save());
159 
161  $customFieldTableName = CustomField::getTableName();
162  $baseCustomFieldTableName = BaseCustomField::getTableName();
163  $valueAttributeColumnName = 'value';
164  $dataAttributeColumnName = RedBeanModel::getForeignKeyName('CustomField', 'data');
165  $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
166  $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
167  $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
168  $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
169  $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id}";
170  $ids = ZurmoRedBean::getCol($sql);
171  $beans = ZurmoRedBean::batch($customFieldTableName, $ids);
172  $customFields = RedBeanModel::makeModels($beans, 'CustomField');
173  $this->assertEquals(4, count($customFields));
174  $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
175  $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
176  $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
177  $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
178  $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
179  $sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'B'";
180  $this->assertEquals(1, count(ZurmoRedBean::getCol($sql)));
181  $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
182  $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
183  $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
184  $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
185  $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
186  $sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'C'";
187  $this->assertEquals(2, count(ZurmoRedBean::getCol($sql)));
188  $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
189  $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
190  $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
191  $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
192  $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
193  $sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'E'";
194  $this->assertEquals(0, count(ZurmoRedBean::getCol($sql)));
195  CustomField::updateValueByDataIdAndOldValueAndNewValue($id, 'C', 'E');
196  $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
197  $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
198  $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
199  $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
200  $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
201  $sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'B'";
202  $this->assertEquals(1, count(ZurmoRedBean::getCol($sql)));
203  $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
204  $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
205  $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
206  $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
207  $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
208  $sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'C'";
209  $this->assertEquals(0, count(ZurmoRedBean::getCol($sql)));
210  $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
211  $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
212  $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
213  $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
214  $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
215  $sql .= "and {$quote}{$valueAttributeColumnName}{$quote} = 'E'";
216  $this->assertEquals(2, count(ZurmoRedBean::getCol($sql)));
217  }
218  }
static getForeignKeyName($modelClassName, $relationName)
static makeModels(array $beans, $modelClassName=null)
static getByName($name, $shouldCache=true)
testSetAttributesWithPostForCustomField()
static getById($id, $modelClassName=null)
static getTableName()
Generated on Fri Jul 3 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.