Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SearchFormAttributesToSearchDataProviderMetadataUtilTest.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  $super = User::getByUsername('super');
44  Yii::app()->user->userModel = $super;
45  }
46 
47  public function testGetMetadata()
48  {
49  $super = User::getByUsername('super');
50  Yii::app()->user->userModel = $super;
51 
53  $metadata = SearchFormAttributesToSearchDataProviderMetadataUtil::getMetadata($searchForm, 'anyA', 'xyz');
54  $compareData = array(array('primaryA' => array('value' => array('name' => 'xyz'))),
55  array('secondaryA' => array('value' => array('name' => 'xyz'))));
56  $this->assertEquals($compareData, $metadata);
57 
58  $metadata = SearchFormAttributesToSearchDataProviderMetadataUtil::getMetadata($searchForm, 'ABName', 'abc');
59  $compareData = array(array('aName' => array('value' => 'abc')),
60  array('bName' => array('value' => 'abc')));
61  $this->assertEquals($compareData, $metadata);
62 
64  getMetadata($searchForm, 'differentOperatorA', '1');
65  $compareData = array(array('primaryA' => array('value' => array('name' => $super->id))));
66  $this->assertEquals($compareData, $metadata);
67 
69  getMetadata($searchForm, 'differentOperatorA', '');
70  $compareData = array(array('primaryA' => array('value' => array('name' => null))));
71  $this->assertEquals($compareData, $metadata);
72 
74  getMetadata($searchForm, 'differentOperatorB', 'def');
75  $compareData = array(array('aName' => array('value' => 'def', 'operatorType' => 'endsWith')));
76  $this->assertEquals($compareData, $metadata);
77  }
78 
79  public function testGetMetadataForDynamicDateAttribute()
80  {
81  $super = User::getByUsername('super');
82  Yii::app()->user->userModel = $super;
83 
85 
86  //TEST when no value present
88  getMetadata($searchForm, 'date__Date', null);
89  $compareData = array(array('date' => array('value' => null)));
90  $this->assertEquals($compareData, $metadata);
91 
92  //Test Date = Today
93  $value = array();
94  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY;
96  getMetadata($searchForm, 'date__Date', $value);
97  $todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
98  $today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
99  $todayDateTime->getTimeStamp());
100  $compareData = array(array('date' => array('value' => $today, 'operatorType' => 'equals')));
101  $this->assertEquals($compareData, $metadata);
102 
103  //Test Date = Tomorrow
104  $value = array();
105  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_TOMORROW;
107  getMetadata($searchForm, 'date__Date', $value);
108  $tomorrowDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
109  $tomorrow = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
110  $tomorrowDateTime->getTimeStamp() + (60 * 60 *24));
111  $compareData = array(array('date' => array('value' => $tomorrow, 'operatorType' => 'equals')));
112  $this->assertEquals($compareData, $metadata);
113 
114  //Test Date = Yesterday
115  $value = array();
116  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_YESTERDAY;
118  getMetadata($searchForm, 'date__Date', $value);
119  $yesterdayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
120  $yesterday = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
121  $yesterdayDateTime->getTimeStamp() - (60 * 60 *24));
122  $compareData = array(array('date' => array('value' => $yesterday, 'operatorType' => 'equals')));
123  $this->assertEquals($compareData, $metadata);
124 
125  //Test Date = After X
126  $value = array();
127  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER;
128  $value['firstDate'] = '2011-05-05';
130  getMetadata($searchForm, 'date__Date', $value);
131  $compareData = array(array('date' => array('value' => '2011-05-05',
132  'operatorType' => 'greaterThanOrEqualTo')));
133  $this->assertEquals($compareData, $metadata);
134 
135  //Test Date = Before X
136  $value = array();
137  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_BEFORE;
138  $value['firstDate'] = '2011-05-04';
140  getMetadata($searchForm, 'date__Date', $value);
141  $compareData = array(array('date' => array('value' => '2011-05-04',
142  'operatorType' => 'lessThanOrEqualTo')));
143  $this->assertEquals($compareData, $metadata);
144 
145  //Test Date = On X
146  $value = array();
147  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_ON;
148  $value['firstDate'] = '2011-05-04';
150  getMetadata($searchForm, 'date__Date', $value);
151  $compareData = array(array('date' => array('value' => '2011-05-04',
152  'operatorType' => 'equals')));
153  $this->assertEquals($compareData, $metadata);
154 
155  //Test Date = Between X and Y
156  $value = array();
157  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_BETWEEN;
158  $value['firstDate'] = '2011-05-04';
159  $value['secondDate'] = '2011-06-04';
161  getMetadata($searchForm, 'date__Date', $value);
162  $compareData = array(array('date' => array('value' => '2011-05-04',
163  'operatorType' => 'greaterThanOrEqualTo',
164  'appendStructureAsAnd' => true)),
165  array('date' => array('value' => '2011-06-04',
166  'operatorType' => 'lessThanOrEqualTo',
167  'appendStructureAsAnd' => true)));
168  $this->assertEquals($compareData, $metadata);
169 
170  //Test Date next 7 days
171  $value = array();
172  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_NEXT_7_DAYS;
174  getMetadata($searchForm, 'date__Date', $value);
175  $todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
176  $today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
177  $todayDateTime->getTimeStamp());
178  $compareData = array(array('date' => array('value' => $today,
179  'operatorType' => 'greaterThanOrEqualTo',
180  'appendStructureAsAnd' => true)),
181  array('date' => array('value' => MixedDateTypesSearchFormAttributeMappingRules::
182  calculateNewDateByDaysFromNow(7),
183  'operatorType' => 'lessThanOrEqualTo',
184  'appendStructureAsAnd' => true)));
185  $this->assertEquals($compareData, $metadata);
186 
187  //Test Date last 7 days
188  $value = array();
189  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_LAST_7_DAYS;
191  getMetadata($searchForm, 'date__Date', $value);
192  $todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
193  $today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
194  $todayDateTime->getTimeStamp());
195  $compareData = array(array('date' => array('value' => MixedDateTypesSearchFormAttributeMappingRules::
196  calculateNewDateByDaysFromNow(-7),
197  'operatorType' => 'greaterThanOrEqualTo',
198  'appendStructureAsAnd' => true)),
199  array('date' => array('value' => $today,
200  'operatorType' => 'lessThanOrEqualTo',
201  'appendStructureAsAnd' => true)));
202  $this->assertEquals($compareData, $metadata);
203  }
204 
205  public function testGetMetadataForDynamicDateTimeAttribute()
206  {
207  $super = User::getByUsername('super');
208  Yii::app()->user->userModel = $super;
209 
211 
212  //Make sure the timeZone is different than UTC for testing.
213  Yii::app()->user->userModel->timeZone = 'America/Chicago';
214 
215  //TEST when no value present
217  getMetadata($searchForm, 'dateTime__DateTime', null);
218  $compareData = array(array('dateTime' => array('value' => null)));
219  $this->assertEquals($compareData, $metadata);
220 
221  //Test Date = Today
222  $value = array();
223  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY;
225  getMetadata($searchForm, 'dateTime__DateTime', $value);
226  $todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
227  $today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
228  $todayDateTime->getTimeStamp());
229  $compareData = array(
230  array('dateTime' =>
231  array('value' =>
233  'operatorType' => 'greaterThanOrEqualTo',
234  'appendStructureAsAnd' => true)),
235  array('dateTime' =>
236  array('value' =>
238  'operatorType' => 'lessThanOrEqualTo',
239  'appendStructureAsAnd' => true)));
240  $this->assertEquals($compareData, $metadata);
241 
242  //Test Date = Tomorrow
243  $value = array();
244  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_TOMORROW;
246  getMetadata($searchForm, 'dateTime__DateTime', $value);
247  $tomorrowDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
248  $tomorrow = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
249  $tomorrowDateTime->getTimeStamp() + (60 * 60 *24));
250  $compareData = array(
251  array('dateTime' =>
252  array('value' =>
254  'operatorType' => 'greaterThanOrEqualTo',
255  'appendStructureAsAnd' => true)),
256  array('dateTime' =>
257  array('value' =>
259  'operatorType' => 'lessThanOrEqualTo',
260  'appendStructureAsAnd' => true)));
261  $this->assertEquals($compareData, $metadata);
262 
263  //Test Date = Yesterday
264  $value = array();
265  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_YESTERDAY;
267  getMetadata($searchForm, 'dateTime__DateTime', $value);
268  $yesterdayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
269  $yesterday = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
270  $yesterdayDateTime->getTimeStamp() - (60 * 60 *24));
271  $compareData = array(
272  array('dateTime' =>
273  array('value' =>
275  'operatorType' => 'greaterThanOrEqualTo',
276  'appendStructureAsAnd' => true)),
277  array('dateTime' =>
278  array('value' =>
280  'operatorType' => 'lessThanOrEqualTo',
281  'appendStructureAsAnd' => true)));
282  $this->assertEquals($compareData, $metadata);
283 
284  //Test Date = After X
285  $value = array();
286  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER;
287  $value['firstDate'] = '2011-05-05';
289  getMetadata($searchForm, 'dateTime__DateTime', $value);
290  $compareData = array(
291  array('dateTime' =>
292  array('value' => DateTimeUtil::
293  convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay('2011-05-05'),
294  'operatorType' => 'greaterThanOrEqualTo')));
295  $this->assertEquals($compareData, $metadata);
296 
297  //Test Date = Before X
298  $value = array();
299  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_BEFORE;
300  $value['firstDate'] = '2011-05-04';
302  getMetadata($searchForm, 'dateTime__DateTime', $value);
303  $compareData = array(
304  array('dateTime' =>
305  array('value' => DateTimeUtil::
306  convertDateIntoTimeZoneAdjustedDateTimeEndOfDay('2011-05-04'),
307  'operatorType' => 'lessThanOrEqualTo')));
308  $this->assertEquals($compareData, $metadata);
309 
310  //Test Date next 7 days
311  $value = array();
312  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_NEXT_7_DAYS;
314  getMetadata($searchForm, 'dateTime__DateTime', $value);
315  $todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
316  $today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
317  $todayDateTime->getTimeStamp());
319  $compareData = array(
320  array('dateTime' =>
321  array('value' =>
323  'operatorType' => 'greaterThanOrEqualTo',
324  'appendStructureAsAnd' => true)),
325  array('dateTime' =>
326  array('value' =>
328  'operatorType' => 'lessThanOrEqualTo',
329  'appendStructureAsAnd' => true)));
330  $this->assertEquals($compareData, $metadata);
331 
332  //Test Date last 7 days
333  $value = array();
334  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_LAST_7_DAYS;
336  getMetadata($searchForm, 'dateTime__DateTime', $value);
337  $todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
338  $today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
339  $todayDateTime->getTimeStamp());
341  $compareData = array(
342  array('dateTime' =>
343  array('value' =>
345  'operatorType' => 'greaterThanOrEqualTo',
346  'appendStructureAsAnd' => true)),
347  array('dateTime' =>
348  array('value' =>
350  'operatorType' => 'lessThanOrEqualTo',
351  'appendStructureAsAnd' => true)));
352  $this->assertEquals($compareData, $metadata);
353  }
354 
355  public function testGetMetadataForDynamicDateTimeAttributeThatIsOnManyRelatedModel()
356  {
357  $super = User::getByUsername('super');
358  Yii::app()->user->userModel = $super;
359 
361 
362  //Make sure the timeZone is different than UTC for testing.
363  Yii::app()->user->userModel->timeZone = 'America/Chicago';
364 
365  //TEST when no value present
367  getMetadata($searchForm, 'dateDateTimeADate__Date', null);
368  $compareData = array(array('manyMany' => array('value' => array('aDate' => null))));
369  $this->assertEquals($compareData, $metadata);
370 
371  //Test Date = Today
372  $value = array();
373  $value['type'] = MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY;
375  getMetadata($searchForm, 'dateDateTimeADateTime__DateTime', $value);
376  $todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
377  $today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
378  $todayDateTime->getTimeStamp());
379  $compareData = array(
380  array('manyMany' =>
381  array('value' => array(
383  'operatorType' => 'greaterThanOrEqualTo',
384  'appendStructureAsAnd' => true)),
385  array('manyMany' =>
386  array('value' => array(
388  'operatorType' => 'lessThanOrEqualTo',
389  'appendStructureAsAnd' => true)));
390  $this->assertEquals($compareData, $metadata);
391  }
392  }
393 ?>
static getByUsername($username)
Definition: User.php:49
static convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($dateValue)
static convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($dateValue)
Generated on Wed Jul 1 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.