public function testAreAllRequiredAttributesMappedOrHaveRules() { Yii::app()->user->userModel = User::getByUsername('super'); $requiredAttributeCollection = ImportModelTestItemImportRules::getRequiredAttributesCollectionNotIncludingReadOnly(); $this->assertEquals(2, count($requiredAttributeCollection)); //Should fail, because nothing has been mapped. $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection('ImportModelTestItem', array()); $passed = ImportRulesUtil::areAllRequiredAttributesMappedOrHaveRules($requiredAttributeCollection, $mappedAttributeImportRulesCollection); $this->assertFalse($passed); //Should fail because only one of 2 required attributes has been mapped. $this->assertEquals(2, count($requiredAttributeCollection)); $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection('ImportModelTestItem', array('boolean')); $passed = ImportRulesUtil::areAllRequiredAttributesMappedOrHaveRules($requiredAttributeCollection, $mappedAttributeImportRulesCollection); $this->assertFalse($passed); //Should pass because all two required attributes are mapped as non-derived $this->assertEquals(2, count($requiredAttributeCollection)); $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection('ImportModelTestItem', array('boolean', 'string', 'lastName')); $passed = ImportRulesUtil::areAllRequiredAttributesMappedOrHaveRules($requiredAttributeCollection, $mappedAttributeImportRulesCollection); $this->assertTrue($passed); //Should pass because 2 of the attributes are mapped as non-derived, and lastName is mapped via derived $this->assertEquals(0, count($requiredAttributeCollection)); $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection('ImportModelTestItem', array('boolean', 'string', 'FullName')); $requiredAttributeCollection = ImportModelTestItemImportRules::getRequiredAttributesCollectionNotIncludingReadOnly(); $passed = ImportRulesUtil::areAllRequiredAttributesMappedOrHaveRules($requiredAttributeCollection, $mappedAttributeImportRulesCollection); $this->assertTrue($passed); //Check related Model where it uses a ModelDerivedAttributeImportRules, should pass $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection('ImportModelTestItem5', array('ImportModelTestItem3Derived')); $passed = ImportRulesUtil::areAllRequiredAttributesMappedOrHaveRules($requiredAttributeCollection, $mappedAttributeImportRulesCollection); $this->assertTrue($passed); }
public function testGetRequiredAttributesCollectionNotIncludingReadOnly() { Yii::app()->user->userModel = User::getByUsername('super'); $requiredAttributesCollection = ImportModelTestItemImportRules::getRequiredAttributesCollectionNotIncludingReadOnly(); $this->assertEquals(2, count($requiredAttributesCollection)); $compareData = array('lastName' => array('attributeLabel' => 'Last Name', 'attributeName' => 'lastName', 'relationAttributeName' => null, 'attributeImportRulesType' => 'Text', 'isRequired' => true), 'string' => array('attributeLabel' => 'String', 'attributeName' => 'string', 'relationAttributeName' => null, 'attributeImportRulesType' => 'Text', 'isRequired' => true)); $this->assertEquals($compareData, $requiredAttributesCollection); }