예제 #1
0
 public function testCreateEntityModel()
 {
     $expectedResult = new EntityConfigModel(self::TEST_ENTITY);
     $expectedResult->setMode(ConfigModelManager::MODE_DEFAULT);
     $this->createRepositoryMock([], [UnitOfWork::STATE_MANAGED]);
     $result = $this->configModelManager->createEntityModel(self::TEST_ENTITY);
     $this->assertEquals($expectedResult, $result);
     // test that the created model is stored in a local cache
     $this->assertSame($result, $this->configModelManager->getEntityModel(self::TEST_ENTITY));
 }
 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());
 }
예제 #3
0
 /**
  * @param array $models
  */
 protected function prepareFlush(&$models)
 {
     foreach ($this->persistConfigs as $config) {
         $this->calculateConfigChangeSet($config);
         $this->eventDispatcher->dispatch(Events::PRE_PERSIST_CONFIG, new PersistConfigEvent($config, $this));
         $configId = $config->getId();
         $configKey = $configId instanceof FieldConfigId ? sprintf('%s_%s', $configId->getClassName(), $configId->getFieldName()) : $configId->getClassName();
         if (isset($models[$configKey])) {
             $model = $models[$configKey];
         } else {
             $model = $configId instanceof FieldConfigId ? $this->modelManager->getFieldModel($configId->getClassName(), $configId->getFieldName()) : $this->modelManager->getEntityModel($configId->getClassName());
             $models[$configKey] = $model;
         }
         $indexedValues = $this->getProvider($config->getId()->getScope())->getPropertyConfig()->getIndexedValues($config->getId());
         $model->fromArray($config->getId()->getScope(), $config->all(), $indexedValues);
         if ($this->cache) {
             $this->cache->removeConfigFromCache($config->getId());
         }
     }
     if (count($this->persistConfigs) != count($this->configChangeSets)) {
         $this->prepareFlush($models);
     }
 }
예제 #4
0
 /**
  * Gets a model for the given config id
  *
  * @param ConfigIdInterface $configId
  *
  * @return ConfigModel
  */
 protected function getModelByConfigId(ConfigIdInterface $configId)
 {
     return $configId instanceof FieldConfigId ? $this->modelManager->getFieldModel($configId->getClassName(), $configId->getFieldName()) : $this->modelManager->getEntityModel($configId->getClassName());
 }