ChangeTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace Gedmo\Blameable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Doctrine\Common\Util\Debug,
  6. Blameable\Fixture\Entity\TitledArticle,
  7. Gedmo\Mapping\Event\Adapter\ORM as BaseAdapterORM,
  8. Gedmo\Blameable\Mapping\Event\BlameableAdapter,
  9. Doctrine\Common\EventArgs;
  10. /**
  11. * These are tests for Blameable behavior
  12. *
  13. * @author Ivan Borzenkov <ivan.borzenkov@gmail.com>
  14. * @link http://www.gediminasm.org
  15. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. class ChangeTest extends BaseTestCaseORM
  18. {
  19. const FIXTURE = "Blameable\\Fixture\\Entity\\TitledArticle";
  20. private $listener;
  21. protected function setUp()
  22. {
  23. parent::setUp();
  24. $evm = new EventManager;
  25. $this->listener = new BlameableListener();
  26. $this->listener->setUserValue('testuser');
  27. $evm->addEventSubscriber($this->listener);
  28. $this->getMockSqliteEntityManager($evm);
  29. }
  30. public function testChange()
  31. {
  32. $test = new TitledArticle();
  33. $test->setTitle('Test');
  34. $test->setText('Test');
  35. $this->em->persist($test);
  36. $this->em->flush();
  37. $this->em->clear();
  38. $test = $this->em->getRepository(self::FIXTURE)->findOneByTitle('Test');
  39. $test->setTitle('New Title');
  40. $this->em->persist($test);
  41. $this->em->flush();
  42. $this->em->clear();
  43. //Changed
  44. $this->assertEquals('testuser', $test->getChtitle());
  45. $this->listener->setUserValue('otheruser');
  46. $test = $this->em->getRepository(self::FIXTURE)->findOneByTitle('New Title');
  47. $test->setText('New Text');
  48. $this->em->persist($test);
  49. $this->em->flush();
  50. $this->em->clear();
  51. //Not Changed
  52. $this->assertEquals('testuser', $test->getChtitle());
  53. }
  54. protected function getUsedEntityFixtures()
  55. {
  56. return array(
  57. self::FIXTURE,
  58. );
  59. }
  60. }