Issue75Test.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 TranslatableListener();
  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. // Step1: article creation in default locale
  37. $image1 = new Image;
  38. $image1->setTitle('img1');
  39. $this->em->persist($image1);
  40. /*$image2 = new Image;
  41. $image2->setTitle('img2');
  42. $this->em->persist($image2);*/
  43. $article = new Article;
  44. $article->setTitle('en art');
  45. // images is not an array
  46. //$article->setImages(array($image1, $image2));
  47. $this->em->persist($article);
  48. //$this->em->flush();*/
  49. $image2 = new Image; //line 62
  50. $image2->setTitle('en img2');
  51. $this->em->persist($image2);
  52. $image32 = new Image; // +
  53. $image32->setTitle('en img3'); // +
  54. $this->em->persist($image32); // +
  55. $article->addImage($image1);
  56. $article->addImage($image2);
  57. $this->em->persist($article); // +
  58. $this->em->flush();
  59. $article->setTitle('nada'); // +
  60. $article->addImage($image32); // +
  61. $this->em->persist($article); // +
  62. $this->em->flush();
  63. //Step2: article update in another locale
  64. $article = $this->em->find(self::ARTICLE, $article->getId());
  65. $image1 = $this->em->find(self::IMAGE, $image1->getId());
  66. $image2 = $this->em->find(self::IMAGE, $image2->getId());
  67. $article->setTitle('en updated');
  68. /**
  69. * here you duplicate the objects in collection, it allready
  70. * contains them. Read more about doctrine collections
  71. */
  72. $article->setImages(array($image1, $image2));
  73. $this->em->persist($article);
  74. $this->em->flush();
  75. }
  76. protected function getUsedEntityFixtures()
  77. {
  78. return array(
  79. self::ARTICLE,
  80. self::TRANSLATION,
  81. self::IMAGE,
  82. self::FILE
  83. );
  84. }
  85. }