TestCase.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Knp\Menu\Tests;
  3. use Knp\Menu\Iterator\CurrentItemFilterIterator;
  4. use Knp\Menu\MenuItem;
  5. use Knp\Menu\MenuFactory;
  6. abstract class TestCase extends \PHPUnit_Framework_TestCase
  7. {
  8. /**
  9. * @var \Knp\Menu\MenuItem
  10. */
  11. protected $menu;
  12. /**
  13. * @var \Knp\Menu\MenuItem
  14. */
  15. protected $pt1;
  16. /**
  17. * @var \Knp\Menu\MenuItem
  18. */
  19. protected $ch1;
  20. /**
  21. * @var \Knp\Menu\MenuItem
  22. */
  23. protected $ch2;
  24. /**
  25. * @var \Knp\Menu\MenuItem
  26. */
  27. protected $ch3;
  28. /**
  29. * @var \Knp\Menu\MenuItem
  30. */
  31. protected $pt2;
  32. /**
  33. * @var \Knp\Menu\MenuItem
  34. */
  35. protected $ch4;
  36. /**
  37. * @var \Knp\Menu\MenuItem
  38. */
  39. protected $gc1;
  40. protected function setUp()
  41. {
  42. $factory = new MenuFactory();
  43. $this->menu = $factory->createItem('Root li', array('attributes' => array('class' => 'root')));
  44. $this->pt1 = $this->menu->addChild('Parent 1');
  45. $this->ch1 = $this->pt1->addChild('Child 1');
  46. $this->ch2 = $this->pt1->addChild('Child 2');
  47. // add the 3rd child via addChild with an object
  48. $this->ch3 = new MenuItem('Child 3', $factory);
  49. $this->pt1->addChild($this->ch3);
  50. $this->pt2 = $this->menu->addChild('Parent 2');
  51. $this->ch4 = $this->pt2->addChild('Child 4');
  52. $this->gc1 = $this->ch4->addChild('Grandchild 1');
  53. }
  54. protected function tearDown()
  55. {
  56. $this->menu = null;
  57. $this->pt1 = null;
  58. $this->ch1 = null;
  59. $this->ch2 = null;
  60. $this->ch3 = null;
  61. $this->pt2 = null;
  62. $this->ch4 = null;
  63. $this->gc1 = null;
  64. }
  65. // prints a visual representation of our basic testing tree
  66. protected function printTestTree()
  67. {
  68. print(' Menu Structure '."\n");
  69. print(' rt '."\n");
  70. print(' / \ '."\n");
  71. print(' pt1 pt2 '."\n");
  72. print(' / | \ | '."\n");
  73. print(' ch1 ch2 ch3 ch4 '."\n");
  74. print(' | '."\n");
  75. print(' gc1 '."\n");
  76. }
  77. }