TwigRendererTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Knp\Menu\Tests\Renderer;
  3. use Knp\Menu\Renderer\TwigRenderer;
  4. use Knp\Menu\MenuItem;
  5. use Knp\Menu\MenuFactory;
  6. use Knp\Menu\Matcher\MatcherInterface;
  7. class TwigRendererTest extends AbstractRendererTest
  8. {
  9. public function createRenderer(MatcherInterface $matcher)
  10. {
  11. if (!class_exists('Twig_Environment')) {
  12. $this->markTestSkipped('Twig is not available');
  13. }
  14. $loader = new \Twig_Loader_Filesystem(__DIR__.'/../../../../../src/Knp/Menu/Resources/views');
  15. $environment = new \Twig_Environment($loader);
  16. $renderer = new TwigRenderer($environment, 'knp_menu.html.twig', $matcher, array('compressed' => true));
  17. return $renderer;
  18. }
  19. public function testRenderOrderedList()
  20. {
  21. $menu = new MenuItem('test', new MenuFactory());
  22. $menu->addChild('About')->addChild('foobar');
  23. $rendered = '<ol><li class="first last"><span>About</span><ol class="menu_level_1"><li class="first last"><span>foobar</span></li></ol></li></ol>';
  24. $this->assertEquals($rendered, $this->renderer->render($menu, array('template' => 'knp_menu_ordered.html.twig')));
  25. }
  26. }