public function testStringIdentifier()
 {
     $object = new StringIdentifier();
     $object->setTitle('title in en');
     $object->setUid(md5(self::FIXTURE . time()));
     $this->em->persist($object);
     $this->em->flush();
     $this->em->clear();
     $this->testObjectId = $object->getUid();
     $repo = $this->em->getRepository(self::TRANSLATION);
     $object = $this->em->find(self::FIXTURE, $this->testObjectId);
     $translations = $repo->findTranslations($object);
     $this->assertEquals(count($translations), 1);
     $this->assertArrayHasKey('en_us', $translations);
     $this->assertArrayHasKey('title', $translations['en_us']);
     $this->assertEquals('title in en', $translations['en_us']['title']);
     $object = $this->em->find(self::FIXTURE, $this->testObjectId);
     $object->setTitle('title in de');
     $object->setTranslatableLocale('de_de');
     $this->em->persist($object);
     $this->em->flush();
     $this->em->clear();
     $repo = $this->em->getRepository(self::TRANSLATION);
     // test the entity load by translated title
     $object = $repo->findObjectByTranslatedField('title', 'title in en', self::FIXTURE);
     $this->assertEquals($this->testObjectId, $object->getUid());
     $object = $repo->findObjectByTranslatedField('title', 'title in de', self::FIXTURE);
     $this->assertEquals($this->testObjectId, $object->getUid());
     $translations = $repo->findTranslations($object);
     $this->assertEquals(count($translations), 2);
     $this->assertArrayHasKey('de_de', $translations);
     $this->assertArrayHasKey('title', $translations['de_de']);
     $this->assertEquals('title in de', $translations['de_de']['title']);
     // dql test object hydration
     $q = $this->em->createQuery('SELECT si FROM ' . self::FIXTURE . ' si WHERE si.uid = :id');
     $data = $q->execute(array('id' => $this->testObjectId), \Doctrine\ORM\Query::HYDRATE_OBJECT);
     $this->assertEquals(count($data), 1);
     $object = $data[0];
     $this->assertEquals('title in en', $object->getTitle());
     $this->translationListener->setTranslatableLocale('de_de');
     $q = $this->em->createQuery('SELECT si FROM ' . self::FIXTURE . ' si WHERE si.uid = :id');
     $data = $q->execute(array('id' => $this->testObjectId), \Doctrine\ORM\Query::HYDRATE_OBJECT);
     $this->assertEquals(count($data), 1);
     $object = $data[0];
     $this->assertEquals('title in de', $object->getTitle());
 }
 /**
  * @test
  */
 function shouldHandleStringIdentifier()
 {
     $object = new StringIdentifier();
     $object->setTitle('title in en');
     $object->setUid(md5(self::FIXTURE . time()));
     $this->em->persist($object);
     $this->em->flush();
     $this->em->clear();
     $this->testObjectId = $object->getUid();
     $repo = $this->em->getRepository(self::TRANSLATION);
     $object = $this->em->find(self::FIXTURE, $this->testObjectId);
     $translations = $repo->findTranslations($object);
     $this->assertCount(0, $translations);
     $object = $this->em->find(self::FIXTURE, $this->testObjectId);
     $object->setTitle('title in de');
     $object->setTranslatableLocale('de_de');
     $this->em->persist($object);
     $this->em->flush();
     $this->em->clear();
     $repo = $this->em->getRepository(self::TRANSLATION);
     // test the entity load by translated title
     $object = $repo->findObjectByTranslatedField('title', 'title in de', self::FIXTURE);
     $this->assertEquals($this->testObjectId, $object->getUid());
     $translations = $repo->findTranslations($object);
     $this->assertCount(1, $translations);
     $this->assertArrayHasKey('de_de', $translations);
     $this->assertArrayHasKey('title', $translations['de_de']);
     $this->assertEquals('title in de', $translations['de_de']['title']);
     // dql test object hydration
     $q = $this->em->createQuery('SELECT si FROM ' . self::FIXTURE . ' si WHERE si.uid = :id')->setParameter('id', $this->testObjectId)->useResultCache(false);
     $data = $q->getResult();
     $this->assertCount(1, $data);
     $object = $data[0];
     $this->assertEquals('title in en', $object->getTitle());
     $this->em->clear();
     // based on 2.3.0 it caches in identity map
     $this->translatableListener->setTranslatableLocale('de_de');
     $data = $q->getResult();
     $this->assertCount(1, $data);
     $object = $data[0];
     $this->assertEquals('title in de', $object->getTitle());
 }