/**
  * Returns a field name from the given config identifier if it represents a field
  *
  * @param ConfigIdInterface $configId
  *
  * @return string|null A field name if $configId represents a field; otherwise, null
  */
 public function getFieldName(ConfigIdInterface $configId)
 {
     if ($configId instanceof FieldConfigId) {
         return $configId->getFieldName();
     }
     return null;
 }
 /**
  * @dataProvider setDefaultOptionsProvider
  */
 public function testSetDefaultOptions(ConfigIdInterface $configId, $isNewConfig, $enumCode, $isSystem, $isImmutablePublic, $hasOtherReferences, $options, $expectedOptions)
 {
     $fieldName = $configId instanceof FieldConfigId ? $configId->getFieldName() : null;
     $enumValueClassName = $enumCode ? ExtendHelper::buildEnumValueClassName($enumCode) : null;
     $this->typeHelper->expects($this->any())->method('getEnumCode')->with($configId->getClassName(), $fieldName)->will($this->returnValue($enumCode));
     $this->typeHelper->expects($this->any())->method('isSystem')->with($configId->getClassName(), $fieldName)->will($this->returnValue($isSystem));
     $this->typeHelper->expects($this->any())->method('isImmutable')->with('enum', $enumValueClassName, null, 'public')->will($this->returnValue($isImmutablePublic));
     $this->typeHelper->expects($this->any())->method('hasOtherReferences')->with($enumCode, $configId->getClassName(), $fieldName)->will($this->returnValue($hasOtherReferences));
     $resolver = $this->getOptionsResolver();
     $this->type->setDefaultOptions($resolver);
     $options['config_id'] = $configId;
     $options['config_is_new'] = $isNewConfig;
     $resolvedOptions = $resolver->resolve($options);
     $this->assertSame($configId, $resolvedOptions['config_id']);
     unset($resolvedOptions['config_id']);
     $this->assertEquals($isNewConfig, $resolvedOptions['config_is_new']);
     unset($resolvedOptions['config_is_new']);
     $this->assertEquals($expectedOptions, $resolvedOptions);
 }
 /**
  * @dataProvider setDefaultOptionsProvider
  */
 public function testSetDefaultOptions(ConfigIdInterface $configId, $isNewConfig, $enumCode, $isImmutableAdd, $isImmutableDelete, $options, $expectedOptions)
 {
     $enumValueClassName = $enumCode ? ExtendHelper::buildEnumValueClassName($enumCode) : null;
     $this->typeHelper->expects($this->any())->method('getEnumCode')->with($configId->getClassName(), $configId instanceof FieldConfigId ? $configId->getFieldName() : null)->will($this->returnValue($enumCode));
     $this->typeHelper->expects($this->any())->method('isImmutable')->will($this->returnValueMap([['enum', $enumValueClassName, null, 'add', $isImmutableAdd], ['enum', $enumValueClassName, null, 'delete', $isImmutableDelete]]));
     $resolver = $this->getOptionsResolver();
     $this->type->setDefaultOptions($resolver);
     $options['config_id'] = $configId;
     $options['config_is_new'] = $isNewConfig;
     $resolvedOptions = $resolver->resolve($options);
     $this->assertSame($configId, $resolvedOptions['config_id']);
     unset($resolvedOptions['config_id']);
     $this->assertEquals($isNewConfig, $resolvedOptions['config_is_new']);
     unset($resolvedOptions['config_is_new']);
     $this->assertFalse($resolvedOptions['handle_primary']);
     unset($resolvedOptions['handle_primary']);
     $this->assertEquals('oro_entity_extend_enum_value', $resolvedOptions['type']);
     unset($resolvedOptions['type']);
     $this->assertEquals($expectedOptions, $resolvedOptions);
 }
 /**
  * @dataProvider setDefaultOptionsProvider
  */
 public function testSetDefaultOptions(ConfigIdInterface $configId, $isNewConfig, $hasEnumCode, $options, $expectedOptions)
 {
     $fieldName = $configId instanceof FieldConfigId ? $configId->getFieldName() : null;
     $this->typeHelper->expects($this->any())->method('hasEnumCode')->with($configId->getClassName(), $fieldName)->will($this->returnValue($hasEnumCode));
     $resolver = $this->getOptionsResolver();
     $this->type->setDefaultOptions($resolver);
     $options['config_id'] = $configId;
     $options['config_is_new'] = $isNewConfig;
     $resolvedOptions = $resolver->resolve($options);
     $this->assertSame($configId, $resolvedOptions['config_id']);
     unset($resolvedOptions['config_id']);
     $this->assertEquals($isNewConfig, $resolvedOptions['config_is_new']);
     unset($resolvedOptions['config_is_new']);
     if ($hasEnumCode) {
         $this->assertCount(2, $resolvedOptions['constraints']);
     } else {
         $this->assertCount(5, $resolvedOptions['constraints']);
     }
     unset($resolvedOptions['constraints']);
     $this->assertEquals($expectedOptions, $resolvedOptions);
 }
Exemple #5
0
 /**
  * @param ConfigIdInterface $configId
  *
  * @return string
  */
 protected function buildConfigCacheKey(ConfigIdInterface $configId)
 {
     return $configId instanceof FieldConfigId ? $configId->getClassName() . '_' . $configId->getFieldName() : $configId->getClassName();
 }
 /**
  * @dataProvider getConfigNotCachedProvider
  */
 public function testGetConfigNotCached(ConfigIdInterface $configId, $getModelResult, $expectedConfig)
 {
     $this->modelManager->expects($this->any())->method('checkDatabase')->willReturn(true);
     if ($configId instanceof FieldConfigId) {
         $this->configCache->expects($this->exactly(2))->method('getConfigurable')->willReturnMap([[$configId->getClassName(), null, true], [$configId->getClassName(), $configId->getFieldName(), true]]);
         $this->configCache->expects($this->once())->method('getFieldConfig')->with($configId->getScope(), $configId->getClassName(), $configId->getFieldName())->willReturn(null);
     } else {
         $this->configCache->expects($this->once())->method('getConfigurable')->with($configId->getClassName())->willReturn(true);
         $this->configCache->expects($this->once())->method('getEntityConfig')->with($configId->getScope(), $configId->getClassName())->willReturn(null);
     }
     $this->configCache->expects($this->once())->method('saveConfig')->with($this->equalTo($expectedConfig));
     if ($configId instanceof FieldConfigId) {
         $this->modelManager->expects($this->never())->method('getEntityModel');
         $this->modelManager->expects($this->once())->method('getFieldModel')->with($configId->getClassName(), $configId->getFieldName())->willReturn($getModelResult);
     } else {
         $this->modelManager->expects($this->once())->method('getEntityModel')->with($configId->getClassName())->willReturn($getModelResult);
         $this->modelManager->expects($this->never())->method('getFieldModel');
     }
     $result = $this->configManager->getConfig($configId);
     $this->assertEquals($expectedConfig, $result);
     $this->configManager->calculateConfigChangeSet($result);
     $this->assertEquals([], $this->configManager->getConfigChangeSet($result));
 }
 /**
  * @param ConfigIdInterface $configId
  * @return bool
  */
 public function hasConfigById(ConfigIdInterface $configId)
 {
     if ($configId instanceof FieldConfigId) {
         return $this->configManager->hasConfig($configId->getClassName(), $configId->getFieldName());
     } else {
         return $this->configManager->hasConfig($configId->getClassName());
     }
 }
Exemple #8
0
 /**
  * Gets configuration data for the given entity or field.
  *
  * @param ConfigIdInterface $configId
  *
  * @return ConfigInterface
  */
 public function getConfigById(ConfigIdInterface $configId)
 {
     $className = $configId->getClassName();
     if ($configId instanceof FieldConfigId) {
         return $this->configManager->getFieldConfig($this->scope, $className, $configId->getFieldName());
     } elseif ($className) {
         return $this->configManager->getEntityConfig($this->scope, $className);
     } else {
         return $this->configManager->createEntityConfig($this->scope);
     }
 }
Exemple #9
0
 /**
  * Returns a string unique identifies each config item
  *
  * @param ConfigIdInterface $configId
  * @return string
  */
 protected function buildConfigKey(ConfigIdInterface $configId)
 {
     return $configId instanceof FieldConfigId ? sprintf('%s_%s_%s', $configId->getScope(), $configId->getClassName(), $configId->getFieldName()) : sprintf('%s_%s', $configId->getScope(), $configId->getClassName());
 }
 /**
  * {@inheritdoc}
  */
 public function getConfigById(ConfigIdInterface $configId)
 {
     return $configId instanceof FieldConfigId ? $this->getConfig($configId->getClassName(), $configId->getFieldName()) : $this->getConfig($configId->getClassName());
 }
 /**
  * @param ConfigIdInterface $configId
  * @return AbstractConfigModel
  */
 public function getModelByConfigId(ConfigIdInterface $configId)
 {
     $fieldName = $configId instanceof FieldConfigId ? $configId->getFieldName() : null;
     return $this->getModel($configId->getClassName(), $fieldName);
 }