TranslatableMappingTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Gedmo\Translatable;
  3. use Doctrine\Common\Util\Debug,
  4. Doctrine\ORM\Mapping\Driver\YamlDriver,
  5. Doctrine\ORM\Mapping\Driver\DriverChain,
  6. Mapping\Fixture\Yaml\User,
  7. Gedmo\Mapping\ExtensionMetadataFactory;
  8. /**
  9. * These are mapping 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 TranslatableMappingTest extends \PHPUnit_Framework_TestCase
  16. {
  17. const TEST_YAML_ENTITY_CLASS = 'Mapping\Fixture\Yaml\User';
  18. private $em;
  19. public function setUp()
  20. {
  21. $config = new \Doctrine\ORM\Configuration();
  22. $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  23. $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  24. $config->setProxyDir(TESTS_TEMP_DIR);
  25. $config->setProxyNamespace('Gedmo\Mapping\Proxy');
  26. $chainDriverImpl = new DriverChain;
  27. $chainDriverImpl->addDriver(
  28. new YamlDriver(array(__DIR__ . '/Driver/Yaml')),
  29. 'Mapping\Fixture\Yaml'
  30. );
  31. $config->setMetadataDriverImpl($chainDriverImpl);
  32. $conn = array(
  33. 'driver' => 'pdo_sqlite',
  34. 'memory' => true,
  35. );
  36. //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
  37. $evm = new \Doctrine\Common\EventManager();
  38. $this->translatableListener = new TranslatableListener();
  39. $this->translatableListener->setTranslatableLocale('en_us');
  40. $evm->addEventSubscriber($this->translatableListener);
  41. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  42. }
  43. public function testYamlMapping()
  44. {
  45. $meta = $this->em->getClassMetadata(self::TEST_YAML_ENTITY_CLASS);
  46. $cacheId = ExtensionMetadataFactory::getCacheId(
  47. self::TEST_YAML_ENTITY_CLASS,
  48. 'Gedmo\Translatable'
  49. );
  50. $config = $this->em->getMetadataFactory()->getCacheDriver()->fetch($cacheId);
  51. $this->assertArrayHasKey('translationClass', $config);
  52. $this->assertEquals('Translatable\Fixture\PersonTranslation', $config['translationClass']);
  53. $this->assertArrayHasKey('fields', $config);
  54. $this->assertCount(3, $config['fields']);
  55. $this->assertEquals('password', $config['fields'][0]);
  56. $this->assertEquals('username', $config['fields'][1]);
  57. $this->assertArrayHasKey('locale', $config);
  58. $this->assertEquals('localeField', $config['locale']);
  59. $this->assertCount(1, $config['fallback']);
  60. $this->assertTrue($config['fallback']['company']);
  61. }
  62. }