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 }