/** * @param string $attributeName */ public function removeAttributeMetadata($attributeName) { assert('is_string($attributeName) && $attributeName != ""'); $modelClassName = get_class($this->model); ModelMetadataUtil::removeAttribute($modelClassName, $attributeName); }
/** * @depends testAttributeLabelsMergeCorrectlyWithExistingData */ public function testSavingCustomFieldDataLabels() { $a = new A(); $this->assertTrue($a->isAttribute('fruitCstm')); unset($a); $appleCustomField = new CustomField(); $appleCustomField->value = 'apple'; $appleCustomField->data = CustomFieldData::getByName('Fruit'); $this->assertTrue($appleCustomField->save()); $attributeLabels = array('en' => 'fruit'); ModelMetadataUtil::addOrUpdateCustomFieldRelation('A', 'fruit', $attributeLabels, $appleCustomField, true, false, 'DropDown', 'Fruit', array('apple', 'grape', 'orange'), array('fr' => array('appleFr', 'grapeFr', 'orangeFr'), 'de' => array('', 'grape', '')), 'CustomField', false); $a = new A(); $a->a = 1; $this->assertTrue($a->isAttribute('fruitCstm')); $this->assertTrue($a->validate()); $this->assertEquals('apple', $a->fruitCstm->value); $compareData = array('fr' => array('appleFr', 'grapeFr', 'orangeFr'), 'de' => array('', 'grape', '')); $this->assertEquals($compareData, unserialize($a->fruitCstm->data->serializedLabels)); unset($a); ModelMetadataUtil::removeAttribute('A', 'fruitCstm'); }
/** * @depends testSetAndGetCustomAttributes */ public function testRemoveAttributeByName() { Yii::app()->user->userModel = User::getByUsername('super'); ModelMetadataUtil::removeAttribute('Account', 'officePhone'); ModelMetadataUtil::removeAttribute('Account', 'doesNotExist'); $account = new Account(); $this->assertFalse($account->isAttribute('officePhone')); unset($account); $attributeForm = new TextAttributeForm(); $attributeForm->attributeName = 'testText2'; $attributeForm->attributeLabels = array('de' => 'Test Text2 de', 'en' => 'Test Text2 en', 'es' => 'Test Text2 es', 'fr' => 'Test Text2 fr', 'it' => 'Test Text2 it'); $attributeForm->isAudited = true; $attributeForm->isRequired = false; $attributeForm->maxLength = 60; $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } $account = new Account(); $this->assertTrue($account->isAttribute('testText2Cstm')); unset($account); $adapter->removeAttributeMetadata('testText2Cstm'); $account = new Account(); $this->assertFalse($account->isAttribute('testText2Cstm')); unset($account); }