Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ReportResultsRowDataTest.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();
44  }
45 
46  public static function getDependentTestModelClassNames()
47  {
48  return array('ReportModelTestItem10', 'ReportModelTestItem11');
49  }
50 
51  public function setup()
52  {
53  parent::setUp();
54  Yii::app()->user->userModel = User::getByUsername('super');
56  }
57 
58  public function testGetCurrencyValueAndDateAttributesOnOwnedModel()
59  {
60  $reportModelTestItem11 = new ReportModelTestItem11();
61  $reportModelTestItem11->date = '2002-12-12';
62  $reportModelTestItem11b = new ReportModelTestItem11();
63  $reportModelTestItem11b->date = '2002-12-13';
64  $reportModelTestItem10 = new ReportModelTestItem10();
65  $reportModelTestItem10->reportModelTestItem11->add($reportModelTestItem11);
66  $reportModelTestItem10->reportModelTestItem11->add($reportModelTestItem11b);
67  $this->assertTrue($reportModelTestItem10->save());
68  $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem10',
70  $displayAttributeX->setModelAliasUsingTableAliasName('abc');
71  $displayAttributeX->attributeIndexOrDerivedType = 'reportModelTestItem11___date';
72  $this->assertEquals('col0', $displayAttributeX->columnAliasName);
73 
74  $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX), 4);
75  $reportResultsRowData->addModelAndAlias($reportModelTestItem11b, 'abc');
76 
77  $model = $reportResultsRowData->getModel('attribute0');
78  $this->assertEquals('2002-12-13', $model->date);
79  }
80 
81  public function testGetModel()
82  {
83  $reportModelTestItemX = new ReportModelTestItem();
84  $reportModelTestItemX->firstName = 'xFirst';
85  $reportModelTestItemX->lastName = 'xLast';
86  $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
88  $displayAttributeX->setModelAliasUsingTableAliasName('abc');
89  $displayAttributeX->attributeIndexOrDerivedType = 'FullName';
90 
91  $reportModelTestItemY = new ReportModelTestItem();
92  $reportModelTestItemY->firstName = 'yFirst';
93  $reportModelTestItemY->lastName = 'yLast';
94  $displayAttributeY = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
96  $displayAttributeY->setModelAliasUsingTableAliasName('def');
97  $displayAttributeY->attributeIndexOrDerivedType = 'FullName';
98 
99  $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX, $displayAttributeY), 4);
100  $reportResultsRowData->addModelAndAlias($reportModelTestItemX, 'abc');
101  $reportResultsRowData->addModelAndAlias($reportModelTestItemY, 'def');
102 
103  $model1 = $reportResultsRowData->getModel('attribute0');
104  $this->assertEquals('xFirst xLast', strval($model1));
105  $model2 = $reportResultsRowData->getModel('attribute1');
106  $this->assertEquals('yFirst yLast', strval($model2));
107  }
108 
109  public function testGettingAttributeForString()
110  {
111  $reportModelTestItemX = new ReportModelTestItem();
112  $reportModelTestItemX->string = 'someString';
113  $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
115  $displayAttributeX->setModelAliasUsingTableAliasName('abc');
116  $displayAttributeX->attributeIndexOrDerivedType = 'string';
117  $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX), 4);
118  $reportResultsRowData->addModelAndAlias($reportModelTestItemX, 'abc');
119 
120  $this->assertEquals('someString', $reportResultsRowData->attribute0);
121  }
122 
123  public function testGettingAttributeForOwnedString()
124  {
125  $reportModelTestItemX = new ReportModelTestItem();
126  $reportModelTestItemX->primaryAddress->street1 = 'someString';
127  $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
129  $displayAttributeX->setModelAliasUsingTableAliasName('abc');
130  $displayAttributeX->attributeIndexOrDerivedType = 'primaryAddress___street1';
131  $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX), 4);
132  $reportResultsRowData->addModelAndAlias($reportModelTestItemX, 'abc');
133 
134  $this->assertEquals('someString', $reportResultsRowData->attribute0);
135  }
136 
137  public function testGettingAttributeForLikeContactState()
138  {
139  $reportModelTestItem7 = new ReportModelTestItem7;
140  $reportModelTestItem7->name = 'someName';
141  $reportModelTestItemX = new ReportModelTestItem();
142  $reportModelTestItemX->likeContactState = $reportModelTestItem7;
143  $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
145  $displayAttributeX->setModelAliasUsingTableAliasName('abc');
146  $displayAttributeX->attributeIndexOrDerivedType = 'likeContactState';
147  $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX), 4);
148  $reportResultsRowData->addModelAndAlias($reportModelTestItemX, 'abc');
149 
150  $this->assertEquals('someName', $reportResultsRowData->attribute0);
151  }
152 
153  public function testGettingAttributeWhenMadeViaSelect()
154  {
155  $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
157  $displayAttributeX->attributeIndexOrDerivedType = 'integer__Maximum';
158  $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX), 4);
159  $reportResultsRowData->addSelectedColumnNameAndValue('col5', 55);
160 
161  $this->assertEquals(55, $reportResultsRowData->col5);
162  }
163 
164  public function testGetDataParamsForDrillDownAjaxCall()
165  {
166  $reportModelTestItem = new ReportModelTestItem();
167  $reportModelTestItem->dropDown->value = 'dropDownValue';
168  $reportModelTestItem->currencyValue->value = 45.05;
169  $reportModelTestItem->owner = Yii::app()->user->userModel;
170 
171  $reportModelTestItem7 = new ReportModelTestItem7;
172  $reportModelTestItem7->name = 'someName';
173  $reportModelTestItem->likeContactState = $reportModelTestItem7;
174 
175  $displayAttribute1 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
177  $displayAttribute1->attributeIndexOrDerivedType = 'dropDown';
178  $displayAttribute1->valueUsedAsDrillDownFilter = true;
179  $displayAttribute1->setModelAliasUsingTableAliasName('abc');
180 
181  $displayAttribute2 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
183  $displayAttribute2->attributeIndexOrDerivedType = 'integer';
184 
185  $displayAttribute3 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
187  $displayAttribute3->attributeIndexOrDerivedType = 'currencyValue';
188  $displayAttribute3->valueUsedAsDrillDownFilter = true;
189  $displayAttribute3->setModelAliasUsingTableAliasName('abc');
190 
191  $displayAttribute4 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
193  $displayAttribute4->attributeIndexOrDerivedType = 'createdDateTime__Day';
194  $displayAttribute4->valueUsedAsDrillDownFilter = true;
195 
196  $displayAttribute5 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
198  $displayAttribute5->attributeIndexOrDerivedType = 'owner__User';
199  $displayAttribute5->valueUsedAsDrillDownFilter = true;
200  $displayAttribute5->setModelAliasUsingTableAliasName('abc');
201 
202  $displayAttribute6 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
204  $displayAttribute6->attributeIndexOrDerivedType = 'likeContactState';
205  $displayAttribute6->valueUsedAsDrillDownFilter = true;
206  $displayAttribute6->setModelAliasUsingTableAliasName('abc');
207 
208  $reportResultsRowData = new ReportResultsRowData(array($displayAttribute1, $displayAttribute2,
209  $displayAttribute3, $displayAttribute4,
210  $displayAttribute5, $displayAttribute6), 4);
211  $reportResultsRowData->addModelAndAlias($reportModelTestItem, 'abc');
212  $reportResultsRowData->addSelectedColumnNameAndValue('col3', 15);
213  $data = $reportResultsRowData->getDataParamsForDrillDownAjaxCall();
214  $userId = Yii::app()->user->userModel->id;
215  $this->assertEquals('dropDownValue', $data[ReportResultsRowData::resolveDataParamKeyForDrillDown('dropDown')]);
216  $this->assertEquals(45.05, $data[ReportResultsRowData::resolveDataParamKeyForDrillDown('currencyValue')]);
217  $this->assertEquals(15, $data[ReportResultsRowData::resolveDataParamKeyForDrillDown('createdDateTime__Day')]);
218  $this->assertEquals($userId, $data[ReportResultsRowData::resolveDataParamKeyForDrillDown('owner__User')]);
219  $this->assertEquals($reportModelTestItem7->id, $data[ReportResultsRowData::resolveDataParamKeyForDrillDown('likeContactState')]);
220  }
221 
222  public function testResolveDataParamKeyForDrillDown()
223  {
224  $this->assertEquals(ReportResultsRowData::DRILL_DOWN_GROUP_BY_VALUE_PREFIX . 'abc',
226  }
227 
228  public function testWhenResolveValueFromModelHasNoModelAndReturnsProperDefaultModel()
229  {
230  $reportModelTestItemX = new ReportModelTestItem();
231  $reportModelTestItemX->string = 'someString';
232  $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
234  $displayAttributeX->setModelAliasUsingTableAliasName('abc');
235  $displayAttributeX->attributeIndexOrDerivedType = 'string';
236  $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX), 4);
237  $this->assertNull($reportResultsRowData->attribute0);
238  }
239 
240  public function testGetAttributeLabel()
241  {
242  $reportModelTestItemX = new ReportModelTestItem();
243  $reportModelTestItemX->string = 'someString';
244  $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
246  $displayAttributeX->setModelAliasUsingTableAliasName('abc');
247  $displayAttributeX->attributeIndexOrDerivedType = 'string';
248  $displayAttributeY = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem',
250  $displayAttributeY->attributeIndexOrDerivedType = 'integer__Maximum';
251 
252  $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX, $displayAttributeY), 4);
253  $reportResultsRowData->addModelAndAlias($reportModelTestItemX, 'abc');
254  $reportResultsRowData->addSelectedColumnNameAndValue('col1', 55);
255 
256  //Test a viaModel attribute
257  $this->assertEquals('String', $reportResultsRowData->getAttributeLabel('attribute0'));
258 
259  //Test a viaSelect attriubte
260  $this->assertEquals('Integer -(Max)', $reportResultsRowData->getAttributeLabel('col1'));
261  }
262 
268  {
269  $contactStates = ContactState::getByName('Qualified');
270  $contact = new Contact();
271  $contact->owner = Yii::app()->user->userModel;
272  $contact->title->value = 'Mr.';
273  $contact->firstName = 'Super';
274  $contact->lastName = 'Man';
275  $contact->jobTitle = 'Superhero';
276  $contact->description = 'Some Description';
277  $contact->department = 'Red Tape';
278  $contact->officePhone = '1234567890';
279  $contact->mobilePhone = '0987654321';
280  $contact->officeFax = '1222222222';
281  $contact->state = $contactStates[0];
282  $contact->primaryAddress->state = 'IL';
283  $this->assertTrue($contact->save());
284  $displayAttribute = new DisplayAttributeForReportForm('ContactsModule', 'Contact',
286  $displayAttribute->setModelAliasUsingTableAliasName('abc');
287  $displayAttribute->attributeIndexOrDerivedType = 'primaryAddress___state';
288  $this->assertEquals('col0', $displayAttribute->columnAliasName);
289 
290  $reportResultsRowData = new ReportResultsRowData(array($displayAttribute), 4);
291  $reportResultsRowData->addModelAndAlias($contact, 'abc');
292 
293  $model = $reportResultsRowData->getModel('attribute0');
294  $this->assertEquals('IL', $model->primaryAddress->state);
295  $this->assertEquals('IL', $reportResultsRowData->attribute0);
296  }
297  }
298 ?>
static resolveDataParamKeyForDrillDown($attributeIndexOrDerivedType)
static getByUsername($username)
Definition: User.php:49
static loadStartingData()
const TYPE_SUMMATION
Definition: Report.php:57
testDisplayingAOwnedModelAttributeThatIsAlsoDefinedAsAnAttributeOnTheOwningModel()
const TYPE_ROWS_AND_COLUMNS
Definition: Report.php:51
Generated on Thu Aug 6 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.