public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; ModulesSearchWithDataProviderTestHelper::createCustomAttributesForModel(new TestOperatorTypeModel()); }
public function testGetApplicableRulesByModelClassNameAndAttributeNameForCustomCreatedTypes() { Yii::app()->user->userModel = User::getByUsername('super'); $import = new Import(); $import->serializedData = serialize(array('importRulesType' => 'Accounts')); $this->assertTrue($import->save()); ModulesSearchWithDataProviderTestHelper::createDateAttribute(new Account(), 'date'); ModulesSearchWithDataProviderTestHelper::createDateTimeAttribute(new Account(), 'dateTime'); ModulesSearchWithDataProviderTestHelper::createCheckBoxAttribute(new Account(), 'checkbox'); ModulesSearchWithDataProviderTestHelper::createDecimalAttribute(new Account(), 'decimal'); ModulesSearchWithDataProviderTestHelper::createIntegerAttribute(new Account(), 'integer'); ModulesSearchWithDataProviderTestHelper::createPhoneAttribute(new Account(), 'phone'); ModulesSearchWithDataProviderTestHelper::createTextAttribute(new Account(), 'text'); ModulesSearchWithDataProviderTestHelper::createTextAreaAttribute(new Account(), 'textArea'); ModulesSearchWithDataProviderTestHelper::createUrlAttribute(new Account(), 'url'); //Test All custom created types since their rules could vary $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'dateCstm', 'defaultValue'); $compareData = array(array('defaultValue', 'TypeValidator', 'type' => 'date')); $this->assertEquals($compareData, $rules); $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'dateTimeCstm', 'defaultValue'); $compareData = array(array('defaultValue', 'TypeValidator', 'type' => 'datetime')); $this->assertEquals($compareData, $rules); $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'checkboxCstm', 'defaultValue'); $compareData = array(array('defaultValue', 'boolean')); $this->assertEquals($compareData, $rules); $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'decimalCstm', 'defaultValue'); $compareData = array(array('defaultValue', 'length', 'max' => 6), array('defaultValue', 'RedBeanModelNumberValidator', 'precision' => 2), array('defaultValue', 'type', 'type' => 'float')); $this->assertEquals($compareData, $rules); $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'integerCstm', 'defaultValue'); $compareData = array(array('defaultValue', 'length', 'max' => 11), array('defaultValue', 'numerical', 'min' => -500000, 'max' => 500000), array('defaultValue', 'type', 'type' => 'integer')); $this->assertEquals($compareData, $rules); $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'phoneCstm', 'defaultValue'); $compareData = array(array('defaultValue', 'length', 'max' => 20), array('defaultValue', 'type', 'type' => 'string')); $this->assertEquals($compareData, $rules); $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'textCstm', 'defaultValue'); $compareData = array(array('defaultValue', 'length', 'max' => 50), array('defaultValue', 'type', 'type' => 'string')); $this->assertEquals($compareData, $rules); $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'textAreaCstm', 'defaultValue'); $compareData = array(array('defaultValue', 'type', 'type' => 'string')); $this->assertEquals($compareData, $rules); $rules = ModelAttributeRulesToDefaultValueMappingRuleUtil::getApplicableRulesByModelClassNameAndAttributeName('Account', 'urlCstm', 'defaultValue'); $compareData = array(array('defaultValue', 'length', 'max' => 50), array('defaultValue', 'url', 'defaultScheme' => 'http')); $this->assertEquals($compareData, $rules); //todo: add the rest of the custom field types that are importable }
public function testProjectValidationWithCustomPickList() { Yii::app()->user->userModel = User::getByUsername('super'); //Create a required picklist for projects ModulesSearchWithDataProviderTestHelper::createDropDownAttribute(new Project(), 'pick', true); $task = new Task(); $task->name = 'MyTestWithCustomPickList'; $this->assertTrue($task->save()); $this->assertCount(0, $task->getErrors()); }
/** * Tests that a bug involving creating a required custom picklist on projects causes the workflow * to break when creating a task */ public function testProcessWorkflowForTaskWhenProjectAsARequiredCustomPicklist() { Yii::app()->user->userModel = User::getByUsername('super'); //Create a required picklist for projects ModulesSearchWithDataProviderTestHelper::createDropDownAttribute(new Project(), 'pick', true); //Create workflow $workflow = new Workflow(); $workflow->setDescription('aDescription'); $workflow->setIsActive(true); $workflow->setOrder(5); $workflow->setModuleClassName('TasksModule'); $workflow->setName('myFirstWorkflow'); $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING); $workflow->setType(Workflow::TYPE_BY_TIME); $workflow->setTriggersStructure('1'); //Add trigger $trigger = new TimeTriggerForWorkflowForm('TasksModule', 'Task', $workflow->getType()); $trigger->attributeIndexOrDerivedType = 'dueDateTime'; $trigger->valueType = MixedDateTypesSearchFormAttributeMappingRules::TYPE_IS_TIME_FOR; $trigger->durationInterval = 5; $trigger->durationType = TimeDurationUtil::DURATION_TYPE_MONTH; $trigger->durationSign = TimeDurationUtil::DURATION_SIGN_NEGATIVE; $workflow->setTimeTrigger($trigger); //Create the saved Workflow $savedWorkflow = new SavedWorkflow(); SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow); $saved = $savedWorkflow->save(); $this->assertTrue($saved); //Confirm that the workflow processes $model = new Task(); $model->name = 'aTask'; $model->dueDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $this->assertTrue($model->save()); }