MenuFactoryTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Knp\Menu\Tests;
  3. use Knp\Menu\MenuFactory;
  4. class MenuFactoryTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function testExtensions()
  7. {
  8. $factory = new MenuFactory();
  9. $extension1 = $this->getMock('Knp\Menu\Factory\ExtensionInterface');
  10. $extension1->expects($this->once())
  11. ->method('buildOptions')
  12. ->with(array('foo' => 'bar'))
  13. ->will($this->returnValue(array('uri' => 'foobar')));
  14. $extension1->expects($this->once())
  15. ->method('buildItem')
  16. ->with($this->isInstanceOf('Knp\Menu\ItemInterface'), $this->contains('foobar'));
  17. $factory->addExtension($extension1);
  18. $extension2 = $this->getMock('Knp\Menu\Factory\ExtensionInterface');
  19. $extension2->expects($this->once())
  20. ->method('buildOptions')
  21. ->with(array('foo' => 'baz'))
  22. ->will($this->returnValue(array('foo' => 'bar')));
  23. $extension1->expects($this->once())
  24. ->method('buildItem')
  25. ->with($this->isInstanceOf('Knp\Menu\ItemInterface'), $this->contains('foobar'));
  26. $factory->addExtension($extension2, 10);
  27. $item = $factory->createItem('test', array('foo' => 'baz'));
  28. $this->assertEquals('foobar', $item->getUri());
  29. }
  30. public function testCreateItem()
  31. {
  32. $factory = new MenuFactory();
  33. $item = $factory->createItem('test', array(
  34. 'uri' => 'http://example.com',
  35. 'linkAttributes' => array('class' => 'foo'),
  36. 'display' => false,
  37. 'displayChildren' => false,
  38. ));
  39. $this->assertInstanceOf('Knp\Menu\ItemInterface', $item);
  40. $this->assertEquals('test', $item->getName());
  41. $this->assertFalse($item->isDisplayed());
  42. $this->assertFalse($item->getDisplayChildren());
  43. $this->assertEquals('foo', $item->getLinkAttribute('class'));
  44. }
  45. }