public function testFixtureGeneratedTranslations() { $person = new Person(); $person->setName('name in en'); $this->em->persist($person); $this->em->flush(); $this->em->clear(); $repo = $this->em->getRepository(self::TRANSLATION); $this->assertTrue($repo instanceof Entity\Repository\TranslationRepository); $translations = $repo->findTranslations($person); $this->assertEquals(count($translations), 1); $this->assertArrayHasKey('en_us', $translations); $this->assertArrayHasKey('name', $translations['en_us']); $this->assertEquals('name in en', $translations['en_us']['name']); // test second translations $person = $this->em->find(self::PERSON, $person->getId()); $this->translatableListener->setTranslatableLocale('de_de'); $person->setName('name in de'); $this->em->persist($person); $this->em->flush(); $this->em->clear(); $translations = $repo->findTranslations($person); $this->assertEquals(count($translations), 2); $this->assertArrayHasKey('de_de', $translations); $this->assertArrayHasKey('name', $translations['de_de']); $this->assertEquals('name in de', $translations['de_de']['name']); $this->translatableListener->setTranslatableLocale('en_us'); }
public function testFixtureGeneratedTranslations() { $person = new Person(); $person->setName('name in en'); $this->em->persist($person); $this->em->flush(); $this->em->clear(); $repo = $this->em->getRepository(self::TRANSLATION); $this->assertTrue($repo instanceof Entity\Repository\TranslationRepository); $translations = $repo->findTranslations($person); //As Translate locale and Default locale are the same, no records should be present in translations table $this->assertCount(0, $translations); // test second translations $person = $this->em->find(self::PERSON, $person->getId()); $this->translatableListener->setTranslatableLocale('de_de'); $person->setName('name in de'); $this->em->persist($person); $this->em->flush(); $this->em->clear(); $translations = $repo->findTranslations($person); //Only one translation should be present $this->assertCount(1, $translations); $this->assertArrayHasKey('de_de', $translations); $this->assertArrayHasKey('name', $translations['de_de']); $this->assertEquals('name in de', $translations['de_de']['name']); $this->translatableListener->setTranslatableLocale('en_us'); }
/** * Covers issue #438 * @test */ function shouldPersistDefaultLocaleValue() { $this->translatableListener->setPersistDefaultLocaleTranslation(true); $this->translatableListener->setTranslatableLocale('de'); $person = new Person(); $person->setName('de'); $repo = $this->em->getRepository(self::TRANSLATION); $repo->translate($person, 'name', 'de', 'de')->translate($person, 'name', 'en_us', 'en_us'); $this->em->persist($person); $this->em->flush(); $this->translatableListener->setTranslatableLocale('en_us'); $articles = $this->em->createQuery('SELECT p FROM ' . self::PERSON . ' p')->getArrayResult(); $this->assertEquals('en_us', $articles[0]['name']); $trans = $this->em->createQuery('SELECT t FROM ' . self::TRANSLATION . ' t')->getArrayResult(); $this->assertCount(2, $trans); foreach ($trans as $item) { $this->assertEquals($item['locale'], $item['content']); } }