|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony CMF package. |
| 5 | + * |
| 6 | + * (c) 2011-2013 Symfony CMF |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | + |
| 13 | +namespace Symfony\Cmf\Bundle\MenuBundle\Tests\Unit\Provider; |
| 14 | + |
| 15 | +use Symfony\Cmf\Bundle\MenuBundle\Provider\PhpcrMenuProvider; |
| 16 | + |
| 17 | +class PhpcrMenuProviderTest extends \PHPUnit_Framework_Testcase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @dataProvider getMenuTests |
| 21 | + */ |
| 22 | + public function testGet($menuRoot, $name, $expectedPath) |
| 23 | + { |
| 24 | + $objectManager = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); |
| 25 | + $objectManager->expects($this->once()) |
| 26 | + ->method('find') |
| 27 | + ->with($this->equalTo(null), $this->equalTo($expectedPath)) |
| 28 | + ->will($this->returnValue($this->getMock('Knp\Menu\NodeInterface'))); |
| 29 | + |
| 30 | + $managerRegistry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry'); |
| 31 | + $managerRegistry->expects($this->once()) |
| 32 | + ->method('getManager') |
| 33 | + ->will($this->returnValue($objectManager)); |
| 34 | + |
| 35 | + $factory = $this->getMock('Knp\Menu\FactoryInterface'); |
| 36 | + $factory->expects($this->once()) |
| 37 | + ->method('createFromNode') |
| 38 | + ->will($this->returnValue($this->getMock('Knp\Menu\ItemInterface'))); |
| 39 | + |
| 40 | + $provider = new PhpcrMenuProvider( |
| 41 | + $factory, |
| 42 | + $managerRegistry, |
| 43 | + $menuRoot |
| 44 | + ); |
| 45 | + |
| 46 | + $provider->setRequest($this->getMock('Symfony\Component\HttpFoundation\Request')); |
| 47 | + |
| 48 | + $provider->get($name); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @dataProvider getMenuTests |
| 53 | + */ |
| 54 | + public function testHas($menuRoot, $name, $expectedPath) |
| 55 | + { |
| 56 | + $objectManager = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); |
| 57 | + $objectManager->expects($this->once()) |
| 58 | + ->method('find') |
| 59 | + ->with($this->equalTo(null), $this->equalTo($expectedPath)) |
| 60 | + ->will($this->returnValue($this->getMock('Knp\Menu\NodeInterface'))); |
| 61 | + |
| 62 | + $managerRegistry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry'); |
| 63 | + $managerRegistry->expects($this->once()) |
| 64 | + ->method('getManager') |
| 65 | + ->will($this->returnValue($objectManager)); |
| 66 | + |
| 67 | + $provider = new PhpcrMenuProvider( |
| 68 | + $this->getMock('Knp\Menu\FactoryInterface'), |
| 69 | + $managerRegistry, |
| 70 | + $menuRoot |
| 71 | + ); |
| 72 | + |
| 73 | + $provider->has($name); |
| 74 | + } |
| 75 | + |
| 76 | + public function getMenuTests() |
| 77 | + { |
| 78 | + return array( |
| 79 | + array('/test/menu', 'foo', '/test/menu/foo'), |
| 80 | + array('/test/menu', '/another/menu/path', '/another/menu/path'), |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | +} |
0 commit comments