All Data Structures Functions Variables Pages
ModelAttributeRulesToDefaultValueMappingRuleUtilTest.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  }
44 
45  public function testGetApplicableRulesByModelClassNameAndAttributeName()
46  {
48  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'boolean', 'defaultValue');
49  $compareData = array(array('defaultValue', 'boolean'));
50  $this->assertEquals($compareData, $rules);
51 
53  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'date', 'defaultValue');
54  $compareData = array(array('defaultValue', 'TypeValidator', 'type' => 'date'));
55  $this->assertEquals($compareData, $rules);
56 
58  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'dateTime', 'defaultValue');
59  $compareData = array(array('defaultValue', 'TypeValidator', 'type' => 'datetime'));
60  $this->assertEquals($compareData, $rules);
61 
62  //Test multiple variations of dateTime. Required/Not-Required. Also when having a dependency
64  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem5', 'requiredDateTime', 'defaultValue', true);
65  $compareData = array(array('defaultValue', 'TypeValidator', 'type' => 'datetime'),
66  array('defaultValue', 'required'));
67  $this->assertEquals($compareData, $rules);
68 
70  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem5', 'startDateTime', 'defaultValue', true);
71  $compareData = array(array('defaultValue', 'required'),
72  array('defaultValue', 'TypeValidator', 'type' => 'datetime'));
73  $this->assertEquals($compareData, $rules);
74 
76  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem5', 'endDateTime', 'defaultValue');
77  $compareData = array(array('defaultValue', 'TypeValidator', 'type' => 'datetime'));
78  $this->assertEquals($compareData, $rules);
79 
81  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'float', 'defaultValue');
82  $compareData = array(array('defaultValue', 'type', 'type' => 'float'));
83  $this->assertEquals($compareData, $rules);
84 
86  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'integer', 'defaultValue');
87  $compareData = array(array('defaultValue', 'type', 'type' => 'integer'));
88  $this->assertEquals($compareData, $rules);
89 
91  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'phone', 'defaultValue');
92  $compareData = array(array('defaultValue', 'type', 'type' => 'string'),
93  array('defaultValue', 'length', 'min' => 1, 'max' => 14));
94  $this->assertEquals($compareData, $rules);
95 
97  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'string', 'defaultValue');
98  $compareData = array(array('defaultValue', 'type', 'type' => 'string'),
99  array('defaultValue', 'length', 'min' => 3, 'max' => 64));
100  $this->assertEquals($compareData, $rules);
101 
103  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'textArea', 'defaultValue');
104  $compareData = array(array('defaultValue', 'type', 'type' => 'string'));
105  $this->assertEquals($compareData, $rules);
106 
108  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'url', 'defaultValue');
109  $compareData = array(array('defaultValue', 'url'));
110  $this->assertEquals($compareData, $rules);
111 
113  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'firstName', 'defaultValue');
114  $compareData = array(array('defaultValue', 'type', 'type' => 'string'),
115  array('defaultValue', 'length', 'min' => 1, 'max' => 32));
116  $this->assertEquals($compareData, $rules);
117 
119  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'lastName', 'defaultValue');
120  $compareData = array(array('defaultValue', 'type', 'type' => 'string'),
121  array('defaultValue', 'length', 'min' => 2, 'max' => 32));
122  $this->assertEquals($compareData, $rules);
123 
124  //Now test lastName and string with required as applicable.
126  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'string', 'defaultValue', true);
127  $compareData = array(array('defaultValue', 'required'),
128  array('defaultValue', 'type', 'type' => 'string'),
129  array('defaultValue', 'length', 'min' => 3, 'max' => 64));
130  $this->assertEquals($compareData, $rules);
131 
133  getApplicableRulesByModelClassNameAndAttributeName('ImportModelTestItem', 'lastName', 'defaultValue', true);
134  $compareData = array(array('defaultValue', 'required'),
135  array('defaultValue', 'type', 'type' => 'string'),
136  array('defaultValue', 'length', 'min' => 2, 'max' => 32));
137  $this->assertEquals($compareData, $rules);
138  }
139 
140  public function testGetApplicableRulesByModelClassNameAndAttributeNameForCustomCreatedTypes()
141  {
142  Yii::app()->user->userModel = User::getByUsername('super');
143  $import = new Import();
144  $import->serializedData = serialize(array('importRulesType' => 'Accounts'));
145  $this->assertTrue($import->save());
146 
147  ModulesSearchWithDataProviderTestHelper::createDateAttribute(new Account(), 'date');
148  ModulesSearchWithDataProviderTestHelper::createDateTimeAttribute(new Account(), 'dateTime');
149  ModulesSearchWithDataProviderTestHelper::createCheckBoxAttribute(new Account(), 'checkbox');
150  ModulesSearchWithDataProviderTestHelper::createDecimalAttribute(new Account(), 'decimal');
151  ModulesSearchWithDataProviderTestHelper::createIntegerAttribute(new Account(), 'integer');
152  ModulesSearchWithDataProviderTestHelper::createPhoneAttribute(new Account(), 'phone');
153  ModulesSearchWithDataProviderTestHelper::createTextAttribute(new Account(), 'text');
154  ModulesSearchWithDataProviderTestHelper::createTextAreaAttribute(new Account(), 'textArea');
155  ModulesSearchWithDataProviderTestHelper::createUrlAttribute(new Account(), 'url');
156 
157  //Test All custom created types since their rules could vary
159  getApplicableRulesByModelClassNameAndAttributeName('Account', 'dateCstm', 'defaultValue');
160  $compareData = array(array('defaultValue', 'TypeValidator', 'type' => 'date'));
161  $this->assertEquals($compareData, $rules);
163  getApplicableRulesByModelClassNameAndAttributeName('Account', 'dateTimeCstm', 'defaultValue');
164  $compareData = array(array('defaultValue', 'TypeValidator', 'type' => 'datetime'));
165  $this->assertEquals($compareData, $rules);
167  getApplicableRulesByModelClassNameAndAttributeName('Account', 'checkboxCstm', 'defaultValue');
168  $compareData = array(array('defaultValue', 'boolean'));
169  $this->assertEquals($compareData, $rules);
171  getApplicableRulesByModelClassNameAndAttributeName('Account', 'decimalCstm', 'defaultValue');
172  $compareData = array(array('defaultValue', 'length', 'max' => 6),
173  array('defaultValue', 'RedBeanModelNumberValidator', 'precision' => 2),
174  array('defaultValue', 'type', 'type' => 'float'));
175  $this->assertEquals($compareData, $rules);
177  getApplicableRulesByModelClassNameAndAttributeName('Account', 'integerCstm', 'defaultValue');
178  $compareData = array(array('defaultValue', 'length', 'max' => 11),
179  array('defaultValue', 'numerical', 'min' => -500000, 'max' => 500000),
180  array('defaultValue', 'type', 'type' => 'integer'));
181  $this->assertEquals($compareData, $rules);
183  getApplicableRulesByModelClassNameAndAttributeName('Account', 'phoneCstm', 'defaultValue');
184  $compareData = array(array('defaultValue', 'length', 'max' => 20),
185  array('defaultValue', 'type', 'type' => 'string'));
186  $this->assertEquals($compareData, $rules);
188  getApplicableRulesByModelClassNameAndAttributeName('Account', 'textCstm', 'defaultValue');
189  $compareData = array(array('defaultValue', 'length', 'max' => 50),
190  array('defaultValue', 'type', 'type' => 'string'));
191  $this->assertEquals($compareData, $rules);
193  getApplicableRulesByModelClassNameAndAttributeName('Account', 'textAreaCstm', 'defaultValue');
194  $compareData = array(array('defaultValue', 'type', 'type' => 'string'));
195  $this->assertEquals($compareData, $rules);
197  getApplicableRulesByModelClassNameAndAttributeName('Account', 'urlCstm', 'defaultValue');
198  $compareData = array(array('defaultValue', 'length', 'max' => 50),
199  array('defaultValue', 'url', 'defaultScheme' => 'http'));
200  $this->assertEquals($compareData, $rules);
201  //todo: add the rest of the custom field types that are importable
202  }
203  }
204 ?>
static getByUsername($username)
Definition: User.php:49
static getApplicableRulesByModelClassNameAndAttributeName($modelClassName, $attributeName, $ruleAttributeName, $requiredRuleIsApplicable=false, $treatDateTimeAsDate=false, $readOnlyRuleIsApplicable=true)
Generated on Sun May 31 2020 07:10:32