PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/modules/workflows/tests/unit/WorkflowTriggersUtilBaseTest.php

https://bitbucket.org/zurmo/zurmo/
PHP | 162 lines | 122 code | 6 blank | 34 comment | 1 complexity | 1d05853159d133f23c1525c3f8507d0c MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2015 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. 2015. All rights reserved".
  35. ********************************************************************************/
  36. class WorkflowTriggersUtilBaseTest extends WorkflowBaseTest
  37. {
  38. public static function getDependentTestModelClassNames()
  39. {
  40. return array('WorkflowModelTestItem');
  41. }
  42. public static function makeOnSaveWorkflowAndTriggerWithoutValueType($attributeIndexOrDerivedType, $operator,
  43. $value,
  44. $moduleClassName = 'WorkflowsTestModule',
  45. $modelClassName = 'WorkflowModelTestItem',
  46. $secondValue = null)
  47. {
  48. assert('is_string($attributeIndexOrDerivedType)'); // Not Coding Standard
  49. assert('is_string($operator)'); // Not Coding Standard
  50. assert('is_string($moduleClassName)'); // Not Coding Standard
  51. assert('is_string($modelClassName)'); // Not Coding Standard
  52. $workflow = new Workflow();
  53. $workflow->setType(Workflow::TYPE_ON_SAVE);
  54. $workflow->setTriggersStructure('1');
  55. $trigger = new TriggerForWorkflowForm($moduleClassName, $modelClassName, $workflow->getType());
  56. $trigger->attributeIndexOrDerivedType = $attributeIndexOrDerivedType;
  57. $trigger->value = $value;
  58. $trigger->secondValue = $secondValue;
  59. $trigger->operator = $operator;
  60. $workflow->addTrigger($trigger);
  61. return $workflow;
  62. }
  63. public static function makeOnSaveWorkflowAndTimeTriggerWithoutValueType($attributeIndexOrDerivedType, $operator,
  64. $value,
  65. $durationInterval = 0,
  66. $moduleClassName = 'WorkflowsTestModule',
  67. $modelClassName = 'WorkflowModelTestItem',
  68. $secondValue = null)
  69. {
  70. assert('is_string($attributeIndexOrDerivedType)'); // Not Coding Standard
  71. assert('is_string($operator)'); // Not Coding Standard
  72. assert('is_int($durationInterval)'); // Not Coding Standard
  73. assert('is_string($moduleClassName)'); // Not Coding Standard
  74. assert('is_string($modelClassName)'); // Not Coding Standard
  75. $workflow = new Workflow();
  76. $workflow->setType(Workflow::TYPE_BY_TIME);
  77. $workflow->setTriggersStructure('1');
  78. $trigger = new TimeTriggerForWorkflowForm($moduleClassName, $modelClassName, $workflow->getType());
  79. $trigger->attributeIndexOrDerivedType = $attributeIndexOrDerivedType;
  80. $trigger->value = $value;
  81. $trigger->secondValue = $secondValue;
  82. $trigger->operator = $operator;
  83. $trigger->durationInterval = $durationInterval;
  84. $workflow->setTimeTrigger($trigger);
  85. return $workflow;
  86. }
  87. public static function makeOnSaveWorkflowAndTriggerForDateOrDateTime($attributeIndexOrDerivedType, $valueType,
  88. $value,
  89. $moduleClassName = 'WorkflowsTestModule',
  90. $modelClassName = 'WorkflowModelTestItem',
  91. $secondValue = null,
  92. $thirdValueDurationInterval = null,
  93. $thirdValueDurationType = null)
  94. {
  95. assert('is_string($attributeIndexOrDerivedType)'); // Not Coding Standard
  96. assert('is_string($valueType)'); // Not Coding Standard
  97. assert('is_string($moduleClassName)'); // Not Coding Standard
  98. assert('is_string($modelClassName)'); // Not Coding Standard
  99. $workflow = new Workflow();
  100. $workflow->setType(Workflow::TYPE_ON_SAVE);
  101. $workflow->setTriggersStructure('1');
  102. $trigger = new TriggerForWorkflowForm($moduleClassName, $modelClassName, $workflow->getType());
  103. $trigger->attributeIndexOrDerivedType = $attributeIndexOrDerivedType;
  104. $trigger->valueType = $valueType;
  105. $trigger->value = $value;
  106. $trigger->secondValue = $secondValue;
  107. $trigger->thirdValueDurationInterval = $thirdValueDurationInterval;
  108. $trigger->thirdValueDurationType = $thirdValueDurationType;
  109. $workflow->addTrigger($trigger);
  110. return $workflow;
  111. }
  112. public static function makeOnSaveWorkflowAndTimeTriggerForDateOrDateTime($attributeIndexOrDerivedType, $valueType,
  113. $value,
  114. $durationInterval = 0,
  115. $moduleClassName = 'WorkflowsTestModule',
  116. $modelClassName = 'WorkflowModelTestItem',
  117. $secondValue = null,
  118. $durationSign = TimeDurationUtil::DURATION_SIGN_POSITIVE,
  119. $durationType = TimeDurationUtil::DURATION_TYPE_DAY)
  120. {
  121. assert('is_string($attributeIndexOrDerivedType)'); // Not Coding Standard
  122. assert('is_string($valueType)'); // Not Coding Standard
  123. assert('is_int($durationInterval)'); // Not Coding Standard
  124. assert('is_string($moduleClassName)'); // Not Coding Standard
  125. assert('is_string($modelClassName)'); // Not Coding Standard
  126. assert('is_string($durationSign)'); // Not Coding Standard
  127. assert('is_string($durationType)'); // Not Coding Standard
  128. $workflow = new Workflow();
  129. $workflow->setType(Workflow::TYPE_BY_TIME);
  130. $workflow->setTriggersStructure('1');
  131. $trigger = new TimeTriggerForWorkflowForm($moduleClassName, $modelClassName, $workflow->getType());
  132. $trigger->attributeIndexOrDerivedType = $attributeIndexOrDerivedType;
  133. $trigger->valueType = $valueType;
  134. $trigger->value = $value;
  135. $trigger->secondValue = $secondValue;
  136. $trigger->durationInterval = $durationInterval;
  137. $trigger->durationSign = $durationSign;
  138. $trigger->durationType = $durationType;
  139. $workflow->setTimeTrigger($trigger);
  140. return $workflow;
  141. }
  142. public static function saveAndReloadModel(RedBeanModel $model)
  143. {
  144. $saved = $model->save();
  145. if (!$saved)
  146. {
  147. throw new FailedToSaveModelException();
  148. }
  149. $modelId = $model->id;
  150. $modelClassName = get_class($model);
  151. $model->forget();
  152. unset($model);
  153. return $modelClassName::getById($modelId);
  154. }
  155. }
  156. ?>