Example #1
0
 public function testSetSameAttributeNameOnDifferenteModelClassNames()
 {
     $compareAttributeLabels = array('de' => 'sameattribute de', 'en' => 'sameattribute en', 'es' => 'sameattribute es', 'fr' => 'sameattribute fr', 'it' => 'sameattribute it');
     $attributeForm = new TextAreaAttributeForm();
     $attributeForm->attributeName = 'same';
     $attributeForm->attributeLabels = $compareAttributeLabels;
     $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
     $adapter = new $modelAttributesAdapterClassName(new Account());
     $adapter->setAttributeMetadataFromForm($attributeForm);
     $attributeForm = new TextAreaAttributeForm();
     $attributeForm->attributeName = 'same';
     $attributeForm->attributeLabels = $compareAttributeLabels;
     $attributeForm->modelClassName = 'Contact';
     $attributeForm->setScenario('createAttribute');
     $this->assertTrue($attributeForm->validate());
 }
 public static function createTextAreaAttribute($attributeName, $withDefaultData, $modelClassName)
 {
     assert('isset($attributeName) && $attributeName != null');
     assert('isset($withDefaultData) && is_bool($withDefaultData)');
     $attributeForm = new TextAreaAttributeForm();
     $attributeForm->attributeName = $attributeName;
     $attributeForm->attributeLabels = array('de' => 'Test' . $attributeName . 'de', 'en' => 'Test' . $attributeName . 'en', 'es' => 'Test' . $attributeName . 'es', 'fr' => 'Test' . $attributeName . 'fr', 'it' => 'Test' . $attributeName . 'it');
     $attributeForm->isAudited = true;
     $attributeForm->isRequired = false;
     if ($withDefaultData) {
         $attributeForm->defaultValue = 'Kangaroo Pouch';
     }
     $validate = $attributeForm->validate();
     if ($validate == false) {
         throw new FailedToValidateException();
     }
     $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
     $adapter = new $modelAttributesAdapterClassName(new $modelClassName());
     try {
         $adapter->setAttributeMetadataFromForm($attributeForm);
     } catch (FailedDatabaseSchemaChangeException $e) {
         echo $e->getMessage();
         Yii::app()->end(0, false);
     }
 }