Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DynamicSearchFormTest.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 
50  public function testValidStructure ()
51  {
52  $searchForm = new AAASearchFormTestModel(new A());
53  $searchForm->dynamicClauses = array(
54  array('structurePosition' => '1'),
55  array('structurePosition' => '2'),
56  array('structurePosition' => '3'));
57  $searchForm->dynamicStructure = '(1 AND 2 )';
58  $searchForm->validateDynamicStructure('dynamicStructure', '');
59  $this->assertFalse($searchForm->hasErrors());
60  $searchForm->clearErrors();
61  $searchForm->dynamicStructure = '1 AND 2 ';
62  $searchForm->validateDynamicStructure('dynamicStructure', '');
63  $this->assertFalse($searchForm->hasErrors());
64  $searchForm->clearErrors();
65  $searchForm->dynamicStructure = '1 and 2 ';
66  $searchForm->validateDynamicStructure('dynamicStructure', '');
67  $this->assertFalse($searchForm->hasErrors());
68  $searchForm->clearErrors();
69  $searchForm->dynamicStructure = '1 oR 2 ';
70  $searchForm->validateDynamicStructure('dynamicStructure', '');
71  $this->assertFalse($searchForm->hasErrors());
72  $searchForm->clearErrors();
73  $searchForm->dynamicStructure = '1 OR 2 AND 3';
74  $searchForm->validateDynamicStructure('dynamicStructure', '');
75  $this->assertFalse($searchForm->hasErrors());
76  $searchForm->clearErrors();
77  $searchForm->dynamicStructure = '(1 OR 2 )AND 3';
78  $searchForm->validateDynamicStructure('dynamicStructure', '');
79  $this->assertFalse($searchForm->hasErrors());
80  $searchForm->clearErrors();
81  $searchForm->dynamicStructure = '1 OR (2 )AND 3';
82  $searchForm->validateDynamicStructure('dynamicStructure', '');
83  $this->assertFalse($searchForm->hasErrors());
84  $searchForm->clearErrors();
85  $searchForm->dynamicStructure = '(1 AND 2 AND 3)';
86  $searchForm->validateDynamicStructure('dynamicStructure', '');
87  $this->assertFalse($searchForm->hasErrors());
88  $searchForm->clearErrors();
89  }
90 
94  public function testValidUseIfNoClauses()
95  {
96  $searchForm = new AAASearchFormTestModel(new A());
97  $searchForm->dynamicClauses = array();
98  $searchForm->dynamicStructure = 'a';
99  $searchForm->validateDynamicStructure('dynamicStructure', '');
100  $this->assertFalse($searchForm->hasErrors());
101  $searchForm->clearErrors();
102  $searchForm->dynamicStructure = null;
103  $searchForm->validateDynamicStructure('dynamicStructure', '');
104  $this->assertFalse($searchForm->hasErrors());
105  $searchForm->clearErrors();
106  $searchForm->dynamicStructure = 'jim';
107  $searchForm->validateDynamicStructure('dynamicStructure', '');
108  $this->assertFalse($searchForm->hasErrors());
109  $searchForm->clearErrors();
110  $searchForm->dynamicStructure = 'jim and me';
111  $searchForm->validateDynamicStructure('dynamicStructure', '');
112  $this->assertFalse($searchForm->hasErrors());
113  $searchForm->clearErrors();
114  }
115 
120  {
121  $searchForm = new AAASearchFormTestModel(new A());
122  $searchForm->dynamicClauses = array(
123  array('structurePosition' => '1'),
124  array('structurePosition' => '2'));
125  $searchForm->dynamicStructure = '1 ( 2';
126  $searchForm->validateDynamicStructure('dynamicStructure', '');
127  $this->assertTrue($searchForm->hasErrors());
128  $searchForm->clearErrors();
129  $searchForm->dynamicStructure = '1 ) 2 )';
130  $searchForm->validateDynamicStructure('dynamicStructure', '');
131  $this->assertTrue($searchForm->hasErrors());
132  $searchForm->clearErrors();
133  $searchForm->dynamicStructure = '1 ( 2 ())))';
134  $searchForm->validateDynamicStructure('dynamicStructure', '');
135  $this->assertTrue($searchForm->hasErrors());
136  $searchForm->clearErrors();
137  }
138 
143  {
144  $searchForm = new AAASearchFormTestModel(new A());
145  $searchForm->dynamicClauses = array(
146  array('structurePosition' => '1'),
147  array('structurePosition' => '2'));
148  $searchForm->dynamicStructure = '1 AND 3';
149  $searchForm->validateDynamicStructure('dynamicStructure', array());
150  $this->assertTrue($searchForm->hasErrors());
151  $searchForm->clearErrors();
152  $searchForm->dynamicStructure = '1 AND 10';
153  $searchForm->validateDynamicStructure('dynamicStructure', array());
154  $this->assertTrue($searchForm->hasErrors());
155  $searchForm->clearErrors();
156  $searchForm->dynamicStructure = '1 AND -5';
157  $searchForm->validateDynamicStructure('dynamicStructure', array());
158  $this->assertTrue($searchForm->hasErrors());
159  $searchForm->clearErrors();
160  $searchForm->dynamicStructure = '1 AND 0';
161  $searchForm->validateDynamicStructure('dynamicStructure', array());
162  $this->assertTrue($searchForm->hasErrors());
163  $searchForm->clearErrors();
164  $searchForm->dynamicStructure = '1 OR 1.4';
165  $searchForm->validateDynamicStructure('dynamicStructure', array());
166  $this->assertTrue($searchForm->hasErrors());
167  $searchForm->clearErrors();
168  $searchForm->dynamicStructure = '1 OR 1,4'; // Not Coding Standard
169  $searchForm->validateDynamicStructure('dynamicStructure', array());
170  $this->assertTrue($searchForm->hasErrors());
171  $searchForm->clearErrors();
172  }
173 
178  {
179  $searchForm = new AAASearchFormTestModel(new A());
180  $searchForm->dynamicClauses = array(
181  array('structurePosition' => '1'),
182  array('structurePosition' => '2'));
183  $searchForm->dynamicStructure = '1 + 2';
184  $searchForm->validateDynamicStructure('dynamicStructure', array());
185  $this->assertTrue($searchForm->hasErrors());
186  $searchForm->clearErrors();
187  $searchForm->dynamicStructure = '1 A* 2';
188  $searchForm->validateDynamicStructure('dynamicStructure', array());
189  $this->assertTrue($searchForm->hasErrors());
190  $searchForm->clearErrors();
191  $searchForm->dynamicStructure = '1 * 2 AND 3';
192  $searchForm->validateDynamicStructure('dynamicStructure', array());
193  $this->assertTrue($searchForm->hasErrors());
194  $searchForm->clearErrors();
195  }
196 
201  {
202  $searchForm = new AAASearchFormTestModel(new A());
203  $searchForm->dynamicClauses = array(
204  array('structurePosition' => '1'),
205  array('structurePosition' => '2'));
206  $searchForm->dynamicStructure = '1 OR OR 2';
207  $searchForm->validateDynamicStructure('dynamicStructure', array());
208  $this->assertTrue($searchForm->hasErrors());
209  $searchForm->clearErrors();
210  $searchForm->dynamicStructure = '1 AND ( 2 ) 2';
211  $searchForm->validateDynamicStructure('dynamicStructure', array());
212  $this->assertTrue($searchForm->hasErrors());
213  $searchForm->clearErrors();
214  $searchForm->dynamicStructure = 'OR 2 AND 1';
215  $searchForm->validateDynamicStructure('dynamicStructure', array());
216  $this->assertTrue($searchForm->hasErrors());
217  $searchForm->clearErrors();
218  $searchForm->dynamicStructure = 'OR 2 AND 1';
219  $searchForm->validateDynamicStructure('dynamicStructure', array());
220  $this->assertTrue($searchForm->hasErrors());
221  $searchForm->clearErrors();
222  $searchForm->dynamicStructure = '5 AND';
223  $searchForm->validateDynamicStructure('dynamicStructure', array());
224  $this->assertTrue($searchForm->hasErrors());
225  $searchForm->clearErrors();
226  }
227 
231  public function testValidateDynamicClauses()
232  {
233  $super = User::getByUsername('super');
234  Yii::app()->user->userModel = $super;
236  $searchForm->dynamicClauses = array(
237  array('structurePosition' => '1',
238  'attributeIndexOrDerivedType' => 'primaryA',
239  'primaryA' => array('name' => 'xtz')));
240  $searchForm->dynamicStructure = '1';
241  $searchForm->validateDynamicClauses('dynamicClauses', array());
242  $this->assertFalse($searchForm->hasErrors());
243  $searchForm->clearErrors();
244  }
245  }
246 ?>
static getByUsername($username)
Definition: User.php:49
Definition: A.php:37
Generated on Tue Jul 14 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.