TimestampableMappingTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\Timestampable\TimestampableListener;
  7. use Tool\BaseTestCaseOM;
  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 TimestampableMappingTest extends BaseTestCaseOM
  16. {
  17. /**
  18. * @var Doctrine\ORM\EntityManager
  19. */
  20. private $em;
  21. /**
  22. * @var Gedmo\Timestampable\TimestampableListener
  23. */
  24. private $timestampable;
  25. public function setUp()
  26. {
  27. parent::setUp();
  28. $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml');
  29. $chain = new DriverChain;
  30. $chain->addDriver($xmlDriver, 'Mapping\Fixture\Xml');
  31. $this->timestampable = new TimestampableListener;
  32. $this->evm = new EventManager;
  33. $this->evm->addEventSubscriber($this->timestampable);
  34. $this->em = $this->getMockSqliteEntityManager(array(
  35. 'Mapping\Fixture\Xml\Timestampable',
  36. 'Mapping\Fixture\Xml\Status',
  37. ), $chain);
  38. }
  39. public function testTimestampableMetadata()
  40. {
  41. $meta = $this->em->getClassMetadata('Mapping\Fixture\Xml\Timestampable');
  42. $config = $this->timestampable->getConfiguration($this->em, $meta->name);
  43. $this->assertArrayHasKey('create', $config);
  44. $this->assertEquals('created', $config['create'][0]);
  45. $this->assertArrayHasKey('update', $config);
  46. $this->assertEquals('updated', $config['update'][0]);
  47. $this->assertArrayHasKey('change', $config);
  48. $onChange = $config['change'][0];
  49. $this->assertEquals('published', $onChange['field']);
  50. $this->assertEquals('status.title', $onChange['trackedField']);
  51. $this->assertEquals('Published', $onChange['value']);
  52. }
  53. }