Issue75Test.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Gedmo\Translatable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Translatable\Fixture\Issue75\Article;
  6. use Translatable\Fixture\Issue75\Image;
  7. use Translatable\Fixture\Issue75\File;
  8. /**
  9. * These are tests for translatable behavior
  10. *
  11. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  12. * @package Gedmo.Translatable
  13. * @link http://www.gediminasm.org
  14. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  15. */
  16. class Issue75Test extends BaseTestCaseORM
  17. {
  18. const ARTICLE = 'Translatable\\Fixture\\Issue75\\Article';
  19. const IMAGE = 'Translatable\\Fixture\\Issue75\\Image';
  20. const FILE = 'Translatable\\Fixture\\Issue75\\File';
  21. const TRANSLATION = 'Gedmo\\Translatable\\Entity\\Translation';
  22. private $translatableListener;
  23. protected function setUp()
  24. {
  25. parent::setUp();
  26. $evm = new EventManager;
  27. $this->translatableListener = new TranslationListener();
  28. $this->translatableListener->setTranslatableLocale('en');
  29. $this->translatableListener->setDefaultLocale('en');
  30. $evm->addEventSubscriber($this->translatableListener);
  31. $this->getMockSqliteEntityManager($evm);
  32. }
  33. public function testIssue75()
  34. {
  35. $repo = $this->em->getRepository(self::TRANSLATION);
  36. $file1 = new File;
  37. $file1->setTitle('en file1');
  38. $this->em->persist($file1);
  39. $file2 = new File;
  40. $file2->setTitle('en file2');
  41. $this->em->persist($file2);
  42. $article = new Article;
  43. $article->setTitle('en art');
  44. $article->addFile($file1);
  45. $article->addFile($file2);
  46. $this->em->persist($article);
  47. $image1 = new Image;
  48. $image1->setTitle('en img1');
  49. $this->em->persist($image1);
  50. $image2 = new Image;
  51. $image2->setTitle('en img2');
  52. $this->em->persist($image2);
  53. $article->addImage($image1);
  54. $article->addImage($image2);
  55. $this->em->flush();
  56. $this->translatableListener->setTranslatableLocale('de');
  57. $image1->setTitle('de img1');
  58. $article->setTitle('de art');
  59. $file2->setTitle('de file2');
  60. $this->em->persist($article);
  61. $this->em->persist($image1);
  62. $this->em->persist($file2);
  63. $this->em->flush();
  64. $trans = $repo->findTranslations($article);
  65. $this->assertEquals(2, count($trans));
  66. $trans = $repo->findTranslations($file2);
  67. $this->assertEquals(2, count($trans));
  68. $trans = $repo->findTranslations($image2);
  69. $this->assertEquals(1, count($trans));
  70. }
  71. protected function getUsedEntityFixtures()
  72. {
  73. return array(
  74. self::ARTICLE,
  75. self::TRANSLATION,
  76. self::IMAGE,
  77. self::FILE
  78. );
  79. }
  80. }