public function testSetAndGetMetadata() { Yii::app()->user->userModel = User::getByUsername('super'); $user = UserTestHelper::createBasicUser('Steven'); $account = new Account(); $view = new AccountEditAndDetailsView('Details', 'whatever', 'whatever', $account); $originalMetadata = AccountEditAndDetailsView::getMetadata($user); $metadataIn = $originalMetadata; $metadataIn['perUser']['junk1'] = 'stuff1'; $metadataIn['global']['junk2'] = 'stuff2'; $view->setMetadata($metadataIn, $user); $metadataOut = AccountEditAndDetailsView::getMetadata($user); $this->assertNotEquals($originalMetadata, $metadataOut); $this->assertEquals($metadataIn, $metadataOut); }
public function __construct($viewData, $params, $uniqueLayoutId) { assert('isset($params["controllerId"])'); assert('isset($params["relationModuleId"])'); assert('$params["relationModel"] instanceof RedBeanModel || $params["relationModel"] instanceof ModelForm'); assert('isset($params["portletId"])'); assert('isset($params["redirectUrl"])'); $this->modelClassName = $this->getModelClassName(); $this->viewData = $viewData; $this->params = $params; $this->uniqueLayoutId = $uniqueLayoutId; $this->gridIdSuffix = $uniqueLayoutId; $this->rowsAreSelectable = false; $this->gridId = 'list-view'; $this->controllerId = $this->resolveControllerId(); $this->moduleId = $this->resolveModuleId(); parent::__construct('Details', $this->controllerId, $this->moduleId, $params["relationModel"]); }
/** * Override to add a starring link to the title * @return string */ public function getTitle() { $starLink = StarredUtil::getToggleStarStatusLink($this->model, null); return parent::getTitle() . $starLink; }
/** * @return array */ public static function getDefaultMetadata() { $metadata = parent::getDefaultMetadata(); $metadata['global']['toolbar']['elements'] = array(array('type' => 'SaveButton', 'renderType' => 'Edit'), array('type' => 'CancelLink', 'renderType' => 'Edit')); return $metadata; }
/** * Gets form id * @return string */ protected static function getFormId() { $getData = GetUtil::getData(); $sourceNameFieldId = $getData['modalTransferInformation']['sourceNameFieldId']; return $sourceNameFieldId . '-' . parent::getFormId(); }
/** * @depends testIsStandardAttributeRequiredByDefault */ public function testSetMetadataFormLayoutWithAndWithOutRequiredCustomFieldForDropDownDependencyAttribute() { Yii::app()->user->userModel = User::getByUsername('super'); $education = array('aaaa', 'bbbb'); $education_labels = array('fr' => array('aaaa fr', 'bbbb fr'), 'de' => array('aaaa de', 'bbbb de')); $educationFieldData = CustomFieldData::getByName('Education'); $educationFieldData->serializedData = serialize($education); $this->assertTrue($educationFieldData->save()); $attributeForm = new DropDownAttributeForm(); $attributeForm->attributeName = 'testEducation'; $attributeForm->attributeLabels = array('de' => 'Test Education 2 de', 'en' => 'Test Education 2 en', 'es' => 'Test Education 2 es', 'fr' => 'Test Education 2 fr', 'it' => 'Test Education 2 it'); $attributeForm->isAudited = true; $attributeForm->isRequired = false; $attributeForm->customFieldDataData = $education; $attributeForm->customFieldDataName = 'Education'; $attributeForm->customFieldDataLabels = $education_labels; $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } $stream = array('aaa1', 'aaa2', 'bbb1', 'bbb2'); $stream_labels = array('fr' => array('aaa1 fr', 'aaa2 fr', 'bbb1 fr', 'bbb2 fr'), 'de' => array('aaa1 de', 'aaa2 de', 'bbb1 de', 'bbb2 de')); $streamFieldData = CustomFieldData::getByName('Stream'); $streamFieldData->serializedData = serialize($stream); $this->assertTrue($streamFieldData->save()); $attributeForm = new DropDownAttributeForm(); $attributeForm->attributeName = 'testStream'; $attributeForm->attributeLabels = array('de' => 'Test Stream 2 de', 'en' => 'Test Stream 2 en', 'es' => 'Test Stream 2 es', 'fr' => 'Test Stream 2 fr', 'it' => 'Test Stream 2 it'); $attributeForm->isAudited = true; $attributeForm->isRequired = true; $attributeForm->customFieldDataData = $stream; $attributeForm->customFieldDataName = 'Stream'; $attributeForm->customFieldDataLabels = $stream_labels; $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } $attributeName = "testQualification"; $attributeForm = new DropDownDependencyAttributeForm(); $attributeForm->attributeName = $attributeName; $attributeForm->attributeLabels = array('de' => 'Test Qualification Value 2 de', 'en' => 'Test Qualification Value 2 en', 'es' => 'Test Qualification Value 2 es', 'fr' => 'Test Qualification Value 2 fr', 'it' => 'Test Qualification Value 2 it'); $attributeForm->mappingData = array(array('attributeName' => 'testEducation'), array('attributeName' => 'testStream', 'valuesToParentValues' => array('aaa1' => 'aaaa', 'aaa2' => 'aaaa', 'bbb1' => 'bbbb', 'bbb2' => 'bbbb'))); $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); $this->fail(); } $layout = array('panels' => array(array('rows' => array(array('cells' => array(array('element' => 'createdDateTime'), array('element' => 'modifiedDateTime'))), array('cells' => array(array('element' => 'owner'), array('element' => 'name'))), array('cells' => array(array('element' => 'industry'))))))); $layout2 = array('panels' => array(array('rows' => array(array('cells' => array(array('element' => 'createdDateTime'), array('element' => 'modifiedDateTime'))), array('cells' => array(array('element' => 'owner'), array('element' => 'name'))), array('cells' => array(array('element' => 'industry'))), array('cells' => array(array('element' => 'testEducationCstm'), array('element' => 'testStreamCstm'))))))); $model = new Account(); $editableMetadata = AccountEditAndDetailsView::getMetadata(); $modelAttributesAdapter = new ModelAttributesAdapter($model); $attributesLayoutAdapter = AttributesLayoutAdapterUtil::makeAttributesLayoutAdapter($modelAttributesAdapter->getAttributes(), new EditAndDetailsViewDesignerRules(), $editableMetadata); $adapter = new LayoutMetadataAdapter('AccountEditAndDetailsView', 'AccountsModule', $editableMetadata, new EditAndDetailsViewDesignerRules(), $attributesLayoutAdapter->getPlaceableLayoutAttributes(), $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()); $this->assertFalse($adapter->setMetadataFromLayout($layout, array())); $this->assertNotEmpty($adapter->getMessage()); $this->assertEquals($adapter->getMessage(), 'All required fields must be placed in this layout.'); $this->assertTrue($adapter->setMetadataFromLayout($layout2, array())); $this->assertEquals($adapter->getMessage(), 'Layout saved successfully.'); }