All Data Structures Functions Variables Pages
ModulesSearchFormTest.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 
41  {
42  public static function setUpBeforeClass()
43  {
44  parent::setUpBeforeClass();
45  SecurityTestHelper::createSuperAdmin();
46  $super = User::getByUsername('super');
47  Yii::app()->user->userModel = $super;
48  }
49 
50  public function testSearchFormAnyAttributes()
51  {
52  $super = User::getByUsername('super');
53  //Confirm the adaptedMetadata is correctly formed, when nothing is inputed for search.
54  $fakePostData = array();
55  $metadataAdapter = new SearchDataProviderMetadataAdapter(new AccountsSearchForm(new Account(false)),
56  $super->id, $fakePostData);
57  $searchAttributeData = $metadataAdapter->getAdaptedMetadata();
58  $this->assertEquals(array(), $searchAttributeData['clauses']);
59  $this->assertEquals('', $searchAttributeData['structure']);
60 
61  //Now search on anyState
62  $this->assertTrue(property_exists('AccountsSearchForm', 'anyState'));
63  $this->assertFalse(property_exists('AccountsSearchForm', 'name'));
64  $fakePostData = array(
65  'anyState' => 'Illinois',
66  'anyStreet' => 'Thompson',
67  );
68  $metadataAdapter = new SearchDataProviderMetadataAdapter(new AccountsSearchForm(new Account(false)),
69  $super->id, $fakePostData);
70  $searchAttributeData = $metadataAdapter->getAdaptedMetadata();
71  $compareClauses = array(
72  1 => array(
73  'attributeName' => 'billingAddress',
74  'relatedAttributeName' => 'state',
75  'operatorType' => 'startsWith',
76  'value' => 'Illinois',
77  ),
78  2 => array(
79  'attributeName' => 'shippingAddress',
80  'relatedAttributeName' => 'state',
81  'operatorType' => 'startsWith',
82  'value' => 'Illinois',
83  ),
84  3 => array(
85  'attributeName' => 'billingAddress',
86  'relatedAttributeName' => 'street1',
87  'operatorType' => 'startsWith',
88  'value' => 'Thompson',
89  ),
90  4 => array(
91  'attributeName' => 'shippingAddress',
92  'relatedAttributeName' => 'street1',
93  'operatorType' => 'startsWith',
94  'value' => 'Thompson',
95  ),
96  );
97  $compareStructure = '(1 or 2) and (3 or 4)';
98  $this->assertEquals($compareClauses, $searchAttributeData['clauses']);
99  $this->assertEquals($compareStructure, $searchAttributeData['structure']);
100 
101  //testCheckBox 'any' search.
102  $fakePostData = array(
103  'anyOptOutEmail' => array('value' => '1'),
104  );
105  $metadataAdapter = new SearchDataProviderMetadataAdapter(new AccountsSearchForm(new Account(false)),
106  $super->id, $fakePostData);
107  $searchAttributeData = $metadataAdapter->getAdaptedMetadata();
108  $compareClauses = array(
109  1 => array(
110  'attributeName' => 'primaryEmail',
111  'relatedAttributeName' => 'optOut',
112  'operatorType' => 'equals',
113  'value' => (bool)1,
114  ),
115  2 => array(
116  'attributeName' => 'secondaryEmail',
117  'relatedAttributeName' => 'optOut',
118  'operatorType' => 'equals',
119  'value' => (bool)1,
120  ),
121  );
122  $compareStructure = '(1 or 2)';
123  $this->assertEquals($compareClauses, $searchAttributeData['clauses']);
124  $this->assertEquals($compareStructure, $searchAttributeData['structure']);
125 
126  //Now add other non 'any' attributes to the search to make sure it works ok.
127  $fakePostData = array(
128  'anyState' => 'Illinois',
129  'anyOptOutEmail' => array('value' => '1'),
130  'name' => 'ABC Company',
131  );
132  $metadataAdapter = new SearchDataProviderMetadataAdapter(new AccountsSearchForm(new Account(false)),
133  $super->id, $fakePostData);
134  $searchAttributeData = $metadataAdapter->getAdaptedMetadata();
135  $compareClauses = array(
136  1 => array(
137  'attributeName' => 'billingAddress',
138  'relatedAttributeName' => 'state',
139  'operatorType' => 'startsWith',
140  'value' => 'Illinois',
141  ),
142  2 => array(
143  'attributeName' => 'shippingAddress',
144  'relatedAttributeName' => 'state',
145  'operatorType' => 'startsWith',
146  'value' => 'Illinois',
147  ),
148  3 => array(
149  'attributeName' => 'primaryEmail',
150  'relatedAttributeName' => 'optOut',
151  'operatorType' => 'equals',
152  'value' => (bool)1,
153  ),
154  4 => array(
155  'attributeName' => 'secondaryEmail',
156  'relatedAttributeName' => 'optOut',
157  'operatorType' => 'equals',
158  'value' => (bool)1,
159  ),
160  5 => array(
161  'attributeName' => 'name',
162  'operatorType' => 'startsWith',
163  'value' => 'ABC Company',
164  ),
165  );
166  $compareStructure = '(1 or 2) and (3 or 4) and 5';
167  $this->assertEquals($compareClauses, $searchAttributeData['clauses']);
168  $this->assertEquals($compareStructure, $searchAttributeData['structure']);
169 
170  //Test using an or clause between everything.
171  $searchAttributeData = $metadataAdapter->getAdaptedMetadata(false);
172  $compareClauses = array(
173  1 => array(
174  'attributeName' => 'billingAddress',
175  'relatedAttributeName' => 'state',
176  'operatorType' => 'startsWith',
177  'value' => 'Illinois',
178  ),
179  2 => array(
180  'attributeName' => 'shippingAddress',
181  'relatedAttributeName' => 'state',
182  'operatorType' => 'startsWith',
183  'value' => 'Illinois',
184  ),
185  3 => array(
186  'attributeName' => 'primaryEmail',
187  'relatedAttributeName' => 'optOut',
188  'operatorType' => 'equals',
189  'value' => (bool)1,
190  ),
191  4 => array(
192  'attributeName' => 'secondaryEmail',
193  'relatedAttributeName' => 'optOut',
194  'operatorType' => 'equals',
195  'value' => (bool)1,
196  ),
197  5 => array(
198  'attributeName' => 'name',
199  'operatorType' => 'startsWith',
200  'value' => 'ABC Company',
201  ),
202  );
203  $compareStructure = '((1 or 2) or (3 or 4) or 5)';
204  $this->assertEquals($compareClauses, $searchAttributeData['clauses']);
205  $this->assertEquals($compareStructure, $searchAttributeData['structure']);
206  }
207 
212  {
213  //get the super user here
214  $super = User::getByUsername('super');
215  Yii::app()->user->userModel = $super;
216 
217  //test the anyOptOut value '' for search.
218  $fakePostData = array(
219  'anyOptOutEmail' => array('value' => ''),
220  );
221  $metadataAdapter = new SearchDataProviderMetadataAdapter(new AccountsSearchForm(new Account(false)),
222  $super->id, $fakePostData);
223  $searchAttributeData = $metadataAdapter->getAdaptedMetadata();
224 
225  $compareStructure = '(1 or 2)';
226 
227  $this->assertEquals(array(), $searchAttributeData['clauses']);
228  $this->assertEquals(null, $searchAttributeData['structure']);
229 
230  //test the anyOptOut value '0' for search.
231  $fakePostData = array(
232  'anyOptOutEmail' => array('value' => '0'),
233  );
234  $metadataAdapter = new SearchDataProviderMetadataAdapter(new AccountsSearchForm(new Account(false)),
235  $super->id, $fakePostData);
236  $searchAttributeData = $metadataAdapter->getAdaptedMetadata();
237  $compareClauses = array(
238  1 => array(
239  'attributeName' => 'primaryEmail',
240  'relatedAttributeName' => 'optOut',
241  'operatorType' => 'equals',
242  'value' => '0',
243  ),
244  2 => array(
245  'attributeName' => 'primaryEmail',
246  'relatedAttributeName' => 'optOut',
247  'operatorType' => 'isNull',
248  'value' => null,
249  ),
250  3 => array(
251  'attributeName' => 'secondaryEmail',
252  'relatedAttributeName' => 'optOut',
253  'operatorType' => 'equals',
254  'value' => '0',
255  ),
256  4 => array(
257  'attributeName' => 'secondaryEmail',
258  'relatedAttributeName' => 'optOut',
259  'operatorType' => 'isNull',
260  'value' => null,
261  ),
262  );
263  $compareStructure = '((1 or 2) or (3 or 4))';
264 
265  $this->assertEquals($compareClauses, $searchAttributeData['clauses']);
266  $this->assertEquals($compareStructure, $searchAttributeData['structure']);
267 
268  //test the anyOptOut value '1' for search.
269  $fakePostData = array(
270  'anyOptOutEmail' => array('value' => '1'),
271  );
272  $metadataAdapter = new SearchDataProviderMetadataAdapter(new AccountsSearchForm(new Account(false)),
273  $super->id, $fakePostData);
274  $searchAttributeData = $metadataAdapter->getAdaptedMetadata();
275  $compareClauses = array(
276  1 => array(
277  'attributeName' => 'primaryEmail',
278  'relatedAttributeName' => 'optOut',
279  'operatorType' => 'equals',
280  'value' => (bool)1,
281  ),
282  2 => array(
283  'attributeName' => 'secondaryEmail',
284  'relatedAttributeName' => 'optOut',
285  'operatorType' => 'equals',
286  'value' => (bool)1,
287  ),
288  );
289  $compareStructure = '(1 or 2)';
290  $this->assertEquals($compareClauses, $searchAttributeData['clauses']);
291  $this->assertEquals($compareStructure, $searchAttributeData['structure']);
292  }
293  }
294 ?>
static getByUsername($username)
Definition: User.php:49
Generated on Wed Feb 26 2020 07:10:43