Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SearchFormTest.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 SearchFormTest extends BaseTest
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  {
53  $searchForm::getSearchFormAttributeMappingRulesTypeByAttribute('AttributeDoesNotExist');
54  }
55 
60  {
62  $mappingRulesType = $searchForm::getSearchFormAttributeMappingRulesTypeByAttribute('differentOperatorA');
63  $this->assertEquals('OwnedItemsOnly', $mappingRulesType);
64  }
65 
70  {
72  $searchForm->something__NotReal;
73  }
74 
75  public function testDynamicDateAttributeOnForm()
76  {
78 
79  //Test get and set.
80  $this->assertEquals(null, $searchForm->date__Date);
81  $searchForm->date__Date = 'aTest';
82  $this->assertEquals('aTest', $searchForm->date__Date);
83 
84  //Test getting attribute names collection
85  $compareData = array('anyA',
86  'ABName',
87  'differentOperatorA',
88  'differentOperatorB',
89  'dateDateTimeADate__Date',
90  'dateDateTimeADateTime__DateTime',
91  'dynamicStructure',
92  'dynamicClauses',
93  'anyMixedAttributes',
94  'filterByStarred',
95  'date__Date',
96  'date2__Date',
97  'dateTime__DateTime',
98  'dateTime2__DateTime',
99  );
100  $this->assertEquals($compareData, $searchForm->attributeNames());
101 
102  //Check some other methods to make sure they work ok.
103  $this->assertFalse ($searchForm::isRelation('date__Date'));
104  $this->assertTrue ($searchForm->isAttribute('date__Date'));
105  $this->assertFalse ($searchForm->isAttributeRequired('date__Date'));
106 
107  //Test attributeRules and attributeLabels
108  $attributeLabels = $searchForm->attributeLabels();
109  $this->assertEquals('Date', $attributeLabels['date__Date']);
110  $this->assertEquals('Date 2', $attributeLabels['date2__Date']);
111  $compareData = array(
112  array('date__Date', 'safe'),
113  array('date2__Date', 'safe'),
114  array('dateTime__DateTime', 'safe'),
115  array('dateTime2__DateTime', 'safe'),
116  array('dynamicStructure', 'safe'),
117  array('dynamicStructure', 'validateDynamicStructure', 'on' => 'validateDynamic, validateSaveSearch'),
118  array('dynamicClauses', 'safe'),
119  array('dynamicClauses', 'validateDynamicClauses', 'on' => 'validateDynamic, validateSaveSearch'),
120  array('anyA', 'safe'),
121  array('ABName', 'safe'),
122  array('differentOperatorA', 'safe'),
123  array('differentOperatorB', 'boolean'),
124  array('dateDateTimeADate__Date', 'safe'),
125  array('dateDateTimeADateTime__DateTime', 'safe'),
126  );
127  $this->assertEquals($compareData, $searchForm->rules());
128 
129  //Test additional methods.
130  $mappedData = $searchForm->getAttributesMappedToRealAttributesMetadata();
131  $this->assertEquals('resolveEntireMappingByRules', $mappedData['date__Date']);
132  $mappingRulesType = $searchForm->getSearchFormAttributeMappingRulesTypeByAttribute('date__Date');
133  $this->assertEquals('MixedDateTypes', $mappingRulesType);
134 
135  //Test that the correct elements are used for the dynamic date attribute.
136  $elementType = ModelAttributeToMixedTypeUtil::getType($searchForm, 'date__Date');
137  $this->assertEquals('MixedDateTypesForSearch', $elementType);
138  }
139 
140  public function testDynamicDateTimeAttributeOnForm()
141  {
143 
144  //Test get and set.
145  $this->assertEquals(null, $searchForm->dateTime__DateTime);
146  $searchForm->dateTime__DateTime = 'aTest';
147  $this->assertEquals('aTest', $searchForm->dateTime__DateTime);
148 
149  //Check some other methods to make sure they work ok.
150  $this->assertFalse ($searchForm::isRelation('dateTime__DateTime'));
151  $this->assertTrue ($searchForm->isAttribute('dateTime__DateTime'));
152  $this->assertFalse ($searchForm->isAttributeRequired('dateTime__DateTime'));
153 
154  //Test attributeRules and attributeLabels
155  $attributeLabels = $searchForm->attributeLabels();
156  $this->assertEquals('Date Time', $attributeLabels['dateTime__DateTime']);
157  $this->assertEquals('Date Time 2', $attributeLabels['dateTime2__DateTime']);
158 
159  //Test additional methods.
160  $mappedData = $searchForm->getAttributesMappedToRealAttributesMetadata();
161  $this->assertEquals('resolveEntireMappingByRules', $mappedData['dateTime__DateTime']);
162  $mappingRulesType = $searchForm->getSearchFormAttributeMappingRulesTypeByAttribute('dateTime__DateTime');
163  $this->assertEquals('MixedDateTimeTypes', $mappingRulesType);
164 
165  //Test that the correct elements are used for the dynamic date attribute.
166  $elementType = ModelAttributeToMixedTypeUtil::getType($searchForm, 'dateTime__DateTime');
167  $this->assertEquals('MixedDateTypesForSearch', $elementType);
168  }
169 
170  public function testGetGlobalSearchAttributeNamesAndLabelsAndAll()
171  {
172  $searchModel = new ASearchFormTestModel(new A());
173  $data = $searchModel->getGlobalSearchAttributeNamesAndLabelsAndAll();
174  $compareData = array('All' => 'All', 'a' => 'A', 'name' => 'Name');
175  $this->assertEquals($compareData, $data);
176  }
177 
178  public function testResolveMixedSearchAttributeMappedToRealAttributesMetadata()
179  {
180  $realAttributesMetadata = array('something' => 'somethingElse');
181  $searchModel = new ASearchFormTestModel(new A());
182  $searchModel->resolveMixedSearchAttributeMappedToRealAttributesMetadata($realAttributesMetadata);
183  $compareData = array('anyMixedAttributes' => array(array('a'), array('name')),
184  'something' => 'somethingElse');
185  $this->assertEquals($compareData, $realAttributesMetadata);
186 
187  //Add scoping.
188  $searchModel = new ASearchFormTestModel(new A());
189  $searchModel->setAnyMixedAttributesScope(array('name'));
190  $searchModel->resolveMixedSearchAttributeMappedToRealAttributesMetadata($realAttributesMetadata);
191  $compareData = array('anyMixedAttributes' => array(array('name')),
192  'something' => 'somethingElse');
193  $this->assertEquals($compareData, $realAttributesMetadata);
194  }
195 
196  public function testGetNonSearchableAttributes()
197  {
198  $data = SearchForm::getNonSearchableAttributes();
199  $compareData = array(SearchForm::ANY_MIXED_ATTRIBUTES_SCOPE_NAME,
200  SearchForm::SELECTED_LIST_ATTRIBUTES,
201  KanbanBoard::GROUP_BY_ATTRIBUTE_VISIBLE_VALUES,
202  KanbanBoard::SELECTED_THEME,
203  'filterByStarred');
204  $this->assertEquals($compareData, $data);
205  }
206  }
207 ?>
static getByUsername($username)
Definition: User.php:49
testGetSearchFormAttributeMappingRulesTypeByAttributeWithValidAttribute()
testInvalidDynamicDateAttributeOnForm()
Definition: A.php:37
static getType($model, $attributeName)
testGetSearchFormAttributeMappingRulesTypeByAttributeWithInvalidAttribute()
Generated on Wed Jul 8 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.