SluggableMappingTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Gedmo\Mapping\Xml;
  3. use Doctrine\Common\EventManager;
  4. use Doctrine\ORM\Mapping\Driver\DriverChain;
  5. use Doctrine\ORM\Mapping\Driver\XmlDriver;
  6. use Gedmo\Sluggable\SluggableListener;
  7. use Tool\BaseTestCaseORM;
  8. /**
  9. * These are mapping extension tests
  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 SluggableMappingTest extends BaseTestCaseORM
  16. {
  17. /**
  18. * @var Gedmo\Sluggable\SluggableListener
  19. */
  20. private $sluggable;
  21. public function setUp()
  22. {
  23. parent::setUp();
  24. $this->sluggable = new SluggableListener;
  25. $evm = new EventManager;
  26. $evm->addEventSubscriber($this->sluggable);
  27. $this->getMockSqliteEntityManager($evm);
  28. }
  29. protected function getUsedEntityFixtures()
  30. {
  31. return array('Mapping\Fixture\Xml\Sluggable');
  32. }
  33. protected function getMetadataDriverImplementation()
  34. {
  35. $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml');
  36. $chain = new DriverChain;
  37. $chain->addDriver($xmlDriver, 'Mapping\Fixture\Xml');
  38. return $chain;
  39. }
  40. /**
  41. * @test
  42. */
  43. public function shouldBeAbleToMapSluggableMetadata()
  44. {
  45. $meta = $this->em->getClassMetadata('Mapping\Fixture\Xml\Sluggable');
  46. $config = $this->sluggable->getConfiguration($this->em, $meta->name);
  47. $this->assertArrayHasKey('slug', $config['slugs']);
  48. $this->assertCount(1, $config['slugs']);
  49. $config = $config['slugs']['slug'];
  50. $this->assertEquals('slug', $config['slug']);
  51. $this->assertArrayHasKey('style', $config);
  52. $this->assertEquals('camel', $config['style']);
  53. $this->assertArrayHasKey('updatable', $config);
  54. $this->assertFalse($config['updatable']);
  55. $this->assertArrayHasKey('unique', $config);
  56. $this->assertTrue($config['unique']);
  57. $this->assertArrayHasKey('separator', $config);
  58. $this->assertEquals('_', $config['separator']);
  59. $this->assertArrayHasKey('fields', $config);
  60. $this->assertCount(3, $config['fields']);
  61. $fields = $config['fields'];
  62. $this->assertEquals('title', $fields[0]);
  63. $this->assertEquals('ean', $fields[1]);
  64. $this->assertEquals('code', $fields[2]);
  65. $this->assertArrayHasKey('handlers', $config);
  66. $this->assertEquals(2, count($config['handlers']));
  67. $handlers = $config['handlers'];
  68. $this->assertArrayHasKey('Gedmo\Sluggable\Handler\TreeSlugHandler', $handlers);
  69. $this->assertArrayHasKey('Gedmo\Sluggable\Handler\RelativeSlugHandler', $handlers);
  70. $first = $handlers['Gedmo\Sluggable\Handler\TreeSlugHandler'];
  71. $this->assertEquals(2, count($first));
  72. $this->assertArrayHasKey('parentRelationField', $first);
  73. $this->assertArrayHasKey('separator', $first);
  74. $this->assertEquals('parent', $first['parentRelationField']);
  75. $this->assertEquals('/', $first['separator']);
  76. $second = $handlers['Gedmo\Sluggable\Handler\RelativeSlugHandler'];
  77. $this->assertEquals(3, count($second));
  78. $this->assertArrayHasKey('relationField', $second);
  79. $this->assertArrayHasKey('relationSlugField', $second);
  80. $this->assertArrayHasKey('separator', $second);
  81. $this->assertEquals('parent', $second['relationField']);
  82. $this->assertEquals('test', $second['relationSlugField']);
  83. $this->assertEquals('-', $second['separator']);
  84. }
  85. }