Ejemplo n.º 1
0
 /**
  * @param string $className
  * @param mixed  $values
  *
  * @return ConfigInterface
  */
 protected function getEntityConfig($className, $values)
 {
     $configId = new EntityConfigId('extend', $className);
     $config = new Config($configId);
     $config->setValues($values);
     return $config;
 }
Ejemplo n.º 2
0
 public function testValueConfig()
 {
     $config = new Config(new EntityConfigId('testScope', 'testClass'));
     $values = array('firstKey' => 'firstValue', 'secondKey' => 'secondValue', 'thirdKey' => 3, 'fourthKey' => new \stdClass(), 'falseKey' => false, 'nullKey' => null);
     $config->setValues($values);
     $this->assertEquals($values, $config->all());
     $this->assertEquals(array('firstKey' => 'firstValue'), $config->all(function ($value) {
         return $value == 'firstValue';
     }));
     $this->assertEquals('firstValue', $config->get('firstKey'));
     $this->assertEquals('secondValue', $config->get('secondKey'));
     $this->assertTrue($config->is('secondKey'));
     $this->assertTrue($config->in('thirdKey', ['3']));
     $this->assertFalse($config->in('thirdKey', ['3'], true));
     $this->assertTrue($config->in('thirdKey', [3]));
     $this->assertTrue($config->in('thirdKey', [3], true));
     $this->assertFalse($config->in('thirdKey', [100]));
     $this->assertTrue($config->has('secondKey'));
     $this->assertFalse($config->has('nonExistKey'));
     $this->assertTrue($config->has('falseKey'));
     $this->assertTrue($config->has('nullKey'));
     $this->assertNull($config->get('nonExistKey'));
     $this->assertFalse($config->get('falseKey'));
     $this->assertNull($config->get('nullKey'));
     $this->assertEquals($config, unserialize(serialize($config)));
     $config->set('secondKey', 'secondValue2');
     $this->assertEquals('secondValue2', $config->get('secondKey'));
     $this->assertEquals(112233, $config->get('nonExistKey', false, 112233));
     $this->assertEquals('default', $config->get('nonExistKey', false, 'default'));
     $this->assertEquals([], $config->get('nonExistKey', false, []));
     $this->setExpectedException('Oro\\Bundle\\EntityConfigBundle\\Exception\\RuntimeException');
     $config->get('nonExistKey', true);
 }
Ejemplo n.º 3
0
 protected function prepareConfigProvider(array $configValues, $className)
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|ConfigIdInterface $configId */
     $configId = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $entityConfig = new Config($configId);
     $entityConfig->setValues($configValues);
     $this->configProvider->expects($this->once())->method('hasConfig')->with($this->equalTo($className))->will($this->returnValue(true));
     $this->configProvider->expects($this->once())->method('getConfig')->with($this->equalTo($className))->will($this->returnValue($entityConfig));
 }
Ejemplo n.º 4
0
 public function testValueConfig()
 {
     $values = array('firstKey' => 'firstValue', 'secondKey' => 'secondValue', 'fourthKey' => new \stdClass());
     $this->config->setValues($values);
     $this->assertEquals($values, $this->config->all());
     $this->assertEquals(array('firstKey' => 'firstValue'), $this->config->all(function ($value) {
         return $value == 'firstValue';
     }));
     $this->assertEquals('firstValue', $this->config->get('firstKey'));
     $this->assertEquals('secondValue', $this->config->get('secondKey'));
     $this->assertEquals(true, $this->config->is('secondKey'));
     $this->assertEquals(true, $this->config->has('secondKey'));
     $this->assertEquals(false, $this->config->has('thirdKey'));
     $this->assertEquals(null, $this->config->get('thirdKey'));
     $this->assertEquals($this->config, unserialize(serialize($this->config)));
     $this->config->set('secondKey', 'secondValue2');
     $this->assertEquals('secondValue2', $this->config->get('secondKey'));
     $this->setExpectedException('Oro\\Bundle\\EntityConfigBundle\\Exception\\RuntimeException');
     $this->config->get('thirdKey', true);
 }
Ejemplo n.º 5
0
 public function testWithoutOwnerType()
 {
     $entity = new BusinessUnit();
     $className = 'Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit';
     /** @var \PHPUnit_Framework_MockObject_MockObject|ConfigIdInterface $configId */
     $configId = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $config = new Config($configId);
     $config->setValues(['another_owner_type' => 'test_type']);
     $this->configProvider->expects($this->once())->method('hasConfig')->with($this->equalTo($className))->will($this->returnValue(true));
     $this->configProvider->expects($this->once())->method('getConfig')->with($this->equalTo($className))->will($this->returnValue($config));
     $this->assertNull($this->extension->getOwnerType($entity));
 }
 public function preSetData()
 {
     $entityConfigId = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\EntityConfigId')->disableOriginalConstructor()->getMock();
     $user = new User();
     $user->setId(1);
     $organization = new Organization();
     $organization->setId(3);
     $userConfig = new Config($entityConfigId);
     $userConfig->setValues(["owner_type" => "USER", "owner_field_name" => "owner", "owner_column_name" => "owner_id", "organization_field_name" => "organization", "organization_column_name" => "organization_id"]);
     $buConfig = new Config($entityConfigId);
     $buConfig->setValues(["owner_type" => "BUSINESS_UNIT", "owner_field_name" => "owner", "owner_column_name" => "owner_id", "organization_field_name" => "organization", "organization_column_name" => "organization_id"]);
     $organizationConfig = new Config($entityConfigId);
     $organizationConfig->setValues(["owner_type" => "ORGANIZATION", "owner_field_name" => "owner", "owner_column_name" => "owner_id"]);
     return ['OwnershipType User with UsernamePasswordOrganizationToken' => [new UsernamePasswordOrganizationToken($user, 'admin', 'key', $organization), $userConfig, ['owner' => $user, 'organization' => $organization]], 'OwnershipType BusinessUnit with UsernamePasswordOrganizationToken' => [new UsernamePasswordOrganizationToken($user, 'admin', 'key', $organization), $buConfig, ['organization' => $organization]], 'OwnershipType Organization with UsernamePasswordOrganizationToken' => [new UsernamePasswordOrganizationToken($user, 'admin', 'key', $organization), $organizationConfig, ['owner' => $organization]], 'OwnershipType User with UsernamePasswordToken' => [new UsernamePasswordToken($user, 'admin', 'key'), $userConfig, ['owner' => $user]], 'OwnershipType BusinessUnit with UsernamePasswordToken' => [new UsernamePasswordToken($user, 'admin', 'key'), $buConfig, []], 'OwnershipType Organization with UsernamePasswordToken' => [new UsernamePasswordToken($user, 'admin', 'key'), $organizationConfig, []]];
 }
Ejemplo n.º 7
0
 /**
  * @param string $className
  * @param string $fieldName
  * @param string $fieldType
  * @param array  $values
  * @param bool   $hidden
  *
  * @return Config
  */
 public function addFieldConfig($className, $fieldName, $fieldType = null, $values = [], $hidden = false)
 {
     if (empty($className)) {
         throw new \InvalidArgumentException('$className must not be empty.');
     }
     if (empty($fieldName)) {
         throw new \InvalidArgumentException('$fieldName must not be empty.');
     }
     $config = new Config(new FieldConfigId($this->getScope(), $className, $fieldName, $fieldType));
     $config->setValues($values);
     $this->fieldConfigs[$className][$fieldName] = $config;
     if ($hidden) {
         $this->hiddenFields[$className][$fieldName] = true;
     } else {
         unset($this->hiddenFields[$className][$fieldName]);
     }
     return $config;
 }
 /**
  * @param string $className
  * @param string $fieldName
  * @param mixed  $values
  * @param string $scope
  *
  * @return Config
  */
 protected function getEntityFieldConfig($className, $fieldName, $values, $scope = 'extend')
 {
     $configId = new FieldConfigId($scope, $className, $fieldName);
     $config = new Config($configId);
     $config->setValues($values);
     return $config;
 }
Ejemplo n.º 9
0
 /**
  * @param  ConfigIdInterface $configId
  * @param  array|null        $values
  *
  * @return Config
  */
 protected function getConfig(ConfigIdInterface $configId, array $values = null)
 {
     $config = new Config($configId);
     if (null !== $values) {
         $config->setValues($values);
     }
     return $config;
 }
Ejemplo n.º 10
0
 protected function getEntityConfig($entityClassName, $values)
 {
     $entityConfigId = new EntityConfigId('entity', $entityClassName);
     $entityConfig = new Config($entityConfigId);
     $entityConfig->setValues($values);
     return $entityConfig;
 }
Ejemplo n.º 11
0
 /**
  * @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);
 }
 /**
  * @param array  $values
  * @param string $className
  *
  * @return Config
  */
 protected function addEntityConfig($values = [], $className = 'Test\\SourceEntity')
 {
     $resultValues = ['owner' => ExtendScope::OWNER_CUSTOM, 'is_extend' => true, 'state' => ExtendScope::STATE_NEW, 'is_deleted' => false, 'upgradeable' => false, 'relation' => [], 'schema' => [], 'index' => []];
     if (!empty($values)) {
         $resultValues = array_merge($resultValues, $values);
     }
     $config = new Config(new EntityConfigId('extend', $className));
     $config->setValues($resultValues);
     $this->configs[null][] = $config;
     return $config;
 }
 /**
  * @param string $entityClassName
  * @param string $fieldName
  * @param string $fieldType
  * @param mixed $values
  * @return Config
  */
 protected function getExtendFieldConfig($entityClassName, $fieldName, $fieldType, $values)
 {
     $extendFieldConfigId = new FieldConfigId('extend', $entityClassName, $fieldName, $fieldType);
     $extendFieldConfig = new Config($extendFieldConfigId);
     $extendFieldConfig->setValues($values);
     return $extendFieldConfig;
 }
 protected function getFieldConfig($fieldName, $fieldType, $values = [])
 {
     $fieldConfigId = new FieldConfigId('extend', CalendarPropertyProvider::CALENDAR_PROPERTY_CLASS, $fieldName, $fieldType);
     $fieldConfig = new Config($fieldConfigId);
     $fieldConfig->setValues($values);
     return $fieldConfig;
 }
 /**
  * @param string $scope
  * @param string $className
  * @param array  $values
  * @return Config
  */
 protected function createEntityConfig($scope, $className, $values = [])
 {
     $config = new Config(new EntityConfigId($scope, $className));
     $config->setValues($values);
     return $config;
 }
 /**
  * EntityConfig
  *
  * @param array $values
  * @param string $scope
  * @return Config
  */
 protected function getEntityConfig($values = [], $scope = 'extend')
 {
     $resultValues = ['owner' => ExtendScope::OWNER_CUSTOM, 'is_extend' => true, 'state' => ExtendScope::STATE_NEW, 'is_deleted' => false, 'upgradeable' => false, 'relation' => [], 'schema' => [], 'index' => []];
     if (count($values)) {
         $resultValues = array_merge($resultValues, $values);
     }
     $entityConfigId = new EntityConfigId($scope, 'TestClass');
     $entityConfig = new Config($entityConfigId);
     $entityConfig->setValues($resultValues);
     return $entityConfig;
 }
 /**
  * @param string $fieldName
  * @param array  $values
  *
  * @return Config
  */
 protected function getFieldConfig($fieldName, $values = [])
 {
     $fieldConfigId = new FieldConfigId('extend', self::ENTITY_CLASS, $fieldName, 'int');
     $fieldConfig = new Config($fieldConfigId);
     $fieldConfig->setValues($values);
     return $fieldConfig;
 }
Ejemplo n.º 18
0
 /**
  * In case of FieldConfigId replaces OLD field name with given NEW one
  *
  * @param ConfigInterface $config
  * @param $newFieldName
  * @return Config|ConfigInterface
  */
 protected function changeConfigFieldName(ConfigInterface $config, $newFieldName)
 {
     $configId = $config->getId();
     if ($configId instanceof FieldConfigId) {
         $newConfigId = new FieldConfigId($configId->getScope(), $configId->getClassName(), $newFieldName, $configId->getFieldType());
         $newConfig = new Config($newConfigId);
         $newConfig->setValues($config->all());
         $config = $newConfig;
     }
     return $config;
 }
 /**
  * @param string $className
  * @param string $fieldName
  * @param array  $values
  *
  * @return Config
  */
 protected function getFieldConfig($className, $fieldName, $values = [])
 {
     $configId = new FieldConfigId('extend', $className, $fieldName);
     $config = new Config($configId);
     $config->setValues($values);
     return $config;
 }
Ejemplo n.º 20
0
 /**
  * @param ConfigIdInterface $configId
  * @throws RuntimeException
  * @throws LogicException
  * @return ConfigInterface
  */
 public function getConfig(ConfigIdInterface $configId)
 {
     if ($this->localCache->containsKey($configId->toString())) {
         return $this->localCache->get($configId->toString());
     }
     if (!$this->modelManager->checkDatabase()) {
         throw new LogicException('Database is not synced, if you use ConfigManager, when a db schema may be hasn\'t synced.' . ' check it by ConfigManager::modelManager::checkDatabase');
     }
     if (!$this->hasConfig($configId->getClassName())) {
         throw new RuntimeException(sprintf('Entity "%s" is not configurable', $configId->getClassName()));
     }
     $resultConfig = null !== $this->cache ? $this->cache->loadConfigFromCache($configId) : null;
     if (!$resultConfig) {
         $model = $this->modelManager->getModelByConfigId($configId);
         $config = new Config($this->getConfigIdByModel($model, $configId->getScope()));
         $config->setValues($model->toArray($configId->getScope()));
         if (null !== $this->cache) {
             $this->cache->putConfigInCache($config);
         }
         $resultConfig = $config;
     }
     //local cache
     $this->localCache->set($resultConfig->getId()->toString(), $resultConfig);
     //for calculate change set
     $this->originalConfigs->set($resultConfig->getId()->toString(), clone $resultConfig);
     return $resultConfig;
 }