All Data Structures Functions Variables Pages
RowsAndColumnsReportWizardFormTest.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 
41  {
42  public static function setUpBeforeClass()
43  {
44  parent::setUpBeforeClass();
45  SecurityTestHelper::createSuperAdmin();
46  }
47 
48  public function setUp()
49  {
50  parent::setUp();
51  Yii::app()->user->userModel = User::getByUsername('super');
52  }
53 
54  public function testValidateFilters()
55  {
56  $rowsAndColumnsReportWizardForm = new RowsAndColumnsReportWizardForm();
57 
58  $filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem',
60  $filter->attributeIndexOrDerivedType = 'string';
61  $filter->operator = OperatorRules::TYPE_EQUALS;
62  $filter->value = 'Zurmo';
63  $rowsAndColumnsReportWizardForm->filters = array($filter);
64  $rowsAndColumnsReportWizardForm->validateFilters();
65  $this->assertFalse($rowsAndColumnsReportWizardForm->hasErrors());
66  }
67 
68  public function testValidateFiltersForErrors()
69  {
70  $rowsAndColumnsReportWizardForm = new RowsAndColumnsReportWizardForm();
71 
72  $filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem',
74  $filter->attributeIndexOrDerivedType = 'string';
75  $filter->operator = OperatorRules::TYPE_EQUALS;
76  $rowsAndColumnsReportWizardForm->filters = array($filter);
77  $validated = $filter->validate();
78  $this->assertFalse($validated);
79  $errors = $filter->getErrors();
80  $compareErrors = array('value' => array('Value cannot be blank.'));
81  $this->assertEquals($compareErrors, $errors);
82  }
83 
84  public function testValidateFiltersStructure()
85  {
86  $rowsAndColumnsReportWizardForm = new RowsAndColumnsReportWizardForm();
87  $filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem',
89  $filter->attributeIndexOrDerivedType = 'createdDateTime';
90  $filter->operator = OperatorRules::TYPE_BETWEEN;
91  $filter->value = '2013-02-19 00:00';
92  $filter->secondValue = '2013-02-20 00:00';
93  $rowsAndColumnsReportWizardForm->filters = array($filter);
94  $rowsAndColumnsReportWizardForm->filtersStructure = '1';
95  $rowsAndColumnsReportWizardForm->validateFiltersStructure();
96  $this->assertFalse($rowsAndColumnsReportWizardForm->hasErrors());
97  }
98 
99  public function testValidateFiltersStructureForError()
100  {
101  $rowsAndColumnsReportWizardForm = new RowsAndColumnsReportWizardForm();
102  $filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem',
104  $filter->attributeIndexOrDerivedType = 'createdDateTime';
105  $filter->operator = OperatorRules::TYPE_BETWEEN;
106  $filter->value = '2013-02-19 00:00';
107  $filter->secondValue = '2013-02-20 00:00';
108  $rowsAndColumnsReportWizardForm->filters = array($filter);
109  $rowsAndColumnsReportWizardForm->filtersStructure = '2';
110  $rowsAndColumnsReportWizardForm->validateFiltersStructure();
111  $errors = $rowsAndColumnsReportWizardForm->getErrors();
112  $compareErrors = array('filtersStructure' => array('The structure is invalid. Please use only integers less than 2.'));
113  $this->assertEquals($compareErrors, $errors);
114  $this->assertTrue($rowsAndColumnsReportWizardForm->hasErrors());
115  }
116 
117  public function testValidateDisplayAttributes()
118  {
119  $rowsAndColumnsReportWizardForm = new RowsAndColumnsReportWizardForm();
120  $reportModelTestItem = new ReportModelTestItem();
121  $reportModelTestItem->date = '2013-02-12';
122  $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule',
123  'ReportModelTestItem', Report::TYPE_ROWS_AND_COLUMNS);
124  $displayAttribute->setModelAliasUsingTableAliasName('model1');
125  $displayAttribute->attributeIndexOrDerivedType = 'date';
126  $rowsAndColumnsReportWizardForm->displayAttributes = array($displayAttribute);
127  $rowsAndColumnsReportWizardForm->validateDisplayAttributes();
128  $this->assertFalse($rowsAndColumnsReportWizardForm->hasErrors());
129  }
130 
131  public function testValidateDisplayAttributesForError()
132  {
133  $rowsAndColumnsReportWizardForm = new RowsAndColumnsReportWizardForm();
134  $rowsAndColumnsReportWizardForm->displayAttributes = array();
135  $content = $rowsAndColumnsReportWizardForm->validateDisplayAttributes();
136  $errors = $rowsAndColumnsReportWizardForm->getErrors();
137  $compareErrors = array('displayAttributes' => array('At least one display column must be selected'));
138  $this->assertEquals($compareErrors, $errors);
139  $this->assertTrue($rowsAndColumnsReportWizardForm->hasErrors());
140  }
141 
142  public function testValidateOrderBys()
143  {
144  $rowsAndColumnsReportWizardForm = new RowsAndColumnsReportWizardForm();
145  $orderBy = new OrderByForReportForm('ReportsTestModule', 'ReportModelTestItem',
147  $orderBy->attributeIndexOrDerivedType = 'modifiedDateTime';
148  $this->assertEquals('asc', $orderBy->order);
149  $orderBy->order = 'desc';
150  $rowsAndColumnsReportWizardForm->orderBys = array($orderBy);
151  $rowsAndColumnsReportWizardForm->validateOrderBys();
152  $this->assertFalse($rowsAndColumnsReportWizardForm->hasErrors());
153  }
154 
155  public function testValidateOrderBysForErrors()
156  {
157  $rowsAndColumnsReportWizardForm = new RowsAndColumnsReportWizardForm();
158  $orderBy = new OrderByForReportForm('ReportsTestModule', 'ReportModelTestItem',
160  $this->assertEquals('asc', $orderBy->order);
161  $orderBy->attributeIndexOrDerivedType = 'modifiedDateTime';
162  $orderBy->order = 'desc1';
163  $rowsAndColumnsReportWizardForm->orderBys = array($orderBy);
164  $rowsAndColumnsReportWizardForm->validateOrderBys();
165  $errors = $orderBy->getErrors();
166  $compareErrors = array('order' => array('Order must be asc or desc.'));
167  $this->assertEquals($compareErrors, $errors);
168  $this->assertTrue($rowsAndColumnsReportWizardForm->hasErrors());
169  }
170 
171  public function testValidateSpotConversionCurrencyCode()
172  {
173  $rowsAndColumnsReportWizardForm = new RowsAndColumnsReportWizardForm();
174  $rowsAndColumnsReportWizardForm->currencyConversionType = 2;
175  $rowsAndColumnsReportWizardForm->spotConversionCurrencyCode = 'CAD';
176  $rowsAndColumnsReportWizardForm->validateSpotConversionCurrencyCode();
177  $this->assertFalse($rowsAndColumnsReportWizardForm->hasErrors());
178  }
179 
180  public function testValidateSpotConversionCurrencyCodeForErrors()
181  {
182  $rowsAndColumnsReportWizardForm = new RowsAndColumnsReportWizardForm();
183  $rowsAndColumnsReportWizardForm->currencyConversionType = 3;
184  $rowsAndColumnsReportWizardForm->spotConversionCurrencyCode = null;
185  $rowsAndColumnsReportWizardForm->validateSpotConversionCurrencyCode();
186  $errors = $rowsAndColumnsReportWizardForm->getErrors();
187  $compareErrors = array('spotConversionCurrencyCode' => array('Spot Currency cannot be blank.'));
188  $this->assertEquals($compareErrors, $errors);
189  $this->assertTrue($rowsAndColumnsReportWizardForm->hasErrors());
190  }
191  }
192 ?>
static getByUsername($username)
Definition: User.php:49
const TYPE_ROWS_AND_COLUMNS
Definition: Report.php:51
Generated on Fri Feb 21 2020 07:10:36