InMemoryUpdatesWithInheritanceTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Gedmo\Tree;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Tree\Fixture\Genealogy\Man;
  6. use Tree\Fixture\Genealogy\Woman;
  7. /**
  8. * Additional tests for tree inheritance and in-memory updates
  9. *
  10. * @author Illya Klymov <xanf@xanf.me>
  11. * @link http://www.gediminasm.org
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. */
  14. class InMemoryUpdatesWithInheritanceTest extends BaseTestCaseORM
  15. {
  16. const PERSON = "Tree\\Fixture\\Genealogy\\Person";
  17. const MAN = "Tree\\Fixture\\Genealogy\\Man";
  18. const WOMAN = "Tree\\Fixture\\Genealogy\\Woman";
  19. protected function setUp()
  20. {
  21. parent::setUp();
  22. $evm = new EventManager;
  23. $evm->addEventSubscriber(new TreeListener);
  24. $this->getMockSqliteEntityManager($evm);
  25. }
  26. public function testInMemoryTreeInsertsWithInheritance()
  27. {
  28. $nodes = array();
  29. $man1 = new Man('Root - Man1');
  30. $this->em->persist($man1);
  31. $woman1 = new Woman('Level 1 - Woman1');
  32. $this->em->persist($woman1);
  33. $woman1->setParent($man1);
  34. $man2 = new Man('Level 2 - Man2');
  35. $this->em->persist($man2);
  36. $man2->setParent($woman1);
  37. $woman2 = new Woman('Level 3 - Woman2');
  38. $this->em->persist($woman2);
  39. $woman2->setParent($man2);
  40. $this->em->flush();
  41. $left = $man1->getLeft();
  42. $right = $man1->getRight();
  43. $level = $man1->getLevel();
  44. $this->assertEquals(1, $left);
  45. $this->assertEquals(8, $right);
  46. $this->assertEquals(0, $level);
  47. $left = $woman1->getLeft();
  48. $right = $woman1->getRight();
  49. $level = $woman1->getLevel();
  50. $this->assertEquals(2, $left);
  51. $this->assertEquals(7, $right);
  52. $this->assertEquals(1, $level);
  53. $left = $man2->getLeft();
  54. $right = $man2->getRight();
  55. $level = $man2->getLevel();
  56. $this->assertEquals(3, $left);
  57. $this->assertEquals(6, $right);
  58. $this->assertEquals(2, $level);
  59. $left = $woman2->getLeft();
  60. $right = $woman2->getRight();
  61. $level = $woman2->getLevel();
  62. $this->assertEquals(4, $left);
  63. $this->assertEquals(5, $right);
  64. $this->assertEquals(3, $level);
  65. }
  66. protected function getUsedEntityFixtures()
  67. {
  68. return array(
  69. self::PERSON,
  70. self::MAN,
  71. self::WOMAN
  72. );
  73. }
  74. }