示例#1
0
 public function testValidateDefaultValue()
 {
     //First test a valid form
     $form = new UrlAttributeForm();
     $form->attributeName = 'customUrl';
     $form->attributeLabels = array('en' => 'customUrl');
     $form->defaultValue = 'www.zurmo.org';
     $this->assertTrue($form->validate());
     //Now test a form with url error
     $form = new UrlAttributeForm();
     $form->attributeName = 'customUrl';
     $form->attributeLabels = array('en' => 'customUrl');
     $form->defaultValue = 'wwwzurmoorg';
     $this->assertFalse($form->validate());
     $this->assertEquals('Default Value is not a valid URL.', $form->getError('defaultValue'));
 }
 public static function createUrlAttribute($attributeName, $withDefaultData, $modelClassName)
 {
     assert('isset($attributeName) && $attributeName != null');
     assert('isset($withDefaultData) && is_bool($withDefaultData)');
     $attributeForm = new UrlAttributeForm();
     $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;
     $attributeForm->maxLength = 50;
     if ($withDefaultData) {
         $attributeForm->defaultValue = 'http://www.outback.com';
     }
     $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);
     }
 }