Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DynamicSearchDataProviderMetadataAdapterTest.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 
51  {
52  $super = User::getByUsername('super');
53  Yii::app()->user->userModel = $super;
54 
55  $sanitizedDynamicSearchAttributes = array(
56  0 => array(
57  'dateTime__DateTime' => array( 'type' => 'Between',
58  'firstDate' => '2012-08-01',
59  'secondDate' => '2012-08-15'),
60  'attributeIndexOrDerivedType' => 'dateTime__DateTime',
61  'structurePosition' => '1',
62  ),
63  1 => array(
64  'iiiMember' => 'abc',
65  'attributeIndexOrDerivedType' => 'iiiMember',
66  'structurePosition' => '2',
67  ),
68  );
69  $dynamicStructure = '1 AND 2';
70  $metadata = array('clauses' => array(), 'structure' => '');
71  $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter(
72  $metadata,
73  new IIISearchFormTestModel(new III(false)),
74  (int)Yii::app()->user->userModel->id,
75  $sanitizedDynamicSearchAttributes,
76  $dynamicStructure);
77  $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
78  $compareClauses = array(
79  1 => array(
80  'attributeName' => 'dateTime',
81  'operatorType' => 'greaterThanOrEqualTo',
82  'value' => '2012-08-01 00:00:00',
83  ),
84  2 => array(
85  'attributeName' => 'dateTime',
86  'operatorType' => 'lessThanOrEqualTo',
87  'value' => '2012-08-15 23:59:59',
88  ),
89  3 => array(
90  'attributeName' => 'iiiMember',
91  'operatorType' => 'startsWith',
92  'value' => 'abc',
93  ),
94  );
95  $compareStructure = '((1 and 2) and 3)';
96  $this->assertEquals($compareClauses, $metadata['clauses']);
97  $this->assertEquals($compareStructure, $metadata['structure']);
98  }
99 
105  {
106  $super = User::getByUsername('super');
107  Yii::app()->user->userModel = $super;
108  $sanitizedDynamicSearchAttributes = array(
109  0 => array(
110  'iiiMember' => 'someThing',
111  'attributeIndexOrDerivedType' => 'iiiMember',
112  'structurePosition' => '1',
113  ),
114  2 => array(
115  'ccc' => array(
116  'relatedData' => true,
117  'cccMember' => 'cccMemberValue',
118  ),
119  'attributeIndexOrDerivedType' => 'ccc' . FormModelUtil::RELATION_DELIMITER . 'cccMember',
120  'structurePosition' => '2',
121  ),
122  4 => array(
123  'ccc' => array(
124  'relatedData' => true,
125  'bbb' => array(
126  'relatedData' => true,
127  'bbbMember' => 'bbbMemberValue',
128 
129  ),
130  ),
131  'attributeIndexOrDerivedType' => 'ccc' . FormModelUtil::RELATION_DELIMITER . 'bbb' . FormModelUtil::RELATION_DELIMITER . 'bbbMember',
132  'structurePosition' => '3',
133  ),
134  );
135  $dynamicStructure = '(1 or 2) and 3';
136  $metadata = array('clauses' => array(), 'structure' => '');
137  $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter(
138  $metadata,
139  new IIISearchFormTestModel(new III(false)),
140  (int)Yii::app()->user->userModel->id,
141  $sanitizedDynamicSearchAttributes,
142  $dynamicStructure);
143  $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
144  $compareClauses = array(
145  1 => array(
146  'attributeName' => 'iiiMember',
147  'operatorType' => 'startsWith',
148  'value' => 'someThing',
149  ),
150  2 => array(
151  'attributeName' => 'ccc',
152  'relatedModelData' => array(
153  'attributeName' => 'cccMember',
154  'operatorType' => 'startsWith',
155  'value' => 'cccMemberValue',
156  ),
157  ),
158  3 => array(
159  'attributeName' => 'ccc',
160  'relatedModelData' => array(
161  'attributeName' => 'bbb',
162  'relatedModelData' => array(
163  'attributeName' => 'bbbMember',
164  'operatorType' => 'startsWith',
165  'value' => 'bbbMemberValue',
166  ),
167  ),
168  ),
169  );
170  $compareStructure = '((1 or 2) and 3)';
171  $this->assertEquals($compareClauses, $metadata['clauses']);
172  $this->assertEquals($compareStructure, $metadata['structure']);
173  }
174 
178  public function testDynamicSearch()
179  {
180  $super = User::getByUsername('super');
181  Yii::app()->user->userModel = $super;
182  $sanitizedDynamicSearchAttributes = array(
183  0 => array(
184  'iiiMember' => 'someThing',
185  'attributeIndexOrDerivedType' => 'iiiMember',
186  'structurePosition' => '1',
187  ),
188  2 => array(
189  'iiiMember2' => 'someThing2',
190  'attributeIndexOrDerivedType' => 'iiiMember2',
191  'structurePosition' => '2',
192  ),
193  4 => array(
194  'iiiMember2' => 'someThing3',
195  'attributeIndexOrDerivedType' => 'iiiMember2',
196  'structurePosition' => '3',
197  )
198  );
199  $dynamicStructure = '(1 or 2) and 3';
200  $metadata = array('clauses' => array(), 'structure' => '');
201  $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter(
202  $metadata,
203  new IIISearchFormTestModel(new III(false)),
204  (int)Yii::app()->user->userModel->id,
205  $sanitizedDynamicSearchAttributes,
206  $dynamicStructure);
207  $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
208  $compareClauses = array(
209  1 => array(
210  'attributeName' => 'iiiMember',
211  'operatorType' => 'startsWith',
212  'value' => 'someThing',
213  ),
214  2 => array(
215  'attributeName' => 'iiiMember2',
216  'operatorType' => 'startsWith',
217  'value' => 'someThing2',
218  ),
219  3 => array(
220  'attributeName' => 'iiiMember2',
221  'operatorType' => 'startsWith',
222  'value' => 'someThing3',
223  ),
224  );
225  $compareStructure = '((1 or 2) and 3)';
226  $this->assertEquals($compareClauses, $metadata['clauses']);
227  $this->assertEquals($compareStructure, $metadata['structure']);
228  }
229 
234  {
235  $super = User::getByUsername('super');
236  Yii::app()->user->userModel = $super;
237  $sanitizedDynamicSearchAttributes = array(
238  0 => array(
239  'iiiMember' => 'someThing',
240  'attributeIndexOrDerivedType' => 'iiiMember',
241  'structurePosition' => '1',
242  ),
243  2 => array(
244  'iiiMember2' => 'someThing2',
245  'attributeIndexOrDerivedType' => 'iiiMember2',
246  'structurePosition' => '2',
247  ),
248  4 => array(
249  'iiiMember2' => 'someThing3',
250  'attributeIndexOrDerivedType' => 'iiiMember2',
251  'structurePosition' => '3',
252  )
253  );
254  $dynamicStructure = '(1 or 2) and 3';
255  $metadata = array('clauses' => array(1 => array(
256  'attributeName' => 'iiiMember',
257  'operatorType' => 'startsWith',
258  'value' => 'someThingFirst'),
259  2 => array(
260  'attributeName' => 'iiiMember',
261  'operatorType' => 'startsWith',
262  'value' => 'someThingSecond')),
263  'structure' => '1 and 2');
264  $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter(
265  $metadata,
266  new IIISearchFormTestModel(new III(false)),
267  (int)Yii::app()->user->userModel->id,
268  $sanitizedDynamicSearchAttributes,
269  $dynamicStructure);
270  $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
271  $compareClauses = array(
272  1 => array(
273  'attributeName' => 'iiiMember',
274  'operatorType' => 'startsWith',
275  'value' => 'someThingFirst',
276  ),
277  2 => array(
278  'attributeName' => 'iiiMember',
279  'operatorType' => 'startsWith',
280  'value' => 'someThingSecond',
281  ),
282  3 => array(
283  'attributeName' => 'iiiMember',
284  'operatorType' => 'startsWith',
285  'value' => 'someThing',
286  ),
287  4 => array(
288  'attributeName' => 'iiiMember2',
289  'operatorType' => 'startsWith',
290  'value' => 'someThing2',
291  ),
292  5 => array(
293  'attributeName' => 'iiiMember2',
294  'operatorType' => 'startsWith',
295  'value' => 'someThing3',
296  ),
297  );
298  $compareStructure = '(1 and 2) and ((3 or 4) and 5)';
299  $this->assertEquals($compareClauses, $metadata['clauses']);
300  $this->assertEquals($compareStructure, $metadata['structure']);
301  }
302 
307  {
308  $super = User::getByUsername('super');
309  Yii::app()->user->userModel = $super;
310  $sanitizedDynamicSearchAttributes = array(
311  0 => array(
312  'iiiMember' => 'someThing',
313  'attributeIndexOrDerivedType' => 'iiiMember',
314  'structurePosition' => '1',
315  ),
316  2 => array(
317  'iiiMember2' => null, //must be null not '' to show its removal in test
318  'attributeIndexOrDerivedType' => 'iiiMember2',
319  'structurePosition' => '2',
320  ),
321  4 => array(
322  'iiiMember2' => 'someThing3',
323  'attributeIndexOrDerivedType' => 'iiiMember2',
324  'structurePosition' => '3',
325  )
326  );
327  $dynamicStructure = '(1 or 2) and 3';
328  $metadata = array('clauses' => array(), 'structure' => '');
329  $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter(
330  $metadata,
331  new IIISearchFormTestModel(new III(false)),
332  (int)Yii::app()->user->userModel->id,
333  $sanitizedDynamicSearchAttributes,
334  $dynamicStructure);
335  $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
336  $compareClauses = array(
337  1 => array(
338  'attributeName' => 'iiiMember',
339  'operatorType' => 'startsWith',
340  'value' => 'someThing',
341  ),
342  2 => array(
343  'attributeName' => 'iiiMember2',
344  'operatorType' => 'startsWith',
345  'value' => 'someThing3',
346  ),
347  );
348  $compareStructure = '((1) and 2)';
349  $this->assertEquals($compareClauses, $metadata['clauses']);
350  $this->assertEquals($compareStructure, $metadata['structure']);
351  }
352 
359  {
360  $super = User::getByUsername('super');
361  Yii::app()->user->userModel = $super;
362  $sanitizedDynamicSearchAttributes = array(
363  0 => array(
364  'iiiMember' => 'someThing12',
365  'attributeIndexOrDerivedType' => 'iiiMember',
366  'structurePosition' => '12',
367  ),
368  1 => array(
369  'iiiMember' => 'someThing1',
370  'attributeIndexOrDerivedType' => 'iiiMember',
371  'structurePosition' => '1',
372  ),
373  2 => array(
374  'iiiMember' => 'someThing2',
375  'attributeIndexOrDerivedType' => 'iiiMember',
376  'structurePosition' => '2',
377  ),
378  3 => array(
379  'iiiMember' => 'someThing11',
380  'attributeIndexOrDerivedType' => 'iiiMember',
381  'structurePosition' => '11',
382  ),
383  4 => array(
384  'iiiMember' => 'someThing22',
385  'attributeIndexOrDerivedType' => 'iiiMember',
386  'structurePosition' => '22',
387  )
388  );
389  $dynamicStructure = '(1 or 11) and 2 and 22 and 12';
390  $metadata = array('clauses' => array(), 'structure' => '');
391  $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter(
392  $metadata,
393  new IIISearchFormTestModel(new III(false)),
394  (int)Yii::app()->user->userModel->id,
395  $sanitizedDynamicSearchAttributes,
396  $dynamicStructure);
397  $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
398  $compareClauses = array(
399  1 => array(
400  'attributeName' => 'iiiMember',
401  'operatorType' => 'startsWith',
402  'value' => 'someThing12',
403  ),
404  2 => array(
405  'attributeName' => 'iiiMember',
406  'operatorType' => 'startsWith',
407  'value' => 'someThing1',
408  ),
409  3 => array(
410  'attributeName' => 'iiiMember',
411  'operatorType' => 'startsWith',
412  'value' => 'someThing2',
413  ),
414  4 => array(
415  'attributeName' => 'iiiMember',
416  'operatorType' => 'startsWith',
417  'value' => 'someThing11',
418  ),
419  5 => array(
420  'attributeName' => 'iiiMember',
421  'operatorType' => 'startsWith',
422  'value' => 'someThing22',
423  ),
424  );
425  $compareStructure = '((2 or 4) and 3 and 5 and 1)';
426  $this->assertEquals($compareClauses, $metadata['clauses']);
427  $this->assertEquals($compareStructure, $metadata['structure']);
428  }
429 
434  {
435  $super = User::getByUsername('super');
436  Yii::app()->user->userModel = $super;
437  $sanitizedDynamicSearchAttributes = array(
438  0 => array(
439  'iiiMember' => 'someThing1',
440  'attributeIndexOrDerivedType' => 'iiiMember',
441  'structurePosition' => '1',
442  ),
443  1 => array(
444  'iiiMember' => 'someThing2',
445  'attributeIndexOrDerivedType' => 'iiiMember',
446  'structurePosition' => '2',
447  ),
448  2 => array(
449  'iiiMember' => 'someThing3',
450  'attributeIndexOrDerivedType' => 'iiiMember',
451  'structurePosition' => '3',
452  ),
453  3 => array(
454  'iiiMember' => 'someThing4',
455  'attributeIndexOrDerivedType' => 'iiiMember',
456  'structurePosition' => '4',
457  ),
458  4 => array(
459  'iiiMember' => 'someThing5',
460  'attributeIndexOrDerivedType' => 'iiiMember',
461  'structurePosition' => '5',
462  ),
463  5 => array(
464  'iiiMember' => 'someThing6',
465  'attributeIndexOrDerivedType' => 'iiiMember',
466  'structurePosition' => '6',
467  ),
468  6 => array(
469  'iiiMember' => 'someThing7',
470  'attributeIndexOrDerivedType' => 'iiiMember',
471  'structurePosition' => '7',
472  ),
473  7 => array(
474  'iiiMember' => 'someThing8',
475  'attributeIndexOrDerivedType' => 'iiiMember',
476  'structurePosition' => '8',
477  ),
478  8 => array(
479  'iiiMember' => 'someThing9',
480  'attributeIndexOrDerivedType' => 'iiiMember',
481  'structurePosition' => '9',
482  ),
483  9 => array(
484  'iiiMember' => 'someThing10',
485  'attributeIndexOrDerivedType' => 'iiiMember',
486  'structurePosition' => '10',
487  ),
488  10 => array(
489  'iiiMember' => 'someThing11',
490  'attributeIndexOrDerivedType' => 'iiiMember',
491  'structurePosition' => '11',
492  ),
493  11 => array(
494  'iiiMember' => 'someThing12',
495  'attributeIndexOrDerivedType' => 'iiiMember',
496  'structurePosition' => '12',
497  ),
498  12 => array(
499  'iiiMember' => 'someThing13',
500  'attributeIndexOrDerivedType' => 'iiiMember',
501  'structurePosition' => '13',
502  ),
503  );
504  $dynamicStructure = '(1 and 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9 and 10 and 11 and 12 and 13)';
505  $metadata = array('clauses' => array(), 'structure' => '');
506  $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter(
507  $metadata,
508  new IIISearchFormTestModel(new III(false)),
509  (int)Yii::app()->user->userModel->id,
510  $sanitizedDynamicSearchAttributes,
511  $dynamicStructure);
512  $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
513  $compareClauses = array(
514  1 => array(
515  'attributeName' => 'iiiMember',
516  'operatorType' => 'startsWith',
517  'value' => 'someThing1',
518  ),
519  2 => array(
520  'attributeName' => 'iiiMember',
521  'operatorType' => 'startsWith',
522  'value' => 'someThing2',
523  ),
524  3 => array(
525  'attributeName' => 'iiiMember',
526  'operatorType' => 'startsWith',
527  'value' => 'someThing3',
528  ),
529  4 => array(
530  'attributeName' => 'iiiMember',
531  'operatorType' => 'startsWith',
532  'value' => 'someThing4',
533  ),
534  5 => array(
535  'attributeName' => 'iiiMember',
536  'operatorType' => 'startsWith',
537  'value' => 'someThing5',
538  ),
539  6 => array(
540  'attributeName' => 'iiiMember',
541  'operatorType' => 'startsWith',
542  'value' => 'someThing6',
543  ),
544  7 => array(
545  'attributeName' => 'iiiMember',
546  'operatorType' => 'startsWith',
547  'value' => 'someThing7',
548  ),
549  8 => array(
550  'attributeName' => 'iiiMember',
551  'operatorType' => 'startsWith',
552  'value' => 'someThing8',
553  ),
554  9 => array(
555  'attributeName' => 'iiiMember',
556  'operatorType' => 'startsWith',
557  'value' => 'someThing9',
558  ),
559  10 => array(
560  'attributeName' => 'iiiMember',
561  'operatorType' => 'startsWith',
562  'value' => 'someThing10',
563  ),
564  11 => array(
565  'attributeName' => 'iiiMember',
566  'operatorType' => 'startsWith',
567  'value' => 'someThing11',
568  ),
569  12 => array(
570  'attributeName' => 'iiiMember',
571  'operatorType' => 'startsWith',
572  'value' => 'someThing12',
573  ),
574  13 => array(
575  'attributeName' => 'iiiMember',
576  'operatorType' => 'startsWith',
577  'value' => 'someThing13',
578  ),
579  );
580  $compareStructure = '((1 and 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9 and 10 and 11 and 12 and 13))';
581  $this->assertEquals($compareClauses, $metadata['clauses']);
582  $this->assertEquals($compareStructure, $metadata['structure']);
583  }
584 
585  public function testNumberToLetter()
586  {
592  $this->assertEquals('o', DynamicSearchDataProviderMetadataAdapter::numberToLetter(15));
593  $this->assertEquals('ss', DynamicSearchDataProviderMetadataAdapter::numberToLetter(45));
594  }
595 
596  public function testGetAdaptedDataProviderMetadataForAttributesMappedToRealAttributesMetadata()
597  {
598  $super = User::getByUsername('super');
599  Yii::app()->user->userModel = $super;
600  $sanitizedDynamicSearchAttributes = array(array('IIIName' => 'IL',
601  'structurePosition' => 1),
602  array('IIIName' => 'CA',
603  'structurePosition' => 2));
604  $dynamicStructure = '1 OR 2';
605  $metadata = array('clauses' => array(), 'structure' => '');
606  $metadataAdapter = new DynamicSearchDataProviderMetadataAdapter(
607  $metadata,
608  new IIISearchFormTestModel(new III(false)),
609  (int)Yii::app()->user->userModel->id,
610  $sanitizedDynamicSearchAttributes,
611  $dynamicStructure);
612  $metadata = $metadataAdapter->getAdaptedDataProviderMetadata();
613  $compareClauses = array(
614  1 => array(
615  'attributeName' => 'iiiMember',
616  'operatorType' => 'startsWith',
617  'value' => 'IL',
618  ),
619  2 => array(
620  'attributeName' => 'iiiMember2',
621  'operatorType' => 'startsWith',
622  'value' => 'IL',
623  ),
624  3 => array(
625  'attributeName' => 'iiiMember',
626  'operatorType' => 'startsWith',
627  'value' => 'CA',
628  ),
629  4 => array(
630  'attributeName' => 'iiiMember2',
631  'operatorType' => 'startsWith',
632  'value' => 'CA',
633  ),
634  );
635  $compareStructure = '((1 or 2) or (3 or 4))';
636  $this->assertEquals($compareClauses, $metadata['clauses']);
637  $this->assertEquals($compareStructure, $metadata['structure']);
638  }
639  }
640 ?>
static getByUsername($username)
Definition: User.php:49
Definition: III.php:37
const RELATION_DELIMITER
Generated on Mon Sep 28 2020 07:10:26
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.