Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SearchUtilTest.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 
37  class SearchUtilTest extends BaseTest
38  {
39  public function testResolveSortFromStickyData()
40  {
41  list($sortAttribute, $sortDescending) = SearchUtil::
42  resolveSortFromStickyData('testing', 'testId');
43  $this->assertEquals(null, $sortAttribute);
44  $this->assertFalse ($sortDescending);
45 
46  $_GET['testing_sort'] = 'name';
47  list($sortAttribute, $sortDescending) = SearchUtil::
48  resolveSortFromStickyData('testing', 'testId');
49  $this->assertEquals('name', $sortAttribute);
50  $this->assertFalse ($sortDescending);
51 
52  $_GET = array();
53  list($sortAttribute, $sortDescending) = SearchUtil::
54  resolveSortFromStickyData('testing', 'testId');
55  $this->assertEquals('name', $sortAttribute);
56  $this->assertFalse ($sortDescending);
57 
58  $_GET['testing_sort'] = 'other.desc';
59  list($sortAttribute, $sortDescending) = SearchUtil::
60  resolveSortFromStickyData('testing', 'testId');
61  $this->assertEquals('other', $sortAttribute);
62  $this->assertTrue ($sortDescending);
63 
64  $_GET = array();
65  list($sortAttribute, $sortDescending) = SearchUtil::
66  resolveSortFromStickyData('testing', 'testId');
67  $this->assertEquals('other', $sortAttribute);
68  $this->assertTrue ($sortDescending);
69  }
70 
71  public function testResolveSearchFormByStickyFilteredByData()
72  {
73  $searchModel = new AFilteredBySearchFormTestModel(new A());
74  SearchUtil::resolveSearchFormByStickyFilteredByData(array(), $searchModel, array());
75  $this->assertEmpty($searchModel->filteredBy);
76  SearchUtil::resolveSearchFormByStickyFilteredByData(array(), $searchModel, array('filteredBy' => 'all'));
77  $this->assertEquals('all', $searchModel->filteredBy);
78  }
79 
80  public function testGetSorAttributeFromSortArray()
81  {
82  $sortAttribute = SearchUtil::getSortAttributeFromSortString('name.desc');
83  $this->assertEquals('name', $sortAttribute);
84  $sortAttribute = SearchUtil::getSortAttributeFromSortString('name');
85  $this->assertEquals('name', $sortAttribute);
86  $sortAttribute = SearchUtil::getSortAttributeFromSortString('name.asc');
87  $this->assertEquals('name', $sortAttribute);
88  $sortAttribute = SearchUtil::getSortAttributeFromSortString('');
89  $this->assertEquals('', $sortAttribute);
90 
91  $_GET['testing_sort'] = 'name.desc';
92  $sortAttribute = SearchUtil::resolveSortAttributeFromArray('testing', $_GET);
93  $this->assertEquals('name', $sortAttribute);
94  $_GET['testing_sort'] = 'name';
95  $sortAttribute = SearchUtil::resolveSortAttributeFromArray('testing', $_GET);
96  $this->assertEquals('name', $sortAttribute);
97  $_GET['testing_sort'] = 'name.asc';
98  $sortAttribute = SearchUtil::resolveSortAttributeFromArray('testing', $_GET);
99  $this->assertEquals('name', $sortAttribute);
100  $_GET['testing_sort'] = '';
101  $sortAttribute = SearchUtil::resolveSortAttributeFromArray('testing', $_GET);
102  $this->assertEquals('', $sortAttribute);
103  }
104 
105  public function testIsSortDescending()
106  {
107  $sortDescending = SearchUtil::isSortDescending('name.desc');
108  $this->assertTrue($sortDescending);
109  $sortDescending = SearchUtil::isSortDescending('name');
110  $this->assertFalse($sortDescending);
111  $sortDescending = SearchUtil::isSortDescending('name.asc');
112  $this->assertFalse($sortDescending);
113 
114  $_GET['testing_sort'] = 'name.desc';
115  $sortDescending = SearchUtil::resolveSortDescendingFromArray('testing', $_GET);
116  $this->assertTrue($sortDescending);
117  $_GET['testing_sort'] = 'name';
118  $sortDescending = SearchUtil::resolveSortDescendingFromArray('testing', $_GET);
119  $this->assertFalse($sortDescending);
120  $_GET['testing_sort'] = 'name.asc';
121  $sortDescending = SearchUtil::resolveSortDescendingFromArray('testing', $_GET);
122  $this->assertFalse($sortDescending);
123  }
124 
125  public function testGetSearchAttributesFromSearchArray()
126  {
127  $searchArray = array(
128  'a' => 'apple',
129  'b' => '',
130  );
131  $testArray = array(
132  'a' => 'apple',
133  'b' => null,
134  );
135  $newArray = SearchUtil::getSearchAttributesFromSearchArray($searchArray);
136  $this->assertEquals($testArray, $newArray);
137 
138  $_GET['testing'] = array(
139  'a' => 'apple',
140  'b' => '',
141  );
142  $newArray = SearchUtil::resolveSearchAttributesFromArray('testing', 'AAASearchFormTestModel', $_GET);
143  $this->assertEquals($testArray, $newArray);
144 
145  //Now test various empty and 0 combinations
146  $_GET['testing'] = array(
147  'a' => null,
148  );
149  $newArray = SearchUtil::resolveSearchAttributesFromArray('testing', 'AAASearchFormTestModel', $_GET);
150  $this->assertEquals(array('a' => null), $newArray);
151 
152  $_GET['testing'] = array(
153  'a' => '',
154  );
155  $newArray = SearchUtil::resolveSearchAttributesFromArray('testing', 'AAASearchFormTestModel', $_GET);
156  $this->assertEquals(array('a' => null), $newArray);
157 
158  $_GET['testing'] = array(
159  'a' => 0,
160  );
161  $newArray = SearchUtil::resolveSearchAttributesFromArray('testing', 'AAASearchFormTestModel', $_GET);
162  $this->assertEquals(array('a' => null), $newArray);
163 
164  $_GET['testing'] = array(
165  'a' => '0',
166  );
167  $newArray = SearchUtil::resolveSearchAttributesFromArray('testing', 'AAASearchFormTestModel', $_GET);
168  $this->assertEquals(array('a' => '0'), $newArray);
169  }
170 
171  public function testResolveSearchAttributesFromGetArrayForDynamicSearch()
172  {
173  $_GET['testing'] = array(
174  'a' => '0',
175  'dynamicClauses' => array(array('b' => '0')),
176  'dynamicStructure' => '1 and 2',
177  );
178  $newArray = SearchUtil::resolveSearchAttributesFromArray('testing', 'AAASearchFormTestModel', $_GET);
179  $this->assertEquals(array('a' => '0'), $newArray);
180  }
181 
182  public function testResolveSearchAttributesFromGetArrayForAnyMixedAttributeScopeName()
183  {
184  $_GET['testing'] = array(
185  'a' => '0',
186  SearchForm::ANY_MIXED_ATTRIBUTES_SCOPE_NAME => 'something',
187  SearchForm::SELECTED_LIST_ATTRIBUTES => array('something'),
188  );
189  $newArray = SearchUtil::resolveSearchAttributesFromArray('testing', 'AAASearchFormTestModel', $_GET);
190  $this->assertEquals(array('a' => '0'), $newArray);
191 
192  $_GET['testing'] = array(
193  'a' => '0',
194  SearchForm::ANY_MIXED_ATTRIBUTES_SCOPE_NAME => null,
195  SearchForm::SELECTED_LIST_ATTRIBUTES => null,
196  );
197  $newArray = SearchUtil::resolveSearchAttributesFromArray('testing', 'AAASearchFormTestModel', $_GET);
198  $this->assertEquals(array('a' => '0'), $newArray);
199 
200  $_GET['testing'] = array(
201  'a' => '0',
202  SearchForm::ANY_MIXED_ATTRIBUTES_SCOPE_NAME => array(),
203  SearchForm::SELECTED_LIST_ATTRIBUTES => array(),
204  );
205  $newArray = SearchUtil::resolveSearchAttributesFromArray('testing', 'AAASearchFormTestModel', $_GET);
206  $this->assertEquals(array('a' => '0'), $newArray);
207 
208  $_GET['testing'] = array(
209  'a' => '0',
210  SearchForm::ANY_MIXED_ATTRIBUTES_SCOPE_NAME => array('a' => 'b'),
211  SearchForm::SELECTED_LIST_ATTRIBUTES => array('a' => 'b'),
212  );
213  $newArray = SearchUtil::resolveSearchAttributesFromArray('testing', 'AAASearchFormTestModel', $_GET);
214  $this->assertEquals(array('a' => '0'), $newArray);
215  }
216 
222  {
223  $searchArray = array('testMultiSelectDropDown' => array('values' => array(0 => '')));
224  $newArray = SearchUtil::getSearchAttributesFromSearchArray($searchArray);
225  $this->assertEquals(array(), $newArray);
226 
227  $searchArray = array('testMultiSelectDropDown' => array('values' => array(0 => null)));
228  $newArray = SearchUtil::getSearchAttributesFromSearchArray($searchArray);
229  $this->assertEquals(array(), $newArray);
230 
231  $searchArray = array('testMultiSelectDropDown' => array('values' => array(0 => null, 1 => 'xyz')));
232  $resultArray = array('testMultiSelectDropDown' => array('values' => array(0 => 'xyz')));
233  $newArray = SearchUtil::getSearchAttributesFromSearchArray($searchArray);
234  $this->assertEquals($resultArray, $newArray);
235 
236  $searchArray = array('testDropDownAsMultiSelectDropDown' => array('value' => array(0 => '')));
237  $newArray = SearchUtil::getSearchAttributesFromSearchArray($searchArray);
238  $this->assertEquals(array(), $newArray);
239 
240  $searchArray = array('testDropDownAsMultiSelectDropDown' => array('value' => array(0 => null)));
241  $newArray = SearchUtil::getSearchAttributesFromSearchArray($searchArray);
242  $this->assertEquals(array(), $newArray);
243 
244  $searchArray = array('testDropDownAsMultiSelectDropDown' => array('value' => array(0 => null, 1 => 'xyz')));
245  $resultArray = array('testDropDownAsMultiSelectDropDown' => array('value' => array(0 => 'xyz')));
246  $newArray = SearchUtil::getSearchAttributesFromSearchArray($searchArray);
247  $this->assertEquals($resultArray, $newArray);
248 
249  //Test recursion
250  $searchArray = array('testDropDownAsMultiSelectDropDown' =>
251  array('abc' => array('value' => array(0 => null, 1 => 'xyz'))));
252  $resultArray = array('testDropDownAsMultiSelectDropDown' =>
253  array('abc' => array('value' => array(0 => 'xyz'))));
254  $newArray = SearchUtil::getSearchAttributesFromSearchArray($searchArray);
255  $this->assertEquals($resultArray, $newArray);
256 
257  $searchArray = array('testMultiSelectDropDown' =>
258  array('abc' => array('values' => array(0 => null, 1 => 'xyz'))));
259  $resultArray = array('testMultiSelectDropDown' =>
260  array('abc' => array('values' => array(0 => 'xyz'))));
261  $newArray = SearchUtil::getSearchAttributesFromSearchArray($searchArray);
262  $this->assertEquals($resultArray, $newArray);
263  }
264 
265  public function testGetSearchAttributesFromSearchArrayForSavingExistingSearchCriteria()
266  {
267  $searchArray = array(
268  'a' => 'apple',
269  'b' => '',
270  );
271  $testArray = array(
272  'a' => 'apple',
273  'b' => null,
274  );
276  $this->assertEquals($testArray, $newArray);
277 
278  $searchArray = array(
279  'a' => 'apple',
280  'b' => '',
281  );
283  $this->assertEquals($testArray, $newArray);
284 
285  //Now test various empty and 0 combinations
286  $searchArray = array(
287  'a' => null,
288  );
290  $this->assertEquals(array('a' => null), $newArray);
291 
292  $searchArray = array(
293  'a' => '',
294  );
296  $this->assertEquals(array('a' => null), $newArray);
297 
298  $searchArray = array(
299  'a' => 0,
300  );
302  $this->assertEquals(array('a' => 0), $newArray);
303 
304  $searchArray = array(
305  'a' => '0',
306  );
308  $this->assertEquals(array('a' => '0'), $newArray);
309 
310  $searchArray = array(
311  'a' => array('values' => array(0 => '')),
312  );
314  $this->assertEquals(array(), $newArray);
315 
316  $searchArray = array(
317  'a' => array('value' => array(0 => '')),
318  );
320  $this->assertEquals(array(), $newArray);
321 
322  $searchArray = array(
323  'a' => array('values' => array(0 => null)),
324  );
326  $this->assertEquals(array(), $newArray);
327 
328  $searchArray = array(
329  'a' => array('value' => array(0 => null)),
330  );
332  $this->assertEquals(array(), $newArray);
333 
334  $searchArray = array(
335  'a' => array('value' => array(0 => null, 1 => 'xyz')),
336  );
338  $this->assertEquals(array('a' => array('value' => array(0 => 'xyz'))), $newArray);
339  }
340 
341  public function testAdaptSearchAttributesToSetInRedBeanModel()
342  {
343  $model = new ASearchFormTestModel(new A(false));
344  $searchAttributes = array(
345  'differentOperatorB' => array('value' => 'thiswillstay'),
346  'a' => array('value' => 'thiswillgo'),
347  'differentOperatorB' => 'something',
348  'name' => array('value' => 'thiswillstay'),
349  );
350  $adaptedSearchAttributes = SearchUtil::adaptSearchAttributesToSetInRedBeanModel($searchAttributes, $model);
351  $compareData = array(
352  'differentOperatorB' => array('value' => 'thiswillstay'),
353  'a' => 'thiswillgo',
354  'differentOperatorB' => 'something',
355  'name' => array('value' => 'thiswillstay'),
356  );
357  $this->assertEquals($compareData, $adaptedSearchAttributes);
358  }
359 
360  public function testResolveAnyMixedAttributesScopeForSearchModelFromGetArray()
361  {
362  $searchModel = new ASearchFormTestModel(new A());
363  $getArrayName = 'someArray';
364  SearchUtil::resolveAnyMixedAttributesScopeForSearchModelFromArray($searchModel, $getArrayName, $_GET);
365  $this->assertNull($searchModel->getAnyMixedAttributesScope());
366 
367  //Test passing a value in the GET
368  $_GET['someArray'][SearchForm::ANY_MIXED_ATTRIBUTES_SCOPE_NAME] = 'notAnArray';
369  SearchUtil::resolveAnyMixedAttributesScopeForSearchModelFromArray($searchModel, $getArrayName, $_GET);
370  $this->assertNull($searchModel->getAnyMixedAttributesScope());
371 
372  $_GET['someArray'][SearchForm::ANY_MIXED_ATTRIBUTES_SCOPE_NAME] = array('All');
373  SearchUtil::resolveAnyMixedAttributesScopeForSearchModelFromArray($searchModel, $getArrayName, $_GET);
374  $this->assertNull($searchModel->getAnyMixedAttributesScope());
375 
376  $_GET['someArray'][SearchForm::ANY_MIXED_ATTRIBUTES_SCOPE_NAME] = array('A', 'B', 'C');
377  SearchUtil::resolveAnyMixedAttributesScopeForSearchModelFromArray($searchModel, $getArrayName, $_GET);
378  $this->assertEquals(array('A', 'B', 'C'), $searchModel->getAnyMixedAttributesScope());
379  }
380 
381  public function testResolveSelectedListAttributesForSearchModelFromGetArray()
382  {
383  $searchModel = new ASearchFormTestModel(new A());
384  $listAttributesSelector = new ListAttributesSelector('AListView', 'TestModule');
385  $searchModel->setListAttributesSelector($listAttributesSelector);
386  $getArrayName = 'someArray';
387  SearchUtil::resolveSelectedListAttributesForSearchModelFromArray($searchModel, $getArrayName, $_GET);
388  $this->assertEquals(array('name'), $searchModel->getListAttributesSelector()->getSelected());
389 
390  //Test passing a value in the GET
391  $_GET['someArray'][SearchForm::SELECTED_LIST_ATTRIBUTES] = array();
392  SearchUtil::resolveSelectedListAttributesForSearchModelFromArray($searchModel, $getArrayName, $_GET);
393  $this->assertEquals(array('name'), $searchModel->getListAttributesSelector()->getSelected());
394 
395  $_GET['someArray'][SearchForm::SELECTED_LIST_ATTRIBUTES] = array('name', 'a');
396  SearchUtil::resolveSelectedListAttributesForSearchModelFromArray($searchModel, $getArrayName, $_GET);
397  $this->assertEquals(array('name', 'a'), $searchModel->getListAttributesSelector()->getSelected());
398  }
399 
400  public function testResolveFilterByStarredFromGetArray()
401  {
402  $searchModel = new ASearchFormTestModel(new A());
403  $getArrayName = 'someArray';
404  SearchUtil::resolveFilterByStarredFromArray($searchModel, $getArrayName, $_GET);
405  $this->assertNull($searchModel->filterByStarred);
406 
407  $_GET['someArray']['filterByStarred'] = true;
408  SearchUtil::resolveFilterByStarredFromArray($searchModel, $getArrayName, $_GET);
409  $this->assertTrue($searchModel->filterByStarred);
410 
411  $_GET['someArray']['filterByStarred'] = false;
412  SearchUtil::resolveFilterByStarredFromArray($searchModel, $getArrayName, $_GET);
413  $this->assertFalse($searchModel->filterByStarred);
414  }
415 
416  public function testResolveFilteredByFromGetArray()
417  {
418  $searchModel = new AFilteredBySearchFormTestModel(new A());
419  $getArrayName = 'someArray';
420  SearchUtil::resolveFilteredByFromArray($searchModel, $getArrayName, $_GET);
421  $this->assertNull($searchModel->filteredBy);
422 
423  $_GET['someArray']['filteredBy'] = 'all';
424  SearchUtil::resolveFilteredByFromArray($searchModel, $getArrayName, $_GET);
425  $this->assertEquals('all', $searchModel->filteredBy);
426 
427  $_GET['someArray']['filteredBy'] = 'none';
428  SearchUtil::resolveFilteredByFromArray($searchModel, $getArrayName, $_GET);
429  $this->assertEquals('none', $searchModel->filteredBy);
430  }
431 
432  public function testGetDynamicSearchAttributesFromGetArray()
433  {
434  //Test without any dynamic search
435  $_GET['testing'] = array(
436  'a' => null,
437  );
438  $newArray = SearchUtil::getDynamicSearchAttributesFromArray('testing', $_GET);
439  $this->assertNull($newArray);
440 
441  //Test with dynamic search
442  $_GET['testing'] = array(
443  'a' => null,
444  'dynamicClauses' => array(array('b' => 'c')),
445  'dynamicStructure' => '1 and 2',
446  );
447  $newArray = SearchUtil::getDynamicSearchAttributesFromArray('testing', $_GET);
448  $compareData = array(array('b' => 'c'));
449  $this->assertEquals($compareData, $newArray);
450 
451  //Test with dynamic search and an undefined sub-array
452  $_GET['testing'] = array(
453  'a' => null,
454  'dynamicClauses' => array(array('b' => 'c'), 'undefined', array('d' => 'simpleDimple')),
455  'dynamicStructure' => '1 and 2',
456  );
457  $newArray = SearchUtil::getDynamicSearchAttributesFromArray('testing', $_GET);
458  $compareData = array(0 => array('b' => 'c'), 2 => array('d' => 'simpleDimple'));
459  $this->assertEquals($compareData, $newArray);
460 
461  //Test with an empty value being converted to null, also tests nested empty values
462  $_GET['testing'] = array(
463  'a' => null,
464  'dynamicClauses' => array(array('b' => 'c'), 'undefined', array('d' => ''),
465  array('e' => array('f' => array('g' => ''))),
466  array('e' => array('f' => '')),
467  ),
468  'dynamicStructure' => '1 and 2',
469  );
470  $newArray = SearchUtil::getDynamicSearchAttributesFromArray('testing', $_GET);
471  $compareData = array(0 => array('b' => 'c'), 2 => array('d' => null),
472  array('e' => array('f' => array('g' => null))),
473  array('e' => array('f' => null)));
474  $this->assertEquals($compareData, $newArray);
475  $this->assertTrue($newArray[2]['d'] === null);
476  $this->assertTrue($newArray[3]['e']['f']['g'] === null);
477  $this->assertTrue($newArray[4]['e']['f'] === null);
478  }
479 
480  public function testSanitizeDynamicSearchAttributesByDesignerTypeForSavingModel()
481  {
482  $searchModel = new ASearchFormTestModel(new A());
483  //Test without anything special sanitizing
484  $dynamicSearchAttributes = array(
485  0 => array('attributeIndexOrDerivedType' => 'a',
486  'structurePosition' => '1',
487  'a' => 'something'),
488  2 => array('attributeIndexOrDerivedType' => 'a',
489  'structurePosition' => '2',
490  'a' => 'somethingElse'));
492  $dynamicSearchAttributes);
493  $this->assertEquals($dynamicSearchAttributes, $newArray);
494  }
495 
496  public function testSanitizeDynamicSearchAttributesByDesignerTypeForSavingModelWithNestedAttributes()
497  {
498  $searchModel = new IIISearchFormTestModel(new III());
499  //Test without anything special sanitizing
500  $dynamicSearchAttributes = array(
501  0 => array('attributeIndexOrDerivedType' => 'iiiMember',
502  'structurePosition' => '1',
503  'iiiMember' => 'something'),
504  1 => array('attributeIndexOrDerivedType' => 'ccc' . FormModelUtil::RELATION_DELIMITER . 'cccMember',
505  'structurePosition' => '2',
506  'ccc' => array(
507  'relatedModelData' => true,
508  'cccMember' => 'somethingElse',
509  )),
510  2 => array('attributeIndexOrDerivedType' => 'ccc' . FormModelUtil::RELATION_DELIMITER .
511  'bbb' . FormModelUtil::RELATION_DELIMITER . 'bbbMember',
512  'structurePosition' => '2',
513  'ccc' => array(
514  'relatedModelData' => true,
515  'bbb' => array(
516  'relatedModelData' => true,
517  'bbbMember' => 'bbbValue',
518  )
519  )));
521  $dynamicSearchAttributes);
522  $this->assertEquals($dynamicSearchAttributes, $newArray);
523  }
524 
525  public function testSanitizeDynamicSearchAttributesByDesignerTypeForSavingModelWithSanitizableItems()
526  {
527  $language = Yii::app()->getLanguage();
528  $this->assertEquals($language, 'en');
529  $searchModel = new IIISearchFormTestModel(new III());
530  $dynamicSearchAttributes = array(
531  0 => array('attributeIndexOrDerivedType' => 'date__Date',
532  'structurePosition' => '1',
533  'date__Date' =>
534  array('firstDate' => '5/4/2011',
535  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER)),
536  2 => array('attributeIndexOrDerivedType' => 'date2__Date',
537  'structurePosition' => '2',
538  'date2__Date' =>
539  array('firstDate' => '5/6/2011',
540  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER)),
541  3 => array('attributeIndexOrDerivedType' => 'dateTime__DateTime',
542  'structurePosition' => '1',
543  'dateTime__DateTime' =>
544  array('firstDate' => '5/7/2011',
545  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER)),
546  5 => array('attributeIndexOrDerivedType' => 'dateTime2__DateTime',
547  'structurePosition' => '2',
548  'dateTime2__DateTime' =>
549  array('firstDate' => '5/8/2011',
550  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER)),
551  );
553  $dynamicSearchAttributes);
554  $compareData = array(
555  0 => array('attributeIndexOrDerivedType' => 'date__Date',
556  'structurePosition' => '1',
557  'date__Date' =>
558  array('firstDate' => '2011-05-04',
559  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER)),
560  2 => array('attributeIndexOrDerivedType' => 'date2__Date',
561  'structurePosition' => '2',
562  'date2__Date' =>
563  array('firstDate' => '2011-05-06',
564  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER)),
565  3 => array('attributeIndexOrDerivedType' => 'dateTime__DateTime',
566  'structurePosition' => '1',
567  'dateTime__DateTime' =>
568  array('firstDate' => '2011-05-07',
569  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER)),
570  5 => array('attributeIndexOrDerivedType' => 'dateTime2__DateTime',
571  'structurePosition' => '2',
572  'dateTime2__DateTime' =>
573  array('firstDate' => '2011-05-08',
574  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER)),
575  );
576  $this->assertEquals($compareData, $newArray);
577  }
578 
579  public function testSanitizeDynamicSearchAttributesByDesignerTypeForSavingModelWithSanitizableItemsNestedSingleLevel()
580  {
581  $language = Yii::app()->getLanguage();
582  $this->assertEquals($language, 'en');
583  $searchModel = new CCCSearchFormTestModel(new CCC());
584  $dynamicSearchAttributes = array(
585  0 => array('attributeIndexOrDerivedType' => 'iii' . FormModelUtil::RELATION_DELIMITER . 'date__Date',
586  'structurePosition' => '1',
587  'iii' => array(
588  'relatedModelData' => true,
589  'date__Date' =>
590  array('firstDate' => '5/4/2011',
591  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER))),
592  1 => array('attributeIndexOrDerivedType' => 'iii' . FormModelUtil::RELATION_DELIMITER . 'dateTime__DateTime',
593  'structurePosition' => '1',
594  'iii' => array(
595  'relatedModelData' => true,
596  'dateTime__DateTime' =>
597  array('firstDate' => '5/7/2011',
598  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER))),
599  );
600 
602  $dynamicSearchAttributes);
603  $compareData = array(
604  0 => array('attributeIndexOrDerivedType' => 'iii' . FormModelUtil::RELATION_DELIMITER . 'date__Date',
605  'structurePosition' => '1',
606  'iii' => array(
607  'relatedModelData' => true,
608  'date__Date' =>
609  array('firstDate' => '2011-05-04',
610  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER))),
611  1 => array('attributeIndexOrDerivedType' => 'iii' . FormModelUtil::RELATION_DELIMITER . 'dateTime__DateTime',
612  'structurePosition' => '1',
613  'iii' => array(
614  'relatedModelData' => true,
615  'dateTime__DateTime' =>
616  array('firstDate' => '2011-05-07',
617  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER))),
618  );
619  $this->assertEquals($compareData, $newArray);
620  }
621 
622  public function testSanitizeDynamicSearchAttributesByDesignerTypeForSavingModelWithSanitizableItemsNestedNMultipleLevelsDeep()
623  {
624  $language = Yii::app()->getLanguage();
625  $this->assertEquals($language, 'en');
626  $searchModel = new AAASearchFormTestModel(new AAA());
627  $dynamicSearchAttributes = array(
628  0 => array('attributeIndexOrDerivedType' => 'bbb' .
629  FormModelUtil::RELATION_DELIMITER . 'ccc' .
630  FormModelUtil::RELATION_DELIMITER . 'iii' .
631  FormModelUtil::RELATION_DELIMITER . 'date__Date',
632  'structurePosition' => '1',
633  'bbb' => array(
634  'relatedModelData' => true,
635  'ccc' => array(
636  'relatedModelData' => true,
637  'iii' => array(
638  'relatedModelData' => true,
639  'date__Date' =>
640  array('firstDate' => '5/4/2011',
641  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER))))),
642  1 => array('attributeIndexOrDerivedType' => 'bbb' .
643  FormModelUtil::RELATION_DELIMITER . 'ccc' .
644  FormModelUtil::RELATION_DELIMITER . 'iii' .
645  FormModelUtil::RELATION_DELIMITER . 'dateTime__DateTime',
646  'structurePosition' => '1',
647  'bbb' => array(
648  'relatedModelData' => true,
649  'ccc' => array(
650  'relatedModelData' => true,
651  'iii' => array(
652  'relatedModelData' => true,
653  'date__Date' =>
654  array('firstDate' => '5/7/2011',
655  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER))))),
656  );
657 
659  $dynamicSearchAttributes);
660  $compareData = array(
661  0 => array('attributeIndexOrDerivedType' => 'bbb' .
662  FormModelUtil::RELATION_DELIMITER . 'ccc' .
663  FormModelUtil::RELATION_DELIMITER . 'iii' .
664  FormModelUtil::RELATION_DELIMITER . 'date__Date',
665  'structurePosition' => '1',
666  'bbb' => array(
667  'relatedModelData' => true,
668  'ccc' => array(
669  'relatedModelData' => true,
670  'iii' => array(
671  'relatedModelData' => true,
672  'date__Date' =>
673  array('firstDate' => '2011-05-04',
674  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER))))),
675  1 => array('attributeIndexOrDerivedType' => 'bbb' .
676  FormModelUtil::RELATION_DELIMITER . 'ccc' .
677  FormModelUtil::RELATION_DELIMITER . 'iii' .
678  FormModelUtil::RELATION_DELIMITER . 'dateTime__DateTime',
679  'structurePosition' => '1',
680  'bbb' => array(
681  'relatedModelData' => true,
682  'ccc' => array(
683  'relatedModelData' => true,
684  'iii' => array(
685  'relatedModelData' => true,
686  'date__Date' =>
687  array('firstDate' => '2011-05-07',
688  'type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER))))),
689  );
690  $this->assertEquals($compareData, $newArray);
691  }
692 
693  public function testGetDynamicSearchStructureFromGetArray()
694  {
695  $_GET['testing'] = array(
696  'a' => '',
697  );
698  $newString = SearchUtil::getDynamicSearchStructureFromArray('testing', $_GET);
699  $this->assertNull($newString);
700  $_GET['testing'] = array(
701  'a' => null,
702  'dynamicStructure' => '1 and 2',
703  );
704  $newString = SearchUtil::getDynamicSearchStructureFromArray('testing', $_GET);
705  $this->assertEquals('1 and 2', $newString);
706  }
707 
712  {
713  $searchArray = array(
714  'a' => 'apple',
715  'b' => array(
716  'relatedModelData' => true,
717  'bMember' => '',
718  ),
719  'c' => array(
720  'relatedModelData' => true,
721  'd' => array(
722  'relatedModelData' => true,
723  'dMember' => '',
724  ),
725  ),
726  );
727  $testArray = array(
728  'a' => 'apple',
729  'b' => array(
730  'relatedModelData' => true,
731  'bMember' => null,
732  ),
733  'c' => array(
734  'relatedModelData' => true,
735  'd' => array(
736  'relatedModelData' => true,
737  'dMember' => null,
738  ),
739  ),
740  );
741  $newArray = SearchUtil::getSearchAttributesFromSearchArray($searchArray);
742  $this->assertEquals($testArray, $newArray);
743  }
744 
745  public function testGetFilteredByFromArray()
746  {
747  $getArrayName = 'someArray';
748  $result = SearchUtil::getFilteredByFromArray($getArrayName, $_GET);
749  $this->assertNull($result);
750 
751  $_GET['someArray']['filteredBy'] = 'all';
752  $result = SearchUtil::getFilteredByFromArray($getArrayName, $_GET);
753  $this->assertEquals('all', $result);
754 
755  $_GET['someArray']['filteredBy'] = 'none';
756  $result = SearchUtil::getFilteredByFromArray($getArrayName, $_GET);
757  $this->assertEquals('none', $result);
758  }
759  }
760 ?>
static resolveSelectedListAttributesForSearchModelFromArray($searchModel, $getArrayName, $sourceData)
Definition: SearchUtil.php:111
static sanitizeDynamicSearchAttributesByDesignerTypeForSavingModel(DynamicSearchForm $searchModel, $dynamicSearchAttributes)
Definition: SearchUtil.php:430
static getSearchAttributesFromSearchArray($searchArray)
Definition: SearchUtil.php:266
Definition: III.php:37
static getDynamicSearchStructureFromArray($getArrayName, $sourceData)
Definition: SearchUtil.php:503
testGetSearchAttributesFromSearchArrayWithRecursiveNullResolution()
static getSortAttributeFromSortString($sortString)
Definition: SearchUtil.php:231
Definition: AAA.php:37
const RELATION_DELIMITER
Definition: A.php:37
static getSearchAttributesFromSearchArrayForSavingExistingSearchCriteria($searchArray)
Definition: SearchUtil.php:342
static getDynamicSearchAttributesFromArray($getArrayName, $sourceData)
Definition: SearchUtil.php:404
Definition: CCC.php:37
testGetSearchAttributesFromSearchArrayChangeEmptyArrayValuesToNull()
static resolveAnyMixedAttributesScopeForSearchModelFromArray($searchModel, $getArrayName, $sourceData)
Definition: SearchUtil.php:80
static resolveFilterByStarredFromArray($searchModel, $getArrayName, $sourceData)
Definition: SearchUtil.php:209
static isSortDescending($sortString)
Definition: SearchUtil.php:248
static resolveSearchAttributesFromArray($getArrayName, $formModelClassName, $sourceData)
Definition: SearchUtil.php:52
static resolveSortAttributeFromArray($getArrayPrefixName, $sourceData)
Definition: SearchUtil.php:173
static resolveSortDescendingFromArray($getArrayPrefixName, $sourceData)
Definition: SearchUtil.php:190
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.