Ejemplo n.º 1
0
 /**
  * Test the save method.
  */
 public function testSave()
 {
     $entityTranslationProvider = $this->getMock('Elcodi\\Component\\EntityTranslator\\Services\\EntityTranslationProvider', [], [], '', false);
     $entityTranslationProvider->expects($this->exactly(4))->method('setTranslation')->withConsecutive([$this->equalTo('product'), $this->equalTo('1'), $this->equalTo('name'), $this->equalTo('el nombre'), $this->equalTo('es')], [$this->equalTo('product'), $this->equalTo('1'), $this->equalTo('description'), $this->equalTo('la descripción'), $this->equalTo('es')], [$this->equalTo('product'), $this->equalTo('1'), $this->equalTo('name'), $this->equalTo('the name'), $this->equalTo('en')], [$this->equalTo('product'), $this->equalTo('1'), $this->equalTo('description'), $this->equalTo('the description'), $this->equalTo('en')]);
     $entityTranslationProvider->expects($this->once())->method('flushTranslations');
     $configuration = ['Elcodi\\Component\\EntityTranslator\\Tests\\Fixtures\\TranslatableProduct' => ['alias' => 'product', 'idGetter' => 'getId', 'fields' => ['name' => ['setter' => 'setName', 'getter' => 'getName'], 'description' => ['setter' => 'setDescription', 'getter' => 'getDescription']]]];
     $translator = new EntityTranslator($entityTranslationProvider, $configuration, true);
     $product = new TranslatableProduct();
     $product->setId(1)->setName('wrong name')->setDescription('wrong description');
     $translator->save($product, ['es' => ['name' => 'el nombre', 'description' => 'la descripción'], 'en' => ['name' => 'the name', 'description' => 'the description', 'anotherfield' => 'some value']]);
 }
Ejemplo n.º 2
0
 /**
  * Test save
  */
 public function testSave()
 {
     $translation = $this->getFactory('entity_translation')->create()->setEntityType('translatable_product')->setEntityId(1)->setEntityField('name')->setLocale('es')->setTranslation('nombre del producto');
     $this->flush($translation);
     $this->get('elcodi.event_dispatcher.entity_translator')->dispatchTranslatorWarmUp();
     $translatableProduct = new TranslatableProduct();
     $translatableProduct->setId(1)->setName('my default name')->setDescription('my default description');
     $this->get('elcodi.entity_translator')->save($translatableProduct, ['es' => ['name' => 'el nombre'], 'en' => ['name' => 'the name'], 'fr' => ['name' => 'le nom']]);
     $this->assertCount(3, $this->findAll('entity_translation'));
     $cache = $this->get('doctrine_cache.providers.elcodi_translations');
     $this->assertEquals('el nombre', $cache->fetch('translation_translatable_product_1_name_es'));
     $this->assertEquals('the name', $cache->fetch('translation_translatable_product_1_name_en'));
     $this->assertEquals('le nom', $cache->fetch('translation_translatable_product_1_name_fr'));
 }