/** * @dataProvider saveConfigurableProvider */ public function testSaveConfigurable($fetchVal, $flag, $fieldName, $saveValue) { $this->modelCache->expects($this->once())->method('fetch')->with(self::ENTITY_CLASS)->willReturn($fetchVal); $this->modelCache->expects($this->exactly(2))->method('save')->with(self::ENTITY_CLASS, $this->identicalTo($saveValue))->willReturn(true); $this->assertTrue($this->configCache->saveConfigurable($flag, self::ENTITY_CLASS, $fieldName)); // test local cache $this->assertTrue($this->configCache->saveConfigurable($flag, self::ENTITY_CLASS, $fieldName)); }
public function testDeleteAllConfigurableLocalCacheOnly() { $this->configCache->saveConfigurable(true, self::ENTITY_CLASS, null, true); $this->modelCache->expects($this->never())->method('deleteAll'); $this->assertTrue($this->configCache->deleteAllConfigurable(true)); // test that a local cache is cleaned up $this->assertNull($this->configCache->getConfigurable(self::ENTITY_CLASS)); }
/** * Checks whether a field is configurable. * * @param string $className * @param string $fieldName * * @return bool */ protected function isConfigurableField($className, $fieldName) { $isConfigurable = $this->cache->getConfigurable($className, $fieldName); if (null === $isConfigurable) { $isConfigurable = null !== $this->modelManager->findFieldModel($className, $fieldName); $this->cache->saveConfigurable($isConfigurable, $className, $fieldName); } return $isConfigurable; }
/** * @param string $className * @param string $fieldName * @param string $fieldType * @param string $mode * @return FieldConfigModel */ public function createConfigFieldModel($className, $fieldName, $fieldType, $mode = ConfigModelManager::MODE_DEFAULT) { $fieldModel = $this->modelManager->findFieldModel($className, $fieldName); if (null === $fieldModel) { $fieldModel = $this->modelManager->createFieldModel($className, $fieldName, $fieldType, $mode); $metadata = $this->getFieldMetadata($className, $fieldName); foreach ($this->getProviders() as $provider) { $configId = new FieldConfigId($provider->getScope(), $className, $fieldName, $fieldType); $config = new Config($configId, $this->getFieldDefaultValues($provider, $className, $fieldName, $fieldType, $metadata)); $this->merge($config); // local cache $this->cache->saveConfig($config, true); $this->cache->saveConfigurable(true, $className, $fieldName, true); // for calculate change set $this->originalConfigs[$this->buildConfigKey($configId)] = clone $config; } $this->eventDispatcher->dispatch(Events::NEW_FIELD_CONFIG, new FieldConfigEvent($className, $fieldName, $this)); } return $fieldModel; }
protected function loadVirtualFields() { $entities = $this->cache->getEntities(); foreach ($entities as $className => $entityData) { $virtualFields = $this->virtualFieldProvider->getVirtualFields($className); if (!empty($virtualFields)) { foreach ($virtualFields as $fieldName) { if (null === $this->cache->getConfigurable($className, $fieldName)) { $this->cache->saveConfigurable(false, $className, $fieldName); } } } $virtualRelations = $this->virtualRelationProvider->getVirtualRelations($className); if (!empty($virtualRelations)) { foreach ($virtualRelations as $fieldName => $config) { if (null === $this->cache->getConfigurable($className, $fieldName)) { $this->cache->saveConfigurable(false, $className, $fieldName); } } } } }