protected function renderContent() { $content = null; $content .= $this->renderBeforeTableContent(); $modelClassName = $this->modelClassName; if (count($this->attributesCollection) > 0) { $content .= '<div>'; $content .= $this->renderTitleContent(); $content .= '<ul class="configuration-list">'; foreach ($this->attributesCollection as $attributeName => $information) { $route = $this->moduleId . '/' . $this->controllerId . '/AttributeEdit/'; $attributeFormClassName = AttributesFormFactory::getFormClassNameByAttributeType($information['elementType']); if ($information['elementType'] == 'EmailAddressInformation' || $information['elementType'] == 'Address' || $information['elementType'] == 'User' || $information['isReadOnly'] || $attributeName == 'id' || $this->isAttributeOnModelOrCastedUp($attributeName) || in_array($attributeName, $modelClassName::getNonConfigurableAttributes())) { //temporary until we figure out how to handle these types. $linkContent = null; } else { $url = Yii::app()->createUrl($route, array('moduleClassName' => $this->moduleClassName, 'attributeTypeName' => $information['elementType'], 'attributeName' => $attributeName)); $linkContent = static::renderConfigureLinkContent($url, 'edit-link-' . $attributeName); } $content .= '<li>'; $content .= '<h4>' . $information['attributeLabel'] . '</h4>'; $content .= ' - ' . $attributeFormClassName::getAttributeTypeDisplayName(); $content .= $linkContent; $content .= '</li>'; } $content .= '</ul>'; $content .= '</div>'; } return $content; }
protected static function getValueTypeDropDownArray() { $data = array('' => Zurmo::t('DesignerModule', 'Select a field type')); $attributeTypes = ModelAttributeToDesignerTypeUtil::getAvailableCustomAttributeTypes(); foreach ($attributeTypes as $attributeType) { $attributeFormClassName = AttributesFormFactory::getFormClassNameByAttributeType($attributeType); $data[$attributeType] = $attributeFormClassName::getAttributeTypeDisplayName(); } return $data; }
/** * Test account attribute that is a hasOne relation off of Opportunity */ public function testModifyingAHasOneModelRelationDoesNotCreateNewAttribute() { $opportunity = new Opportunity(false); $this->assertEquals(17, count($opportunity->getAttributes())); $validated = $opportunity->validate(); $this->assertFalse($validated); $this->assertEquals(6, count($opportunity->getErrors())); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($opportunity, 'account'); $this->assertFalse($attributeForm->isRequired); $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Opportunity()); $attributeForm->isRequired = true; $adapter->setAttributeMetadataFromForm($attributeForm); $opportunity = new Opportunity(false); $this->assertEquals(17, count($opportunity->getAttributes())); $validated = $opportunity->validate(); $this->assertFalse($validated); $this->assertEquals(7, count($opportunity->getErrors())); }
public function testSetAndGetMultiSelectDropDownAttribute() { $attributeName = 'testHobbies'; $values = array('Reading', 'Writing', 'Singing', 'Surfing'); $labels = array('fr' => array('Reading fr', 'Writing fr', 'Singing fr', 'Surfing fr'), 'de' => array('Reading de', 'Writing de', 'Singing de', 'Surfing de')); $hobbiesFieldData = CustomFieldData::getByName('Hobbies'); $hobbiesFieldData->serializedData = serialize($values); $this->assertTrue($hobbiesFieldData->save()); $attributeForm = new MultiSelectDropDownAttributeForm(); $attributeForm->attributeName = $attributeName; $attributeForm->attributeLabels = array('de' => 'Test Hobbies 2 de', 'en' => 'Test Hobbies 2 en', 'es' => 'Test Hobbies 2 es', 'fr' => 'Test Hobbies 2 fr', 'it' => 'Test Hobbies 2 it'); $attributeForm->isAudited = true; $attributeForm->isRequired = true; $attributeForm->defaultValueOrder = 1; $attributeForm->customFieldDataData = $values; $attributeForm->customFieldDataName = 'Hobbies'; $attributeForm->customFieldDataLabels = $labels; $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('MultiSelectDropDown', $attributeForm->getAttributeTypeName()); $this->assertEquals($attributeName . 'Cstm', $attributeForm->attributeName); $compareAttributeLabels = array('de' => 'Test Hobbies 2 de', 'en' => 'Test Hobbies 2 en', 'es' => 'Test Hobbies 2 es', 'fr' => 'Test Hobbies 2 fr', 'it' => 'Test Hobbies 2 it'); $this->assertEquals($compareAttributeLabels, $attributeForm->attributeLabels); $this->assertEquals(true, $attributeForm->isAudited); $this->assertEquals(true, $attributeForm->isRequired); $this->assertEquals('Writing', $attributeForm->defaultValue); $this->assertEquals(1, $attributeForm->defaultValueOrder); $this->assertEquals('Hobbies', $attributeForm->customFieldDataName); $this->assertEquals($values, $attributeForm->customFieldDataData); $this->assertEquals($labels, $attributeForm->customFieldDataLabels); }
protected function setAndGetUrlAttribute($attributeName, $withDefaultData) { $this->assertTrue(isset($attributeName) && $attributeName != ''); $this->assertTrue(isset($withDefaultData) && is_bool($withDefaultData)); $attributeForm = new UrlAttributeForm(); $attributeForm->attributeName = $attributeName; $attributeForm->attributeLabels = array('de' => 'Test Url 2 de', 'en' => 'Test Url 2 en', 'es' => 'Test Url 2 es', 'fr' => 'Test Url 2 fr', 'it' => 'Test Url 2 it'); $attributeForm->isAudited = true; $attributeForm->isRequired = true; $attributeForm->maxLength = 50; if ($withDefaultData) { $attributeForm->defaultValue = 'http://www.outback.com'; } $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Account(), $attributeName . 'Cstm'); $this->assertEquals('Url', $attributeForm->getAttributeTypeName()); $this->assertEquals($attributeName . 'Cstm', $attributeForm->attributeName); $compareAttributeLabels = array('de' => 'Test Url 2 de', 'en' => 'Test Url 2 en', 'es' => 'Test Url 2 es', 'fr' => 'Test Url 2 fr', 'it' => 'Test Url 2 it'); $this->assertEquals($compareAttributeLabels, $attributeForm->attributeLabels); $this->assertEquals(true, $attributeForm->isAudited); $this->assertEquals(true, $attributeForm->isRequired); $this->assertEquals(50, $attributeForm->maxLength); if ($withDefaultData) { $this->assertEquals('http://www.outback.com', $attributeForm->defaultValue); } else { $this->assertEquals(null, $attributeForm->defaultValue); } }
public function testContactStateModelAttributesAdapter() { Yii::app()->user->userModel = User::getByUsername('super'); $this->assertTrue(ContactsModule::loadStartingData()); $this->assertEquals(6, count(ContactState::GetAll())); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(0 => 'New', 1 => 'In Progress', 2 => 'Recycled', 3 => 'Dead', 4 => 'Qualified', 5 => 'Customer'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals(null, $attributeForm->contactStatesLabels); $this->assertEquals(4, $attributeForm->startingStateOrder); //Now add new values. $attributeForm->contactStatesData = array(0 => 'New', 1 => 'In Progress', 2 => 'Recycled', 3 => 'Dead', 4 => 'Qualified', 5 => 'Customer', 6 => 'AAA', 7 => 'BBB'); $contactStatesLabels = array('fr' => array('New', 'In ProgressFr', 'RecycledFr', 'DeadFr', 'QualifiedFr', 'CustomerFr', 'AAAFr', 'BBBFr')); $attributeForm->contactStatesLabels = $contactStatesLabels; $attributeForm->startingStateOrder = 5; $adapter = new ContactStateModelAttributesAdapter(new Contact()); $adapter->setAttributeMetadataFromForm($attributeForm); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(0 => 'New', 1 => 'In Progress', 2 => 'Recycled', 3 => 'Dead', 4 => 'Qualified', 5 => 'Customer', 6 => 'AAA', 7 => 'BBB'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals($contactStatesLabels, $attributeForm->contactStatesLabels); $contactState = ContactState::getByName('Customer'); $this->assertEquals(5, $contactState[0]->order); $this->assertEquals(5, $attributeForm->startingStateOrder); //Test removing existing values. $attributeForm->contactStatesData = array(0 => 'New', 1 => 'In Progress', 2 => 'Recycled', 3 => 'Customer', 4 => 'AAA', 5 => 'BBB'); $attributeForm->startingStateOrder = 5; $adapter = new ContactStateModelAttributesAdapter(new Contact()); $adapter->setAttributeMetadataFromForm($attributeForm); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(0 => 'New', 1 => 'In Progress', 2 => 'Recycled', 3 => 'Customer', 4 => 'AAA', 5 => 'BBB'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals(5, $attributeForm->startingStateOrder); //Test switching order of existing values. $attributeForm->contactStatesData = array(0 => 'New', 3 => 'In Progress', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB'); $attributeForm->startingStateOrder = 2; $adapter = new ContactStateModelAttributesAdapter(new Contact()); $adapter->setAttributeMetadataFromForm($attributeForm); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(0 => 'New', 3 => 'In Progress', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals(2, $attributeForm->startingStateOrder); //Test switching order of existing values and adding new values mixed in. $attributeForm->contactStatesData = array(3 => 'New', 6 => 'In Progress', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB', 0 => 'CCC'); $attributeForm->startingStateOrder = 2; $adapter = new ContactStateModelAttributesAdapter(new Contact()); $adapter->setAttributeMetadataFromForm($attributeForm); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(3 => 'New', 6 => 'In Progress', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB', 0 => 'CCC'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals(2, $attributeForm->startingStateOrder); //Switching name of existing state $this->assertEquals(7, ContactState::getCount()); $attributeForm->contactStatesDataExistingValues = array(3 => 'New', 6 => 'In Progress', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB', 0 => 'CCC'); $attributeForm->contactStatesData = array(3 => 'New', 6 => 'In Progress Plastic', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB', 0 => 'CCC'); $attributeForm->startingStateOrder = 2; $adapter = new ContactStateModelAttributesAdapter(new Contact()); $adapter->setAttributeMetadataFromForm($attributeForm); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Contact(), 'state'); $compareData = array(3 => 'New', 6 => 'In Progress Plastic', 5 => 'Recycled', 1 => 'Customer', 4 => 'AAA', 2 => 'BBB', 0 => 'CCC'); $this->assertEquals($compareData, $attributeForm->contactStatesData); $this->assertEquals(2, $attributeForm->startingStateOrder); $this->assertEquals(7, ContactState::getCount()); }
/** * @depends testRequiredAttributesAreMissingFromLayout */ public function testMakingAlreadyPlacedNonrequiredStandardAttributeRequiredAndThenMakingItUnrequired() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/create'); $this->assertNotContains('There are required fields missing from the following layout', $content); //Now make industry required. $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Account(), 'industry'); $this->assertFalse($attributeForm->isRequired); $attributeForm->isRequired = true; $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } RequiredAttributesValidViewUtil::resolveToSetAsMissingRequiredAttributesByModelClassName('Account', 'industry'); RedBeanModelsCache::forgetAll(); $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/create'); $this->assertNotContains('There are required fields missing from the following layout', $content); //Now make industry unrequired. $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Account(), 'industry'); $this->assertTrue($attributeForm->isRequired); $attributeForm->isRequired = false; $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } RequiredAttributesValidViewUtil::resolveToRemoveAttributeAsMissingRequiredAttribute('Account', 'industry'); RedBeanModelsCache::forgetAll(); //Confirm industry is truly unrequired. $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Account(), 'industry'); $this->assertFalse($attributeForm->isRequired); //Now the layout should not show an error message. $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/create'); $this->assertNotContains('There are required fields missing from the following layout', $content); }
/** * @depends testExistingModelsShowCustomFieldDataCorrectlyWhenAttributeIsAddedAsDatabaseColumn */ public function testStandardAttributeThatBecomesRequiredCanStillBeChangedToBeUnrequired() { Yii::app()->user->userModel = User::getByUsername('super'); $account = new Account(); //Name for example, is required by default. $adapter = new ModelAttributesAdapter($account); $this->assertTrue($adapter->isStandardAttributeRequiredByDefault('name')); //Industry is not required by default. $adapter = new DropDownModelAttributesAdapter($account); $this->assertFalse($adapter->isStandardAttributeRequiredByDefault('industry')); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'industry'); $this->assertFalse($attributeForm->isRequired); $this->assertTrue($attributeForm->canUpdateAttributeProperty('isRequired')); //Now make industry required. $attributeForm->isRequired = true; $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } RedBeanModelsCache::forgetAll(); $account = new Account(); $adapter = new DropDownModelAttributesAdapter($account); $this->assertFalse($adapter->isStandardAttributeRequiredByDefault('industry')); $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'industry'); $this->assertTrue($attributeForm->isRequired); $this->assertTrue($attributeForm->canUpdateAttributeProperty('isRequired')); }
public function testWhenRoleIsRequired() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; //Set role as required but without a default value. $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new AccountContactAffiliation(), 'role'); $attributeForm->isRequired = true; $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new AccountContactAffiliation()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } //Now create an affiliation, the role should be the first value. $this->assertEquals(0, count(AccountContactAffiliation::getAll())); $account = AccountTestHelper::createAccountByNameForOwner('thirdAccount', $super); $contact = ContactTestHelper::createContactWithAccountByNameForOwner('thirdContact', $super, $account); $accountContactAffiliations = AccountContactAffiliation::getAll(); $this->assertEquals(1, count($accountContactAffiliations)); $this->assertEquals(1, $accountContactAffiliations[0]->primary); $this->assertEquals('AAA', $accountContactAffiliations[0]->role->value); $this->assertTrue($accountContactAffiliations[0]->account->isSame($account)); $this->assertTrue($accountContactAffiliations[0]->contact->isSame($contact)); $this->assertTrue($contact->delete()); $accountContactAffiliations = AccountContactAffiliation::getAll(); $this->assertEquals(0, count($accountContactAffiliations)); //Now add a default value, so the role should be the default value. $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new AccountContactAffiliation(), 'role'); $attributeForm->defaultValueOrder = 1; $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new AccountContactAffiliation()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } //Now create an account/contact and an affiliation. The role should be BBB $this->assertEquals(0, count(AccountContactAffiliation::getAll())); $account = AccountTestHelper::createAccountByNameForOwner('fourthAccount', $super); $contact = ContactTestHelper::createContactWithAccountByNameForOwner('fourthContact', $super, $account); $accountContactAffiliations = AccountContactAffiliation::getAll(); $this->assertEquals(1, count($accountContactAffiliations)); $this->assertEquals(1, $accountContactAffiliations[0]->primary); $this->assertEquals('BBB', $accountContactAffiliations[0]->role->value); $this->assertTrue($accountContactAffiliations[0]->account->isSame($account)); $this->assertTrue($accountContactAffiliations[0]->contact->isSame($contact)); $this->assertTrue($contact->delete()); $accountContactAffiliations = AccountContactAffiliation::getAll(); $this->assertEquals(0, count($accountContactAffiliations)); }
/** * @depends testUsingTheAdapterAsAWrapperToUpdateValueInMappingByOldAndNewValue */ public function testUsingTheAdapterAsAWrapperToResolveValuesInMappingWhenValueWasRemoved() { Yii::app()->user->userModel = User::getByUsername('super'); $account = new Account(); //Remove a1 $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'aaaCstm'); $attributeForm->customFieldDataData = array('a2New', 'a3', 'a4'); $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName($account); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } //Confirm a1 has been removed from the mapping. $metadata = DropDownDependencyDerivedAttributeMetadata::getByNameAndModelClassName('aName', 'Account'); $unserializedData = unserialize($metadata->serializedMetadata); $compareData = array(array('attributeName' => 'aaaCstm'), array('attributeName' => 'bbbCstm', 'valuesToParentValues' => array('b1' => null, 'b2' => 'a2New', 'b3New' => 'a3', 'b4' => 'a4')), array('attributeName' => 'cccCstm', 'valuesToParentValues' => array('c1New' => 'b1', 'c2New' => 'b2', 'c3' => 'b3New', 'c4' => 'b4'))); $this->assertEquals(array('a' => 'b'), $unserializedData['attributeLabels']); $this->assertEquals($compareData, $unserializedData['mappingData']); //Remove b4 $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'bbbCstm'); $attributeForm->customFieldDataData = array('b1', 'b2', 'b3New'); $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName($account); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } //Confirm b4 has been removed from the mapping. $metadata = DropDownDependencyDerivedAttributeMetadata::getByNameAndModelClassName('aName', 'Account'); $unserializedData = unserialize($metadata->serializedMetadata); $compareData = array(array('attributeName' => 'aaaCstm'), array('attributeName' => 'bbbCstm', 'valuesToParentValues' => array('b1' => null, 'b2' => 'a2New', 'b3New' => 'a3')), array('attributeName' => 'cccCstm', 'valuesToParentValues' => array('c1New' => 'b1', 'c2New' => 'b2', 'c3' => 'b3New', 'c4' => null))); $this->assertEquals(array('a' => 'b'), $unserializedData['attributeLabels']); $this->assertEquals($compareData, $unserializedData['mappingData']); }
/** * Action called from user interface when the attributeName drop down is changed in the edit view for a dropdown * dependency. */ public function actionChangeDropDownDependencyAttribute() { assert('!empty($_GET["moduleClassName"])'); assert('!empty($_GET["attributeTypeName"])'); $attributeFormClassName = $_GET['attributeTypeName'] . 'AttributeForm'; $moduleClassName = $_GET['moduleClassName']; $modelClassName = $moduleClassName::getPrimaryModelName(); $model = new $modelClassName(); if (!empty($_GET['attributeName'])) { $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($model, $_GET["attributeName"]); $attributeForm->setModelClassName($modelClassName); } else { $attributeForm = new $attributeFormClassName(); $attributeForm->setScenario('createAttribute'); $attributeForm->setModelClassName($modelClassName); } if (isset($_POST[get_class($attributeForm)])) { $attributeForm->sanitizeFromPostAndSetAttributes($_POST[get_class($attributeForm)]); } else { throw new NotSupportedException(); } $content = DropDownDependencyAttributeEditView::renderContainerAndMappingLayoutContent($attributeForm, $this->getId(), $this->getModule()->getId(), false); Yii::app()->getClientScript()->setToAjaxMode(); Yii::app()->getClientScript()->render($content); echo $content; }