Пример #1
0
 protected function buildSitemap()
 {
     $sitemap = new Sitemap("h-1", "home", new RouteBasedLocation("root"));
     $node_1 = $sitemap->getRoot()->addChild(new Node("h-1-1", "node_1", new RouteBasedLocation("node_1")));
     $node_2 = $sitemap->getRoot()->addChild(new DynamicLabelNodeMock(new Node("h-1-2", "node_2", new RouteBasedLocation("node_2", array("param_1" => "param_1_value")))));
     $node_2_1 = $node_2->addChild(new Node("h-1-2-1", "node_2_1", new RouteBasedLocation("node_2_1", array("param_1" => "param_1_value"))));
     return $sitemap;
 }
 public function testIterate()
 {
     $sitemap = new Sitemap("h-1", "home", new RouteBasedLocation("test"));
     $n1 = $sitemap->getRoot()->addChild(new Node("h-1-1", "n1", new RouteBasedLocation("test")));
     $n2 = $n1->addChild(new Node("h-1-1-1", "n2", new RouteBasedLocation("test")));
     $n3 = $n1->addChild(new Node("h-1-1-2", "n3", null));
     $it = new RecursiveIteratorIterator(new NavigableSitemapNodeIterator($sitemap->getIterator()), RecursiveIteratorIterator::SELF_FIRST);
     $it->rewind();
     $this->assertEquals($sitemap->getRoot(), $it->current(), "Se esperaba que el primer elemento del iterador sea la raiz.");
     $it->next();
     $this->assertEquals($n1, $it->current(), "Se esperaba que el segundo elemento del iterador sea el primer hijo de la raiz.");
     $it->next();
     $this->assertEquals($n2, $it->current(), "Se esperaba que el tercer elemento del iterador sea el primer hijo del primer hijo de la raiz.");
     $it->next();
     $this->assertFalse($it->valid(), "Se esperaba que el luego del tercer elemento el iterador quede inválido.");
 }