/**
  * @covers Navinator\Collection::getNodeMatchingUrl
  */
 public function testNodeMatchingUrl()
 {
     $nodeData = array('alpha', 'alpha-2/a', 'alpha-2', 'alpha-2/b', 'alpha-3/a/b', 'alpha-3/a', 'alpha-3/a/b/c');
     $testMatches = array('/alpha/' => 'alpha', '/alpha-2/' => 'alpha-2', '/alpha-2/a/' => 'alpha-2/a', '/alpha-2/b/' => 'alpha-2/b', '/alpha-3/a/' => 'alpha-3/a', '/alpha-3/a/b/' => 'alpha-3/a/b', '/alpha-3/a/b/ddddd/' => 'alpha-3/a/b', '/alpha-3/a/b/' => 'alpha-3/a/b', '/alpha-3/a/b/c/' => 'alpha-3/a/b/c', '/alpha-3/a/b/c/ddddddd/' => 'alpha-3/a/b/c');
     $nodes = array();
     $c = new Collection();
     foreach ($nodeData as $path) {
         $n = new Node($path);
         $nodes[$path] = $n;
         $c->addNode($n);
     }
     foreach ($testMatches as $url => $nodePath) {
         $this->assertSame($nodes[$nodePath], $c->getNodeMatchingUrl($url));
     }
     foreach ($testMatches as $url => $nodePath) {
         $_SERVER['REQUEST_URI'] = $url;
         $this->assertSame($nodes[$nodePath], $c->getNodeMatchingUrl());
     }
 }
Example #2
0
 /**
  *
  * @dataProvider testFilterCallbackProvider
  * @group latest
  */
 public function testFilterCallback($testData)
 {
     $testNodeArr = $testData['nodes'];
     $nodes = array();
     $c = new Collection();
     foreach ($testNodeArr as $arr) {
         $contructorArr = $arr['constructor_array'];
         $path = $contructorArr['path'];
         $n = new Node($contructorArr);
         $nodes[$path] = $n;
         $c->addNode($n);
     }
     $testObj = $this;
     foreach ($testNodeArr as $testNode) {
         $path = $testNode['constructor_array']['path'];
         $expectedNode = $nodes[$path];
         $expectedArr = $testNode['expected'];
         $expectedCurrentNodePath = $expectedArr['current_node_path'];
         $expectedCurrentNode = null;
         if ($expectedCurrentNodePath) {
             $expectedCurrentNode = $nodes[$expectedCurrentNodePath];
         }
         $expectedCurrentNodeAncestorPaths = $expectedArr['current_node_ancestor_paths'];
         $expectedOutput = $expectedArr['output'];
         $expectedSortedSiblings = array();
         foreach ($expectedArr['sorted_sibling_paths'] as $path) {
             $expectedSortedSiblings[] = $nodes[$path];
         }
         // make sure passed params are correct
         $filter = function ($node, $output, $collection, $sortedSiblings, $currentNode, $currentNodeAncestorPaths) use($expectedNode, $testObj, $c, $expectedSortedSiblings, $expectedCurrentNode, $expectedCurrentNodeAncestorPaths, $expectedOutput) {
             $testObj->assertEquals($expectedNode, $node, '!= Expected $node');
             $testObj->assertEquals($expectedOutput, $output, '!= Expected $output');
             $testObj->assertEquals($c, $collection, '!= Expected $collection');
             $testObj->assertEquals($expectedCurrentNode, $currentNode, '!= Expected $currentNode');
             $testObj->assertEquals($expectedCurrentNodeAncestorPaths, $currentNodeAncestorPaths, '!= Expected $currentNodeAncestorPaths');
             $testObj->assertEquals($expectedSortedSiblings, $sortedSiblings);
         };
         $currentNodePath = $testNode['current_node_path'];
         $currentNode = null;
         if ($currentNodePath) {
             $currentNode = $nodes[$currentNodePath];
         }
         $currentNodeAncestorPaths = $testNode['current_node_ancestor_paths'];
         $expectedNode->prepareForTemplate($c, $expectedSortedSiblings, $currentNode, $currentNodeAncestorPaths, $filter);
     }
 }