LoggableMappingTest.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. * @package Gedmo.Mapping
  15. * @link http://www.gediminasm.org
  16. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  17. */
  18. class LoggableMappingTest extends BaseTestCaseOM
  19. {
  20. /**
  21. * @var Doctrine\ORM\EntityManager
  22. */
  23. private $em;
  24. /**
  25. * @var Gedmo\Loggable\LoggableListener
  26. */
  27. private $loggable;
  28. public function setUp()
  29. {
  30. parent::setUp();
  31. $reader = new AnnotationReader();
  32. $annotationDriver = new AnnotationDriver($reader);
  33. $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml');
  34. $chain = new DriverChain;
  35. $chain->addDriver($annotationDriver, 'Gedmo\Loggable');
  36. $chain->addDriver($xmlDriver, 'Mapping\Fixture\Xml');
  37. $this->loggable = new LoggableListener;
  38. $this->evm = new EventManager;
  39. $this->evm->addEventSubscriber($this->loggable);
  40. $this->em = $this->getMockSqliteEntityManager(array(
  41. 'Gedmo\Loggable\Entity\LogEntry',
  42. 'Mapping\Fixture\Xml\Loggable',
  43. 'Mapping\Fixture\Xml\Status'
  44. ), $chain);
  45. }
  46. public function testLoggableMetadata()
  47. {
  48. $meta = $this->em->getClassMetadata('Mapping\Fixture\Xml\Loggable');
  49. $config = $this->loggable->getConfiguration($this->em, $meta->name);
  50. $this->assertArrayHasKey('logEntryClass', $config);
  51. $this->assertEquals('Gedmo\Loggable\Entity\LogEntry', $config['logEntryClass']);
  52. $this->assertArrayHasKey('loggable', $config);
  53. $this->assertTrue($config['loggable']);
  54. $this->assertArrayHasKey('versioned', $config);
  55. $this->assertCount(2, $config['versioned']);
  56. $this->assertContains('title', $config['versioned']);
  57. $this->assertContains('status', $config['versioned']);
  58. }
  59. }