Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SQLOperatorUtilTest.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 function testIsValidOperatorTypeByValue()
40  {
41  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('startsWith', 'abc'));
42  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('doesNotStartsWith', 'abc'));
43  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('doesNotEndsWith', 'abc'));
44  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('doesNotContains', 'abc'));
45  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('greaterThan', 'abc'));
46  $this->assertFalse(SQLOperatorUtil::isValidOperatorTypeByValue ('startsWith', 5));
47  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('greaterThan', 5));
48  $this->assertFalse(SQLOperatorUtil::isValidOperatorTypeByValue ('doesNotMatter', null));
49  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('oneOf', array(4, 5, 6)));
50  $this->assertFalse(SQLOperatorUtil::isValidOperatorTypeByValue ('oneOf', null));
51  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('greaterThanOrEqualTo', 'abc'));
52  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('lessThanOrEqualTo', 'abc'));
53  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('isNull', null));
54  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('isNotNull', null));
55  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('isEmpty', null));
56  $this->assertTrue(SQLOperatorUtil::isValidOperatorTypeByValue ('isNotEmpty', null));
57  }
58 
59  public function testGetOperatorByType()
60  {
61  $this->assertEquals('>', SQLOperatorUtil::getOperatorByType('greaterThan'));
62  $this->assertEquals('not like', SQLOperatorUtil::getOperatorByType('doesNotStartsWith'));
63  $this->assertEquals('not like', SQLOperatorUtil::getOperatorByType('doesNotEndsWith'));
64  $this->assertEquals('not like', SQLOperatorUtil::getOperatorByType('doesNotContains'));
65  }
66 
67  public function testResolveOperatorAndValueForOneOf()
68  {
69  $queryPart = SQLOperatorUtil::resolveOperatorAndValueForOneOf('oneOf', array(5, 6, 7));
70  $compareQueryPart = "IN(5,6,7)"; // Not Coding Standard
71  $this->assertEquals($compareQueryPart, $queryPart);
72  $queryPart = SQLOperatorUtil::resolveOperatorAndValueForOneOf('oneOf', array('a', 'b', 'c'));
73  $compareQueryPart = "IN('a','b','c')"; // Not Coding Standard
74  $this->assertEquals($compareQueryPart, $queryPart);
75  }
76 
77  public function testResolveOperatorAndValueForNullOrEmpty()
78  {
79  $queryPart = SQLOperatorUtil::resolveOperatorAndValueForNullOrEmpty('isNull');
80  $compareQueryPart = "IS NULL"; // Not Coding Standard
81  $this->assertEquals($compareQueryPart, $queryPart);
82  $queryPart = SQLOperatorUtil::resolveOperatorAndValueForNullOrEmpty('isNotNull');
83  $compareQueryPart = "IS NOT NULL"; // Not Coding Standard
84  $this->assertEquals($compareQueryPart, $queryPart);
85  $queryPart = SQLOperatorUtil::resolveOperatorAndValueForNullOrEmpty('isEmpty');
86  $compareQueryPart = "= ''"; // Not Coding Standard
87  $this->assertEquals($compareQueryPart, $queryPart);
88  $queryPart = SQLOperatorUtil::resolveOperatorAndValueForNullOrEmpty('isNotEmpty');
89  $compareQueryPart = "!= ''"; // Not Coding Standard
90  $this->assertEquals($compareQueryPart, $queryPart);
91  }
92 
97  {
98  SQLOperatorUtil::resolveOperatorAndValueForOneOf('oneOf', array(array()));
99  }
100 
105  {
106  SQLOperatorUtil::GetOperatorByType('isNull');
107  }
108 
113  {
114  SQLOperatorUtil::GetOperatorByType('isNotNull');
115  }
116 
121  {
122  SQLOperatorUtil::GetOperatorByType('isEmpty');
123  }
124 
129  {
130  SQLOperatorUtil::GetOperatorByType('isNotEmpty');
131  }
132 
133  public function testResolveOperatorAndValueForOneOfWithEscapedContent()
134  {
135  $queryPart = SQLOperatorUtil::resolveOperatorAndValueForOneOf('oneOf', array('a', "b'd", 'c'));
136  $compareQueryPart = "IN('a','b\'d','c')"; // Not Coding Standard
137  $this->assertEquals($compareQueryPart, $queryPart);
138  }
139 
140  public function testDoesOperatorTypeAllowNullValues()
141  {
142  $this->assertTrue(SQLOperatorUtil::doesOperatorTypeAllowNullValues('isNull'));
143  $this->assertTrue(SQLOperatorUtil::doesOperatorTypeAllowNullValues('isEmpty'));
144  $this->assertTrue(SQLOperatorUtil::doesOperatorTypeAllowNullValues('isNotNull'));
145  $this->assertTrue(SQLOperatorUtil::doesOperatorTypeAllowNullValues('isNotEmpty'));
146  $this->assertFalse(SQLOperatorUtil::doesOperatorTypeAllowNullValues('startsWith'));
147  }
148 
149  public function testResolveValueLeftSideLikePartByOperatorType()
150  {
151  $this->assertEquals(null, SQLOperatorUtil::resolveValueLeftSideLikePartByOperatorType('doesNotStartsWith'));
152  $this->assertEquals('%', SQLOperatorUtil::resolveValueLeftSideLikePartByOperatorType('doesNotEndsWith'));
153  $this->assertEquals('%', SQLOperatorUtil::resolveValueLeftSideLikePartByOperatorType('doesNotContains'));
154  $this->assertEquals('%', SQLOperatorUtil::resolveValueLeftSideLikePartByOperatorType('contains'));
155  }
156 
157  public function testResolveValueRightSideLikePartByOperatorType()
158  {
159  $this->assertEquals('%', SQLOperatorUtil::resolveValueRightSideLikePartByOperatorType('doesNotStartsWith'));
160  $this->assertEquals(null, SQLOperatorUtil::resolveValueRightSideLikePartByOperatorType('doesNotEndsWith'));
161  $this->assertEquals('%', SQLOperatorUtil::resolveValueRightSideLikePartByOperatorType('doesNotContains'));
162  $this->assertEquals('%', SQLOperatorUtil::resolveValueRightSideLikePartByOperatorType('contains'));
163  }
164 
165  public function testResolveValidationForATemplateSqlStatementAndReturnErrorMessage()
166  {
167  $this->assertEquals('The structure is invalid. Please fix conditions.', SQLOperatorUtil::
168  resolveValidationForATemplateSqlStatementAndReturnErrorMessage('', 1));
169  $this->assertEquals('The structure is invalid. Please fix conditions.', SQLOperatorUtil::
170  resolveValidationForATemplateSqlStatementAndReturnErrorMessage('dumb structure', 1));
171  $this->assertEquals('The structure is invalid. Please use only integers less than 2.', SQLOperatorUtil::
172  resolveValidationForATemplateSqlStatementAndReturnErrorMessage('4', 1));
173  $this->assertEquals('The structure is invalid. Please fix your parenthesis.', SQLOperatorUtil::
174  resolveValidationForATemplateSqlStatementAndReturnErrorMessage('()))', 1));
175  $this->assertEquals('The structure is invalid. Please fix your parenthesis around the not operator.', SQLOperatorUtil::
176  resolveValidationForATemplateSqlStatementAndReturnErrorMessage('(not) 2 and 1', 2));
177  $this->assertEquals('The structure is invalid. Please fix conditions.', SQLOperatorUtil::
178  resolveValidationForATemplateSqlStatementAndReturnErrorMessage('or 2 and 1', 2));
179  $this->assertEquals('The structure is invalid. Please, only use one of the operators: not, and, or.', SQLOperatorUtil::
180  resolveValidationForATemplateSqlStatementAndReturnErrorMessage('1 e 2 ou 1', 2));
181  $this->assertEquals('', SQLOperatorUtil::
182  resolveValidationForATemplateSqlStatementAndReturnErrorMessage('not (not (2 and 4) or 1 and not 4)', 4));
183  }
184  }
185 ?>
static getOperatorByType($operatorType)
static isValidOperatorTypeByValue($operatorType, $value)
static resolveValueLeftSideLikePartByOperatorType($operatorType)
testResolveOperatorAndValueForOneOfUnsupportedValue()
static resolveValueRightSideLikePartByOperatorType($operatorType)
Generated on Fri Jul 10 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.