Issue75Test.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * @link http://www.gediminasm.org
  13. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  14. */
  15. class Issue75Test extends BaseTestCaseORM
  16. {
  17. const ARTICLE = 'Translatable\\Fixture\\Issue75\\Article';
  18. const IMAGE = 'Translatable\\Fixture\\Issue75\\Image';
  19. const FILE = 'Translatable\\Fixture\\Issue75\\File';
  20. const TRANSLATION = 'Gedmo\\Translatable\\Entity\\Translation';
  21. private $translatableListener;
  22. protected function setUp()
  23. {
  24. parent::setUp();
  25. $evm = new EventManager;
  26. $this->translatableListener = new TranslatableListener();
  27. $this->translatableListener->setTranslatableLocale('en');
  28. $this->translatableListener->setDefaultLocale('en');
  29. $evm->addEventSubscriber($this->translatableListener);
  30. $this->getMockSqliteEntityManager($evm);
  31. }
  32. public function testIssue75()
  33. {
  34. $repo = $this->em->getRepository(self::TRANSLATION);
  35. // Step1: article creation in default locale
  36. $image1 = new Image;
  37. $image1->setTitle('img1');
  38. $this->em->persist($image1);
  39. /*$image2 = new Image;
  40. $image2->setTitle('img2');
  41. $this->em->persist($image2);*/
  42. $article = new Article;
  43. $article->setTitle('en art');
  44. // images is not an array
  45. //$article->setImages(array($image1, $image2));
  46. $this->em->persist($article);
  47. //$this->em->flush();*/
  48. $image2 = new Image; //line 62
  49. $image2->setTitle('en img2');
  50. $this->em->persist($image2);
  51. $image32 = new Image; // +
  52. $image32->setTitle('en img3'); // +
  53. $this->em->persist($image32); // +
  54. $article->addImage($image1);
  55. $article->addImage($image2);
  56. $this->em->persist($article); // +
  57. $this->em->flush();
  58. $article->setTitle('nada'); // +
  59. $article->addImage($image32); // +
  60. $this->em->persist($article); // +
  61. $this->em->flush();
  62. //Step2: article update in another locale
  63. $article = $this->em->find(self::ARTICLE, $article->getId());
  64. $image1 = $this->em->find(self::IMAGE, $image1->getId());
  65. $image2 = $this->em->find(self::IMAGE, $image2->getId());
  66. $article->setTitle('en updated');
  67. /**
  68. * here you duplicate the objects in collection, it allready
  69. * contains them. Read more about doctrine collections
  70. */
  71. $article->setImages(array($image1, $image2));
  72. $this->em->persist($article);
  73. $this->em->flush();
  74. }
  75. protected function getUsedEntityFixtures()
  76. {
  77. return array(
  78. self::ARTICLE,
  79. self::TRANSLATION,
  80. self::IMAGE,
  81. self::FILE
  82. );
  83. }
  84. }