Ejemplo n.º 1
0
 /**
  * @depends testSetAndGetActionForCreatingRelatedAction
  */
 public function testValidate()
 {
     $action = new ActionForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
     $validated = $action->validate();
     $this->assertFalse($validated);
     $errors = $action->getErrors();
     $compareErrors = array('type' => array('Type cannot be blank.', 'Invalid Type'));
     $this->assertEquals($compareErrors, $errors);
     //Update type does not require any related information
     $action->type = ActionForWorkflowForm::TYPE_UPDATE_SELF;
     $validated = $action->validate();
     $this->assertTrue($validated);
     //When the type is update_related, related information is required
     $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
     $action->relationFilter = 'somethingInvalid';
     $action->type = ActionForWorkflowForm::TYPE_UPDATE_RELATED;
     $validated = $action->validate();
     $this->assertFalse($validated);
     $errors = $action->getErrors();
     $compareErrors = array('relation' => array('Relation cannot be blank.'), 'relationFilter' => array('Invalid Relation Filter'));
     $this->assertEquals($compareErrors, $errors);
     $action->relation = 'hasMany2';
     $action->relationFilter = ActionForWorkflowForm::RELATION_FILTER_ALL;
     $validated = $action->validate();
     $this->assertTrue($validated);
     //When the type is create, related information is required
     $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_CREATE;
     $action->relationFilter = ActionForWorkflowForm::RELATION_FILTER_ALL;
     $validated = $action->validate();
     $this->assertFalse($validated);
     $errors = $action->getErrors();
     $compareErrors = array('relation' => array('Relation cannot be blank.'));
     $this->assertEquals($compareErrors, $errors);
     $action->relation = 'hasMany2';
     $validated = $action->validate();
     $this->assertTrue($validated);
     //When the type is create related, additional related information is required
     $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_CREATE_RELATED;
     $action->relation = 'hasMany2';
     $action->relationFilter = ActionForWorkflowForm::RELATION_FILTER_ALL;
     $validated = $action->validate();
     $this->assertFalse($validated);
     $errors = $action->getErrors();
     $compareErrors = array('relatedModelRelation' => array('Related Model Relation cannot be blank.'));
     $this->assertEquals($compareErrors, $errors);
     $action->relatedModelRelation = 'hasOne';
     $validated = $action->validate();
     $this->assertTrue($validated);
 }