本文整理汇总了PHP中Oro\Bundle\EntityConfigBundle\Config\Config::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::getId方法的具体用法?PHP Config::getId怎么用?PHP Config::getId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityConfigBundle\Config\Config
的用法示例。
在下文中一共展示了Config::getId方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPostSubmit
/**
* @dataProvider postSubmitProvider
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testPostSubmit($data, $isValid, $model, $trans, $expectedConfigData, $expectedTrans)
{
$provider1 = $this->getConfigProvider('entity', ['entity' => ['items' => ['icon' => [], 'label' => ['options' => ['translatable' => true]]]]], isset($data['entity']));
$config1 = new Config(new EntityConfigId('entity', 'Entity\\Test'));
$config1->set('label', 'label_key');
if (isset($data['entity'])) {
$provider1->expects($this->once())->method('getConfigById')->with($config1->getId())->will($this->returnValue($config1));
} else {
$provider1->expects($this->never())->method('getConfigById');
}
$providers = new ArrayCollection();
$providers->add($provider1);
$this->configManager->expects($this->any())->method('getConfigIdByModel')->will($this->returnCallback(function ($configModel, $scope) {
return new EntityConfigId($scope, 'Entity\\Test');
}));
$this->translator->expects($this->any())->method('trans')->will($this->returnCallback(function ($id) use(&$trans) {
if (isset($trans[$id])) {
return $trans[$id];
} else {
return $id;
}
}));
$form = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface');
$event = $this->getFormEvent($data, $model, $form);
$this->configManager->expects($this->once())->method('getProviders')->will($this->returnValue($providers));
if (null === $expectedConfigData) {
$this->configManager->expects($this->never())->method('persist');
} else {
$expectedConfig = new Config(new EntityConfigId('entity', 'Entity\\Test'));
foreach ($expectedConfigData as $code => $val) {
$expectedConfig->set($code, $val);
}
$this->configManager->expects($this->once())->method('persist')->with($expectedConfig);
}
$form->expects($this->once())->method('isValid')->will($this->returnValue($isValid));
if (null === $expectedTrans) {
$this->translator->expects($this->never())->method('getLocale');
$this->dbTranslationMetadataCache->expects($this->never())->method('updateTimestamp');
} else {
$translationEm = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$translationValue = new Translation();
$this->translator->expects($this->once())->method('getLocale')->will($this->returnValue('testLocale'));
$this->dbTranslationMetadataCache->expects($this->once())->method('updateTimestamp')->with('testLocale');
$repo = $this->getMockBuilder('Oro\\Bundle\\TranslationBundle\\Entity\\Repository\\TranslationRepository')->disableOriginalConstructor()->getMock();
$this->doctrine->expects($this->once())->method('getManagerForClass')->with(Translation::ENTITY_NAME)->will($this->returnValue($translationEm));
$translationEm->expects($this->once())->method('getRepository')->with(Translation::ENTITY_NAME)->will($this->returnValue($repo));
$repo->expects($this->once())->method('saveValue')->with($expectedTrans[0], $expectedTrans[1], $expectedTrans[2], TranslationRepository::DEFAULT_DOMAIN, Translation::SCOPE_UI)->willReturn($translationValue);
$translationEm->expects($this->once())->method('flush')->with([$translationValue]);
}
if ($isValid) {
$this->configManager->expects($this->once())->method('flush');
} else {
$this->configManager->expects($this->never())->method('flush');
}
$this->subscriber->postSubmit($event);
}
示例2: hasFieldNameConflict
/**
* Checks whether the name of a new field conflicts with the name of existing field.
*
* @param string $newFieldName
* @param Config $existingFieldConfig
*
* @return bool
*/
public function hasFieldNameConflict($newFieldName, Config $existingFieldConfig)
{
$existingFieldName = $existingFieldConfig->getId()->getFieldName();
if (strtolower($newFieldName) === strtolower($existingFieldName)) {
return true;
}
if ($this->normalizeFieldName($newFieldName) === $this->normalizeFieldName($existingFieldName) && !$existingFieldConfig->is('is_deleted') && !$existingFieldConfig->is('state', ExtendScope::STATE_DELETE)) {
return true;
}
return false;
}
示例3: preSubmitData
public function preSubmitData(FormEvent $event)
{
$form = $event->getForm();
$data = $event->getData();
if (!$data) {
$data = $form->getParent()->getData();
}
if ($this->config->get('owner') === ExtendScope::OWNER_CUSTOM) {
$targetEntity = $this->getArrayValue($data, 'target_entity');
$relationType = $this->config->getId()->getFieldType();
if ($relationType == 'manyToOne') {
$this->addTargetField($form, 'target_field', $targetEntity, $this->getArrayValue($data, 'target_field'));
} else {
$this->addTargetField($form, 'target_grid', $targetEntity, $this->getArrayValue($data, 'target_grid'), 'Related entity data fields', true);
$this->addTargetField($form, 'target_title', $targetEntity, $this->getArrayValue($data, 'target_title'), 'Related entity info title', true);
$this->addTargetField($form, 'target_detailed', $targetEntity, $this->getArrayValue($data, 'target_detailed'), 'Related entity detailed', true);
}
}
if ($event->getName() == FormEvents::PRE_SUBMIT) {
$form->getParent()->setData(array_merge($form->getParent()->getData(), $data));
}
}
示例4: doTestSubmit
/**
* @param string $formName
* @param AbstractType $formType
* @param array $options
* @param \PHPUnit_Framework_MockObject_MockObject[] $configProviders
* @param mixed $newVal
* @param mixed $oldVal
* @param string $state
* @param bool $isSetStateExpected
*
* @return mixed The form data
*/
protected function doTestSubmit($formName, AbstractType $formType, array $options, array $configProviders, $newVal, $oldVal, $state, $isSetStateExpected)
{
$config = new Config(new EntityConfigId('test', 'Test\\Entity'));
$config->set($formName, $oldVal);
$propertyConfig = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\PropertyConfigContainer')->disableOriginalConstructor()->getMock();
$propertyConfig->expects($this->once())->method('isSchemaUpdateRequired')->with($formName, $config->getId())->will($this->returnValue(true));
$this->testConfigProvider->expects($this->once())->method('getPropertyConfig')->will($this->returnValue($propertyConfig));
$extendConfigId = new EntityConfigId('extend', 'Test\\Entity');
$extendConfig = new Config($extendConfigId);
$extendConfig->set('state', $state);
$extendConfigProvider = $this->getConfigProviderMock();
$extendConfigProvider->expects($this->any())->method('getConfig')->with('Test\\Entity')->will($this->returnValue($extendConfig));
$this->configManager->expects($this->any())->method('getConfig')->with($config->getId())->will($this->returnValue($config));
$this->setConfigProvidersForSubmitTest($configProviders);
$configProviders['extend'] = $extendConfigProvider;
$configProvidersMap = [];
foreach ($configProviders as $configProviderScope => $configProvider) {
$configProvidersMap[] = [$configProviderScope, $configProvider];
}
$this->configManager->expects($this->any())->method('getProvider')->will($this->returnValueMap($configProvidersMap));
$expectedExtendConfig = new Config($extendConfigId);
if ($isSetStateExpected) {
$expectedExtendConfig->set('state', ExtendScope::STATE_UPDATE);
$this->configManager->expects($this->once())->method('persist')->with($expectedExtendConfig);
} else {
$expectedExtendConfig->set('state', $state);
$this->configManager->expects($this->never())->method('persist');
}
// flush should be never called
foreach ($configProviders as $configProvider) {
$configProvider->expects($this->never())->method('flush');
}
$this->configManager->expects($this->never())->method('flush');
$form = $this->factory->createNamed($formName, $formType, $oldVal, $options);
$form->submit($newVal);
$this->assertTrue($form->isSynchronized(), 'Expected that a form is synchronized');
$this->assertEquals($expectedExtendConfig, $extendConfig);
return $form->getData();
}
示例5: testGetConfigs
public function testGetConfigs()
{
$this->configManager->expects($this->exactly(4))->method('getIds')->with('testScope', DemoEntity::ENTITY_NAME)->will($this->returnValue(array($this->entityConfig->getId())));
$this->assertEquals(array($this->entityConfig->getId()), $this->configProvider->getIds(DemoEntity::ENTITY_NAME));
$this->assertEquals(array($this->entityConfig), $this->configProvider->getConfigs(DemoEntity::ENTITY_NAME));
$this->assertEquals(array(), $this->configProvider->filter(function (ConfigInterface $config) {
return $config->getId()->getScope() == 'wrongScope';
}, DemoEntity::ENTITY_NAME));
$entityConfig = new Config(new EntityConfigId(DemoEntity::ENTITY_NAME, 'testScope'));
$entityConfig->set('key', 'value');
$this->assertEquals(array($entityConfig), $this->configProvider->map(function (ConfigInterface $config) {
return $config->set('key', 'value');
}, DemoEntity::ENTITY_NAME));
}
示例6: testAddManyToManyRelationForAlreadyExistRelationWithOptions
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testAddManyToManyRelationForAlreadyExistRelationWithOptions()
{
$relationName = 'testRelation';
$relationKey = 'manyToMany|Test\\SourceEntity|Test\\TargetEntity|testRelation';
$targetTitleFieldName = 'field1';
$targetDetailedFieldName = 'field2';
$targetGridFieldName = 'field3';
$extendConfig = new Config(new EntityConfigId('extend', self::SOURCE_CLASS));
$extendConfig->set('relation', [$relationKey => []]);
$extendFieldConfig = new Config(new FieldConfigId('extend', self::SOURCE_CLASS, $relationName, 'manyToMany'));
$testFieldConfig = new Config(new FieldConfigId('test', self::SOURCE_CLASS, $relationName, 'manyToOne'));
$expectedExtendFieldConfig = new Config($extendFieldConfig->getId());
$expectedExtendFieldConfig->setValues(['owner' => ExtendScope::OWNER_CUSTOM, 'is_extend' => true, 'relation_key' => $relationKey, 'target_entity' => self::TARGET_CLASS, 'target_title' => [$targetTitleFieldName], 'target_detailed' => [$targetDetailedFieldName], 'target_grid' => [$targetGridFieldName]]);
$expectedTestFieldConfig = new Config($testFieldConfig->getId());
$expectedTestFieldConfig->setValues(['test_attr' => 123]);
$fieldConfigModel = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Entity\\FieldConfigModel')->disableOriginalConstructor()->getMock();
$this->configManager->expects($this->once())->method('hasConfigFieldModel')->with(self::SOURCE_CLASS, $relationName)->will($this->returnValue(true));
$this->configManager->expects($this->never())->method('createConfigFieldModel');
$this->configManager->expects($this->once())->method('getConfigFieldModel')->with(self::SOURCE_CLASS, $relationName)->will($this->returnValue($fieldConfigModel));
$fieldConfigModel->expects($this->once())->method('getType')->will($this->returnValue('manyToMany'));
$this->configManager->expects($this->never())->method('changeFieldType');
$extendConfigProvider = $this->getConfigProviderMock();
$extendConfigProvider->expects($this->once())->method('getConfig')->with(self::SOURCE_CLASS, $relationName)->will($this->returnValue($extendFieldConfig));
$extendConfigProvider->expects($this->once())->method('persist')->with($this->identicalTo($extendFieldConfig));
$testConfigProvider = $this->getConfigProviderMock();
$testConfigProvider->expects($this->once())->method('getConfig')->with(self::SOURCE_CLASS, $relationName)->will($this->returnValue($testFieldConfig));
$testConfigProvider->expects($this->once())->method('persist')->with($this->identicalTo($testFieldConfig));
$this->configManager->expects($this->any())->method('getProvider')->will($this->returnValueMap([['extend', $extendConfigProvider], ['test', $testConfigProvider]]));
$this->builder->addManyToManyRelation($extendConfig, self::TARGET_CLASS, $relationName, [$targetTitleFieldName], [$targetDetailedFieldName], [$targetGridFieldName], ['extend' => ['owner' => ExtendScope::OWNER_CUSTOM], 'test' => ['test_attr' => 123]]);
$this->assertEquals($expectedExtendFieldConfig, $extendFieldConfig);
$this->assertEquals($expectedTestFieldConfig, $testFieldConfig);
}
示例7: testGetIdsWithHidden
public function testGetIdsWithHidden()
{
$this->configManager->expects($this->once())->method('getIds')->with('testScope', DemoEntity::ENTITY_NAME, true)->will($this->returnValue(array($this->entityConfig->getId())));
$this->assertEquals(array($this->entityConfig->getId()), $this->configProvider->getIds(DemoEntity::ENTITY_NAME, true));
}
示例8: testPreUpdateForNoChanges
public function testPreUpdateForNoChanges()
{
$config = new Config(new EntityConfigId('extend', 'Test\\Entity1'));
$config->set('is_extend', true);
$config->set('index', ['field1' => true]);
$fieldConfig1 = new Config(new FieldConfigId('extend', $config->getId()->getClassName(), 'field1', 'string'));
$fieldConfig1->set('is_extend', true);
$fieldConfig2 = new Config(new FieldConfigId('extend', $config->getId()->getClassName(), 'field2', 'string'));
$fieldConfig2->set('is_extend', true);
$datagridFieldConfig1 = new Config(new FieldConfigId('datagrid', $config->getId()->getClassName(), 'field1', 'string'));
$datagridFieldConfig1->set('is_visible', true);
$datagridFieldConfig2 = new Config(new FieldConfigId('datagrid', $config->getId()->getClassName(), 'field2', 'string'));
$extendConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
$datagridConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
$this->configManager->expects($this->exactly(4))->method('getProvider')->will($this->returnValueMap([['extend', $extendConfigProvider], ['datagrid', $datagridConfigProvider]]));
$extendConfigProvider->expects($this->exactly(2))->method('getConfigs')->will($this->returnCallback(function ($className) use($config, $fieldConfig1, $fieldConfig2) {
if (empty($className)) {
return [$config];
}
return [$fieldConfig1, $fieldConfig2];
}));
$datagridConfigProvider->expects($this->at(0))->method('hasConfig')->with($datagridFieldConfig1->getId()->getClassName(), $datagridFieldConfig1->getId()->getFieldName())->will($this->returnValue(true));
$datagridConfigProvider->expects($this->at(1))->method('getConfig')->with($datagridFieldConfig1->getId()->getClassName(), $datagridFieldConfig1->getId()->getFieldName())->will($this->returnValue($datagridFieldConfig1));
$datagridConfigProvider->expects($this->at(2))->method('hasConfig')->with($datagridFieldConfig2->getId()->getClassName(), $datagridFieldConfig2->getId()->getFieldName())->will($this->returnValue(true));
$datagridConfigProvider->expects($this->at(3))->method('getConfig')->with($datagridFieldConfig2->getId()->getClassName(), $datagridFieldConfig2->getId()->getFieldName())->will($this->returnValue($datagridFieldConfig2));
$this->configManager->expects($this->never())->method('persist');
$this->extension->preUpdate();
}
示例9: testSyncForNewField
/**
* @dataProvider enumTypeProvider
*/
public function testSyncForNewField($enumType)
{
$enumCode = 'test_enum';
$enumName = 'Test Enum';
$locale = 'fr';
$enumPublic = true;
$enumOptions = [['label' => 'Opt1']];
$enumValueClassName = 'Test\\EnumValue';
$entityConfig = new Config(new EntityConfigId('extend', 'Test\\Entity1'));
$entityConfig->set('is_extend', true);
$fieldConfig = new Config(new FieldConfigId('extend', 'Test\\Entity1', 'field1', $enumType));
$fieldConfig->set('target_entity', $enumValueClassName);
$enumFieldConfig = new Config(new FieldConfigId('enum', 'Test\\Entity1', 'field1', $enumType));
$enumFieldConfig->set('enum_code', $enumCode);
$enumFieldConfig->set('enum_name', $enumName);
$enumFieldConfig->set('enum_locale', $locale);
$enumFieldConfig->set('enum_public', $enumPublic);
$enumFieldConfig->set('enum_options', $enumOptions);
$expectedEnumFieldConfig = new Config($enumFieldConfig->getId());
$expectedEnumFieldConfig->set('enum_code', $enumCode);
$enumConfigProvider = $this->getConfigProviderMock();
$extendConfigProvider = $this->getConfigProviderMock();
$this->configManager->expects($this->exactly(2))->method('getProvider')->will($this->returnValueMap([['extend', $extendConfigProvider], ['enum', $enumConfigProvider]]));
$extendConfigProvider->expects($this->at(0))->method('getConfigs')->will($this->returnValue([$entityConfig]));
$extendConfigProvider->expects($this->at(1))->method('getConfigs')->with($entityConfig->getId()->getClassName())->will($this->returnValue([$fieldConfig]));
$enumConfigProvider->expects($this->once())->method('getConfig')->with('Test\\Entity1', 'field1')->will($this->returnValue($enumFieldConfig));
$this->configManager->expects($this->once())->method('persist')->with($this->identicalTo($enumFieldConfig));
$this->configManager->expects($this->once())->method('flush');
/** @var EnumSynchronizer|\PHPUnit_Framework_MockObject_MockObject $synchronizer */
$synchronizer = $this->getMock('Oro\\Bundle\\EntityExtendBundle\\Tools\\EnumSynchronizer', ['applyEnumNameTrans', 'applyEnumOptions', 'applyEnumEntityOptions'], [$this->configManager, $this->doctrine, $this->translator, $this->dbTranslationMetadataCache]);
$synchronizer->expects($this->once())->method('applyEnumNameTrans')->with($enumCode, $enumName, $locale);
$synchronizer->expects($this->once())->method('applyEnumOptions')->with($enumValueClassName, $enumOptions, $locale);
$synchronizer->expects($this->once())->method('applyEnumEntityOptions')->with($enumValueClassName, $enumPublic, false);
$synchronizer->sync();
$this->assertEquals($expectedEnumFieldConfig, $enumFieldConfig);
}
示例10: testPostUpdateForMultiEnumFieldsInCustomEntity
public function testPostUpdateForMultiEnumFieldsInCustomEntity()
{
$entityConfig1 = new Config(new EntityConfigId('extend', 'Extend\\EnumValue1'));
$entityConfig1->set('owner', ExtendScope::OWNER_CUSTOM);
$entityConfig1->set('is_extend', true);
$entityConfig1->set('schema', ['doctrine' => ['Extend\\EnumValue1' => ['fields' => [ExtendHelper::getMultiEnumSnapshotFieldName('field2') => ['column' => 'field2']]]]]);
$entityConfig2 = new Config(new EntityConfigId('extend', 'Extend\\EnumValue2'));
$fieldConfig1 = new Config(new FieldConfigId('extend', 'Extend\\EnumValue1', 'field1', 'multiEnum'));
$fieldConfig2 = new Config(new FieldConfigId('extend', 'Extend\\EnumValue1', 'field2', 'multiEnum'));
$fieldConfig3 = new Config(new FieldConfigId('extend', 'Extend\\EnumValue1', 'field3', 'enum'));
$entityConfigs = [$entityConfig1, $entityConfig2];
$fieldConfigs = [$fieldConfig1, $fieldConfig2, $fieldConfig3];
$extendConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
$this->configManager->expects($this->once())->method('getProvider')->with('extend')->will($this->returnValue($extendConfigProvider));
$extendConfigProvider->expects($this->at(0))->method('getConfigs')->with(null, true)->will($this->returnValue($entityConfigs));
$extendConfigProvider->expects($this->at(1))->method('getConfigs')->with($entityConfig1->getId()->getClassName())->will($this->returnValue($fieldConfigs));
$this->configManager->expects($this->once())->method('persist')->with($this->identicalTo($entityConfig1));
$this->extension->postUpdate();
$this->assertEquals(['doctrine' => ['Extend\\EnumValue1' => ['fields' => [ExtendHelper::getMultiEnumSnapshotFieldName('field1') => ['column' => $this->nameGenerator->generateMultiEnumSnapshotColumnName('field1'), 'type' => 'string', 'nullable' => true, 'length' => ExtendHelper::MAX_ENUM_SNAPSHOT_LENGTH], ExtendHelper::getMultiEnumSnapshotFieldName('field2') => ['column' => 'field2']]]], 'property' => [ExtendHelper::getMultiEnumSnapshotFieldName('field1') => ExtendHelper::getMultiEnumSnapshotFieldName('field1')]], $entityConfig1->get('schema'));
}
示例11: testSaveFieldConfigValues
public function testSaveFieldConfigValues()
{
$config1 = new Config(new FieldConfigId('scope1', self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE), ['key1' => 'val1']);
$config2 = new Config(new FieldConfigId('scope2', self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE), ['key2' => 'val2']);
$this->cache->expects($this->once())->method('save')->willReturnCallback(function ($key, $data) {
$this->cache->expects($this->once())->method('fetch')->with($key)->willReturn($data);
return true;
});
$this->assertTrue($this->configCache->saveFieldConfigValues([$config1->getId()->getScope() => $config1->getValues(), $config2->getId()->getScope() => $config2->getValues()], self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE));
// test that configs saved right
$this->assertEquals($config1, $this->configCache->getFieldConfig($config1->getId()->getScope(), self::ENTITY_CLASS, self::FIELD_NAME));
$this->assertEquals($config2, $this->configCache->getFieldConfig($config2->getId()->getScope(), self::ENTITY_CLASS, self::FIELD_NAME));
}
示例12: createTargetRelation
protected function createTargetRelation(Config $fieldConfig, $relationKey)
{
$selfEntityClass = $fieldConfig->getId()->getClassName();
$targetEntityClass = $fieldConfig->get('target_entity');
$selfConfig = $this->extendConfigProvider->getConfig($selfEntityClass);
$selfRelations = $selfConfig->get('relation');
$selfRelationConfig =& $selfRelations[$relationKey];
$selfRelationConfig['field_id'] = $fieldConfig;
$targetConfig = $this->extendConfigProvider->getConfig($targetEntityClass);
$targetRelations = $targetConfig->get('relation');
$targetRelationConfig =& $targetRelations[$relationKey];
$targetRelationConfig['target_field_id'] = $fieldConfig;
$selfConfig->set('relation', $selfRelations);
$targetConfig->set('relation', $targetRelations);
$this->extendConfigProvider->persist($targetConfig);
}