/** * This tests calls two indexed Relations and ensure that indexes are restored after fetching from persistence * * @test */ public function collectionsWithIndexAttributeAreIndexed() { $entityWithIndexedRelation = new Fixtures\EntityWithIndexedRelation(); for ($i = 0; $i < 3; $i++) { $annotatedIdentitiesEntity = new Fixtures\AnnotatedIdentitiesEntity(); $annotatedIdentitiesEntity->setAuthor('Author' . (string) $i); $annotatedIdentitiesEntity->setTitle('Author' . (string) $i); $entityWithIndexedRelation->getAnnotatedIdentitiesEntities()->add($annotatedIdentitiesEntity); } $entityWithIndexedRelation->setRelatedIndexEntity('test', new Fixtures\RelatedIndexEntity()); $this->persistenceManager->add($entityWithIndexedRelation); $this->persistenceManager->persistAll(); $id = $this->persistenceManager->getIdentifierByObject($entityWithIndexedRelation); // Reset persistence manager to make sure fresh instances will be created $this->persistenceManager->clearState(); unset($entityWithIndexedRelation); $entityWithIndexedRelation = $this->persistenceManager->getObjectByIdentifier($id, Fixtures\EntityWithIndexedRelation::class); for ($i = 0; $i < 3; $i++) { $this->assertArrayHasKey('Author' . (string) $i, $entityWithIndexedRelation->getAnnotatedIdentitiesEntities()); } $this->assertArrayNotHasKey(0, $entityWithIndexedRelation->getAnnotatedIdentitiesEntities()); $this->assertArrayHasKey('test', $entityWithIndexedRelation->getRelatedIndexEntities()); $this->assertArrayNotHasKey(0, $entityWithIndexedRelation->getRelatedIndexEntities()); $this->assertInstanceOf(Fixtures\RelatedIndexEntity::class, $entityWithIndexedRelation->getRelatedIndexEntities()->get('test')); }
/** * @test */ public function validatorBehavesCorrectlyOnDuplicateEntityWithMultipleAnnotatedIdentityProperties() { $validator = new \Neos\Flow\Validation\Validator\UniqueEntityValidator(); $book = new AnnotatedIdentitiesEntity(); $book->setTitle('Watership Down'); $book->setAuthor('Richard Adams'); $this->persistenceManager->add($book); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $richardsOtherBook = new AnnotatedIdentitiesEntity(); $richardsOtherBook->setTitle('The Plague Dogs'); $richardsOtherBook->setAuthor('Richard Adams'); $this->assertFalse($validator->validate($richardsOtherBook)->hasErrors()); $otherWatershipDown = new AnnotatedIdentitiesEntity(); $otherWatershipDown->setTitle('Watership Down'); $otherWatershipDown->setAuthor('Martin Rosen'); $this->assertFalse($validator->validate($otherWatershipDown)->hasErrors()); $sameWatershipDown = new AnnotatedIdentitiesEntity(); $sameWatershipDown->setTitle('Watership Down'); $sameWatershipDown->setAuthor('Richard Adams'); $this->assertTrue($validator->validate($sameWatershipDown)->hasErrors()); }