Issue114Test.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace Gedmo\Translatable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Translatable\Fixture\Issue114\Article;
  6. use Translatable\Fixture\Issue114\Category;
  7. /**
  8. * These are tests for translatable behavior
  9. *
  10. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  11. * @link http://www.gediminasm.org
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. */
  14. class Issue114Test extends BaseTestCaseORM
  15. {
  16. const CATEGORY = 'Translatable\\Fixture\\Issue114\\Category';
  17. const ARTICLE = 'Translatable\\Fixture\\Issue114\\Article';
  18. const TRANSLATION = 'Gedmo\\Translatable\\Entity\\Translation';
  19. private $translatableListener;
  20. protected function setUp()
  21. {
  22. parent::setUp();
  23. $evm = new EventManager;
  24. $this->translatableListener = new TranslatableListener();
  25. $this->translatableListener->setTranslatableLocale('en');
  26. $this->translatableListener->setDefaultLocale('en');
  27. $evm->addEventSubscriber($this->translatableListener);
  28. $this->getMockSqliteEntityManager($evm);
  29. }
  30. public function testIssue114()
  31. {
  32. $repo = $this->em->getRepository(self::TRANSLATION);
  33. //Categories
  34. $category1 = new Category;
  35. $category1->setTitle('en category1');
  36. $category2 = new Category;
  37. $category2->setTitle('en category2');
  38. $this->em->persist($category1);
  39. $this->em->persist($category2);
  40. $this->em->flush();
  41. //Articles
  42. $article1 = new Article;
  43. $article1->setTitle('en article1');
  44. $article1->setCategory($category1);
  45. $article2 = new Article;
  46. $article2->setTitle('en article2');
  47. $article2->setCategory($category1);
  48. $article3 = new Article;
  49. $article3->setTitle('en article3');
  50. $article3->setCategory($category1);
  51. $this->em->persist($article1);
  52. $this->em->persist($article2);
  53. $this->em->persist($article3);
  54. $this->em->flush();
  55. $this->translatableListener->setTranslatableLocale('es');
  56. // Setting es_ES title.
  57. $article1->setTitle('es article1');
  58. $article2->setTitle('es article2');
  59. $article3->setTitle('es article3');
  60. $this->em->persist($article1);
  61. $this->em->persist($article2);
  62. $this->em->persist($article3);
  63. $this->em->flush();
  64. // Updating articles' category
  65. $article1->setCategory($category2);
  66. $article2->setCategory($category2);
  67. $article3->setCategory($category2);
  68. $this->em->persist($article1);
  69. $this->em->persist($article2);
  70. $this->em->persist($article3);
  71. $this->em->flush();
  72. // Removing $category1
  73. $this->em->remove($category1);
  74. $this->em->flush();
  75. $trans = $repo->findTranslations($article2);
  76. $this->assertEquals(1, count($trans));
  77. $trans = $repo->findTranslations($article3);
  78. $this->assertEquals(1, count($trans));
  79. $trans = $repo->findTranslations($article1);
  80. $this->assertEquals(1, count($trans));
  81. }
  82. protected function getUsedEntityFixtures()
  83. {
  84. return array(
  85. self::CATEGORY,
  86. self::ARTICLE,
  87. self::TRANSLATION,
  88. );
  89. }
  90. }