/**
  * @cover BreadcrumbService::__construct()
  * @cover BreadcrumbService::getBreadcrumbs()
  * @cover BreadcrumbService::getBreadcrumbView()
  */
 public function testConstructor()
 {
     $link = new BreadcrumbLink(uniqid(), 'bootstrap-bundle-test-route', 'Testlink');
     $breadcrumbService = new BreadcrumbService();
     $this->assertEquals(array(), $breadcrumbService->getBreadcrumbs());
     $this->assertNull($breadcrumbService->getBreadcrumb(uniqid()));
     $breadcrumbService->pushLink($link);
     $breadcrumbView = $breadcrumbService->getBreadcrumbView();
     $this->assertEquals('bootstrap-bundle-test-route', $breadcrumbView[0]->getLink());
     $breadcrumbService = new BreadcrumbService($this->urlGenerator);
     $this->assertEquals(array(), $breadcrumbService->getBreadcrumbs());
     $breadcrumbService->pushLink($link);
     $breadcrumbView = $breadcrumbService->getBreadcrumbView();
     $this->assertNotEquals('bootstrap-bundle-test-route', $breadcrumbView[0]->getLink());
     $this->assertEquals('/this/is/a/test', $breadcrumbView[0]->getLink());
 }
 /**
  * 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);
 }