Example #1
0
 protected function setAndGetTagCloudAttribute($attributeName, $withDefaultData)
 {
     $this->assertTrue(isset($attributeName) && $attributeName != '');
     $this->assertTrue(isset($withDefaultData) && is_bool($withDefaultData));
     $values = array('English', 'French', 'Danish', 'Spanish');
     $labels = array('fr' => array('English fr', 'French fr', 'Danish fr', 'Spanish fr'), 'de' => array('English de', 'French de', 'Danish de', 'Spanish de'));
     $languageFieldData = CustomFieldData::getByName('Languages');
     $languageFieldData->serializedData = serialize($values);
     $this->assertTrue($languageFieldData->save());
     $attributeForm = new TagCloudAttributeForm();
     $attributeForm->attributeName = $attributeName;
     $attributeForm->attributeLabels = array('de' => 'Test Languages 2 de', 'en' => 'Test Languages 2 en', 'es' => 'Test Languages 2 es', 'fr' => 'Test Languages 2 fr', 'it' => 'Test Languages 2 it');
     $attributeForm->isAudited = true;
     $attributeForm->isRequired = true;
     $attributeForm->customFieldDataData = $values;
     $attributeForm->customFieldDataName = 'Languages';
     $attributeForm->customFieldDataLabels = $labels;
     if ($withDefaultData) {
         $attributeForm->defaultValueOrder = 1;
     } else {
         $attributeForm->defaultValueOrder = null;
     }
     $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
     $adapter = new $modelAttributesAdapterClassName(new Account());
     try {
         $adapter->setAttributeMetadataFromForm($attributeForm);
     } catch (FailedDatabaseSchemaChangeException $e) {
         echo $e->getMessage();
         $this->fail();
     }
     $account = new Account();
     $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, $attributeName . 'Cstm');
     $this->assertEquals('TagCloud', $attributeForm->getAttributeTypeName());
     $this->assertEquals($attributeName . 'Cstm', $attributeForm->attributeName);
     $compareAttributeLabels = array('de' => 'Test Languages 2 de', 'en' => 'Test Languages 2 en', 'es' => 'Test Languages 2 es', 'fr' => 'Test Languages 2 fr', 'it' => 'Test Languages 2 it');
     $this->assertEquals($compareAttributeLabels, $attributeForm->attributeLabels);
     $this->assertEquals(true, $attributeForm->isAudited);
     $this->assertEquals(true, $attributeForm->isRequired);
     $this->assertEquals('Languages', $attributeForm->customFieldDataName);
     $this->assertEquals($values, $attributeForm->customFieldDataData);
     $this->assertEquals($labels, $attributeForm->customFieldDataLabels);
     if ($withDefaultData) {
         $this->assertEquals('French', $attributeForm->defaultValue);
         $this->assertEquals(1, $attributeForm->defaultValueOrder);
     } else {
         $this->assertEquals(null, $attributeForm->defaultValue);
         $this->assertEquals(null, $attributeForm->defaultValueOrder);
     }
     //Test that validation on completely new multi select picklists works correctly and is inline with the rules
     //from the CustomFieldData model.
     $attributeForm = new TagCloudAttributeForm();
     $attributeForm->attributeName = 's';
     //name to short. test that this fails.
     $attributeForm->attributeLabels = array('de' => 'Test Languages 3 de', 'en' => 'Test Languages 3 en', 'es' => 'Test Languages 3 es', 'fr' => 'Test Languages 3 fr', 'it' => 'Test Languages 3 it');
     $attributeForm->isAudited = true;
     $attributeForm->isRequired = true;
     $attributeForm->defaultValueOrder = 1;
     $attributeForm->customFieldDataData = array('a', 'b', 'c');
     $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
     $adapter = new $modelAttributesAdapterClassName(new Account());
     $this->assertFalse($attributeForm->validate());
     $attributeForm->attributeName = 'camelcased';
     $this->assertTrue($attributeForm->validate());
     try {
         $adapter->setAttributeMetadataFromForm($attributeForm);
     } catch (Exception $e) {
         echo $e->getMessage();
         $this->fail();
     }
 }
 public static function createTagCloudAttribute($attributeName, $withDefaultData, $modelClassName)
 {
     assert('isset($attributeName) && $attributeName != null');
     assert('isset($withDefaultData) && is_bool($withDefaultData)');
     $values = array('English', 'French', 'Danish', 'Spanish');
     $labels = array('fr' => array('English fr', 'French fr', 'Danish fr', 'Spanish fr'), 'de' => array('English de', 'French de', 'Danish de', 'Spanish de'));
     $languageFieldData = CustomFieldData::getByName('Languages');
     $languageFieldData->save();
     $attributeForm = new TagCloudAttributeForm();
     $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->customFieldDataData = $values;
     $attributeForm->customFieldDataName = 'Languages';
     $attributeForm->customFieldDataLabels = $labels;
     if ($withDefaultData) {
         $attributeForm->defaultValueOrder = 1;
     } else {
         $attributeForm->defaultValueOrder = null;
     }
     $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);
     }
 }