/** * Test to ensure weight of paths is handled correctly */ public function testWeight() { $router = new PathRouter(); $router->addStrict("/Bar", array('ping' => 'pong')); $router->add("/asdf-\$1", array('title' => 'qwerty-$1')); $router->add("/\$1"); $router->add("/qwerty-\$1", array('title' => 'asdf-$1')); $router->addStrict("/Baz", array('marco' => 'polo')); $router->add("/a/\$1"); $router->add("/asdf/\$1"); $router->add("/\$2/\$1", array('unrestricted' => '$2')); $router->add(array('qwerty' => "/qwerty/\$1"), array('qwerty' => '$key')); $router->add("/\$2/\$1", array('restricted-to-y' => '$2'), array('$2' => 'y')); foreach (array('/Foo' => array('title' => 'Foo'), '/Bar' => array('ping' => 'pong'), '/Baz' => array('marco' => 'polo'), '/asdf-foo' => array('title' => 'qwerty-foo'), '/qwerty-bar' => array('title' => 'asdf-bar'), '/a/Foo' => array('title' => 'Foo'), '/asdf/Foo' => array('title' => 'Foo'), '/qwerty/Foo' => array('title' => 'Foo', 'qwerty' => 'qwerty'), '/baz/Foo' => array('title' => 'Foo', 'unrestricted' => 'baz'), '/y/Foo' => array('title' => 'Foo', 'restricted-to-y' => 'y')) as $path => $result) { $this->assertEquals($router->parse($path), $result); } }
/** * Test to ensure weight of paths is handled correctly */ public function testWeight() { $router = new PathRouter(); $router->addStrict("/Bar", ['ping' => 'pong']); $router->add("/asdf-\$1", ['title' => 'qwerty-$1']); $router->add("/\$1"); $router->add("/qwerty-\$1", ['title' => 'asdf-$1']); $router->addStrict("/Baz", ['marco' => 'polo']); $router->add("/a/\$1"); $router->add("/asdf/\$1"); $router->add("/\$2/\$1", ['unrestricted' => '$2']); $router->add(['qwerty' => "/qwerty/\$1"], ['qwerty' => '$key']); $router->add("/\$2/\$1", ['restricted-to-y' => '$2'], ['$2' => 'y']); foreach (['/Foo' => ['title' => 'Foo'], '/Bar' => ['ping' => 'pong'], '/Baz' => ['marco' => 'polo'], '/asdf-foo' => ['title' => 'qwerty-foo'], '/qwerty-bar' => ['title' => 'asdf-bar'], '/a/Foo' => ['title' => 'Foo'], '/asdf/Foo' => ['title' => 'Foo'], '/qwerty/Foo' => ['title' => 'Foo', 'qwerty' => 'qwerty'], '/baz/Foo' => ['title' => 'Foo', 'unrestricted' => 'baz'], '/y/Foo' => ['title' => 'Foo', 'restricted-to-y' => 'y']] as $path => $result) { $this->assertEquals($router->parse($path), $result); } }