public function __construct(RedBeanModel $model = null, $attributeName = null) { assert('$attributeName === null || is_string($attributeName)'); assert('$model === null || $model->isAttribute($attributeName)'); if ($model !== null) { $this->attributeName = $attributeName; $this->attributeLabels = $model->getAttributeLabelsForAllActiveLanguagesByAttributeName($attributeName); $this->attributePropertyToDesignerFormAdapter = new AttributePropertyToDesignerFormAdapter(); $validators = $model->getValidators($attributeName); foreach ($validators as $validator) { if ($validator instanceof CDefaultValueValidator) { $this->defaultValue = $validator->value; } elseif ($validator instanceof CRequiredValidator) { $this->isRequired = true; $modelAttributesAdapter = new ModelAttributesAdapter($model); if ($modelAttributesAdapter->isStandardAttribute($attributeName) && $modelAttributesAdapter->isStandardAttributeRequiredByDefault($attributeName)) { $this->attributePropertyToDesignerFormAdapter->setUpdateRequiredFieldStatus(false); } } } if ($model instanceof Item && $attributeName != null) { $this->isAudited = $model->isAttributeAudited($attributeName); } } }
/** * @depends testRemoveAttributeByName */ public function testModelAttributesAdapterIsStandardAttribute() { Yii::app()->user->userModel = User::getByUsername('super'); $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(); } $adapter = new ModelAttributesAdapter(new Account()); $this->assertFalse($adapter->isStandardAttribute('testText2')); $this->assertTrue($adapter->isStandardAttribute('name')); }