Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ActionForWorkflowFormTest.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 testGetDisplayLabel()
40  {
41  $form = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
43  $label = $form->getDisplayLabel();
44  $this->assertEquals('Update', $label);
45 
46  $form = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
48  $form->relation = 'hasMany2';
49  $label = $form->getDisplayLabel();
50  $this->assertEquals('Update Related Workflows Tests', $label);
51 
52  //Test update a derived related model (this is like account's meetings)
53  $form = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
55  $form->relation = 'model5ViaItem';
56  $label = $form->getDisplayLabel();
57  $this->assertEquals('Update Related WorkflowModelTestItem5s', $label);
58 
59  $form = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
61  $form->relation = 'hasMany2';
62  $label = $form->getDisplayLabel();
63  $this->assertEquals('Create Workflows Test', $label);
64 
65  //Test update a inferred related model (this is like a meeting's accounts)
66  $form = new ActionForWorkflowForm('WorkflowModelTestItem5', Workflow::TYPE_ON_SAVE);
68  $form->relation = 'WorkflowModelTestItem__workflowItems__Inferred';
69  $label = $form->getDisplayLabel();
70  $this->assertEquals('Update Related Workflows Tests', $label);
71 
72  //Test create a related, derived related model (this is like account's meetings)
73  $form = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
75  $form->relation = 'hasMany2';
76  $form->relatedModelRelation = 'model5ViaItem';
77  $label = $form->getDisplayLabel();
78  $this->assertEquals('Create Related Workflows Tests WorkflowModelTestItem5', $label);
79 
80  //Test create a related, inferred related model (this is like a meeting's accounts)
81  $form = new ActionForWorkflowForm('WorkflowModelTestItem7', Workflow::TYPE_ON_SAVE);
83  $form->relation ='model5';
84  $form->relatedModelRelation = 'WorkflowModelTestItem__workflowItems__Inferred';
85  $label = $form->getDisplayLabel();
86  $this->assertEquals('Create Related WorkflowModelTestItem5s Workflows Test', $label);
87  }
88 
93  {
94  $action = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
96  $attributes = array(
97  'string' => array('shouldSetValue' => '1',
98  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
99  'value' => 'jason'));
100  $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
101 
102  $this->assertEquals(ActionForWorkflowForm::TYPE_UPDATE_SELF, $action->type);
103  $this->assertEquals(1, $action->getActionAttributeFormsCount());
104 
105  $this->assertTrue($action->getActionAttributeFormByName('string') instanceof TextWorkflowActionAttributeForm);
106  $this->assertEquals('Static', $action->getActionAttributeFormByName('string')->type);
107  $this->assertEquals('jason', $action->getActionAttributeFormByName('string')->value);
108  }
109 
114  {
115  $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
117  $action->relation = 'hasMany2';
118  $action->relationFilter = ActionForWorkflowForm::RELATION_FILTER_ALL;
119  $attributes = array(
120  'string' => array('shouldSetValue' => '1',
121  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
122  'value' => 'jason'));
123  $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
124 
125  $this->assertEquals(ActionForWorkflowForm::TYPE_UPDATE_RELATED, $action->type);
126  $this->assertEquals('hasMany2', $action->relation );
127  $this->assertEquals(ActionForWorkflowForm::RELATION_FILTER_ALL, $action->relationFilter);
128  $this->assertEquals(1, $action->getActionAttributeFormsCount());
129 
130  $this->assertTrue($action->getActionAttributeFormByName('string') instanceof TextWorkflowActionAttributeForm);
131  $this->assertEquals('Static', $action->getActionAttributeFormByName('string')->type);
132  $this->assertEquals('jason', $action->getActionAttributeFormByName('string')->value);
133  }
134 
139  {
140  $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
141  $action->type = ActionForWorkflowForm::TYPE_CREATE;
142  $action->relation = 'hasMany2';
143  $attributes = array(
144  'string' => array('shouldSetValue' => '1',
145  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
146  'value' => 'jason'));
147  $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
148 
149  $this->assertEquals(ActionForWorkflowForm::TYPE_CREATE, $action->type);
150  $this->assertEquals('hasMany2', $action->relation );
151  $this->assertEquals(1, $action->getActionAttributeFormsCount());
152 
153  $this->assertTrue($action->getActionAttributeFormByName('string') instanceof TextWorkflowActionAttributeForm);
154  $this->assertEquals('Static', $action->getActionAttributeFormByName('string')->type);
155  $this->assertEquals('jason', $action->getActionAttributeFormByName('string')->value);
156  }
157 
162  {
163  $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
165  $action->relation = 'hasMany2';
166  $action->relationFilter = ActionForWorkflowForm::RELATION_FILTER_ALL;
167  $action->relatedModelRelation = 'hasMany';
168  $attributes = array(
169  'name' => array('shouldSetValue' => '1',
170  'type' => WorkflowActionAttributeForm::TYPE_STATIC,
171  'value' => 'jason'));
172  $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
173 
174  $this->assertEquals(ActionForWorkflowForm::TYPE_CREATE_RELATED, $action->type);
175  $this->assertEquals('hasMany2', $action->relation );
176  $this->assertEquals(ActionForWorkflowForm::RELATION_FILTER_ALL, $action->relationFilter);
177  $this->assertEquals('hasMany', $action->relatedModelRelation);
178  $this->assertEquals(1, $action->getActionAttributeFormsCount());
179 
180  $this->assertTrue($action->getActionAttributeFormByName('name') instanceof TextWorkflowActionAttributeForm);
181  $this->assertEquals('Static', $action->getActionAttributeFormByName('name')->type);
182  $this->assertEquals('jason', $action->getActionAttributeFormByName('name')->value);
183  }
184 
188  public function testValidate()
189  {
190  $action = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
191  $validated = $action->validate();
192  $this->assertFalse($validated);
193  $errors = $action->getErrors();
194  $compareErrors = array('type' => array('Type cannot be blank.', 'Invalid Type'));
195  $this->assertEquals($compareErrors, $errors);
196  //Update type does not require any related information
198  $validated = $action->validate();
199  $this->assertTrue($validated);
200 
201  //When the type is update_related, related information is required
202  $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
203  $action->relationFilter = 'somethingInvalid';
205  $validated = $action->validate();
206  $this->assertFalse($validated);
207  $errors = $action->getErrors();
208  $compareErrors = array('relation' => array('Relation cannot be blank.'),
209  'relationFilter' => array('Invalid Relation Filter'));
210  $this->assertEquals($compareErrors, $errors);
211  $action->relation = 'hasMany2';
212  $action->relationFilter = ActionForWorkflowForm::RELATION_FILTER_ALL;
213  $validated = $action->validate();
214  $this->assertTrue($validated);
215 
216  //When the type is create, related information is required
217  $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
218  $action->type = ActionForWorkflowForm::TYPE_CREATE;
219  $action->relationFilter = ActionForWorkflowForm::RELATION_FILTER_ALL;
220  $validated = $action->validate();
221  $this->assertFalse($validated);
222  $errors = $action->getErrors();
223  $compareErrors = array('relation' => array('Relation cannot be blank.'));
224  $this->assertEquals($compareErrors, $errors);
225  $action->relation = 'hasMany2';
226  $validated = $action->validate();
227  $this->assertTrue($validated);
228 
229  //When the type is create related, additional related information is required
230  $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
232  $action->relation = 'hasMany2';
233  $action->relationFilter = ActionForWorkflowForm::RELATION_FILTER_ALL;
234  $validated = $action->validate();
235  $this->assertFalse($validated);
236  $errors = $action->getErrors();
237  $compareErrors = array('relatedModelRelation' => array('Related Model Relation cannot be blank.'));
238  $this->assertEquals($compareErrors, $errors);
239  $action->relatedModelRelation = 'hasOne';
240  $validated = $action->validate();
241  $this->assertTrue($validated);
242  }
243 
248  {
249  $form = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
251  $form->relation = 'hasMany2';
252  $data = $form->resolveAllActionAttributeFormsAndLabelsAndSort();
253  $this->assertEquals(42, count($data));
254  }
255 
260  {
261  $form = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
263  $form->relation = 'hasMany2';
264  $data = $form->resolveAllRequiredActionAttributeFormsAndLabelsAndSort();
265  $this->assertEquals(4, count($data));
266  $this->assertTrue(isset($data['permissions']));
267  }
268 
273  {
274  $form = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
276  $form->relation = 'hasMany2';
277  $data = $form->resolveAllNonRequiredActionAttributeFormsAndLabelsAndSort();
278  $this->assertEquals(39, count($data));
279 
280  //Test update a derived related model (this is like account's meetings)
281  $form = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
283  $form->relation = 'model5ViaItem';
284  $data = $form->resolveAllNonRequiredActionAttributeFormsAndLabelsAndSort();
285  $this->assertEquals(2, count($data));
286 
287  //Test update a inferred related model (this is like a meeting's accounts)
288  $form = new ActionForWorkflowForm('WorkflowModelTestItem5', Workflow::TYPE_ON_SAVE);
290  $form->relation = 'WorkflowModelTestItem__workflowItems__Inferred';
291  $data = $form->resolveAllNonRequiredActionAttributeFormsAndLabelsAndSort();
292  $this->assertEquals(39, count($data));
293 
294  //Test create a related, derived related model (this is like account's meetings)
295  $form = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
297  $form->relation = 'hasMany2';
298  $form->relatedModelRelation = 'model5ViaItem';
299  $data = $form->resolveAllNonRequiredActionAttributeFormsAndLabelsAndSort();
300  $this->assertEquals(2, count($data));
301 
302  //Test create a related, inferred related model (this is like a meeting's accounts)
303  $form = new ActionForWorkflowForm('WorkflowModelTestItem7', Workflow::TYPE_ON_SAVE);
305  $form->relation ='model5';
306  $form->relatedModelRelation = 'WorkflowModelTestItem__workflowItems__Inferred';
307  $data = $form->resolveAllNonRequiredActionAttributeFormsAndLabelsAndSort();
308  $this->assertEquals(39, count($data));
309  }
310  }
311 ?>
Generated on Thu Mar 4 2021 07:10:27
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.