All Data Structures Functions Variables Pages
CalculatedNumberForReportListViewColumnAdapterTest.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 + currencyValue';
48  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
49  $adapter = new $modelAttributesAdapterClassName(new ReportModelTestItem10());
50  $adapter->setAttributeMetadataFromForm($attributeForm);
51 
52  $attributeName = 'calculated2';
53  $attributeForm = new CalculatedNumberAttributeForm();
54  $attributeForm->attributeName = $attributeName;
55  $attributeForm->attributeLabels = array('en' => 'Test Calculated');
56  $attributeForm->formula = 'integer + amount';
57  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
58  $adapter = new $modelAttributesAdapterClassName(new ReportModelTestItem11());
59  $adapter->setAttributeMetadataFromForm($attributeForm);
60  }
61 
62  public static function getDependentTestModelClassNames()
63  {
64  return array('ReportModelTestItem10', 'ReportModelTestItem11');
65  }
66 
67  public function setup()
68  {
69  parent::setUp();
70  Yii::app()->user->userModel = User::getByUsername('super');
72  ModelRelationsAndAttributesToSummableReportAdapter::forgetAll();
73  ModelRelationsAndAttributesToRowsAndColumnsReportAdapter::forgetAll();
74  ModelRelationsAndAttributesToMatrixReportAdapter::forgetAll();
75  }
76 
77  public function testResolveValueOnBaseModelAndRelatedModel()
78  {
79  $reportModelTestItem11 = new ReportModelTestItem11();
80  $reportModelTestItem11->integer = 5;
81  $currencies = Currency::getAll();
82  $currencyValue = new CurrencyValue();
83  $currencyValue->value = 100;
84  $currencyValue->currency = $currencies[0];
85 
86  $reportModelTestItem11->amount = $currencyValue;
87  $reportModelTestItem11b = new ReportModelTestItem11();
88  $reportModelTestItem11b->integer = 7;
89  $currencyValue = new CurrencyValue();
90  $currencyValue->value = 200;
91  $currencyValue->currency = $currencies[0];
92  $reportModelTestItem11b->amount = $currencyValue;
93 
94  $reportModelTestItem10 = new ReportModelTestItem10();
95  $reportModelTestItem10->integer = 12;
96  $currencyValue = new CurrencyValue();
97  $currencyValue->value = 400;
98  $currencyValue->currency = $currencies[0];
99  $reportModelTestItem10->currencyValue = $currencyValue;
100  $reportModelTestItem10->reportModelTestItem11->add($reportModelTestItem11);
101  $reportModelTestItem10->reportModelTestItem11->add($reportModelTestItem11b);
102  $saved = $reportModelTestItem10->save();
103  $this->assertTrue($saved);
104  $displayAttributeX = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem10',
106  $displayAttributeX->setModelAliasUsingTableAliasName('abc');
107  $displayAttributeX->attributeIndexOrDerivedType = 'reportModelTestItem11___calculated2';
108  $this->assertEquals('col0', $displayAttributeX->columnAliasName);
109 
110  $displayAttributeY = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem10',
112  $displayAttributeY->setModelAliasUsingTableAliasName('def');
113  $displayAttributeY->attributeIndexOrDerivedType = 'calculated';
114  $this->assertEquals('col1', $displayAttributeY->columnAliasName);
115 
116  $reportResultsRowData = new ReportResultsRowData(array($displayAttributeX, $displayAttributeY), 4);
117  $reportResultsRowData->addModelAndAlias($reportModelTestItem11b, 'abc');
118  $reportResultsRowData->addModelAndAlias($reportModelTestItem10, 'def');
119 
120  //Get value for calculated which is on base model
121  $value = CalculatedNumberForReportListViewColumnAdapter::resolveValue('attribute1', $reportResultsRowData);
122  $this->assertEquals('$412.00', $value);
123  //Get value for calculated2 which is on a relateds model
124  $value = CalculatedNumberForReportListViewColumnAdapter::resolveValue('attribute0', $reportResultsRowData);
125  $this->assertEquals('$207.00', $value);
126  }
127  }
128 ?>
static getByUsername($username)
Definition: User.php:49
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null, $buildFirstCurrency=true)
Definition: Currency.php:107
const TYPE_ROWS_AND_COLUMNS
Definition: Report.php:51
Generated on Sun May 31 2020 07:10:34