TestCase.php 2.1 KB

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