/**
  * Helper which inserts example data into the database.
  *
  * @param string $name
  */
 protected function insertExampleEntity($name = 'Flow')
 {
     $testEntity = new TestEntity();
     $testEntity->setName($name);
     $this->testEntityRepository->add($testEntity);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
 }
 /**
  * @test
  */
 public function validationIsEnforcedForParentObject()
 {
     $entity = new TestEntity();
     $entity->setName('Some Name');
     $this->testEntityRepository->add($entity);
     $subEntity = new SubEntity();
     $subEntity->setContent('Sub Entity');
     $subEntity->setParentEntity($entity);
     $entity->addSubEntity($subEntity);
     $this->persistenceManager->add($subEntity);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $entityIdentifier = $this->persistenceManager->getIdentifierByObject($entity);
     $subEntityIdentifier = $this->persistenceManager->getIdentifierByObject($subEntity);
     $invalidArguments = array('entity' => array('__identity' => $entityIdentifier, 'name' => 'xx', 'subEntities' => array(array('__identity' => $subEntityIdentifier, 'content' => 'some valid content'))));
     $response = $this->browser->request('http://localhost/test/validation/entity/update', 'POST', $invalidArguments);
     $this->assertSame('An error occurred while trying to call TYPO3\\Flow\\Tests\\Functional\\Mvc\\Fixtures\\Controller\\EntityController->updateAction().' . PHP_EOL . 'Error for entity.name:  This field must contain at least 3 characters.' . PHP_EOL, $response->getContent());
 }
 /**
  * @test
  */
 public function doctrineEmbeddablesAreActuallyEmbedded()
 {
     /* @var $entityManager \Doctrine\Common\Persistence\ObjectManager */
     $entityManager = $this->objectManager->get('Doctrine\\Common\\Persistence\\ObjectManager');
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
     $metaData = $entityManager->getClassMetadata('TYPO3\\Flow\\Tests\\Functional\\Persistence\\Fixtures\\TestEntity');
     $this->assertTrue($metaData->hasField('embedded.value'), 'ClassMetadata does not contain embedded value');
     $schema = $schemaTool->getSchemaFromMetadata(array($metaData));
     $this->assertTrue($schema->getTable('persistence_testentity')->hasColumn('embedded_value'), 'Database schema does not contain embedded value field');
     $embeddable = new TestEmbeddable('someValue');
     $testEntity = new TestEntity();
     $testEntity->setEmbedded($embeddable);
     $this->testEntityRepository->add($testEntity);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     /* @var $testEntity TestEntity */
     $testEntity = $this->testEntityRepository->findAll()->getFirst();
     $this->assertEquals('someValue', $testEntity->getEmbedded()->getValue());
 }
 /**
  * @test
  */
 public function validationIsStoppedAtAggregateBoundaries()
 {
     $relatedEntity = new TestEntity();
     $relatedEntity->setName('Spy');
     $this->testEntityRepository->add($relatedEntity);
     $entity = new TestEntity();
     $entity->setName('Some Name');
     $entity->setRelatedEntity($relatedEntity);
     $this->testEntityRepository->add($entity);
     $this->persistenceManager->persistAll();
     $entityIdentifier = $this->persistenceManager->getIdentifierByObject($relatedEntity);
     /* @var $entityManager \Doctrine\ORM\EntityManagerInterface */
     $entityManager = ObjectAccess::getProperty($this->persistenceManager, 'entityManager', true);
     $dql = 'UPDATE ' . TestEntity::class . " e SET e.name = 'xx' WHERE e.Persistence_Object_Identifier = '{$entityIdentifier}'";
     $query = $entityManager->createQuery($dql);
     $query->getScalarResult();
     $this->persistenceManager->clearState();
     $entityIdentifier = $this->persistenceManager->getIdentifierByObject($entity);
     $invalidArguments = array('entity' => array('__identity' => $entityIdentifier, 'name' => 'Some other Name'));
     $response = $this->browser->request('http://localhost/test/validation/entity/update', 'POST', $invalidArguments);
     $this->assertNotSame('An error occurred while trying to call TYPO3\\Flow\\Tests\\Functional\\Mvc\\Fixtures\\Controller\\EntityController->updateAction().' . PHP_EOL . 'Error for entity.relatedEntity.name:  This field must contain at least 3 characters.' . PHP_EOL, $response->getContent());
     $this->assertSame(200, $response->getStatusCode());
 }