Issue165Test.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Gedmo\Translatable;
  3. use Tool\BaseTestCaseMongoODM;
  4. use Doctrine\Common\EventManager;
  5. use Translatable\Fixture\Issue165\SimpleArticle;
  6. /**
  7. * These are tests for Translatable behavior ODM implementation
  8. *
  9. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  10. * @link http://www.gediminasm.org
  11. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  12. */
  13. class Issue165Test extends BaseTestCaseMongoODM
  14. {
  15. const ARTICLE = 'Translatable\Fixture\Issue165\SimpleArticle';
  16. const TRANSLATION = 'Gedmo\\Translatable\\Document\\Translation';
  17. private $translatableListener;
  18. private $articleId;
  19. protected function setUp()
  20. {
  21. parent::setUp();
  22. $evm = new EventManager();
  23. $this->translatableListener = new TranslatableListener;
  24. $this->translatableListener->setDefaultLocale('en');
  25. $this->translatableListener->setTranslatableLocale('en');
  26. $evm->addEventSubscriber($this->translatableListener);
  27. $this->getMockDocumentManager($evm);
  28. }
  29. /**
  30. * @test
  31. */
  32. public function shouldPersistUntranslatedFields()
  33. {
  34. $article = new SimpleArticle;
  35. $article->setTitle('en');
  36. $article->setContent('en');
  37. $article->setUntranslated('en');
  38. $this->dm->persist($article);
  39. $this->dm->flush();
  40. $this->assertEquals('en', $article->getUntranslated());
  41. $this->translatableListener->setTranslatableLocale('ru');
  42. $article->setTitle('ru');
  43. $article->setContent('ru');
  44. $article->setUntranslated('ru');
  45. $this->dm->persist($article);
  46. $this->dm->flush();
  47. $this->assertEquals('ru', $article->getUntranslated());
  48. $this->translatableListener->setTranslatableLocale('de');
  49. $newarticle = new SimpleArticle;
  50. $newarticle->setTitle('de');
  51. $newarticle->setContent('de');
  52. $newarticle->setUntranslated('de');
  53. $this->dm->persist($newarticle);
  54. $this->dm->flush();
  55. $this->dm->refresh($article);
  56. $this->assertEquals('de', $newarticle->getUntranslated());
  57. $this->translatableListener->setTranslatableLocale('en');
  58. $id = $newarticle->getId();
  59. $newarticle = $this->dm->getRepository('Translatable\Fixture\Issue165\SimpleArticle')->find($id);
  60. $newarticle->setTitle('en');
  61. $newarticle->setContent('en');
  62. $newarticle->setUntranslated('en');
  63. $this->dm->persist($newarticle);
  64. $this->dm->flush();
  65. $this->dm->refresh($newarticle);
  66. $this->assertEquals('en', $newarticle->getUntranslated());
  67. $this->translatableListener->setTranslatableLocale('de');
  68. $newarticle->setTitle('de2');
  69. $newarticle->setContent('de2');
  70. $newarticle->setUntranslated('de2');
  71. $this->dm->persist($newarticle);
  72. $this->dm->flush();
  73. $id = $newarticle->getId();
  74. $newarticle = $this->dm->getRepository('Translatable\Fixture\Issue165\SimpleArticle')->find($id);
  75. $this->assertEquals('de2', $newarticle->getUntranslated());
  76. }
  77. }