Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ModelAttributeToOperatorTypeUtilTest.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  ModulesSearchWithDataProviderTestHelper::createCustomAttributesForModel(new TestOperatorTypeModel());
46  }
47 
48  public function setup()
49  {
50  Yii::app()->user->userModel = User::getByUsername('super');
51  }
52 
53  public function testGetValidOperatorTypesForAllAttributeTypes()
54  {
55  $model = new TestOperatorTypeModel();
56  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'integerStandard'));
57  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'dateStandard'));
58  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'dateTimeStandard'));
59  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'floatStandard'));
60  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'timeStandard'));
61  $this->assertEquals('startsWith', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'emailStandard'));
62  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'booleanStandard'));
63  $this->assertEquals('contains', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'urlStandard'));
64  //Test all custom fields
65  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'checkBoxCstm'));
66  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'currencyCstm'));
67  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'dateCstm'));
68  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'dateTimeCstm'));
69  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'decimalCstm'));
70  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'dropDownCstm'));
71  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'integerCstm'));
72  $this->assertEquals('startsWith', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'phoneCstm'));
73  $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'radioCstm'));
74  $this->assertEquals('startsWith', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'textCstm'));
75  $this->assertEquals('contains', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'textAreaCstm'));
76  $this->assertEquals('contains', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'urlCstm'));
77  }
78 
79  public function testGetAvailableOperatorsType()
80  {
81  $model = new TestOperatorTypeModel();
82  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER,
84  $this->assertNull( ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'dateStandard'));
85  $this->assertNull( ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'dateTimeStandard'));
86  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER,
88  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING,
90  $this->assertNull( ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'booleanStandard'));
91  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING,
93  //Test all custom fields
94  $this->assertNull( ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'checkBoxCstm'));
95  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER,
97  $this->assertNull( ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'dateCstm'));
98  $this->assertNull( ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'dateTimeCstm'));
99  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER,
101  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_DROPDOWN,
103  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER,
105  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING,
107  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_DROPDOWN,
109  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING,
111  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING,
113  $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING,
115  }
116 
117  public function testResolveOperatorsToIncludeByType()
118  {
119  $data = array();
120  ModelAttributeToOperatorTypeUtil::resolveOperatorsToIncludeByType($data, ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING);
121  $expectedData = array(
122  'equals' => 'Equals',
123  'doesNotEqual' => 'Does Not Equal',
124  'isNull' => 'Is Null', // Not Coding Standard
125  'isNotNull' => 'Is Not Null', // Not Coding Standard
126  'startsWith' => 'Starts With',
127  'doesNotStartsWith' => 'Does Not Start With',
128  'endsWith' => 'Ends With',
129  'doesNotEndsWith' => 'Does Not End With',
130  'contains' => 'Contains',
131  'doesNotContains' => 'Does Not Contain',
132  'isEmpty' => 'Is Empty',
133  'isNotEmpty' => 'Is Not Empty'
134  );
135  $this->assertEquals($expectedData, $data);
136  }
137  }
138 ?>
static getByUsername($username)
Definition: User.php:49
static getAvailableOperatorsType($model, $attributeName)
Generated on Sun Jul 12 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.