Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DisplayAttributeForReportFormTest.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  $attributeName = 'calculated';
44  $attributeForm = new CalculatedNumberAttributeForm();
45  $attributeForm->attributeName = $attributeName;
46  $attributeForm->attributeLabels = array('en' => 'Test Calculated');
47  $attributeForm->formula = 'integer + float';
48  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
49  $adapter = new $modelAttributesAdapterClassName(new ReportModelTestItem());
50  $adapter->setAttributeMetadataFromForm($attributeForm);
51 
52  $values = array(
53  'Test1',
54  'Test2',
55  'Test3',
56  'Sample',
57  'Demo',
58  );
59  $labels = array('fr' => array('Test1 fr', 'Test2 fr', 'Test3 fr', 'Sample fr', 'Demo fr'),
60  'de' => array('Test1 de', 'Test2 de', 'Test3 de', 'Sample de', 'Demo de'),
61  );
62  $customFieldData = CustomFieldData::getByName('ReportTestDropDown');
63  $customFieldData->serializedData = serialize($values);
64  $customFieldData->serializedLabels = serialize($labels);
65  $saved = $customFieldData->save();
66  assert('$saved'); // Not Coding Standard
68  }
69 
70  public function setup()
71  {
72  parent::setUp();
73  Yii::app()->user->userModel = User::getByUsername('super');
74  ModelRelationsAndAttributesToSummableReportAdapter::forgetAll();
75  ModelRelationsAndAttributesToRowsAndColumnsReportAdapter::forgetAll();
76  ModelRelationsAndAttributesToMatrixReportAdapter::forgetAll();
77  }
78 
79  public function testGetDisplayLabelForCalculations()
80  {
81  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
83  $this->assertNull($displayAttribute->label);
84  $displayAttribute->attributeIndexOrDerivedType = 'float__Summation';
85  $this->assertEquals('Float -(Sum)', $displayAttribute->label);
86  $this->assertEquals('Float -(Sum)', $displayAttribute->getDisplayLabel());
87  }
88 
89  public function testSetAndGetDisplayAttribute()
90  {
91  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
93  $this->assertNull($displayAttribute->label);
94  $displayAttribute->attributeIndexOrDerivedType = 'string';
95  $this->assertEquals('String', $displayAttribute->label);
96  $displayAttribute->label = 'someLabel';
97  $this->assertEquals('string', $displayAttribute->attributeAndRelationData);
98  $this->assertEquals('string', $displayAttribute->attributeIndexOrDerivedType);
99  $this->assertEquals('string', $displayAttribute->getResolvedAttribute());
100  $this->assertEquals('String', $displayAttribute->getDisplayLabel());
101  $this->assertEquals('someLabel', $displayAttribute->label);
102  $validated = $displayAttribute->validate();
103  $this->assertTrue($validated);
104 
105  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
107  $displayAttribute->label = null;
108  $validated = $displayAttribute->validate();
109  $this->assertFalse($validated);
110  $errors = $displayAttribute->getErrors();
111  $compareErrors = array('label' => array('Label cannot be blank.'));
112  $this->assertEquals($compareErrors, $errors);
113 
114  $displayAttribute->label = '';
115  $validated = $displayAttribute->validate();
116  $this->assertFalse($validated);
117  $errors = $displayAttribute->getErrors();
118  $compareErrors = array('label' => array('Label cannot be blank.'));
119  $this->assertEquals($compareErrors, $errors);
120 
121  $displayAttribute->label = 'test';
122  $displayAttribute->setAttributes(array('label' => ''));
123  $validated = $displayAttribute->validate();
124  $this->assertFalse($validated);
125  $errors = $displayAttribute->getErrors();
126  $compareErrors = array('label' => array('Label cannot be blank.'));
127  $this->assertEquals($compareErrors, $errors);
128  }
129 
130  public function testGetDisplayElementTypeForRowsAndColumnsReport()
131  {
132  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
134  $displayAttribute->attributeIndexOrDerivedType = 'calculated';
135  $this->assertEquals('CalculatedNumber', $displayAttribute->getDisplayElementType());
136  }
137 
138  public function testGetDisplayElementTypeForSummationReport()
139  {
140  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
142  $displayAttribute->attributeIndexOrDerivedType = 'boolean';
143  $this->assertEquals('CheckBox', $displayAttribute->getDisplayElementType());
144  $displayAttribute->attributeIndexOrDerivedType = 'date';
145  $this->assertEquals('Date', $displayAttribute->getDisplayElementType());
146  $displayAttribute->attributeIndexOrDerivedType = 'dateTime';
147  $this->assertEquals('DateTime', $displayAttribute->getDisplayElementType());
148  $displayAttribute->attributeIndexOrDerivedType = 'float';
149  $this->assertEquals('Decimal', $displayAttribute->getDisplayElementType());
150  $displayAttribute->attributeIndexOrDerivedType = 'integer';
151  $this->assertEquals('Integer', $displayAttribute->getDisplayElementType());
152  $displayAttribute->attributeIndexOrDerivedType = 'phone';
153  $this->assertEquals('Phone', $displayAttribute->getDisplayElementType());
154  $displayAttribute->attributeIndexOrDerivedType = 'textArea';
155  $this->assertEquals('TextArea', $displayAttribute->getDisplayElementType());
156  $displayAttribute->attributeIndexOrDerivedType = 'url';
157  $this->assertEquals('Url', $displayAttribute->getDisplayElementType());
158  $displayAttribute->attributeIndexOrDerivedType = 'currencyValue';
159  $this->assertEquals('CurrencyValue', $displayAttribute->getDisplayElementType());
160  $displayAttribute->attributeIndexOrDerivedType = 'dropDown';
161  $this->assertEquals('DropDown', $displayAttribute->getDisplayElementType());
162  $displayAttribute->attributeIndexOrDerivedType = 'radioDropDown';
163  $this->assertEquals('RadioDropDown', $displayAttribute->getDisplayElementType());
164  $displayAttribute->attributeIndexOrDerivedType = 'multiDropDown';
165  $this->assertEquals('MultiSelectDropDown', $displayAttribute->getDisplayElementType());
166  $displayAttribute->attributeIndexOrDerivedType = 'tagCloud';
167  $this->assertEquals('TagCloud', $displayAttribute->getDisplayElementType());
168  $displayAttribute->attributeIndexOrDerivedType = 'primaryEmail___emailAddress';
169  $this->assertEquals('Email', $displayAttribute->getDisplayElementType());
170  $displayAttribute->attributeIndexOrDerivedType = 'FullName';
171  $this->assertEquals('FullName', $displayAttribute->getDisplayElementType());
172  $displayAttribute->attributeIndexOrDerivedType = 'likeContactState';
173  $this->assertEquals('ContactState', $displayAttribute->getDisplayElementType());
174  $displayAttribute->attributeIndexOrDerivedType = 'calculated';
175  $this->assertEquals('CalculatedNumber', $displayAttribute->getDisplayElementType());
176  $displayAttribute->attributeIndexOrDerivedType = 'createdByUser__User';
177  $this->assertEquals('User', $displayAttribute->getDisplayElementType());
178  }
179 
180  public function testGetDisplayElementTypeDisplayCalculationsAndGroupModifiers()
181  {
182  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
184  $displayAttribute->attributeIndexOrDerivedType = 'integer__Minimum';
185  $this->assertEquals('Decimal', $displayAttribute->getDisplayElementType());
186  $displayAttribute->attributeIndexOrDerivedType = 'float__Minimum';
187  $this->assertEquals('Decimal', $displayAttribute->getDisplayElementType());
188  $displayAttribute->attributeIndexOrDerivedType = 'date__Minimum';
189  $this->assertEquals('Date', $displayAttribute->getDisplayElementType());
190  $displayAttribute->attributeIndexOrDerivedType = 'dateTime__Minimum';
191  $this->assertEquals('DateTime', $displayAttribute->getDisplayElementType());
192  $displayAttribute->attributeIndexOrDerivedType = 'currencyValue__Minimum';
193  $this->assertEquals('CalculatedCurrencyValue', $displayAttribute->getDisplayElementType());
194  $displayAttribute->attributeIndexOrDerivedType = 'dateTime__Day';
195  $this->assertEquals('Text', $displayAttribute->getDisplayElementType());
196  $displayAttribute->attributeIndexOrDerivedType = 'dateTime__Week';
197  $this->assertEquals('Text', $displayAttribute->getDisplayElementType());
198  $displayAttribute->attributeIndexOrDerivedType = 'dateTime__Month';
199  $this->assertEquals('GroupByModifierMonth', $displayAttribute->getDisplayElementType());
200  $displayAttribute->attributeIndexOrDerivedType = 'dateTime__Quarter';
201  $this->assertEquals('Text', $displayAttribute->getDisplayElementType());
202  $displayAttribute->attributeIndexOrDerivedType = 'dateTime__Year';
203  $this->assertEquals('Text', $displayAttribute->getDisplayElementType());
204  }
205 
206  public function testResolveValueAsLabelForHeaderCellForADropDown()
207  {
208  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
210  $displayAttribute->attributeIndexOrDerivedType = 'dropDown';
211  $this->assertEquals('Sample', $displayAttribute->resolveValueAsLabelForHeaderCell('Sample'));
212  //Test translating to a different language
213  $oldLanguage = Yii::app()->language;
214  Yii::app()->language = 'de';
215  $this->assertEquals('Sample de', $displayAttribute->resolveValueAsLabelForHeaderCell('Sample'));
216  Yii::app()->language = $oldLanguage;
217  }
218 
219  public function testResolveValueAsLabelForHeaderCellForACheckBox()
220  {
221  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
223  $displayAttribute->attributeIndexOrDerivedType = 'boolean';
224  $this->assertEquals('Yes', $displayAttribute->resolveValueAsLabelForHeaderCell(true));
225  //false will evaluate as '', so it wont show No, not sure if this is right
226  $this->assertEquals('No', $displayAttribute->resolveValueAsLabelForHeaderCell('0'));
227  $this->assertEquals('', $displayAttribute->resolveValueAsLabelForHeaderCell(''));
228  }
229 
230  public function testResolveValueAsLabelForHeaderCellForADynamicUser()
231  {
232  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
234  $displayAttribute->attributeIndexOrDerivedType = 'owner__User';
235  $this->assertEquals('Clark Kent', $displayAttribute->resolveValueAsLabelForHeaderCell(Yii::app()->user->userModel->id));
236  }
237 
238  public function testResolveValueAsLabelForHeaderCellForAString()
239  {
240  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
242  $displayAttribute->attributeIndexOrDerivedType = 'string';
243  $this->assertEquals('', $displayAttribute->resolveValueAsLabelForHeaderCell(null));
244  }
245 
246  public function testResolveValueAsLabelForHeaderCellForAnAttributeLikeContactState()
247  {
248  $contactStates = ContactState::getAll();
249  $displayAttribute = new DisplayAttributeForReportForm('ContactsModule', 'Contact',
251  $displayAttribute->attributeIndexOrDerivedType = 'state';
252  $this->assertEquals('Recycled', $contactStates[2]->name);
253  $this->assertEquals('Recycled', $displayAttribute->resolveValueAsLabelForHeaderCell($contactStates[2]->id));
254  }
255 
256  public function testResolveValueAsLabelForHeaderCellForAnLinkableAttribute()
257  {
258  $account1 = AccountTestHelper::createAccountByNameForOwner('account name', Yii::app()->user->userModel);
259  $account2 = AccountTestHelper::createAccountByNameForOwner('account name', Yii::app()->user->userModel);
260  $displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account',
262  $displayAttribute->attributeIndexOrDerivedType = 'name';
263  //Make a tooltip for multiple results
264  $this->assertEquals('<span id="report-multiple-link-AccountsModule-' . $account2->id . '">account name' .
265  '<span class="tooltip">2</span></span>',
266  $displayAttribute->resolveValueAsLabelForHeaderCell('account name'));
267  $this->assertEquals($account1->name,
268  $displayAttribute->resolveValueAsLabelForHeaderCell('account name', true));
269  }
270 
271  public function testGetDisplayLabel()
272  {
273  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
275  $displayAttribute->attributeIndexOrDerivedType = 'string';
276  $this->assertEquals('String', $displayAttribute->getDisplayLabel());
277  $displayAttribute->attributeIndexOrDerivedType = 'hasOne___name';
278  $this->assertEquals('ReportModelTestItem2 >> Name', $displayAttribute->getDisplayLabel());
279  $displayAttribute->attributeIndexOrDerivedType = 'hasMany___name';
280  $this->assertEquals('ReportModelTestItem3s >> Name', $displayAttribute->getDisplayLabel());
281  $displayAttribute->attributeIndexOrDerivedType = 'primaryAddress___street1';
282  $this->assertEquals('Primary Address >> Street 1', $displayAttribute->getDisplayLabel());
283  }
284  }
285 ?>
static getByUsername($username)
Definition: User.php:49
static loadStartingData()
const TYPE_SUMMATION
Definition: Report.php:57
static getByName($name, $shouldCache=true)
const TYPE_ROWS_AND_COLUMNS
Definition: Report.php:51
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Sat Jul 4 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.