Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DropDownDependencyDerivedAttributeDesignerUtilTest.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 function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  SecurityTestHelper::createSuperAdmin();
43  }
44 
45  public function testUpdateValueInMappingByOldAndNewValue()
46  {
47  //First create a dependency
48  $mappingData = array(array('attributeName' => 'a'),
49  array('attributeName' => 'b',
50  'valuesToParentValues' =>
51  array('b1' => 'a1',
52  'b2' => 'a2',
53  'b3' => 'a3',
54  'b4' => 'a4'
55  )),
56  array('attributeName' => 'c',
57  'valuesToParentValues' =>
58  array('c1' => 'b1',
59  'c2' => 'b2',
60  'c3' => 'b3',
61  'c4' => 'b4'
62  )));
64  $metadata->setScenario('nonAutoBuild');
65  $metadata->name = 'aName';
66  $metadata->modelClassName = 'aModelClassName';
67  $metadata->serializedMetadata = serialize(array('attributeLabels' => array('a' => 'b'),
68  'mappingData' => $mappingData));
69  $this->assertTrue($metadata->save());
70 
71  //Change b3 to b3New
72  $oldAndNewValuePairs = array('b3' => 'b3New');
74  updateValueInMappingByOldAndNewValue('aModelClassName', 'b', $oldAndNewValuePairs);
75 
76  //Confirm b3 values changed correctly to b3New
77  $metadata = DropDownDependencyDerivedAttributeMetadata::getById($metadata->id);
78  $unserializedData = unserialize($metadata->serializedMetadata);
79 
80  $compareData = array(array('attributeName' => 'a'),
81  array('attributeName' => 'b',
82  'valuesToParentValues' =>
83  array('b1' => 'a1',
84  'b2' => 'a2',
85  'b3New' => 'a3',
86  'b4' => 'a4'
87  )),
88  array('attributeName' => 'c',
89  'valuesToParentValues' =>
90  array('c1' => 'b1',
91  'c2' => 'b2',
92  'c3' => 'b3New',
93  'c4' => 'b4'
94  )));
95  $this->assertEquals(array('a' => 'b'), $unserializedData['attributeLabels']);
96  $this->assertEquals($compareData, $unserializedData['mappingData']);
97 
98  //Now change a value for a dropdown that is the first level of the dependency. This will only change the
99  //value when it is a parent value.
100  $oldAndNewValuePairs = array('a2' => 'a2New');
102  updateValueInMappingByOldAndNewValue('aModelClassName', 'a', $oldAndNewValuePairs);
103 
104  //Confirm a2 values changed correctly to a2New
105  $metadata = DropDownDependencyDerivedAttributeMetadata::getById($metadata->id);
106  $unserializedData = unserialize($metadata->serializedMetadata);
107 
108  $compareData = array(array('attributeName' => 'a'),
109  array('attributeName' => 'b',
110  'valuesToParentValues' =>
111  array('b1' => 'a1',
112  'b2' => 'a2New',
113  'b3New' => 'a3',
114  'b4' => 'a4'
115  )),
116  array('attributeName' => 'c',
117  'valuesToParentValues' =>
118  array('c1' => 'b1',
119  'c2' => 'b2',
120  'c3' => 'b3New',
121  'c4' => 'b4'
122  )));
123  $this->assertEquals(array('a' => 'b'), $unserializedData['attributeLabels']);
124  $this->assertEquals($compareData, $unserializedData['mappingData']);
125 
126  //Now change 2 values at once.
127  $oldAndNewValuePairs = array('c1' => 'c1New', 'c2' => 'c2New');
129  updateValueInMappingByOldAndNewValue('aModelClassName', 'c', $oldAndNewValuePairs);
130 
131  //Confirm c1, c2 both changed.
132  $metadata = DropDownDependencyDerivedAttributeMetadata::getById($metadata->id);
133  $unserializedData = unserialize($metadata->serializedMetadata);
134 
135  $compareData = array(array('attributeName' => 'a'),
136  array('attributeName' => 'b',
137  'valuesToParentValues' =>
138  array('b1' => 'a1',
139  'b2' => 'a2New',
140  'b3New' => 'a3',
141  'b4' => 'a4'
142  )),
143  array('attributeName' => 'c',
144  'valuesToParentValues' =>
145  array('c1New' => 'b1',
146  'c2New' => 'b2',
147  'c3' => 'b3New',
148  'c4' => 'b4'
149  )));
150  $this->assertEquals(array('a' => 'b'), $unserializedData['attributeLabels']);
151  $this->assertEquals($compareData, $unserializedData['mappingData']);
152  }
153 
158  {
159  //Remove a1
160  $customFieldDataData = array('a2New', 'a3', 'a4');
162  resolveValuesInMappingWhenValueWasRemoved('aModelClassName', 'a', $customFieldDataData);
163 
164  //Confirm a1 has been removed from the mapping.
166  getByNameAndModelClassName('aName', 'aModelClassName');
167  $unserializedData = unserialize($metadata->serializedMetadata);
168 
169  $compareData = array(array('attributeName' => 'a'),
170  array('attributeName' => 'b',
171  'valuesToParentValues' =>
172  array('b1' => null,
173  'b2' => 'a2New',
174  'b3New' => 'a3',
175  'b4' => 'a4'
176  )),
177  array('attributeName' => 'c',
178  'valuesToParentValues' =>
179  array('c1New' => 'b1',
180  'c2New' => 'b2',
181  'c3' => 'b3New',
182  'c4' => 'b4'
183  )));
184  $this->assertEquals(array('a' => 'b'), $unserializedData['attributeLabels']);
185  $this->assertEquals($compareData, $unserializedData['mappingData']);
186 
187  //Remove b4
188  $customFieldDataData = array('b1', 'b2', 'b3New');
190  resolveValuesInMappingWhenValueWasRemoved('aModelClassName', 'b', $customFieldDataData);
191 
192  //Confirm b4 has been removed from the mapping.
194  getByNameAndModelClassName('aName', 'aModelClassName');
195  $unserializedData = unserialize($metadata->serializedMetadata);
196 
197  $compareData = array(array('attributeName' => 'a'),
198  array('attributeName' => 'b',
199  'valuesToParentValues' =>
200  array('b1' => null,
201  'b2' => 'a2New',
202  'b3New' => 'a3',
203  )),
204  array('attributeName' => 'c',
205  'valuesToParentValues' =>
206  array('c1New' => 'b1',
207  'c2New' => 'b2',
208  'c3' => 'b3New',
209  'c4' => null
210  )));
211  $this->assertEquals(array('a' => 'b'), $unserializedData['attributeLabels']);
212  $this->assertEquals($compareData, $unserializedData['mappingData']);
213  }
214  }
215 ?>
static updateValueInMappingByOldAndNewValue($modelClassName, $attributeName, $oldAndNewValuePairs)
static resolveValuesInMappingWhenValueWasRemoved($modelClassName, $attributeName, $customFieldDataData)
static getById($id, $modelClassName=null)
static getByNameAndModelClassName($name, $modelClassName)
Generated on Mon Jul 6 2020 07:10:33
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.