/**
  * Get the rendered breadcrumb.
  * @param string $breadcrumb_name The name of the used breadcrumb
  * @return string The breadcrumb html.
  */
 public function breadcrumbRender($breadcrumb_name = null)
 {
     $breadcrumb = $this->containerService->getBreadcrumbView($breadcrumb_name);
     return $this->environment->render($this->getTemplateName(), array('breadcrumb' => $breadcrumb ? $breadcrumb->getLinks() : array()));
 }
 /**
  * Test if the breadcrumb is functionnal.
  *
  * @cover BreadcrumbExtension::getTemplateName()
  * @cover BreadcrumbExtension::breadcrumbRender()
  * @cover BreadcrumbExtension::breadcrumbDisplay()
  */
 public function testFunctionnal()
 {
     $service = new BreadcrumbService();
     $extension = new BreadcrumbExtension($this->environment, $service);
     // Test default
     $template = $extension->getTemplateName();
     $this->assertEquals('bs_breadcrumb/breadcrumb.html.twig', $template);
     $this->assertTrue($this->filesystemLoader->exists($template));
     ob_start();
     $extension->breadcrumbDisplay();
     $display = ob_get_contents();
     ob_end_clean();
     $html = $extension->breadcrumbRender();
     $this->assertTrue(is_string($html));
     $this->assertGreaterThan(20, strlen($html));
     $this->assertEquals($display, $html);
     $dom = new \DOMDocument();
     $dom->loadXML($html);
     $this->assertTrue($dom->hasChildNodes());
     $container = $dom->firstChild;
     $this->assertEquals('div', $container->nodeName);
     $this->assertEquals('container-fluid', $container->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(1, $container->childNodes->length);
     $row = $container->firstChild;
     $this->assertEquals('div', $row->nodeName);
     $this->assertEquals('row', $row->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(1, $row->childNodes->length);
     $breadcrumb = $row->firstChild;
     $this->assertEquals('ol', $breadcrumb->nodeName);
     $this->assertEquals('breadcrumb', $breadcrumb->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(0, $breadcrumb->childNodes->length);
     // Test content
     $data_test = array(array('Page 1 ' . uniqid(), '/', 'glyphicon-home'), array('Page 2 ' . uniqid(), 'bootstrap-bundle-test-route', null), array('Page 3 ' . uniqid(), null, null));
     foreach ($data_test as $attrs) {
         $link = new BreadcrumbLink($attrs[0], $attrs[1], $attrs[2]);
         $service->pushLink($link);
     }
     $html = $extension->breadcrumbRender();
     $dom->loadXML($html);
     $breadcrumb = $dom->firstChild->firstChild->firstChild;
     $this->assertEquals('ol', $breadcrumb->nodeName);
     $this->assertEquals('breadcrumb', $breadcrumb->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(3, $breadcrumb->childNodes->length);
     foreach ($breadcrumb->childNodes as $k => $node) {
         $this->assertEquals($data_test[$k][0], $node->nodeValue);
     }
     $this->assertEquals('a', $breadcrumb->childNodes->item(0)->firstChild->nodeName);
     $this->assertEquals('a', $breadcrumb->childNodes->item(1)->firstChild->nodeName);
     $this->assertEquals('#text', $breadcrumb->childNodes->item(2)->firstChild->nodeName);
     $this->assertEquals($data_test[0][1], $breadcrumb->childNodes->item(0)->firstChild->attributes->getNamedItem('href')->nodeValue);
     $this->assertEquals($data_test[1][1], $breadcrumb->childNodes->item(1)->firstChild->attributes->getNamedItem('href')->nodeValue);
     $this->assertEquals('i', $breadcrumb->childNodes->item(0)->firstChild->firstChild->nodeName);
     $this->assertEquals('#text', $breadcrumb->childNodes->item(1)->firstChild->firstChild->nodeName);
     $this->assertEquals('glyphicon ' . $data_test[0][2], $breadcrumb->childNodes->item(0)->firstChild->firstChild->attributes->getNamedItem('class')->nodeValue);
     // Test with the url generator
     $service = new BreadcrumbService($this->urlGenerator);
     $extension = new BreadcrumbExtension($this->environment, $service);
     foreach ($data_test as $attrs) {
         $link = new BreadcrumbLink($attrs[0], $attrs[1], $attrs[2]);
         $service->pushLink($link);
     }
     $html = $extension->breadcrumbRender();
     $dom->loadXML($html);
     $breadcrumb = $dom->firstChild->firstChild->firstChild;
     $this->assertEquals($data_test[0][1], $breadcrumb->childNodes->item(0)->firstChild->attributes->getNamedItem('href')->nodeValue);
     $this->assertEquals($this->urlGenerator->generate($data_test[1][1]), $breadcrumb->childNodes->item(1)->firstChild->attributes->getNamedItem('href')->nodeValue);
 }
 /**
  * Test if breadcrumbPush() function is well deprecated.
  * @expectedException PHPUnit_Framework_Error_Deprecated
  */
 public function testGetContainerDeprecation()
 {
     $breadcrumbService = new BreadcrumbService();
     $breadcrumbService->getContainer();
 }