TimestampableMappingTest.php 2.1 KB

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