ChainProviderTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Knp\Menu\Tests\Provider;
  3. use Knp\Menu\Provider\ChainProvider;
  4. class ChainProviderTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function testHas()
  7. {
  8. $innerProvider = $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
  9. $innerProvider->expects($this->at(0))
  10. ->method('has')
  11. ->with('first')
  12. ->will($this->returnValue(true))
  13. ;
  14. $innerProvider->expects($this->at(1))
  15. ->method('has')
  16. ->with('second')
  17. ->will($this->returnValue(false))
  18. ;
  19. $innerProvider->expects($this->at(2))
  20. ->method('has')
  21. ->with('third', array('foo' => 'bar'))
  22. ->will($this->returnValue(false))
  23. ;
  24. $provider = new ChainProvider(array($innerProvider));
  25. $this->assertTrue($provider->has('first'));
  26. $this->assertFalse($provider->has('second'));
  27. $this->assertFalse($provider->has('third', array('foo' => 'bar')));
  28. }
  29. public function testGetExistentMenu()
  30. {
  31. $menu = $this->getMock('Knp\Menu\ItemInterface');
  32. $innerProvider = $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
  33. $innerProvider->expects($this->any())
  34. ->method('has')
  35. ->with('default')
  36. ->will($this->returnValue(true))
  37. ;
  38. $innerProvider->expects($this->once())
  39. ->method('get')
  40. ->with('default')
  41. ->will($this->returnValue($menu))
  42. ;
  43. $provider = new ChainProvider(array($innerProvider));
  44. $this->assertSame($menu, $provider->get('default'));
  45. }
  46. public function testGetWithOptions()
  47. {
  48. $menu = $this->getMock('Knp\Menu\ItemInterface');
  49. $innerProvider = $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
  50. $innerProvider->expects($this->any())
  51. ->method('has')
  52. ->with('default', array('foo' => 'bar'))
  53. ->will($this->returnValue(true))
  54. ;
  55. $innerProvider->expects($this->once())
  56. ->method('get')
  57. ->with('default', array('foo' => 'bar'))
  58. ->will($this->returnValue($menu))
  59. ;
  60. $provider = new ChainProvider(array($innerProvider));
  61. $this->assertSame($menu, $provider->get('default', array('foo' => 'bar')));
  62. }
  63. /**
  64. * @expectedException InvalidArgumentException
  65. */
  66. public function testGetNonExistentMenu()
  67. {
  68. $provider = new ChainProvider(array());
  69. $provider->get('non-existent');
  70. }
  71. }