/**
  * Test if any entity exists that holds a reference to the entity being
  * deleted and is not marked for deletion itself.
  *
  * @param type $identifier Identifier of the entity to check
  * @return void
  */
 protected function checkEntityReferencesForDeletion($identifier)
 {
     $referencedIdentifier = $this->flow3Design->entityReferences($identifier);
     $referenceByIdentifier = array();
     foreach ($referencedIdentifier as $reference) {
         $referenceByIdentifier[$reference] = TRUE;
     }
     foreach ($this->deletedEntities as $deletedEntity) {
         $deletedEntityIdentifier = $this->persistenceSession->getIdentifierByObject($deletedEntity);
         if (isset($referenceByIdentifier[$deletedEntityIdentifier])) {
             unset($referenceByIdentifier[$deletedEntityIdentifier]);
         }
     }
     if (count($referenceByIdentifier) > 0) {
         throw new \TYPO3\Flow\Persistence\Exception('Wont remove entity "' . $identifier . '", still referenced from ' . implode(', ', array_keys($referenceByIdentifier)), 1316526986);
     }
 }
 /**
  * @test
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function entityReferencesReturnsSimpleAndArrayReferences()
 {
     $baseEntity = new \TYPO3\CouchDB\Tests\Functional\Fixtures\Domain\Model\TestEntity();
     $simpleReferencedEntity = new \TYPO3\CouchDB\Tests\Functional\Fixtures\Domain\Model\TestEntity();
     $baseEntity->setRelatedEntity($simpleReferencedEntity);
     $arrayReferencedEntity = new \TYPO3\CouchDB\Tests\Functional\Fixtures\Domain\Model\TestEntity();
     $relatedEntities = new \Doctrine\Common\Collections\ArrayCollection();
     $relatedEntities->add($arrayReferencedEntity);
     $relatedEntities->add($baseEntity);
     $baseEntity->setRelatedEntities($relatedEntities);
     $this->persistenceManager->add($baseEntity);
     $baseIdentifier = $this->persistenceManager->getIdentifierByObject($baseEntity);
     $simpleReferenceIdentifier = $this->persistenceManager->getIdentifierByObject($simpleReferencedEntity);
     $arrayReferenceIdentifier = $this->persistenceManager->getIdentifierByObject($arrayReferencedEntity);
     $this->persistenceManager->persistAll();
     $identifiers = $this->design->entityReferences($simpleReferenceIdentifier);
     $this->assertEquals(1, count($identifiers));
     $this->assertEquals($baseIdentifier, $identifiers[0]);
     $identifiers = $this->design->entityReferences($arrayReferenceIdentifier);
     $this->assertEquals(1, count($identifiers));
     $this->assertEquals($baseIdentifier, $identifiers[0]);
     $identifiers = $this->design->entityReferences($baseIdentifier);
     $this->assertEquals(0, count($identifiers));
 }