Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SearchDataProviderMetadataAdapterTest.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 testEmptyConcatedValue()
48  {
49  $super = User::getByUsername('super');
50  Yii::app()->user->userModel = $super;
51  $searchAttributes = array(
52  'concatedName' => null, //should resolve to no clause
53  );
54  $metadataAdapter = new SearchDataProviderMetadataAdapter(
55  new AAASearchFormTestModel(new AAA(false)),
56  1,
57  $searchAttributes
58  );
59  $metadata = $metadataAdapter->getAdaptedMetadata();
60  $compareStructure = '';
61  $this->assertEquals(array(), $metadata['clauses']);
62  $this->assertEquals($compareStructure, $metadata['structure']);
63  }
64 
65  public function testSearchingOnACustomFieldWithMultipleValues()
66  {
67  $searchAttributes = array(
68  'industry' => array(
69  'value' => array('A', 'B', 'C'),
70  )
71  );
72  $metadataAdapter = new SearchDataProviderMetadataAdapter(
73  new TestCustomFieldsModel(false),
74  1,
75  $searchAttributes
76  );
77  $metadata = $metadataAdapter->getAdaptedMetadata();
78  $compareClauses = array(
79  1 => array(
80  'attributeName' => 'industry',
81  'relatedAttributeName' => 'value',
82  'operatorType' => 'oneOf',
83  'value' => array('A', 'B', 'C'),
84  ),
85  );
86  $compareStructure = '1';
87  $this->assertEquals($compareClauses, $metadata['clauses']);
88  $this->assertEquals($compareStructure, $metadata['structure']);
89  }
90 
91  public function testSearchingOnACustomFieldWithMultipleValuesWhereWithEmptyValueSpecified()
92  {
93  $searchAttributes = array(
94  'industry' => array(
95  'value' => array(''),
96  )
97  );
98  $metadataAdapter = new SearchDataProviderMetadataAdapter(
99  new TestCustomFieldsModel(false),
100  1,
101  $searchAttributes
102  );
103  $metadata = $metadataAdapter->getAdaptedMetadata();
104  $compareClauses = array();
105  $compareStructure = null;
106  $this->assertEquals($compareClauses, $metadata['clauses']);
107  $this->assertEquals($compareStructure, $metadata['structure']);
108  }
109 
110  public function testGetAdaptedMetadataForhasManyRelationAttributes()
111  {
112  $super = User::getByUsername('super');
113  Yii::app()->user->userModel = $super;
114 
115  $searchAttributes = array(
116  'ks' => array(
117  'kMember' => 'some Value',
118  )
119  );
120  $metadataAdapter = new SearchDataProviderMetadataAdapter(
121  new I(false),
122  1,
123  $searchAttributes
124  );
125  $metadata = $metadataAdapter->getAdaptedMetadata();
126  $compareClauses = array(
127  1 => array(
128  'attributeName' => 'ks',
129  'relatedAttributeName' => 'kMember',
130  'operatorType' => 'startsWith',
131  'value' => 'some Value',
132  ),
133  );
134 
135  $compareStructure = '1';
136  $this->assertEquals($compareClauses, $metadata['clauses']);
137  $this->assertEquals($compareStructure, $metadata['structure']);
138  }
139 
140  public function testSearchFormDynamicAttributesForRelatedManyManyDateTimeAttributes()
141  {
142  $super = User::getByUsername('super');
143  Yii::app()->user->userModel = $super;
144 
145  $searchAttributes = array(
146  'dateDateTimeADate__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER,
147  'firstDate' => '1993-04-04'),
148  'dateDateTimeADateTime__DateTime' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY),
149  );
151  $this->assertTrue($searchForm->isAttributeOnForm('dateDateTimeADate__Date'));
152  $metadataAdapter = new SearchDataProviderMetadataAdapter(
153  $searchForm,
154  $super->id,
155  $searchAttributes
156  );
157  $todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
158  $today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
159  $todayDateTime->getTimeStamp());
161  $metadata = $metadataAdapter->getAdaptedMetadata();
162  $compareClauses = array(
163  1 => array(
164  'attributeName' => 'manyMany',
165  'relatedAttributeName' => 'aDate',
166  'operatorType' => 'greaterThanOrEqualTo',
167  'value' => '1993-04-04',
168  ),
169  2 => array(
170  'attributeName' => 'manyMany',
171  'relatedAttributeName' => 'aDateTime',
172  'operatorType' => 'greaterThanOrEqualTo',
173  'value' => DateTimeUtil::
174  convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($today),
175  ),
176  3 => array(
177  'attributeName' => 'manyMany',
178  'relatedAttributeName' => 'aDateTime',
179  'operatorType' => 'lessThanOrEqualTo',
180  'value' => DateTimeUtil::
181  convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($today),
182  ),
183  );
184 
185  $compareStructure = '(1) and (2 and 3)';
186  $this->assertEquals($compareClauses, $metadata['clauses']);
187  $this->assertEquals($compareStructure, $metadata['structure']);
188  }
189 
190  public function testAdaptingBooleanValues()
191  {
192  $super = User::getByUsername('super');
193  Yii::app()->user->userModel = $super;
194  //Test with blank values for boolean on model and on related model.
195  //Will treat as '0'. Normally you would sanitize $searchAttributes so that this
196  //would be removed before passing into the adapter.
197  $searchAttributes = array(
198  'bool' => '',
199  'a' => array('a' => ''),
200  );
201  $metadataAdapter = new SearchDataProviderMetadataAdapter(
202  new TestBooleanAttributeModel(false),
203  1,
204  $searchAttributes
205  );
206  $metadata = $metadataAdapter->getAdaptedMetadata();
207  $compareClauses = array(
208  1 => array(
209  'attributeName' => 'bool',
210  'operatorType' => 'equals',
211  'value' => '0',
212  ),
213  2 => array(
214  'attributeName' => 'bool',
215  'operatorType' => 'isNull',
216  'value' => null,
217  ),
218  3 => array(
219  'attributeName' => 'a',
220  'relatedAttributeName' => 'a',
221  'operatorType' => 'equals',
222  'value' => '0',
223  ),
224  4 => array(
225  'attributeName' => 'a',
226  'relatedAttributeName' => 'a',
227  'operatorType' => 'isNull',
228  'value' => null,
229  ),
230  );
231  $compareStructure = '(1 or 2) and (3 or 4)';
232  $this->assertEquals($compareClauses, $metadata['clauses']);
233  $this->assertEquals($compareStructure, $metadata['structure']);
234 
235  $searchAttributes = array(
236  'bool' => false,
237  );
238  $metadataAdapter = new SearchDataProviderMetadataAdapter(
239  new TestBooleanAttributeModel(false),
240  1,
241  $searchAttributes
242  );
243  $metadata = $metadataAdapter->getAdaptedMetadata();
244  $compareClauses = array(
245  1 => array(
246  'attributeName' => 'bool',
247  'operatorType' => 'equals',
248  'value' => '0',
249  ),
250  2 => array(
251  'attributeName' => 'bool',
252  'operatorType' => 'isNull',
253  'value' => null,
254  )
255  );
256  $compareStructure = '(1 or 2)';
257  $this->assertEquals($compareClauses, $metadata['clauses']);
258  $this->assertEquals($compareStructure, $metadata['structure']);
259  //Now test with populated as '0'
260  $searchAttributes = array(
261  'bool' => '0',
262  'a' => array('a' => '0'),
263  );
264  $metadataAdapter = new SearchDataProviderMetadataAdapter(
265  new TestBooleanAttributeModel(false),
266  1,
267  $searchAttributes
268  );
269  $metadata = $metadataAdapter->getAdaptedMetadata();
270  $compareClauses = array(
271  1 => array(
272  'attributeName' => 'bool',
273  'operatorType' => 'equals',
274  'value' => '0',
275  ),
276  2 => array(
277  'attributeName' => 'bool',
278  'operatorType' => 'isNull',
279  'value' => null,
280  ),
281  3 => array(
282  'attributeName' => 'a',
283  'relatedAttributeName' => 'a',
284  'operatorType' => 'equals',
285  'value' => '0',
286  ),
287  4 => array(
288  'attributeName' => 'a',
289  'relatedAttributeName' => 'a',
290  'operatorType' => 'isNull',
291  'value' => null,
292  ),
293  );
294  $compareStructure = '(1 or 2) and (3 or 4)';
295  $this->assertEquals($compareClauses, $metadata['clauses']);
296  $this->assertEquals($compareStructure, $metadata['structure']);
297 
298  //Now test with populated as '1'
299  $searchAttributes = array(
300  'bool' => '1',
301  'a' => array('a' => '1'),
302  );
303  $metadataAdapter = new SearchDataProviderMetadataAdapter(
304  new TestBooleanAttributeModel(false),
305  1,
306  $searchAttributes
307  );
308  $metadata = $metadataAdapter->getAdaptedMetadata();
309  $compareClauses = array(
310  1 => array(
311  'attributeName' => 'bool',
312  'operatorType' => 'equals',
313  'value' => (bool)1,
314  ),
315  2 => array(
316  'attributeName' => 'a',
317  'relatedAttributeName' => 'a',
318  'operatorType' => 'equals',
319  'value' => (bool)1,
320  ),
321  );
322  $compareStructure = '1 and 2';
323  $this->assertEquals($compareClauses, $metadata['clauses']);
324  $this->assertEquals($compareStructure, $metadata['structure']);
325  }
326 
327  public function testAdaptingBooleanValuesWithSearchForms()
328  {
329  $super = User::getByUsername('super');
330  Yii::app()->user->userModel = $super;
331  //Test with blank values for boolean on model and on related model.
332  //Will treat as '0'. Normally you would sanitize $searchAttributes so that this
333  //would be removed before passing into the adapter.
334  $searchAttributes = array(
335  'aaaBoolean' => '',
336  );
337  $metadataAdapter = new SearchDataProviderMetadataAdapter(
338  new AAASearchFormTestModel(new AAA()),
339  1,
340  $searchAttributes
341  );
342  $metadata = $metadataAdapter->getAdaptedMetadata();
343  $compareClauses = array(
344  1 => array(
345  'attributeName' => 'aaaBoolean',
346  'operatorType' => 'equals',
347  'value' => '0',
348  ),
349  2 => array(
350  'attributeName' => 'aaaBoolean',
351  'operatorType' => 'isNull',
352  'value' => null,
353  ),
354  );
355  $compareStructure = '(1 or 2)';
356  $this->assertEquals($compareClauses, $metadata['clauses']);
357  $this->assertEquals($compareStructure, $metadata['structure']);
358 
359  $searchAttributes = array(
360  'aaaBoolean' => false,
361  );
362  $metadataAdapter = new SearchDataProviderMetadataAdapter(
363  new AAASearchFormTestModel(new AAA()),
364  1,
365  $searchAttributes
366  );
367  $metadata = $metadataAdapter->getAdaptedMetadata();
368  $compareClauses = array(
369  1 => array(
370  'attributeName' => 'aaaBoolean',
371  'operatorType' => 'equals',
372  'value' => '0',
373  ),
374  2 => array(
375  'attributeName' => 'aaaBoolean',
376  'operatorType' => 'isNull',
377  'value' => null,
378  ),
379  );
380  $compareStructure = '(1 or 2)';
381  $this->assertEquals($compareClauses, $metadata['clauses']);
382  $this->assertEquals($compareStructure, $metadata['structure']);
383  //Now test with populated as '0'
384  $searchAttributes = array(
385  'aaaBoolean' => '0',
386  );
387  $metadataAdapter = new SearchDataProviderMetadataAdapter(
388  new AAASearchFormTestModel(new AAA()),
389  1,
390  $searchAttributes
391  );
392  $metadata = $metadataAdapter->getAdaptedMetadata();
393  $compareClauses = array(
394  1 => array(
395  'attributeName' => 'aaaBoolean',
396  'operatorType' => 'equals',
397  'value' => '0',
398  ),
399  2 => array(
400  'attributeName' => 'aaaBoolean',
401  'operatorType' => 'isNull',
402  'value' => null,
403  ),
404  );
405  $compareStructure = '(1 or 2)';
406  $this->assertEquals($compareClauses, $metadata['clauses']);
407  $this->assertEquals($compareStructure, $metadata['structure']);
408 
409  //Now test with populated as '1'
410  $searchAttributes = array(
411  'aaaBoolean' => '1',
412  );
413  $metadataAdapter = new SearchDataProviderMetadataAdapter(
414  new AAASearchFormTestModel(new AAA()),
415  1,
416  $searchAttributes
417  );
418  $metadata = $metadataAdapter->getAdaptedMetadata();
419  $compareClauses = array(
420  1 => array(
421  'attributeName' => 'aaaBoolean',
422  'operatorType' => 'equals',
423  'value' => (bool)1,
424  ),
425  );
426  $compareStructure = '1';
427  $this->assertEquals($compareClauses, $metadata['clauses']);
428  $this->assertEquals($compareStructure, $metadata['structure']);
429  }
430 
431  public function testGetAdaptedMetadata()
432  {
433  $super = User::getByUsername('super');
434  Yii::app()->user->userModel = $super;
435 
436  $searchAttributes = array(
437  'name' => 'Vomitorio Corp',
438  'officePhone' => '5',
439  'billingAddress' => array(
440  'street1' => null,
441  'street2' => 'Suite 101',
442  )
443  );
444  $metadataAdapter = new SearchDataProviderMetadataAdapter(
445  new Account(false),
446  1,
447  $searchAttributes
448  );
449  $metadata = $metadataAdapter->getAdaptedMetadata();
450  $compareClauses = array(
451  1 => array(
452  'attributeName' => 'name',
453  'operatorType' => 'startsWith',
454  'value' => 'Vomitorio Corp',
455  ),
456  2 => array(
457  'attributeName' => 'officePhone',
458  'operatorType' => 'startsWith',
459  'value' => 5,
460  ),
461  3 => array(
462  'attributeName' => 'billingAddress',
463  'relatedAttributeName' => 'street2',
464  'operatorType' => 'startsWith',
465  'value' => 'Suite 101',
466  ),
467  );
468  $compareStructure = '1 and 2 and 3';
469  $this->assertEquals($compareClauses, $metadata['clauses']);
470  $this->assertEquals($compareStructure, $metadata['structure']);
471  }
472 
473  public function testSearchingOnMultipleValuesCustomFields()
474  {
475  $searchAttributes = array(
476  'multipleIndustries' => array(
477  'values' => array('Something'),
478  )
479  );
480  $metadataAdapter = new SearchDataProviderMetadataAdapter(
481  new TestCustomFieldsModel(false),
482  1,
483  $searchAttributes
484  );
485  $metadata = $metadataAdapter->getAdaptedMetadata();
486  $compareClauses = array(
487  1 => array(
488  'attributeName' => 'multipleIndustries',
489  'relatedAttributeName' => 'values',
490  'operatorType' => 'oneOf',
491  'value' => array('Something'),
492  ),
493  );
494  $compareStructure = '1';
495  $this->assertEquals($compareClauses, $metadata['clauses']);
496  $this->assertEquals($compareStructure, $metadata['structure']);
497  }
498 
499  public function testSearchingOnMultipleValuesCustomFieldsWithVariousNullOrEmptyValues()
500  {
501  $searchAttributes = array(
502  'multipleIndustries' => array(
503  'values' => array(0 => null),
504  )
505  );
506  $metadataAdapter = new SearchDataProviderMetadataAdapter(
507  new TestCustomFieldsModel(false),
508  1,
509  $searchAttributes
510  );
511  $metadata = $metadataAdapter->getAdaptedMetadata();
512  $this->assertEquals(array(), $metadata['clauses']);
513  $this->assertEquals(null, $metadata['structure']);
514 
515  $searchAttributes = array(
516  'multipleIndustries' => array(
517  'values' => null,
518  )
519  );
520  $metadataAdapter = new SearchDataProviderMetadataAdapter(
521  new TestCustomFieldsModel(false),
522  1,
523  $searchAttributes
524  );
525  $metadata = $metadataAdapter->getAdaptedMetadata();
526  $this->assertEquals(array(), $metadata['clauses']);
527  $this->assertEquals(null, $metadata['structure']);
528 
529  $searchAttributes = array(
530  'multipleIndustries' => array(
531  'values' => array(0 => ''),
532  )
533  );
534  $metadataAdapter = new SearchDataProviderMetadataAdapter(
535  new TestCustomFieldsModel(false),
536  1,
537  $searchAttributes
538  );
539  $metadata = $metadataAdapter->getAdaptedMetadata();
540  $this->assertEquals(array(), $metadata['clauses']);
541  $this->assertEquals(null, $metadata['structure']);
542  }
543 
544  public function testGetAdaptedMetadataUsingOrClause()
545  {
546  $super = User::getByUsername('super');
547  Yii::app()->user->userModel = $super;
548 
549  $searchAttributes = array(
550  'name' => 'Vomitorio Corp',
551  'officePhone' => '5',
552  'billingAddress' => array(
553  'street1' => null,
554  'street2' => 'Suite 101',
555  )
556  );
557  $metadataAdapter = new SearchDataProviderMetadataAdapter(
558  new Account(false),
559  1,
560  $searchAttributes
561  );
562  $metadata = $metadataAdapter->getAdaptedMetadata(false);
563  $compareClauses = array(
564  1 => array(
565  'attributeName' => 'name',
566  'operatorType' => 'startsWith',
567  'value' => 'Vomitorio Corp',
568  ),
569  2 => array(
570  'attributeName' => 'officePhone',
571  'operatorType' => 'startsWith',
572  'value' => 5,
573  ),
574  3 => array(
575  'attributeName' => 'billingAddress',
576  'relatedAttributeName' => 'street2',
577  'operatorType' => 'startsWith',
578  'value' => 'Suite 101',
579  ),
580  );
581 
582  $compareStructure = '(1 or 2 or 3)';
583  $this->assertEquals($compareClauses, $metadata['clauses']);
584  $this->assertEquals($compareStructure, $metadata['structure']);
585  }
586 
587  public function testSearchFormAttributesAreAdaptedProperly()
588  {
589  $super = User::getByUsername('super');
590  Yii::app()->user->userModel = $super;
591 
592  $searchAttributes = array(
593  'ABName' => null,
594  'anyA' => null,
595  );
597  $metadataAdapter = new SearchDataProviderMetadataAdapter(
598  $searchForm,
599  $super->id,
600  $searchAttributes
601  );
602  $metadata = $metadataAdapter->getAdaptedMetadata();
603  $compareClauses = array();
604 
605  $compareStructure = null;
606  $this->assertEquals($compareClauses, $metadata['clauses']);
607  $this->assertEquals($compareStructure, $metadata['structure']);
608 
609  //Now put values in for the search.
610  $searchAttributes = array(
611  'ABName' => 'something',
612  'anyA' => 'nothing',
613  );
615  $metadataAdapter = new SearchDataProviderMetadataAdapter(
616  $searchForm,
617  $super->id,
618  $searchAttributes
619  );
620  $metadata = $metadataAdapter->getAdaptedMetadata();
621  $compareClauses = array(
622  1 => array(
623  'attributeName' => 'aName',
624  'operatorType' => 'startsWith',
625  'value' => 'something',
626  ),
627  2 => array(
628  'attributeName' => 'bName',
629  'operatorType' => 'startsWith',
630  'value' => 'something',
631  ),
632  3 => array(
633  'attributeName' => 'primaryA',
634  'relatedAttributeName' => 'name',
635  'operatorType' => 'startsWith',
636  'value' => 'nothing',
637  ),
638  4 => array(
639  'attributeName' => 'secondaryA',
640  'relatedAttributeName' => 'name',
641  'operatorType' => 'startsWith',
642  'value' => 'nothing',
643  ),
644  );
645 
646  $compareStructure = '(1 or 2) and (3 or 4)';
647  $this->assertEquals($compareClauses, $metadata['clauses']);
648  $this->assertEquals($compareStructure, $metadata['structure']);
649  }
650 
651  public function testOwnedItemsOnlyAttribute()
652  {
653  $super = User::getByUsername('super');
654  Yii::app()->user->userModel = $super;
655 
656  //Try where the value for differentOperatorA is specified (Checkbox is checked)
657  $searchAttributes = array(
658  'differentOperatorA' => '1',
659  );
661  $metadataAdapter = new SearchDataProviderMetadataAdapter(
662  $searchForm,
663  $super->id,
664  $searchAttributes
665  );
666  $metadata = $metadataAdapter->getAdaptedMetadata();
667  $compareClauses = array(
668  1 => array(
669  'attributeName' => 'primaryA',
670  'relatedAttributeName' => 'name',
671  'operatorType' => 'startsWith',
672  'value' => $super->id,
673  ),
674  );
675 
676  $compareStructure = '(1)';
677  $this->assertEquals($compareClauses, $metadata['clauses']);
678  $this->assertEquals($compareStructure, $metadata['structure']);
679 
680  //Now try where the value for differentOperatorA is not specified (Checkbox not checked)
681  $searchAttributes = array(
682  'differentOperatorA' => '',
683  );
685  $metadataAdapter = new SearchDataProviderMetadataAdapter(
686  $searchForm,
687  $super->id,
688  $searchAttributes
689  );
690  $metadata = $metadataAdapter->getAdaptedMetadata();
691  $compareClauses = array();
692  $compareStructure = null;
693  $this->assertEquals($compareClauses, $metadata['clauses']);
694  $this->assertEquals($compareStructure, $metadata['structure']);
695  }
696 
697  public function testCustomOperatorTypeOnAttribute()
698  {
699  $super = User::getByUsername('super');
700  Yii::app()->user->userModel = $super;
701 
702  $searchAttributes = array(
703  'differentOperatorB' => 'something',
704  );
706  $metadataAdapter = new SearchDataProviderMetadataAdapter(
707  $searchForm,
708  $super->id,
709  $searchAttributes
710  );
711  $metadata = $metadataAdapter->getAdaptedMetadata();
712  $compareClauses = array(
713  1 => array(
714  'attributeName' => 'aName',
715  'operatorType' => 'endsWith',
716  'value' => 'something',
717  ),
718  );
719 
720  $compareStructure = '(1)';
721  $this->assertEquals($compareClauses, $metadata['clauses']);
722  $this->assertEquals($compareStructure, $metadata['structure']);
723  }
724 
725  public function testSearchFormDynamicAttributes()
726  {
727  $super = User::getByUsername('super');
728  Yii::app()->user->userModel = $super;
729 
730  $searchAttributes = array(
731  'date__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER,
732  'firstDate' => '1991-03-04'),
733  'dateTime__DateTime' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY),
734  'dateTime2__DateTime' => array('value' => null)
735  );
737  $metadataAdapter = new SearchDataProviderMetadataAdapter(
738  $searchForm,
739  $super->id,
740  $searchAttributes
741  );
742  $todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
743  $today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
744  $todayDateTime->getTimeStamp());
746  $metadata = $metadataAdapter->getAdaptedMetadata();
747  $compareClauses = array(
748  1 => array(
749  'attributeName' => 'date',
750  'operatorType' => 'greaterThanOrEqualTo',
751  'value' => '1991-03-04',
752  ),
753  2 => array(
754  'attributeName' => 'dateTime',
755  'operatorType' => 'greaterThanOrEqualTo',
756  'value' => DateTimeUtil::
757  convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($today),
758  ),
759  3 => array(
760  'attributeName' => 'dateTime',
761  'operatorType' => 'lessThanOrEqualTo',
762  'value' => DateTimeUtil::
763  convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($today),
764  ),
765  );
766 
767  $compareStructure = '(1) and (2 and 3)';
768  $this->assertEquals($compareClauses, $metadata['clauses']);
769  $this->assertEquals($compareStructure, $metadata['structure']);
770  }
771 
772  public function testSearchFormDynamicAttributesBetweenAndOnDateSearch()
773  {
774  $super = User::getByUsername('super');
775  Yii::app()->user->userModel = $super;
776 
777  $searchAttributes = array(
778  'date__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_ON,
779  'firstDate' => '1991-03-04'),
780  'date2__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_BETWEEN,
781  'firstDate' => '1991-03-05',
782  'secondDate' => '1992-04-04'),
783  );
785  $metadataAdapter = new SearchDataProviderMetadataAdapter(
786  $searchForm,
787  $super->id,
788  $searchAttributes
789  );
790  $metadata = $metadataAdapter->getAdaptedMetadata();
791  $compareClauses = array(
792  1 => array(
793  'attributeName' => 'date',
794  'operatorType' => 'equals',
795  'value' => '1991-03-04',
796  ),
797  2 => array(
798  'attributeName' => 'date2',
799  'operatorType' => 'greaterThanOrEqualTo',
800  'value' => '1991-03-05',
801  ),
802  3 => array(
803  'attributeName' => 'date2',
804  'operatorType' => 'lessThanOrEqualTo',
805  'value' => '1992-04-04',
806  ),
807  );
808 
809  $compareStructure = '(1) and (2 and 3)';
810  $this->assertEquals($compareClauses, $metadata['clauses']);
811  $this->assertEquals($compareStructure, $metadata['structure']);
812  }
813 
814  public function testSearchFormDynamicAttributesTodayAndBeforeTodayDateSearch()
815  {
816  $super = User::getByUsername('super');
817  Yii::app()->user->userModel = $super;
818 
819  $searchAttributes = array(
820  'date__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY),
821  'date2__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_BEFORE_TODAY),
822  );
824  $metadataAdapter = new SearchDataProviderMetadataAdapter(
825  $searchForm,
826  $super->id,
827  $searchAttributes
828  );
829  $metadata = $metadataAdapter->getAdaptedMetadata();
831  new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser())));
832  $compareClauses = array(
833  1 => array(
834  'attributeName' => 'date',
835  'operatorType' => 'equals',
836  'value' => $today,
837  ),
838  2 => array(
839  'attributeName' => 'date2',
840  'operatorType' => 'lessThan',
841  'value' => $today,
842  ),
843  );
844 
845  $compareStructure = '(1) and (2)';
846  $this->assertEquals($compareClauses, $metadata['clauses']);
847  $this->assertEquals($compareStructure, $metadata['structure']);
848  }
849 
850  public function testSearchFormDynamicAttributesBetweenAndOnDateTimeSearch()
851  {
852  $super = User::getByUsername('super');
853  Yii::app()->user->userModel = $super;
854 
855  $searchAttributes = array(
856  'dateTime__DateTime' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_ON,
857  'firstDate' => '1991-03-04'),
858  'dateTime2__DateTime' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_BETWEEN,
859  'firstDate' => '1991-03-05',
860  'secondDate' => '1992-04-04'),
861  );
863  $metadataAdapter = new SearchDataProviderMetadataAdapter(
864  $searchForm,
865  $super->id,
866  $searchAttributes
867  );
868  $metadata = $metadataAdapter->getAdaptedMetadata();
869  $compareClauses = array(
870  1 => array(
871  'attributeName' => 'dateTime',
872  'operatorType' => 'greaterThanOrEqualTo',
873  'value' => '1991-03-04 00:00:00',
874  ),
875  2 => array(
876  'attributeName' => 'dateTime',
877  'operatorType' => 'lessThanOrEqualTo',
878  'value' => '1991-03-04 23:59:59',
879  ),
880  3 => array(
881  'attributeName' => 'dateTime2',
882  'operatorType' => 'greaterThanOrEqualTo',
883  'value' => '1991-03-05 00:00:00',
884  ),
885  4 => array(
886  'attributeName' => 'dateTime2',
887  'operatorType' => 'lessThanOrEqualTo',
888  'value' => '1992-04-04 23:59:59',
889  ),
890  );
891 
892  $compareStructure = '(1 and 2) and (3 and 4)';
893  $this->assertEquals($compareClauses, $metadata['clauses']);
894  $this->assertEquals($compareStructure, $metadata['structure']);
895  }
896  }
897 ?>
Definition: I.php:37
static getByUsername($username)
Definition: User.php:49
Definition: AAA.php:37
static calculateNew($calculation, DateTime $dateTime)
Generated on Sun Jul 5 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.