public function testProperties() { /** test ConfigEntity */ $this->assertNull($this->configEntity->getClassName()); $this->assertEmpty($this->configEntity->getId()); $this->assertNull($this->configEntity->getCreated()); $this->configEntity->setCreated(new \DateTime('2013-01-01')); $this->assertEquals('2013-01-01', $this->configEntity->getCreated()->format('Y-m-d')); $this->assertNull($this->configEntity->getUpdated()); $this->configEntity->setUpdated(new \DateTime('2013-01-01')); $this->assertEquals('2013-01-01', $this->configEntity->getUpdated()->format('Y-m-d')); /** test ConfigEntity prePersist */ $this->configEntity->prePersist(); $currentDate = new \DateTime('now', new \DateTimeZone('UTC')); $this->assertEquals($currentDate->format('Y-m-d'), $this->configEntity->getCreated()->format('Y-m-d')); /** test ConfigEntity preUpdate */ $this->configEntity->preUpdate(); $currentDate = new \DateTime('now', new \DateTimeZone('UTC')); $this->assertEquals($currentDate->format('Y-m-d'), $this->configEntity->getUpdated()->format('Y-m-d')); /** test ConfigField */ $this->assertEmpty($this->configField->getId()); $this->configField->setMode(ConfigModelManager::MODE_READONLY); $this->assertEquals(ConfigModelManager::MODE_READONLY, $this->configField->getMode()); /** test ConfigValue */ $this->assertEmpty($this->configValue->getId()); $this->assertEmpty($this->configValue->getScope()); $this->assertEmpty($this->configValue->getCode()); $this->assertEmpty($this->configValue->getValue()); $this->assertEmpty($this->configValue->getField()); $this->assertFalse($this->configValue->getSerializable()); $this->configValue->setSerializable(true); $this->assertTrue($this->configValue->getSerializable()); $this->assertEmpty($this->configValue->getEntity()); $this->configValue->setEntity($this->configEntity); $this->assertEquals($this->configEntity, $this->configValue->getEntity()); }
protected function createFieldConfigModel(EntityConfigModel $entityConfigModel, $fieldName, $fieldType, $mode = ConfigModel::MODE_DEFAULT) { $result = new FieldConfigModel($fieldName, $fieldType); $result->setEntity($entityConfigModel); $result->setMode($mode); return $result; }
public function testCreateFieldModel() { $entityModel = $this->createEntityModel(self::TEST_ENTITY); $expectedResult = new FieldConfigModel(self::TEST_FIELD, 'int'); $expectedResult->setMode(ConfigModelManager::MODE_DEFAULT); $expectedResult->setEntity($entityModel); $this->createRepositoryMock([$entityModel], [UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED]); $result = $this->configModelManager->createFieldModel(self::TEST_ENTITY, self::TEST_FIELD, 'int', ConfigModelManager::MODE_DEFAULT); $this->assertEquals($expectedResult, $result); // test that the created model is stored in a local cache $this->assertSame($result, $this->configModelManager->getFieldModel(self::TEST_ENTITY, self::TEST_FIELD)); }
/** * @return FieldConfigModel[] */ protected function getFieldConfigModels() { $models = []; for ($i = 1; $i <= self::NUMBER_OF_FIELDS; $i++) { $model = new FieldConfigModel('field' . $i, 'string'); if ($i % 5 === 0) { $model->setMode(ConfigModel::MODE_HIDDEN); } $models[] = $model; } return $models; }
/** * @param string $className * @param string $fieldName * @param string $fieldType * @param string $mode * * @return FieldConfigModel * * @throws \InvalidArgumentException if $className is empty or $mode is invalid * @throws RuntimeException if models are locked */ public function createFieldModel($className, $fieldName, $fieldType, $mode = ConfigModel::MODE_DEFAULT) { if (empty($className)) { throw new \InvalidArgumentException('$className must not be empty'); } if (!$this->isValidMode($mode)) { throw new \InvalidArgumentException(sprintf('Invalid $mode: "%s"', $mode)); } if ($this->lockObject->isLocked()) { throw new RuntimeException(sprintf('Cannot create field model for "%s::%s" because config models are locked.', $className, $fieldName)); } $entityModel = $this->getEntityModel($className); $fieldModel = new FieldConfigModel($fieldName, $fieldType); $fieldModel->setMode($mode); $entityModel->addField($fieldModel); if (!empty($fieldName)) { $this->ensureFieldCacheWarmed($className); $this->fields[$className][$fieldName] = $fieldModel; } return $fieldModel; }
/** * @param string $className * @param string $fieldName * @param string $fieldType * @param string $mode * @return FieldConfigModel * @throws \InvalidArgumentException */ public function createFieldModel($className, $fieldName, $fieldType, $mode = self::MODE_DEFAULT) { if (empty($className)) { throw new \InvalidArgumentException('$className must not be empty'); } if (!in_array($mode, array(self::MODE_DEFAULT, self::MODE_HIDDEN, self::MODE_READONLY))) { throw new \InvalidArgumentException(sprintf('Invalid $mode: "%s"', $mode)); } $entityModel = $this->getEntityModel($className); $fieldModel = new FieldConfigModel($fieldName, $fieldType); $fieldModel->setMode($mode); $entityModel->addField($fieldModel); if (!empty($fieldName)) { $this->ensureFieldLocalCacheWarmed($className); $this->fieldLocalCache[$className][$fieldName] = $fieldModel; } return $fieldModel; }
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)); }
/** * @param string $className * @param string $fieldName * @param string $fieldType * @param string $mode * @throws \InvalidArgumentException * @return FieldConfigModel */ public function createFieldModel($className, $fieldName, $fieldType, $mode = self::MODE_DEFAULT) { if (!in_array($mode, array(self::MODE_DEFAULT, self::MODE_HIDDEN, self::MODE_READONLY))) { throw new \InvalidArgumentException(sprintf('FieldConfigModel give invalid parameter "mode" : "%s"', $mode)); } /** @var EntityConfigModel $entityModel */ $entityModel = $this->getModel($className); $fieldModel = new FieldConfigModel($fieldName, $fieldType); $fieldModel->setMode($mode); $entityModel->addField($fieldModel); $this->localCache->set($className . $fieldName, $fieldModel); return $fieldModel; }