/** * 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; }
public function testChangeEntityMode() { $entityModel = $this->createEntityModel(self::TEST_ENTITY); $this->createRepositoryMock([$entityModel], [UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED]); $this->em->expects($this->once())->method('persist')->with($this->equalTo($entityModel)); $this->em->expects($this->never())->method('flush'); $result = $this->configModelManager->changeEntityMode(self::TEST_ENTITY, ConfigModelManager::MODE_HIDDEN); $this->assertTrue($result); $this->assertEquals(ConfigModelManager::MODE_HIDDEN, $this->configModelManager->getEntityModel(self::TEST_ENTITY)->getMode()); }
public function testChangeFieldType() { $entityModel = $this->createEntityModel(self::TEST_ENTITY); $fieldModel = $this->createFieldModel($entityModel, self::TEST_FIELD); $this->createRepositoryMock([$entityModel], [UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED]); $this->em->expects($this->once())->method('persist')->with($this->equalTo($fieldModel)); $this->em->expects($this->never())->method('flush'); $result = $this->configModelManager->changeFieldType(self::TEST_ENTITY, self::TEST_FIELD, 'int'); $this->assertTrue($result); $this->assertEquals('int', $this->configModelManager->getFieldModel(self::TEST_ENTITY, self::TEST_FIELD)->getType()); }
/** * @param string $className * @param string $fieldName * @param string $fieldType * @param string $mode * @return FieldConfigModel */ public function createConfigFieldModel($className, $fieldName, $fieldType, $mode = ConfigModelManager::MODE_DEFAULT) { if (!($fieldModel = $this->modelManager->findModel($className, $fieldName))) { $fieldModel = $this->modelManager->createFieldModel($className, $fieldName, $fieldType, $mode); foreach ($this->getProviders() as $provider) { $defaultValues = array(); $metadata = $this->getFieldMetadata($className, $fieldName); if ($metadata && isset($metadata->defaultValues[$provider->getScope()])) { $defaultValues = $metadata->defaultValues[$provider->getScope()]; } $fieldId = new FieldConfigId($className, $provider->getScope(), $fieldName, $fieldType); $config = $provider->createConfig($fieldId, $defaultValues); $this->localCache->set($config->getId()->toString(), $config); } $this->eventDispatcher->dispatch(Events::NEW_FIELD_CONFIG_MODEL, new NewFieldConfigModelEvent($fieldModel, $this)); } return $fieldModel; }
/** * Changes a type of a field * * @param string $className * @param string $fieldName * @param string $fieldType * @return bool TRUE if the type was changed; otherwise, FALSE */ public function changeFieldType($className, $fieldName, $fieldType) { return $this->modelManager->changeFieldType($className, $fieldName, $fieldType); }
public function testCreateFieldModel() { $meta = $this->em->getClassMetadata(EntityConfigModel::ENTITY_NAME); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $em->expects($this->any())->method('getRepository')->will($this->returnValue(new FoundEntityConfigRepository($em, $meta))); $serviceLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->disableOriginalConstructor()->getMock(); $serviceLink->expects($this->any())->method('getService')->will($this->returnValue($em)); $configModelManager = new ConfigModelManager($serviceLink); $entityModel = FoundEntityConfigRepository::getResultConfigEntity(); $result = new FieldConfigModel('test', 'string'); $result->setMode(ConfigModelManager::MODE_DEFAULT); $entityModel->addField($result); $this->assertEquals($result, $configModelManager->createFieldModel(DemoEntity::ENTITY_NAME, 'test', 'string', ConfigModelManager::MODE_DEFAULT)); }
/** * Gets a model for the given config id * * @param ConfigIdInterface $configId * * @return EntityConfigModel|FieldConfigModel */ protected function getModelByConfigId(ConfigIdInterface $configId) { return $configId instanceof FieldConfigId ? $this->modelManager->getFieldModel($configId->getClassName(), $configId->getFieldName()) : $this->modelManager->getEntityModel($configId->getClassName()); }
/** * @param EntityConfigModel[] $entityModels * @param array $entityStates * @return \PHPUnit_Framework_MockObject_MockObject */ protected function prepareEntityConfigRepository($entityModels = [], $entityStates = []) { $this->repo->expects($this->once())->method('findAll')->will($this->returnValue($entityModels)); $this->prepareCheckDetached($entityStates); $this->configModelManager->getModels(); }