public function testGetConfig()
 {
     $this->assertEquals('Test\\Class', $this->fieldId->getClassName());
     $this->assertEquals('testScope', $this->fieldId->getScope());
     $this->assertEquals('testField', $this->fieldId->getFieldName());
     $this->assertEquals('string', $this->fieldId->getFieldType());
     $this->assertEquals('field_testScope_Test-Class_testField', $this->fieldId->toString());
     $this->fieldId->setFieldType('integer');
     $this->assertEquals('integer', $this->fieldId->getFieldType());
 }
Example #2
0
 public function testGetFieldConfigNotCachedScope()
 {
     $configId = new FieldConfigId(self::SCOPE, self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE);
     $anotherConfigId = new FieldConfigId('another', self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE);
     $anotherConfigValues = ['key2' => 'val2'];
     $anotherConfig = new Config($anotherConfigId, $anotherConfigValues);
     $cacheKey = self::ENTITY_CLASS . '.' . self::FIELD_NAME;
     $this->cache->expects($this->once())->method('fetch')->with($cacheKey)->willReturn([ConfigCache::VALUES_KEY => ['another' => $anotherConfigValues], ConfigCache::FIELD_TYPE_KEY => self::FIELD_TYPE]);
     $this->assertNull($this->configCache->getFieldConfig($configId->getScope(), $configId->getClassName(), $configId->getFieldName()));
     // test local cache
     $this->assertNull($this->configCache->getFieldConfig($configId->getScope(), $configId->getClassName(), $configId->getFieldName()));
     $this->assertEquals($anotherConfig, $this->configCache->getFieldConfig($anotherConfigId->getScope(), $anotherConfigId->getClassName(), $anotherConfigId->getFieldName()));
 }
Example #3
0
 /**
  * Changes a type of a field
  *
  * @param string $className
  * @param string $fieldName
  * @param string $newFieldName
  * @return bool TRUE if the name was changed; otherwise, FALSE
  */
 public function changeFieldName($className, $fieldName, $newFieldName)
 {
     $result = $this->modelManager->changeFieldName($className, $fieldName, $newFieldName);
     if ($result) {
         $this->eventDispatcher->dispatch(Events::RENAME_FIELD, new RenameFieldEvent($className, $fieldName, $newFieldName, $this));
         foreach ($this->getProviders() as $provider) {
             /** @var FieldConfigId $newConfigId */
             $newConfigId = $this->getId($provider->getScope(), $className, $newFieldName);
             $newConfigKey = $this->buildConfigKey($newConfigId);
             $configId = new FieldConfigId($newConfigId->getScope(), $newConfigId->getClassName(), $fieldName, $newConfigId->getFieldType());
             $cachedConfig = $this->cache->getFieldConfig($configId->getScope(), $configId->getClassName(), $configId->getFieldName(), true);
             if ($cachedConfig) {
                 $this->cache->saveConfig($this->changeConfigFieldName($cachedConfig, $newFieldName), true);
                 $this->cache->deleteFieldConfig($configId->getClassName(), $configId->getFieldName(), true);
             }
             $configKey = $this->buildConfigKey($configId);
             if (isset($this->persistConfigs[$configKey])) {
                 $this->persistConfigs[$newConfigKey] = $this->changeConfigFieldName($this->persistConfigs[$configKey], $newFieldName);
                 unset($this->persistConfigs[$configKey]);
             }
             if (isset($this->originalConfigs[$configKey])) {
                 $this->originalConfigs[$newConfigKey] = $this->changeConfigFieldName($this->originalConfigs[$configKey], $newFieldName);
                 unset($this->originalConfigs[$configKey]);
             }
             if (isset($this->configChangeSets[$configKey])) {
                 $this->configChangeSets[$newConfigKey] = $this->configChangeSets[$configKey];
                 unset($this->configChangeSets[$configKey]);
             }
         }
     }
     return $result;
 }