Issue75Test.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // 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. //Step2: article update in another locale
  50. $article = $this->em->find(self::ARTICLE, $article->getId());
  51. $image1 = $this->em->find(self::IMAGE, $image1->getId());
  52. $image2 = $this->em->find(self::IMAGE, $image2->getId());
  53. $article->setTitle('en updated');
  54. /**
  55. * here you duplicate the objects in collection, it allready
  56. * contains them. Read more about doctrine collections
  57. */
  58. $article->setImages(array($image1, $image2));
  59. $this->em->persist($article);
  60. $this->em->flush();
  61. }
  62. protected function getUsedEntityFixtures()
  63. {
  64. return array(
  65. self::ARTICLE,
  66. self::TRANSLATION,
  67. self::IMAGE,
  68. self::FILE
  69. );
  70. }
  71. }