Issue114Test.php 3.4KB

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