/** * @test */ public function validatorBehavesCorrectlyOnDuplicateEntityWithSingleConfiguredIdentityProperty() { $validator = new \TYPO3\Flow\Validation\Validator\UniqueEntityValidator(array('identityProperties' => array('title'))); $post = new Post(); $post->setTitle('The title of the initial post'); $this->postRepository->add($post); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $differentPost = new Post(); $differentPost->setTitle('A different title'); $this->assertFalse($validator->validate($differentPost)->hasErrors()); $nextPost = new Post(); $nextPost->setTitle('The title of the initial post'); $this->assertTrue($validator->validate($nextPost)->hasErrors()); }
/** * @test */ public function modificationsOnRetrievedEntitiesArePersistedIfUpdateHasBeenCalled() { $this->postRepository = $this->objectManager->get('TYPO3\\Flow\\Tests\\Functional\\Persistence\\Fixtures\\PostRepository'); $post = new Post(); $post->setTitle('Sample'); $this->postRepository->add($post); $this->persistenceManager->persistAll(); $post = $this->postRepository->findOneByTitle('Sample'); $post->setTitle('Modified Sample'); $this->postRepository->update($post); $this->persistenceManager->persistAll(); $post = $this->postRepository->findOneByTitle('Modified Sample'); $this->assertNotNull($post); $this->assertEquals('Modified Sample', $post->getTitle()); }
/** * @test */ public function entitiesWithOwnRepositoryAreNotRemovedIfRelatedRootEntityIsRemoved() { $comment = new Comment(); $this->commentRepository->add($comment); $post = new Post(); $post->setComment($comment); $this->postRepository->add($post); $this->persistenceManager->persistAll(); $commentIdentifier = $this->persistenceManager->getIdentifierByObject($comment); $retrievedComment = $this->persistenceManager->getObjectByIdentifier($commentIdentifier, 'TYPO3\\Flow\\Tests\\Functional\\Persistence\\Fixtures\\Comment'); $this->assertSame($comment, $retrievedComment); $this->postRepository->remove($post); $this->persistenceManager->persistAll(); $retrievedComment = $this->persistenceManager->getObjectByIdentifier($commentIdentifier, 'TYPO3\\Flow\\Tests\\Functional\\Persistence\\Fixtures\\Comment'); $this->assertSame($comment, $retrievedComment); }
/** * This test fixes FLOW-296 but is only affecting MySQL. * * @test */ public function valueObjectsAreNotCascadeRemovedWhenARelatedEntityIsDeleted() { $post1 = new Post(); $post1->setAuthor(new TestValueObject('Some Name')); $post2 = new Post(); $post2->setAuthor(new TestValueObject('Some Name')); $this->postRepository->add($post1); $this->postRepository->add($post2); $this->persistenceManager->persistAll(); $this->postRepository->remove($post1); $this->persistenceManager->persistAll(); // if all goes well the value object is not deleted $this->assertTrue(true); }