|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Symfony\Cmf\Bundle\MenuBundle\Tests\Unit; |
| 4 | + |
| 5 | +use Symfony\Cmf\Bundle\MenuBundle\QuietFactory; |
| 6 | + |
| 7 | +class QuietFactoryTest extends \PHPUnit_Framework_TestCase |
| 8 | +{ |
| 9 | + private $innerFactory; |
| 10 | + private $logger; |
| 11 | + |
| 12 | + protected function setUp() |
| 13 | + { |
| 14 | + $this->innerFactory = $this->prophesize('Knp\Menu\FactoryInterface'); |
| 15 | + $this->logger = $this->prophesize('Psr\Log\LoggerInterface'); |
| 16 | + } |
| 17 | + |
| 18 | + public function provideItemsWithNotExistingLinks() |
| 19 | + { |
| 20 | + return array( |
| 21 | + array(array('route' => 'not_existent')), |
| 22 | + array(array('content' => 'not_existent')), |
| 23 | + array(array('linkType' => 'route', 'route' => 'not_existent')), |
| 24 | + ); |
| 25 | + } |
| 26 | + |
| 27 | + /** @dataProvider provideItemsWithNotExistingLinks */ |
| 28 | + public function testAllowEmptyItemsReturnsItemWithoutURL(array $options) |
| 29 | + { |
| 30 | + $this->innerFactory->createItem('Home', $options) |
| 31 | + ->willThrow('Symfony\Component\Routing\Exception\RouteNotFoundException'); |
| 32 | + |
| 33 | + $homeMenuItem = new \stdClass(); |
| 34 | + $this->innerFactory->createItem('Home', array())->willReturn($homeMenuItem); |
| 35 | + |
| 36 | + $factory = new QuietFactory($this->innerFactory->reveal(), $this->logger->reveal(), true); |
| 37 | + |
| 38 | + $this->assertEquals($homeMenuItem, $factory->createItem('Home', $options)); |
| 39 | + } |
| 40 | + |
| 41 | + public function testDisallowEmptyItemsReturnsNull() |
| 42 | + { |
| 43 | + $this->innerFactory->createItem('Home', array('route' => 'not_existent')) |
| 44 | + ->willThrow('Symfony\Component\Routing\Exception\RouteNotFoundException'); |
| 45 | + |
| 46 | + $factory = new QuietFactory($this->innerFactory->reveal(), $this->logger->reveal(), false); |
| 47 | + |
| 48 | + $this->assertEquals(null, $factory->createItem('Home', array('route' => 'not_existent'))); |
| 49 | + } |
| 50 | +} |
0 commit comments