Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SearchDataProviderMetadataAdapterForRecursiveSearchesTest.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 
64  {
65  public static function setUpBeforeClass()
66  {
67  parent::setUpBeforeClass();
68  SecurityTestHelper::createSuperAdmin();
69  $super = User::getByUsername('super');
70  Yii::app()->user->userModel = $super;
71  }
72 
73  public function testGetAdaptedMetadataForConcatedAttributesAcrossRelations()
74  {
75  $super = User::getByUsername('super');
76  Yii::app()->user->userModel = $super;
77  $searchAttributes = array(
78  'aaaMember' => 'Vomitorio Corp',
79  'bbb' => array(
80  'relatedData' => true,
81  'bbbMember' => 'bbbMemberValue',
82  'ccc' => array(
83  'relatedData' => true,
84  'cccMember' => 'cccMemberValue',
85  'eee' => array(
86  'relatedData' => true,
87  'eeeMember' => 'eeeMemberValue',
88  ),
89  'concatedName' => 'Jimmy Jam',
90  'iii' => array(
91  'relatedData' => true,
92  'concatedName' => 'Jimmy Jam',
93  'eee' => array(
94  'relatedData' => true,
95  'eeeMember' => 'eeeMemberValue',
96  )
97  )
98  )
99  )
100  );
101  $metadataAdapter = new SearchDataProviderMetadataAdapter(
102  new AAA(false),
103  1,
104  $searchAttributes
105  );
106  $metadata = $metadataAdapter->getAdaptedMetadata();
107  $compareClauses = array(
108  //Standard attribute on model
109  1 => array(
110  'attributeName' => 'aaaMember',
111  'operatorType' => 'startsWith',
112  'value' => 'Vomitorio Corp',
113  ),
114  //Standard attribute on related model
115  2 => array(
116  'attributeName' => 'bbb',
117  'relatedModelData' => array(
118  'attributeName' => 'bbbMember',
119  'operatorType' => 'startsWith',
120  'value' => 'bbbMemberValue',
121  ),
122  ),
123  //Standard attribute on related related model
124  3 => array(
125  'attributeName' => 'bbb',
126  'relatedModelData' => array(
127  'attributeName' => 'ccc',
128  'relatedModelData' => array(
129  'attributeName' => 'cccMember',
130  'operatorType' => 'startsWith',
131  'value' => 'cccMemberValue',
132  ),
133  ),
134  ),
135  //Standard attribute on related related related model
136  4 => array(
137  'attributeName' => 'bbb',
138  'relatedModelData' => array(
139  'attributeName' => 'ccc',
140  'relatedModelData' => array(
141  'attributeName' => 'eee',
142  'relatedModelData' => array(
143  'attributeName' => 'eeeMember',
144  'operatorType' => 'startsWith',
145  'value' => 'eeeMemberValue',
146  ),
147  ),
148  ),
149  ),
150  //Concated nested attribute first part
151  5 => array(
152  'attributeName' => 'bbb',
153  'relatedModelData' => array(
154  'attributeName' => 'ccc',
155  'relatedModelData' => array(
156  'attributeName' => 'cccMember',
157  'operatorType' => 'startsWith',
158  'value' => 'Jimmy Jam',
159  ),
160  ),
161  ),
162  //Concated nested attribute second part
163  6 => array(
164  'attributeName' => 'bbb',
165  'relatedModelData' => array(
166  'attributeName' => 'ccc',
167  'relatedModelData' => array(
168  'attributeName' => 'cccMember2',
169  'operatorType' => 'startsWith',
170  'value' => 'Jimmy Jam',
171  ),
172  ),
173  ),
174  //Concated nested attribute third part
175  7 => array(
176  'attributeName' => 'bbb',
177  'relatedModelData' => array(
178  'attributeName' => 'ccc',
179  'relatedModelData' => array(
180  'concatedAttributeNames' => array('cccMember', 'cccMember2'),
181  'operatorType' => 'startsWith',
182  'value' => 'Jimmy Jam',
183  ),
184  ),
185  ),
186  //Concated nested nested attribute first part
187  8 => array(
188  'attributeName' => 'bbb',
189  'relatedModelData' => array(
190  'attributeName' => 'ccc',
191  'relatedModelData' => array(
192  'attributeName' => 'iii',
193  'relatedModelData' => array(
194  'attributeName' => 'iiiMember',
195  'operatorType' => 'startsWith',
196  'value' => 'Jimmy Jam',
197  ),
198  ),
199  ),
200  ),
201  //Concated nested nested attribute second part
202  9 => array(
203  'attributeName' => 'bbb',
204  'relatedModelData' => array(
205  'attributeName' => 'ccc',
206  'relatedModelData' => array(
207  'attributeName' => 'iii',
208  'relatedModelData' => array(
209  'attributeName' => 'iiiMember2',
210  'operatorType' => 'startsWith',
211  'value' => 'Jimmy Jam',
212  ),
213  ),
214  ),
215  ),
216  //Concated nested nested attribute third part
217  10 => array(
218  'attributeName' => 'bbb',
219  'relatedModelData' => array(
220  'attributeName' => 'ccc',
221  'relatedModelData' => array(
222  'attributeName' => 'iii',
223  'relatedModelData' => array(
224  'concatedAttributeNames' => array('iiiMember', 'iiiMember2'),
225  'operatorType' => 'startsWith',
226  'value' => 'Jimmy Jam',
227  ),
228  ),
229  ),
230  ),
231  //Standard nested nested nested attribute
232  11 => array(
233  'attributeName' => 'bbb',
234  'relatedModelData' => array(
235  'attributeName' => 'ccc',
236  'relatedModelData' => array(
237  'attributeName' => 'iii',
238  'relatedModelData' => array(
239  'attributeName' => 'eee',
240  'relatedModelData' => array(
241  'attributeName' => 'eeeMember',
242  'operatorType' => 'startsWith',
243  'value' => 'eeeMemberValue',
244  ),
245  ),
246  ),
247  ),
248  ),
249  );
250  $compareStructure = '1 and 2 and 3 and 4 and (5 or 6 or 7) and (8 or 9 or 10) and 11';
251  $this->assertEquals($compareClauses, $metadata['clauses']);
252  $this->assertEquals($compareStructure, $metadata['structure']);
253  }
254 
259  {
260  $super = User::getByUsername('super');
261  Yii::app()->user->userModel = $super;
262  $searchAttributes = array(
263  'id' => '5',
264  'bbb' => array(
265  'relatedData' => true,
266  'id' => '6',
267  'aaa' => array(
268  'relatedData' => true,
269  'id' => '7',
270  )
271  )
272  );
273  $metadataAdapter = new SearchDataProviderMetadataAdapter(
274  new DDD(false),
275  1,
276  $searchAttributes
277  );
278  $metadata = $metadataAdapter->getAdaptedMetadata();
279  $compareClauses = array(
280  //Standard attribute on model
281  1 => array(
282  'attributeName' => 'id',
283  'operatorType' => 'equals',
284  'value' => '5',
285  ),
286  //Standard attribute on related model
287  2 => array(
288  'attributeName' => 'bbb',
289  'relatedModelData' => array(
290  'attributeName' => 'id',
291  'operatorType' => 'equals',
292  'value' => '6',
293  ),
294  ),
295  //Standard attribute on related related model
296  3 => array(
297  'attributeName' => 'bbb',
298  'relatedModelData' => array(
299  'attributeName' => 'aaa',
300  'relatedModelData' => array(
301  'attributeName' => 'id',
302  'operatorType' => 'equals',
303  'value' => '7',
304  ),
305  ),
306  ),
307  );
308  $compareStructure = '1 and 2 and 3';
309  $this->assertEquals($compareClauses, $metadata['clauses']);
310  $this->assertEquals($compareStructure, $metadata['structure']);
311  }
312 
317  {
318  $super = User::getByUsername('super');
319  Yii::app()->user->userModel = $super;
320  $searchAttributes = array(
321  'dddMember' => 'Vomitorio Corp',
322  'bbb' => array(
323  'relatedData' => true,
324  'bbbMember' => 'bbbMemberValue',
325  'aaa' => array(
326  'relatedData' => true,
327  'aaaMember' => 'aaaMemberValue',
328  )
329  )
330  );
331  $metadataAdapter = new SearchDataProviderMetadataAdapter(
332  new DDD(false),
333  1,
334  $searchAttributes
335  );
336  $metadata = $metadataAdapter->getAdaptedMetadata();
337  $compareClauses = array(
338  //Standard attribute on model
339  1 => array(
340  'attributeName' => 'dddMember',
341  'operatorType' => 'startsWith',
342  'value' => 'Vomitorio Corp',
343  ),
344  //Standard attribute on related model
345  2 => array(
346  'attributeName' => 'bbb',
347  'relatedModelData' => array(
348  'attributeName' => 'bbbMember',
349  'operatorType' => 'startsWith',
350  'value' => 'bbbMemberValue',
351  ),
352  ),
353  //Standard attribute on related related model
354  3 => array(
355  'attributeName' => 'bbb',
356  'relatedModelData' => array(
357  'attributeName' => 'aaa',
358  'relatedModelData' => array(
359  'attributeName' => 'aaaMember',
360  'operatorType' => 'startsWith',
361  'value' => 'aaaMemberValue',
362  ),
363  ),
364  ),
365  );
366  $compareStructure = '1 and 2 and 3';
367  $this->assertEquals($compareClauses, $metadata['clauses']);
368  $this->assertEquals($compareStructure, $metadata['structure']);
369  }
370 
375  {
376  $super = User::getByUsername('super');
377  Yii::app()->user->userModel = $super;
378  $searchAttributes = array(
379  'cccMember' => 'Vomitorio Corp',
380  'bbb' => array(
381  'relatedData' => true,
382  'bbbMember' => 'bbbMemberValue',
383  'aaa' => array(
384  'relatedData' => true,
385  'aaaMember' => 'aaaMemberValue',
386  )
387  )
388  );
389  $metadataAdapter = new SearchDataProviderMetadataAdapter(
390  new CCC(false),
391  1,
392  $searchAttributes
393  );
394  $metadata = $metadataAdapter->getAdaptedMetadata();
395  $compareClauses = array(
396  //Standard attribute on model
397  1 => array(
398  'attributeName' => 'cccMember',
399  'operatorType' => 'startsWith',
400  'value' => 'Vomitorio Corp',
401  ),
402  //Standard attribute on related model
403  2 => array(
404  'attributeName' => 'bbb',
405  'relatedModelData' => array(
406  'attributeName' => 'bbbMember',
407  'operatorType' => 'startsWith',
408  'value' => 'bbbMemberValue',
409  ),
410  ),
411  //Standard attribute on related related model
412  3 => array(
413  'attributeName' => 'bbb',
414  'relatedModelData' => array(
415  'attributeName' => 'aaa',
416  'relatedModelData' => array(
417  'attributeName' => 'aaaMember',
418  'operatorType' => 'startsWith',
419  'value' => 'aaaMemberValue',
420  ),
421  ),
422  ),
423  );
424  $compareStructure = '1 and 2 and 3';
425  $this->assertEquals($compareClauses, $metadata['clauses']);
426  $this->assertEquals($compareStructure, $metadata['structure']);
427  }
428 
433  {
434  $super = User::getByUsername('super');
435  Yii::app()->user->userModel = $super;
436  $searchAttributes = array(
437  'aaaMember' => 'Vomitorio Corp',
438  'bbb' => array(
439  'relatedData' => true,
440  'bbbMember' => 'bbbMemberValue',
441  'ccc' => array(
442  'relatedData' => true,
443  'cccMember' => 'cccMemberValue',
444  'eee' => array(
445  'relatedData' => true,
446  'eeeMember' => 'eeeMemberValue',
447  ),
448  'iii' => array(
449  'relatedData' => true,
450  'eee' => array(
451  'relatedData' => true,
452  'eeeMember' => 'eeeMemberValue',
453  )
454  )
455  )
456  )
457  );
458  $metadataAdapter = new SearchDataProviderMetadataAdapter(
459  new AAA(false),
460  1,
461  $searchAttributes
462  );
463  $metadata = $metadataAdapter->getAdaptedMetadata();
464  $compareClauses = array(
465  //Standard attribute on model
466  1 => array(
467  'attributeName' => 'aaaMember',
468  'operatorType' => 'startsWith',
469  'value' => 'Vomitorio Corp',
470  ),
471  //Standard attribute on related model
472  2 => array(
473  'attributeName' => 'bbb',
474  'relatedModelData' => array(
475  'attributeName' => 'bbbMember',
476  'operatorType' => 'startsWith',
477  'value' => 'bbbMemberValue',
478  ),
479  ),
480  //Standard attribute on related related model
481  3 => array(
482  'attributeName' => 'bbb',
483  'relatedModelData' => array(
484  'attributeName' => 'ccc',
485  'relatedModelData' => array(
486  'attributeName' => 'cccMember',
487  'operatorType' => 'startsWith',
488  'value' => 'cccMemberValue',
489  ),
490  ),
491  ),
492  //Standard attribute on related related related model
493  4 => array(
494  'attributeName' => 'bbb',
495  'relatedModelData' => array(
496  'attributeName' => 'ccc',
497  'relatedModelData' => array(
498  'attributeName' => 'eee',
499  'relatedModelData' => array(
500  'attributeName' => 'eeeMember',
501  'operatorType' => 'startsWith',
502  'value' => 'eeeMemberValue',
503  ),
504  ),
505  ),
506  ),
507  5 => array(
508  'attributeName' => 'bbb',
509  'relatedModelData' => array(
510  'attributeName' => 'ccc',
511  'relatedModelData' => array(
512  'attributeName' => 'iii',
513  'relatedModelData' => array(
514  'attributeName' => 'eee',
515  'relatedModelData' => array(
516  'attributeName' => 'eeeMember',
517  'operatorType' => 'startsWith',
518  'value' => 'eeeMemberValue',
519  ),
520  ),
521  ),
522  ),
523  ),
524  );
525  $compareStructure = '1 and 2 and 3 and 4 and 5';
526  $this->assertEquals($compareClauses, $metadata['clauses']);
527  $this->assertEquals($compareStructure, $metadata['structure']);
528  }
529 
534  {
535  $searchAttributes = array(
536  'industry' => array(
537  'value' => array('A', 'B', 'C'),
538  ),
539  'bbb' => array(
540  'relatedData' => true,
541  'industry' => array(
542  'value' => array('A', 'B', 'C'),
543  ),
544  'ccc' => array(
545  'relatedData' => true,
546  'cccMember' => 'cccMemberValue',
547  'industry' => array(
548  'value' => array('A', 'B', 'C'),
549  ),
550  'eee' => array(
551  'relatedData' => true,
552  'eeeMember' => 'eeeMemberValue',
553  ),
554  'iii' => array(
555  'relatedData' => true,
556  'eee' => array(
557  'relatedData' => true,
558  'industry' => array(
559  'value' => array('A', 'B', 'C'),
560  ),
561  'eeeMember' => 'eeeMemberValue',
562  )
563  )
564  )
565  )
566  );
567  $metadataAdapter = new SearchDataProviderMetadataAdapter(
568  new AAA(false),
569  1,
570  $searchAttributes
571  );
572  $metadata = $metadataAdapter->getAdaptedMetadata();
573  $compareClauses = array(
574  //Standard attribute on model
575  1 => array(
576  'attributeName' => 'industry',
577  'relatedAttributeName' => 'value',
578  'operatorType' => 'oneOf',
579  'value' => array('A', 'B', 'C'),
580  ),
581  //Standard attribute on related model
582  2 => array(
583  'attributeName' => 'bbb',
584  'relatedModelData' => array(
585  'attributeName' => 'industry',
586  'relatedAttributeName' => 'value',
587  'operatorType' => 'oneOf',
588  'value' => array('A', 'B', 'C'),
589  ),
590  ),
591  //Standard attribute on related related model
592  3 => array(
593  'attributeName' => 'bbb',
594  'relatedModelData' => array(
595  'attributeName' => 'ccc',
596  'relatedModelData' => array(
597  'attributeName' => 'cccMember',
598  'operatorType' => 'startsWith',
599  'value' => 'cccMemberValue',
600  ),
601  ),
602  ),
603  //Custom Field attribute on related related model
604  4 => array(
605  'attributeName' => 'bbb',
606  'relatedModelData' => array(
607  'attributeName' => 'ccc',
608  'relatedModelData' => array(
609  'attributeName' => 'industry',
610  'relatedAttributeName' => 'value',
611  'operatorType' => 'oneOf',
612  'value' => array('A', 'B', 'C'),
613  ),
614  ),
615  ),
616  //Standard attribute on related related related model
617  5 => array(
618  'attributeName' => 'bbb',
619  'relatedModelData' => array(
620  'attributeName' => 'ccc',
621  'relatedModelData' => array(
622  'attributeName' => 'eee',
623  'relatedModelData' => array(
624  'attributeName' => 'eeeMember',
625  'operatorType' => 'startsWith',
626  'value' => 'eeeMemberValue',
627  ),
628  ),
629  ),
630  ),
631  //Custom Field attribute on related related related related model
632  6 => array(
633  'attributeName' => 'bbb',
634  'relatedModelData' => array(
635  'attributeName' => 'ccc',
636  'relatedModelData' => array(
637  'attributeName' => 'iii',
638  'relatedModelData' => array(
639  'attributeName' => 'eee',
640  'relatedModelData' => array(
641  'attributeName' => 'industry',
642  'relatedAttributeName' => 'value',
643  'operatorType' => 'oneOf',
644  'value' => array('A', 'B', 'C'),
645  ),
646  ),
647  ),
648  ),
649  ),
650  //Standard attribute on related related related related model
651  7 => array(
652  'attributeName' => 'bbb',
653  'relatedModelData' => array(
654  'attributeName' => 'ccc',
655  'relatedModelData' => array(
656  'attributeName' => 'iii',
657  'relatedModelData' => array(
658  'attributeName' => 'eee',
659  'relatedModelData' => array(
660  'attributeName' => 'eeeMember',
661  'operatorType' => 'startsWith',
662  'value' => 'eeeMemberValue',
663  ),
664  ),
665  ),
666  ),
667  ),
668  );
669  $compareStructure = '1 and 2 and 3 and 4 and 5 and 6 and 7';
670  $this->assertEquals($compareClauses, $metadata['clauses']);
671  $this->assertEquals($compareStructure, $metadata['structure']);
672  }
673 
678  {
679  $searchAttributes = array(
680  'industry' => array(
681  'value' => array(''),
682  ),
683  'bbb' => array(
684  'relatedData' => true,
685  'industry' => array(
686  'value' => array(''),
687  ),
688  'ccc' => array(
689  'relatedData' => true,
690  'cccMember' => 'cccMemberValue',
691  'industry' => array(
692  'value' => array(''),
693  ),
694  'eee' => array(
695  'relatedData' => true,
696  'eeeMember' => 'eeeMemberValue',
697  ),
698  'iii' => array(
699  'relatedData' => true,
700  'eee' => array(
701  'relatedData' => true,
702  'industry' => array(
703  'value' => array(''),
704  ),
705  'eeeMember' => 'eeeMemberValue',
706  )
707  )
708  )
709  )
710  );
711  $metadataAdapter = new SearchDataProviderMetadataAdapter(
712  new AAA(false),
713  1,
714  $searchAttributes
715  );
716  $metadata = $metadataAdapter->getAdaptedMetadata();
717  $compareClauses = array(
718  //Standard attribute on model
719  //Standard attribute on related related model
720  1 => array(
721  'attributeName' => 'bbb',
722  'relatedModelData' => array(
723  'attributeName' => 'ccc',
724  'relatedModelData' => array(
725  'attributeName' => 'cccMember',
726  'operatorType' => 'startsWith',
727  'value' => 'cccMemberValue',
728  ),
729  ),
730  ),
731  //Standard attribute on related related related model
732  2 => array(
733  'attributeName' => 'bbb',
734  'relatedModelData' => array(
735  'attributeName' => 'ccc',
736  'relatedModelData' => array(
737  'attributeName' => 'eee',
738  'relatedModelData' => array(
739  'attributeName' => 'eeeMember',
740  'operatorType' => 'startsWith',
741  'value' => 'eeeMemberValue',
742  ),
743  ),
744  ),
745  ),
746  //Standard attribute on related related related related model
747  3 => array(
748  'attributeName' => 'bbb',
749  'relatedModelData' => array(
750  'attributeName' => 'ccc',
751  'relatedModelData' => array(
752  'attributeName' => 'iii',
753  'relatedModelData' => array(
754  'attributeName' => 'eee',
755  'relatedModelData' => array(
756  'attributeName' => 'eeeMember',
757  'operatorType' => 'startsWith',
758  'value' => 'eeeMemberValue',
759  ),
760  ),
761  ),
762  ),
763  ),
764  );
765  $compareStructure = '1 and 2 and 3';
766  $this->assertEquals($compareClauses, $metadata['clauses']);
767  $this->assertEquals($compareStructure, $metadata['structure']);
768  }
769 
775  {
776  $super = User::getByUsername('super');
777  Yii::app()->user->userModel = $super;
778  $searchAttributes = array(
779  'aaaMember' => 'Vomitorio Corp',
780  'bbb' => array(
781  'relatedData' => true,
782  'bbbMember' => 'bbbMemberValue',
783  'ccc' => array(
784  'relatedData' => true,
785  'cccMember' => 'cccMemberValue',
786  'CCCName' => 'someCCCValue',
787  'differentOperatorA' => '1',
788  'differentOperatorB' => 'something',
789  'eee' => array(
790  'relatedData' => true,
791  'eeeMember' => 'eeeMemberValue',
792  ),
793  'iii' => array(
794  'relatedData' => true,
795  'IIIName' => 'someIIIValue',
796  'differentOperatorA' => '1',
797  'differentOperatorB' => 'something',
798  'eee' => array(
799  'relatedData' => true,
800  'eeeMember' => 'eeeMemberValue',
801  )
802  )
803  )
804  )
805  );
806  $metadataAdapter = new SearchDataProviderMetadataAdapter(
807  new AAA(false),
808  1,
809  $searchAttributes
810  );
811  $metadata = $metadataAdapter->getAdaptedMetadata();
812  $compareClauses = array(
813  //Standard attribute on model
814  1 => array(
815  'attributeName' => 'aaaMember',
816  'operatorType' => 'startsWith',
817  'value' => 'Vomitorio Corp',
818  ),
819  //Standard attribute on related model
820  2 => array(
821  'attributeName' => 'bbb',
822  'relatedModelData' => array(
823  'attributeName' => 'bbbMember',
824  'operatorType' => 'startsWith',
825  'value' => 'bbbMemberValue',
826  ),
827  ),
828  //Standard attribute on related related model
829  3 => array(
830  'attributeName' => 'bbb',
831  'relatedModelData' => array(
832  'attributeName' => 'ccc',
833  'relatedModelData' => array(
834  'attributeName' => 'cccMember',
835  'operatorType' => 'startsWith',
836  'value' => 'cccMemberValue',
837  ),
838  ),
839  ),
840  //Search form attribute , part #1 of 2
841  4 => array(
842  'attributeName' => 'bbb',
843  'relatedModelData' => array(
844  'attributeName' => 'ccc',
845  'relatedModelData' => array(
846  'attributeName' => 'cccMember',
847  'operatorType' => 'startsWith',
848  'value' => 'someCCCValue',
849  ),
850  ),
851  ),
852  //Search form attribute , part #2 of 2
853  5 => array(
854  'attributeName' => 'bbb',
855  'relatedModelData' => array(
856  'attributeName' => 'ccc',
857  'relatedModelData' => array(
858  'attributeName' => 'cccMember2',
859  'operatorType' => 'startsWith',
860  'value' => 'someCCCValue',
861  ),
862  ),
863  ),
864  //Search form attribute , owner Only
865  6 => array(
866  'attributeName' => 'bbb',
867  'relatedModelData' => array(
868  'attributeName' => 'ccc',
869  'relatedModelData' => array(
870  'attributeName' => 'cccMember',
871  'operatorType' => 'startsWith',
872  'value' => $super->id,
873  ),
874  ),
875  ),
876  //Search form attribute , alternative operator
877  7 => array(
878  'attributeName' => 'bbb',
879  'relatedModelData' => array(
880  'attributeName' => 'ccc',
881  'relatedModelData' => array(
882  'attributeName' => 'cccMember',
883  'operatorType' => 'endsWith',
884  'value' => 'something',
885  ),
886  ),
887  ),
888  //Standard attribute on related related related model
889  8 => array(
890  'attributeName' => 'bbb',
891  'relatedModelData' => array(
892  'attributeName' => 'ccc',
893  'relatedModelData' => array(
894  'attributeName' => 'eee',
895  'relatedModelData' => array(
896  'attributeName' => 'eeeMember',
897  'operatorType' => 'startsWith',
898  'value' => 'eeeMemberValue',
899  ),
900  ),
901  ),
902  ),
903  //Search form attribute , part #1 of 2 (recursively nested)
904  9 => array(
905  'attributeName' => 'bbb',
906  'relatedModelData' => array(
907  'attributeName' => 'ccc',
908  'relatedModelData' => array(
909  'attributeName' => 'iii',
910  'relatedModelData' => array(
911  'attributeName' => 'iiiMember',
912  'operatorType' => 'startsWith',
913  'value' => 'someIIIValue',
914  ),
915  ),
916  ),
917  ),
918  //Search form attribute , part #2 of 2 (recursively nested)
919  10 => array(
920  'attributeName' => 'bbb',
921  'relatedModelData' => array(
922  'attributeName' => 'ccc',
923  'relatedModelData' => array(
924  'attributeName' => 'iii',
925  'relatedModelData' => array(
926  'attributeName' => 'iiiMember2',
927  'operatorType' => 'startsWith',
928  'value' => 'someIIIValue',
929  ),
930  ),
931  ),
932  ),
933  //Search form attribute , owner Only (recursively nested)
934  11 => array(
935  'attributeName' => 'bbb',
936  'relatedModelData' => array(
937  'attributeName' => 'ccc',
938  'relatedModelData' => array(
939  'attributeName' => 'iii',
940  'relatedModelData' => array(
941  'attributeName' => 'iiiMember',
942  'operatorType' => 'startsWith',
943  'value' => $super->id,
944  ),
945  ),
946  ),
947  ),
948  //Search form attribute , alternative operator
949  12 => array(
950  'attributeName' => 'bbb',
951  'relatedModelData' => array(
952  'attributeName' => 'ccc',
953  'relatedModelData' => array(
954  'attributeName' => 'iii',
955  'relatedModelData' => array(
956  'attributeName' => 'iiiMember',
957  'operatorType' => 'endsWith',
958  'value' => 'something',
959  ),
960  ),
961  ),
962  ),
963  //Standard attribute recursively nested
964  13 => array(
965  'attributeName' => 'bbb',
966  'relatedModelData' => array(
967  'attributeName' => 'ccc',
968  'relatedModelData' => array(
969  'attributeName' => 'iii',
970  'relatedModelData' => array(
971  'attributeName' => 'eee',
972  'relatedModelData' => array(
973  'attributeName' => 'eeeMember',
974  'operatorType' => 'startsWith',
975  'value' => 'eeeMemberValue',
976  ),
977  ),
978  ),
979  ),
980  ),
981  );
982  $compareStructure = '1 and 2 and 3 and (4 or 5) and (6) and (7) and 8 and (9 or 10) and (11) and (12) and 13';
983  $this->assertEquals($compareClauses, $metadata['clauses']);
984  $this->assertEquals($compareStructure, $metadata['structure']);
985  }
986 
987  public function testSearchFormDynamicAttributes()
988  {
989  $super = User::getByUsername('super');
990  Yii::app()->user->userModel = $super;
991  $searchAttributes = array(
992  'aaaMember' => 'Vomitorio Corp',
993  'bbb' => array(
994  'relatedData' => true,
995  'ccc' => array(
996  'relatedData' => true,
997  'date__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER,
998  'firstDate' => '1991-03-04'),
999  'dateTime__DateTime' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY),
1000  'dateTime2__DateTime' => array('value' => null),
1001  'eee' => array(
1002  'relatedData' => true,
1003  'eeeMember' => 'eeeMemberValue',
1004  ),
1005  'iii' => array(
1006  'relatedData' => true,
1007  'date__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER,
1008  'firstDate' => '1991-03-04'),
1009  'dateTime__DateTime' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY),
1010  'dateTime2__DateTime' => array('value' => null),
1011  )
1012  )
1013  )
1014  );
1015  $metadataAdapter = new SearchDataProviderMetadataAdapter(
1016  new AAA(false),
1017  1,
1018  $searchAttributes
1019  );
1020  $todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser()));
1021  $today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(),
1022  $todayDateTime->getTimeStamp());
1024  $metadata = $metadataAdapter->getAdaptedMetadata();
1025  $compareClauses = array(
1026  //Standard attribute on model
1027  1 => array(
1028  'attributeName' => 'aaaMember',
1029  'operatorType' => 'startsWith',
1030  'value' => 'Vomitorio Corp',
1031  ),
1032  //Standard date attribute on related model
1033  2 => array(
1034  'attributeName' => 'bbb',
1035  'relatedModelData' => array(
1036  'attributeName' => 'ccc',
1037  'relatedModelData' => array(
1038  'attributeName' => 'date',
1039  'operatorType' => 'greaterThanOrEqualTo',
1040  'value' => '1991-03-04',
1041  ),
1042  ),
1043  ),
1044  //Standard dateTime attribute on related model
1045  3 => array(
1046  'attributeName' => 'bbb',
1047  'relatedModelData' => array(
1048  'attributeName' => 'ccc',
1049  'relatedModelData' => array(
1050  'attributeName' => 'dateTime',
1051  'operatorType' => 'greaterThanOrEqualTo',
1052  'value' => DateTimeUtil::
1053  convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($today),
1054  ),
1055  ),
1056  ),
1057  //Standard dateTime attribute on related model
1058  4 => array(
1059  'attributeName' => 'bbb',
1060  'relatedModelData' => array(
1061  'attributeName' => 'ccc',
1062  'relatedModelData' => array(
1063  'attributeName' => 'dateTime',
1064  'operatorType' => 'lessThanOrEqualTo',
1065  'value' => DateTimeUtil::
1066  convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($today),
1067  ),
1068  ),
1069  ),
1070  //Standard attribute recursively nested
1071  5 => array(
1072  'attributeName' => 'bbb',
1073  'relatedModelData' => array(
1074  'attributeName' => 'ccc',
1075  'relatedModelData' => array(
1076  'attributeName' => 'eee',
1077  'relatedModelData' => array(
1078  'attributeName' => 'eeeMember',
1079  'operatorType' => 'startsWith',
1080  'value' => 'eeeMemberValue',
1081  ),
1082  ),
1083  ),
1084  ),
1085  //Date attribute recursively nested
1086  6 => array(
1087  'attributeName' => 'bbb',
1088  'relatedModelData' => array(
1089  'attributeName' => 'ccc',
1090  'relatedModelData' => array(
1091  'attributeName' => 'iii',
1092  'relatedModelData' => array(
1093  'attributeName' => 'date',
1094  'operatorType' => 'greaterThanOrEqualTo',
1095  'value' => '1991-03-04',
1096  ),
1097  ),
1098  ),
1099  ),
1100  //DateTime attribute recursively nested
1101  7 => array(
1102  'attributeName' => 'bbb',
1103  'relatedModelData' => array(
1104  'attributeName' => 'ccc',
1105  'relatedModelData' => array(
1106  'attributeName' => 'iii',
1107  'relatedModelData' => array(
1108  'attributeName' => 'dateTime',
1109  'operatorType' => 'greaterThanOrEqualTo',
1110  'value' => DateTimeUtil::
1111  convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($today),
1112  ),
1113  ),
1114  ),
1115  ),
1116  //DateTime attribute recursively nested
1117  8 => array(
1118  'attributeName' => 'bbb',
1119  'relatedModelData' => array(
1120  'attributeName' => 'ccc',
1121  'relatedModelData' => array(
1122  'attributeName' => 'iii',
1123  'relatedModelData' => array(
1124  'attributeName' => 'dateTime',
1125  'operatorType' => 'lessThanOrEqualTo',
1126  'value' => DateTimeUtil::
1127  convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($today),
1128  ),
1129  ),
1130  ),
1131  ),
1132  );
1133  $compareStructure = '1 and (2) and (3 and 4) and 5 and (6) and (7 and 8)';
1134  $this->assertEquals($compareClauses, $metadata['clauses']);
1135  $this->assertEquals($compareStructure, $metadata['structure']);
1136  }
1137  }
1138 ?>
static getByUsername($username)
Definition: User.php:49
Definition: AAA.php:37
Definition: DDD.php:37
Definition: CCC.php:37
Generated on Sun Jul 12 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.