Exemplo n.º 1
0
 /**
  * @depends testResolveBeforeSaveByModelForByTime
  */
 public function testResolveAfterSaveByModel()
 {
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('aDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(5);
     $workflow->setModuleClassName('WorkflowsTestModule');
     $workflow->setName('myFirstWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     $workflow->setIsActive(true);
     //Add trigger
     $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType());
     $trigger->attributeIndexOrDerivedType = 'string';
     $trigger->value = 'aValue';
     $trigger->operator = 'equals';
     $workflow->addTrigger($trigger);
     //Add action
     $action = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_CREATE;
     $action->relation = 'hasOne';
     $attributes = array('name' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'));
     $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
     $workflow->addAction($action);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $model = new WorkflowModelTestItem();
     $model->string = 'aValue';
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $model->addWorkflowToProcessAfterSave($workflow);
     $this->assertEquals(0, count(WorkflowModelTestItem2::getAll()));
     SavedWorkflowsUtil::resolveAfterSaveByModel($model, Yii::app()->user->userModel);
     $this->assertEquals(1, count(WorkflowModelTestItem2::getAll()));
 }
 /**
  * @depends testMakeRecipientsForAHasManyRelation
  */
 public function testMakeRecipientsForAHasOneRelation()
 {
     $form = new DynamicTriggeredModelRelationUserWorkflowEmailMessageRecipientForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
     $form->relation = 'hasOne';
     $form->dynamicUserType = DynamicTriggeredModelRelationUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_OWNER;
     $model = new WorkflowModelTestItem();
     $model->lastName = 'lastName';
     $model->string = 'string';
     $this->assertTrue($model->save());
     //Test without any related model
     $recipients = $form->makeRecipients($model, self::$sarah);
     $this->assertEquals(0, count($recipients));
     //Test with a related model
     $model2 = new WorkflowModelTestItem2();
     $model2->name = 'model 2';
     $this->assertTrue($model2->save());
     $this->assertTrue($model2->id > 0);
     $model->hasOne = $model2;
     $this->assertTrue($model->save());
     $this->assertTrue($model->hasOne->id > 0);
     $recipients = $form->makeRecipients($model, self::$sarah);
     $this->assertEquals(1, count($recipients));
     $this->assertTrue($recipients[0]->personOrAccount->isSame(self::$super));
 }
 /**
  * @depends testProcessBeforeSave
  */
 public function testProcessAfterSave()
 {
     //Save everyone group
     $group = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $this->assertTrue($group->save());
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('aDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(5);
     $workflow->setModuleClassName('WorkflowsTestModule');
     $workflow->setName('myFirstWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     $workflow->setIsActive(true);
     //Add trigger
     $trigger = new TriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType());
     $trigger->attributeIndexOrDerivedType = 'string';
     $trigger->value = 'aValue';
     $trigger->operator = 'equals';
     $workflow->addTrigger($trigger);
     //Add action
     $action = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_CREATE;
     $action->relation = 'hasOne';
     $attributes = array('name' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'), 'permissions' => array('shouldSetValue' => '1', 'type' => ExplicitReadWriteModelPermissionsWorkflowActionAttributeForm::TYPE_DYNAMIC_EVERYONE_GROUP));
     $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
     $workflow->addAction($action);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $model = new WorkflowModelTestItem();
     $model->string = 'aValue';
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, WorkflowModelTestItem2::getCount());
     WorkflowActionsUtil::processAfterSave($workflow, $model, Yii::app()->user->userModel);
     $workflowModelTestItem2s = WorkflowModelTestItem2::getAll();
     $this->assertEquals(1, count($workflowModelTestItem2s));
     //Confirm permissions are on the everyone group
     $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($workflowModelTestItem2s[0]);
     $this->assertEquals(1, $explicitReadWriteModelPermissions->getReadWritePermitablesCount());
     $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $this->assertTrue(isset($readWritePermitables[$everyoneGroup->getClassId('Permitable')]));
 }