public function testUserResolveValueAndSetToModelUpdateAsDynamicCreatedByUser() { //Setup a triggered model that has Sarah creating and owning it. $super = Yii::app()->user->userModel; Yii::app()->user->userModel = User::getByUsername('sarah'); $triggeredModel = new WorkflowModelTestItem(); $triggeredModel->lastName = 'test'; $triggeredModel->string = 'test'; $saved = $triggeredModel->save(); $this->assertTrue($saved); Yii::app()->user->userModel = $super; //Now the super is who modified it $triggeredModel->string = 'test2'; $saved = $triggeredModel->save(); $this->assertTrue($saved); //Test created by user $form = new UserWorkflowActionAttributeForm('WorkflowsTestModule', 'WorkflowModelTestItem'); $form->type = UserWorkflowActionAttributeForm::TYPE_DYNAMIC_CREATED_BY_USER; $model = new WorkflowModelTestItem(); $adapter = new WorkflowActionProcessingModelAdapter($model, Yii::app()->user->userModel, $triggeredModel); $this->assertTrue($model->user->id < 0); $form->resolveValueAndSetToModel($adapter, 'user'); $this->assertEquals(self::$sarahUserId, $model->user->id); //Test modified by user $form = new UserWorkflowActionAttributeForm('WorkflowsTestModule', 'WorkflowModelTestItem'); $form->type = UserWorkflowActionAttributeForm::TYPE_DYNAMIC_MODIFIED_BY_USER; $model = new WorkflowModelTestItem(); $adapter = new WorkflowActionProcessingModelAdapter($model, User::getByUsername('bobby'), $triggeredModel); $this->assertTrue($model->user->id < 0); $form->resolveValueAndSetToModel($adapter, 'user'); $this->assertEquals(self::$superUserId, $model->user->id); //Test triggered by user $form = new UserWorkflowActionAttributeForm('WorkflowsTestModule', 'WorkflowModelTestItem'); $form->type = UserWorkflowActionAttributeForm::TYPE_DYNAMIC_TRIGGERED_BY_USER; $model = new WorkflowModelTestItem(); $adapter = new WorkflowActionProcessingModelAdapter($model, User::getByUsername('bobby'), $triggeredModel); $this->assertTrue($model->user->id < 0); $form->resolveValueAndSetToModel($adapter, 'user'); $this->assertEquals(self::$bobbyUserId, $model->user->id); //Test owner of triggered model $form = new UserWorkflowActionAttributeForm('WorkflowsTestModule', 'WorkflowModelTestItem'); $form->type = UserWorkflowActionAttributeForm::TYPE_DYNAMIC_OWNER_OF_TRIGGERED_MODEL; $model = new WorkflowModelTestItem(); $adapter = new WorkflowActionProcessingModelAdapter($model, User::getByUsername('bobby'), $triggeredModel); $this->assertTrue($model->user->id < 0); $form->resolveValueAndSetToModel($adapter, 'user'); $this->assertEquals(self::$sarahUserId, $model->user->id); }
public function testGetTypeValuesAndLabels() { $form = new CheckBoxWorkflowActionAttributeForm('WorkflowModelTestItem', 'boolean'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new CurrencyValueWorkflowActionAttributeForm('WorkflowModelTestItem', 'currencyValue'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new DateWorkflowActionAttributeForm('WorkflowModelTestItem', 'date'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(2, count($valuesAndLabels)); $valuesAndLabels = $form->getTypeValuesAndLabels(false, true); $this->assertEquals(3, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new DateTimeWorkflowActionAttributeForm('WorkflowModelTestItem', 'dateTime'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(2, count($valuesAndLabels)); $valuesAndLabels = $form->getTypeValuesAndLabels(false, true); $this->assertEquals(3, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new DecimalWorkflowActionAttributeForm('WorkflowModelTestItem', 'float'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new DropDownWorkflowActionAttributeForm('WorkflowModelTestItem', 'dropDowns'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $valuesAndLabels = $form->getTypeValuesAndLabels(false, true); $this->assertEquals(2, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new EmailWorkflowActionAttributeForm('WorkflowModelTestItem', 'email'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $valuesAndLabels = $form->getTypeValuesAndLabels(true, false); $this->assertEquals(2, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new IntegerWorkflowActionAttributeForm('WorkflowModelTestItem', 'integer'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new ContactStateWorkflowActionAttributeForm('WorkflowModelTestItem', 'likeContactState'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new MultiSelectDropDownWorkflowActionAttributeForm('WorkflowModelTestItem', 'multiDropDown'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new PhoneWorkflowActionAttributeForm('WorkflowModelTestItem', 'phone'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $valuesAndLabels = $form->getTypeValuesAndLabels(true, false); $this->assertEquals(2, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new RadioDropDownWorkflowActionAttributeForm('WorkflowModelTestItem', 'radioDropDown'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $valuesAndLabels = $form->getTypeValuesAndLabels(false, true); $this->assertEquals(2, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new TagCloudWorkflowActionAttributeForm('WorkflowModelTestItem', 'tagCloud'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new TextWorkflowActionAttributeForm('WorkflowModelTestItem', 'text'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $valuesAndLabels = $form->getTypeValuesAndLabels(true, false); $this->assertEquals(2, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new TextAreaWorkflowActionAttributeForm('WorkflowModelTestItem', 'textArea'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $valuesAndLabels = $form->getTypeValuesAndLabels(true, false); $this->assertEquals(2, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new UrlWorkflowActionAttributeForm('WorkflowModelTestItem', 'url'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(1, count($valuesAndLabels)); $valuesAndLabels = $form->getTypeValuesAndLabels(true, false); $this->assertEquals(2, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new UserWorkflowActionAttributeForm('WorkflowModelTestItem', 'user'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(2, count($valuesAndLabels)); $valuesAndLabels = $form->getTypeValuesAndLabels(false, true); $this->assertEquals(4, count($valuesAndLabels)); $this->assertTrue($form->resolveValueBeforeSave()); $form = new ExplicitReadWriteModelPermissionsWorkflowActionAttributeForm('WorkflowModelTestItem', 'permissions'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(3, count($valuesAndLabels)); $this->assertFalse($form->resolveValueBeforeSave()); //Make new group and confirm it shows up $group = new Group(); $group->name = 'test'; $this->assertTrue($group->save()); $form = new ExplicitReadWriteModelPermissionsWorkflowActionAttributeForm('WorkflowModelTestItem', 'permissions'); $valuesAndLabels = $form->getTypeValuesAndLabels(true, true); $this->assertEquals(4, count($valuesAndLabels)); }
/** * @depends testTextWorkflowAttributeFormSetGetAndValidate */ public function testUserWorkflowAttributeFormSetGetAndValidate() { $bobby = User::getByUsername('bobby'); $form = new UserWorkflowActionAttributeForm('WorkflowModelTestItem', 'owner'); $form->type = WorkflowActionAttributeForm::TYPE_STATIC; $form->shouldSetValue = true; $form->value = $bobby->id; $validated = $form->validate(); $this->assertTrue($validated); //Test invalid value $form->value = 'invalid value, should be integer'; $validated = $form->validate(); $this->assertFalse($validated); //test with a value still, it shouldn't validate because with dynamic user, it doesn't need a value $form->type = UserWorkflowActionAttributeForm::TYPE_DYNAMIC_CREATED_BY_USER; $validated = $form->validate(); $this->assertFalse($validated); //Test without a value and it should pass $form->value = null; $validated = $form->validate(); $this->assertTrue($validated); }