MenuItemReorderTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Knp\Menu\Tests;
  3. use Knp\Menu\MenuItem;
  4. use Knp\Menu\MenuFactory;
  5. class MenuItemReorderTest extends \PHPUnit_Framework_TestCase
  6. {
  7. public function testReordering()
  8. {
  9. $factory = new MenuFactory();
  10. $menu = new MenuItem('root', $factory);
  11. $menu->addChild('c1');
  12. $menu->addChild('c2');
  13. $menu->addChild('c3');
  14. $menu->addChild('c4');
  15. $menu->reorderChildren(array('c4', 'c3', 'c2', 'c1'));
  16. $arr = array_keys($menu->getChildren());
  17. $this->assertEquals(array('c4', 'c3', 'c2', 'c1'), $arr);
  18. }
  19. /**
  20. * @expectedException \InvalidArgumentException
  21. */
  22. public function testReorderingWithTooManyItemNames()
  23. {
  24. $factory = new MenuFactory();
  25. $menu = new MenuItem('root', $factory);
  26. $menu->addChild('c1');
  27. $menu->reorderChildren(array('c1', 'c3'));
  28. }
  29. /**
  30. * @expectedException \InvalidArgumentException
  31. */
  32. public function testReorderingWithWrongItemNames()
  33. {
  34. $factory = new MenuFactory();
  35. $menu = new MenuItem('root', $factory);
  36. $menu->addChild('c1');
  37. $menu->addChild('c2');
  38. $menu->reorderChildren(array('c1', 'c3'));
  39. }
  40. }