/**
  * @dataProvider canFieldBeRestoredProvider
  *
  * @param string $fieldName
  * @param bool   $expectedResult
  */
 public function testCanFieldBeRestored($fieldName, $expectedResult)
 {
     $entity = new EntityConfigModel(self::ENTITY_CLASS);
     $field = new FieldConfigModel($fieldName);
     $entity->addField($field);
     $this->addFieldConfig($fieldName, 'int');
     $this->addFieldConfig('active_field', 'int');
     $this->addFieldConfig('active_hidden_field', 'int', [], true);
     $this->addFieldConfig('deleted_field', 'int', ['is_deleted' => true]);
     $this->addFieldConfig('to_be_deleted_field', 'int', ['state' => ExtendScope::STATE_DELETE]);
     $this->assertEquals($expectedResult, $this->validationHelper->canFieldBeRestored($field));
 }
 public function test()
 {
     $this->assertEquals('test', $this->configField->getFieldName($this->configField->setFieldName('test')));
     $this->assertEquals('string', $this->configField->getType($this->configField->setType('string')));
     $this->assertEquals('Acme\\Bundle\\DemoBundle\\Entity\\TestAccount', $this->configEntity->getClassName($this->configEntity->setClassName('Acme\\Bundle\\DemoBundle\\Entity\\TestAccount')));
     /** test ConfigField set/getEntity */
     $this->configField->setEntity($this->configEntity);
     $this->assertEquals($this->configEntity, $this->configField->getEntity());
     /** test ConfigField getOptions */
     $this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $this->configField->getOptions());
     /** test ConfigEntity addField */
     $this->configEntity->addField($this->configField);
     $this->assertEquals($this->configField, $this->configEntity->getField('test'));
     /** test ConfigEntity setFields */
     $this->configEntity->setFields(array($this->configField));
     $this->assertEquals(array($this->configField), $this->configEntity->getFields());
     /** test ConfigValue */
     $this->configValue->setCode('is_extend')->setScope('extend')->setValue(true)->setField($this->configField);
     $this->assertEquals(array('code' => 'is_extend', 'scope' => 'extend', 'value' => true, 'serializable' => false), $this->configValue->toArray());
     /** test Config setValues() */
     $this->configEntity->setValues(array($this->configValue));
     $this->assertEquals($this->configValue, $this->configEntity->getValue('is_extend', 'extend'));
 }
Exemple #3
0
 public function testFieldsCollectionOfEntityConfigModel()
 {
     $entityModel = new EntityConfigModel();
     $this->assertCount(0, $entityModel->getFields());
     $fieldModel1 = new FieldConfigModel('field1', 'string');
     $fieldModel2 = new FieldConfigModel('field2', 'integer');
     $entityModel->addField($fieldModel1);
     $entityModel->addField($fieldModel2);
     $fields = $entityModel->getFields();
     $this->assertCount(2, $fields);
     $this->assertSame($fieldModel1, $fields->first());
     $this->assertSame($fieldModel2, $fields->last());
     $this->assertSame($fieldModel1, $entityModel->getField('field1'));
     $this->assertSame($fieldModel2, $entityModel->getField('field2'));
     $fields = $entityModel->getFields(function (FieldConfigModel $model) {
         return $model->getFieldName() === 'field2';
     });
     $this->assertCount(1, $fields);
     $this->assertSame($fieldModel2, $fields->first());
     $entityModel->setFields(new ArrayCollection([$fieldModel1]));
     $fields = $entityModel->getFields();
     $this->assertCount(1, $fields);
     $this->assertSame($fieldModel1, $fields->first());
 }
 /**
  * @dataProvider validateProvider
  *
  * @param string $fieldName
  * @param string $fieldType
  * @param string $expectedValidationMessageType
  */
 public function testValidate($fieldName, $fieldType, $expectedValidationMessageType)
 {
     $entity = new EntityConfigModel(self::ENTITY_CLASS);
     $field = new FieldConfigModel($fieldName, $fieldType);
     $entity->addField($field);
     $context = $this->getMock('Symfony\\Component\\Validator\\Context\\ExecutionContextInterface');
     $this->validator->initialize($context);
     $constraint = new DefaultRelationField();
     if ($expectedValidationMessageType) {
         $message = PropertyAccess::createPropertyAccessor()->getValue($constraint, $expectedValidationMessageType);
         $violation = $this->getMock('Symfony\\Component\\Validator\\Violation\\ConstraintViolationBuilderInterface');
         $context->expects($this->once())->method('buildViolation')->with($message)->willReturn($violation);
         $violation->expects($this->once())->method('atPath')->with('fieldName')->willReturnSelf();
         $violation->expects($this->once())->method('addViolation');
     } else {
         $context->expects($this->never())->method('buildViolation');
     }
     $this->validator->validate($field, $constraint);
 }
 /**
  * @param EntityConfigModel $entityModel
  * @param string            $fieldName
  * @return FieldConfigModel
  */
 public static function createFieldModel($entityModel, $fieldName)
 {
     $fieldModel = new FieldConfigModel($fieldName, 'string');
     $entityModel->addField($fieldModel);
     return $fieldModel;
 }
 /**
  * @return EntityConfigModel[]
  */
 protected function getEntityConfigModels()
 {
     $models = [];
     for ($i = 1; $i <= self::NUMBER_OF_ENTITIES; $i++) {
         $model = new EntityConfigModel('Entity' . $i);
         if ($i % 20 === 0) {
             $model->setMode(ConfigModel::MODE_HIDDEN);
         }
         foreach ($this->getFieldConfigModels() as $field) {
             $model->addField($field);
         }
         $models[] = $model;
     }
     return $models;
 }