/** * @test */ public function embeddablesInsideClonedProxiedEntitiesAreCorrectlyLoaded() { $this->markTestSkipped('This is possibly a bug of Doctrine'); $entity = new TestEntity(); $entity->setName('Andi'); $relatedEntity = new TestEntity(); $relatedEntity->setName('Robert'); $embedded = new TestEmbeddable('Foo'); $relatedEntity->setEmbedded($embedded); $valueObject = new TestValueObject('Bar'); $relatedEntity->setRelatedValueObject($valueObject); $entity->setRelatedEntity($relatedEntity); $clonedRelatedEntity = clone $entity->getRelatedEntity(); $this->assertNotNull($clonedRelatedEntity->getEmbedded(), 'Unproxied clone embedded is null'); $this->testEntityRepository->add($entity); $this->testEntityRepository->add($relatedEntity); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $entityIdentifier = $this->persistenceManager->getIdentifierByObject($entity); $loadedEntity = $this->testEntityRepository->findByIdentifier($entityIdentifier); $clonedRelatedEntity = clone $loadedEntity->getRelatedEntity(); $this->assertNotNull($clonedRelatedEntity->getRelatedValueObject(), 'Proxied clone value object is null'); $this->assertNotNull($clonedRelatedEntity->getEmbedded(), 'Proxied clone embedded is null'); $this->assertEquals('Foo', $clonedRelatedEntity->getEmbedded()->getValue()); }
/** * @test */ public function aopIsCorrectlyInitializedEvenIfADoctrineProxyGetsInitializedOnTheFlyFromTheOutside() { $entity = new TestEntity(); $entity->setName('Andi'); $relatedEntity = new TestEntity(); $relatedEntity->setName('Robert'); $entity->setRelatedEntity($relatedEntity); $this->testEntityRepository->add($entity); $this->testEntityRepository->add($relatedEntity); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $entityIdentifier = $this->persistenceManager->getIdentifierByObject($entity); $loadedEntity = $this->testEntityRepository->findByIdentifier($entityIdentifier); $this->testEntityRepository->findOneByName('Robert'); $loadedRelatedEntity = $loadedEntity->getRelatedEntity(); $this->assertEquals($loadedRelatedEntity->sayHello(), 'Hello Andi!'); }
/** * @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 relatedEntitiesCanBePersistedWhenFetchedAsDoctrineProxy() { $entity = new TestEntity(); $entity->setName('Andi'); $relatedEntity = new TestEntity(); $relatedEntity->setName('Robert'); $entity->setRelatedEntity($relatedEntity); $this->testEntityRepository->add($entity); $this->testEntityRepository->add($relatedEntity); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $entityIdentifier = $this->persistenceManager->getIdentifierByObject($entity); $loadedEntity = $this->testEntityRepository->findByIdentifier($entityIdentifier); $clonedRelatedEntity = clone $loadedEntity->getRelatedEntity(); $this->testEntityRepository->add($clonedRelatedEntity); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $clonedEntityIdentifier = $this->persistenceManager->getIdentifierByObject($clonedRelatedEntity); $clonedLoadedEntity = $this->testEntityRepository->findByIdentifier($clonedEntityIdentifier); $this->assertInstanceOf(\TYPO3\Flow\Tests\Functional\Persistence\Fixtures\TestEntity::class, $clonedLoadedEntity); }
/** * @test */ public function trustedPropertiesConfigurationDoesNotIgnoreWildcardConfigurationInController() { $entity = new TestEntity(); $entity->setName('Foo'); $this->persistenceManager->add($entity); $identifier = $this->persistenceManager->getIdentifierByObject($entity); $trustedPropertiesService = new \TYPO3\Flow\Mvc\Controller\MvcPropertyMappingConfigurationService(); $trustedProperties = $trustedPropertiesService->generateTrustedPropertiesToken(array('entity[__identity]', 'entity[subEntities][0][content]', 'entity[subEntities][0][date]', 'entity[subEntities][1][content]', 'entity[subEntities][1][date]')); $form = array('entity' => array('__identity' => $identifier, 'subEntities' => array(array('content' => 'Bar', 'date' => '1.1.2016'), array('content' => 'Baz', 'date' => '30.12.2016'))), '__trustedProperties' => $trustedProperties); $request = Request::create(new Uri('http://localhost/test/mvc/actioncontrollertestc/' . $identifier . '/update'), 'POST', $form); $response = $this->browser->sendRequest($request); $this->assertSame('Entity "Foo" updated', $response->getContent()); }
/** * 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 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()); }