All Data Structures Functions Variables Pages
ModelAttributeRulesToWorkflowActionAttributeUtilTest.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 testGetApplicableRulesByModelClassNameAndAttributeName()
40  {
42  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'boolean', 'value');
43  $compareData = array();
44  $this->assertEquals($compareData, $rules);
45 
47  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'date', 'value');
48  $compareData = array();
49  $this->assertEquals($compareData, $rules);
50 
52  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'dateTime', 'value');
53  $compareData = array();
54  $this->assertEquals($compareData, $rules);
55 
57  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'float', 'value');
58  $compareData = array(array('value', 'length', 'min' => 2, 'max' => 64));
59  $this->assertEquals($compareData, $rules);
60 
62  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'integer', 'value');
63  $compareData = array(array('value', 'length', 'min' => 2, 'max' => 64));
64  $this->assertEquals($compareData, $rules);
65 
67  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'phone', 'value');
68  $compareData = array(array('value', 'length', 'min' => 1, 'max' => 14));
69  $this->assertEquals($compareData, $rules);
70 
72  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'string', 'value');
73  $compareData = array(array('value', 'length', 'min' => 1, 'max' => 64));
74  $this->assertEquals($compareData, $rules);
75 
77  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'textArea', 'value');
78  $compareData = array();
79  $this->assertEquals($compareData, $rules);
80 
82  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'url', 'value');
83  $compareData = array();
84  $this->assertEquals($compareData, $rules);
85 
87  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'firstName', 'value');
88  $compareData = array(array('value', 'length', 'min' => 1, 'max' => 32));
89  $this->assertEquals($compareData, $rules);
90 
92  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'lastName', 'value');
93  $compareData = array(array('value', 'length', 'min' => 2, 'max' => 32));
94  $this->assertEquals($compareData, $rules);
95 
96  //Now test lastName and string with required as applicable.
98  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'string', 'value', true);
99  $compareData = array(array('value', 'length', 'min' => 1, 'max' => 64));
100  $this->assertEquals($compareData, $rules);
101 
102  //Variations of dropdowns should return array() because they will be always the same and already defined
103  //in the rules of the corresponding forms.
105  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'dropDown', 'value');
106  $compareData = array();
107  $this->assertEquals($compareData, $rules);
108 
110  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'multiDropDown', 'value');
111  $compareData = array();
112  $this->assertEquals($compareData, $rules);
113 
115  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'radioDropDown', 'value');
116  $compareData = array();
117  $this->assertEquals($compareData, $rules);
118 
120  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'tagCloud', 'value');
121  $compareData = array();
122  $this->assertEquals($compareData, $rules);
123 
124  //CurrencyValue should return array() as well since the rules never change so they can be specified in the
125  //form.
127  getApplicableRulesByModelClassNameAndAttributeName('WorkflowModelTestItem', 'currencyValue', 'value');
128  $compareData = array();
129  $this->assertEquals($compareData, $rules);
130  }
131 
135  public function testOwnedEmailModel()
136  {
138  getApplicableRulesByModelClassNameAndAttributeName('Email', 'emailAddress', 'value');
139  $compareData = array();
140  $this->assertEquals($compareData, $rules);
141 
143  getApplicableRulesByModelClassNameAndAttributeName('Email', 'optOut', 'value');
144  $compareData = array();
145  $this->assertEquals($compareData, $rules);
146  }
147 
151  public function testOwnedAddressModel()
152  {
154  getApplicableRulesByModelClassNameAndAttributeName('Address', 'city', 'value');
155  $compareData = array(array('value', 'length', 'max' => 32));
156  $this->assertEquals($compareData, $rules);
157 
159  getApplicableRulesByModelClassNameAndAttributeName('Address', 'latitude', 'value');
160  $compareData = array(array('value', 'length', 'max' => 12),
161  array('value', 'RedBeanModelNumberValidator', 'precision' => 7));
162  $this->assertEquals($compareData, $rules);
163  }
164 
169  {
170  Yii::app()->user->userModel = User::getByUsername('super');
171  $import = new Import();
172  $import->serializedData = serialize(array('importRulesType' => 'Accounts'));
173  $this->assertTrue($import->save());
174 
175  ModulesSearchWithDataProviderTestHelper::createDateAttribute(new Account(), 'date');
176  ModulesSearchWithDataProviderTestHelper::createDateTimeAttribute(new Account(), 'dateTime');
177  ModulesSearchWithDataProviderTestHelper::createCheckBoxAttribute(new Account(), 'checkbox');
178  ModulesSearchWithDataProviderTestHelper::createDecimalAttribute(new Account(), 'decimal');
179  ModulesSearchWithDataProviderTestHelper::createIntegerAttribute(new Account(), 'integer');
180  ModulesSearchWithDataProviderTestHelper::createPhoneAttribute(new Account(), 'phone');
181  ModulesSearchWithDataProviderTestHelper::createTextAttribute(new Account(), 'text');
182  ModulesSearchWithDataProviderTestHelper::createTextAreaAttribute(new Account(), 'textArea');
183  ModulesSearchWithDataProviderTestHelper::createUrlAttribute(new Account(), 'url');
184 
185  //Test All custom created types since their rules could vary
187  getApplicableRulesByModelClassNameAndAttributeName('Account', 'dateCstm', 'value');
188  $compareData = array();
189  $this->assertEquals($compareData, $rules);
191  getApplicableRulesByModelClassNameAndAttributeName('Account', 'dateTimeCstm', 'value');
192  $compareData = array();
193  $this->assertEquals($compareData, $rules);
195  getApplicableRulesByModelClassNameAndAttributeName('Account', 'checkboxCstm', 'value');
196  $compareData = array();
197  $this->assertEquals($compareData, $rules);
199  getApplicableRulesByModelClassNameAndAttributeName('Account', 'decimalCstm', 'value');
200  $compareData = array(array('value', 'length', 'max' => 6),
201  array('value', 'RedBeanModelNumberValidator', 'precision' => 2));
202  $this->assertEquals($compareData, $rules);
204  getApplicableRulesByModelClassNameAndAttributeName('Account', 'integerCstm', 'value');
205  $compareData = array(array('value', 'length', 'max' => 11),
206  array('value', 'numerical', 'min' => -500000, 'max' => 500000));
207  $this->assertEquals($compareData, $rules);
209  getApplicableRulesByModelClassNameAndAttributeName('Account', 'phoneCstm', 'value');
210  $compareData = array(array('value', 'length', 'max' => 20));
211  $this->assertEquals($compareData, $rules);
213  getApplicableRulesByModelClassNameAndAttributeName('Account', 'textCstm', 'value');
214  $compareData = array(array('value', 'length', 'max' => 50));
215  $this->assertEquals($compareData, $rules);
217  getApplicableRulesByModelClassNameAndAttributeName('Account', 'textAreaCstm', 'value');
218  $compareData = array();
219  $this->assertEquals($compareData, $rules);
221  getApplicableRulesByModelClassNameAndAttributeName('Account', 'urlCstm', 'value');
222  $compareData = array(array('value', 'length', 'max' => 50));
223  $this->assertEquals($compareData, $rules);
224  }
225  }
226 ?>
static getByUsername($username)
Definition: User.php:49
static getApplicableRulesByModelClassNameAndAttributeName($modelClassName, $attributeName, $ruleAttributeName)
Generated on Tue May 26 2020 07:10:35