TranslatableMappingTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Gedmo\Mapping\Xml;
  3. use Doctrine\Common\EventManager;
  4. use Doctrine\Common\Annotations\AnnotationReader;
  5. use Doctrine\ORM\Mapping\Driver\DriverChain;
  6. use Doctrine\ORM\Mapping\Driver\XmlDriver;
  7. use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
  8. use Gedmo\Translatable\TranslatableListener;
  9. use Tool\BaseTestCaseOM;
  10. /**
  11. * These are mapping extension tests
  12. *
  13. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  14. * @link http://www.gediminasm.org
  15. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. class TranslatableMappingTest extends BaseTestCaseOM
  18. {
  19. /**
  20. * @var Doctrine\ORM\EntityManager
  21. */
  22. private $em;
  23. /**
  24. * @var Gedmo\Translatable\TranslatableListener
  25. */
  26. private $translatable;
  27. public function setUp()
  28. {
  29. parent::setUp();
  30. $reader = new AnnotationReader();
  31. $annotationDriver = new AnnotationDriver($reader);
  32. $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml');
  33. $chain = new DriverChain;
  34. $chain->addDriver($annotationDriver, 'Gedmo\Translatable');
  35. $chain->addDriver($xmlDriver, 'Mapping\Fixture\Xml');
  36. $this->translatable = new TranslatableListener;
  37. $this->evm = new EventManager;
  38. $this->evm->addEventSubscriber($this->translatable);
  39. $this->em = $this->getMockSqliteEntityManager(array(
  40. 'Gedmo\Translatable\Entity\Translation',
  41. 'Mapping\Fixture\Xml\Translatable',
  42. ), $chain);
  43. }
  44. public function testTranslatableMetadata()
  45. {
  46. $meta = $this->em->getClassMetadata('Mapping\Fixture\Xml\Translatable');
  47. $config = $this->translatable->getConfiguration($this->em, $meta->name);
  48. $this->assertArrayHasKey('translationClass', $config);
  49. $this->assertEquals('Gedmo\Translatable\Entity\Translation', $config['translationClass']);
  50. $this->assertArrayHasKey('locale', $config);
  51. $this->assertEquals('locale', $config['locale']);
  52. $this->assertArrayHasKey('fields', $config);
  53. $this->assertCount(4, $config['fields']);
  54. $this->assertTrue(in_array('title', $config['fields']));
  55. $this->assertTrue(in_array('content', $config['fields']));
  56. $this->assertTrue(in_array('author', $config['fields']));
  57. $this->assertTrue(in_array('views', $config['fields']));
  58. $this->assertTrue($config['fallback']['author']);
  59. $this->assertFalse($config['fallback']['views']);
  60. }
  61. }