LoggableMappingTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\Loggable\LoggableListener;
  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 LoggableMappingTest extends BaseTestCaseOM
  18. {
  19. /**
  20. * @var Doctrine\ORM\EntityManager
  21. */
  22. private $em;
  23. /**
  24. * @var Gedmo\Loggable\LoggableListener
  25. */
  26. private $loggable;
  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\Loggable');
  35. $chain->addDriver($xmlDriver, 'Mapping\Fixture\Xml');
  36. $this->loggable = new LoggableListener;
  37. $this->evm = new EventManager;
  38. $this->evm->addEventSubscriber($this->loggable);
  39. $this->em = $this->getMockSqliteEntityManager(array(
  40. 'Gedmo\Loggable\Entity\LogEntry',
  41. 'Mapping\Fixture\Xml\Loggable',
  42. 'Mapping\Fixture\Xml\Status'
  43. ), $chain);
  44. }
  45. public function testLoggableMetadata()
  46. {
  47. $meta = $this->em->getClassMetadata('Mapping\Fixture\Xml\Loggable');
  48. $config = $this->loggable->getConfiguration($this->em, $meta->name);
  49. $this->assertArrayHasKey('logEntryClass', $config);
  50. $this->assertEquals('Gedmo\Loggable\Entity\LogEntry', $config['logEntryClass']);
  51. $this->assertArrayHasKey('loggable', $config);
  52. $this->assertTrue($config['loggable']);
  53. $this->assertArrayHasKey('versioned', $config);
  54. $this->assertCount(2, $config['versioned']);
  55. $this->assertContains('title', $config['versioned']);
  56. $this->assertContains('status', $config['versioned']);
  57. }
  58. }