public function testFindUrl() { $r = new Router($this->container); $r->addRoute('a/b', 'controller1', 'action1'); $r->addRoute('a/:myvar1/b/:myvar2', 'controller2', 'action2', array('myvar1', 'myvar2')); $this->assertEquals('a/1/b/2', $r->findUrl('controller2', 'action2', array('myvar1' => 1, 'myvar2' => 2))); $this->assertEquals('', $r->findUrl('controller2', 'action2', array('myvar1' => 1))); $this->assertEquals('a/b', $r->findUrl('controller1', 'action1')); $this->assertEquals('', $r->findUrl('controller1', 'action2')); }
public function testDispatcherWithUrlRewriteWithPlugin() { $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/kanboard/index.php', 'REQUEST_URI' => '/kanboard/my/plugin/route/123?myvar=value1', 'QUERY_STRING' => 'myvar=value1', 'REQUEST_METHOD' => 'GET'), array('myvar' => 'value1')); $this->container['route'] = new Route($this->container); $this->container['route']->enable(); $dispatcher = new Router($this->container); $this->container['route']->addRoute('/my/plugin/route/:param', 'fakeController', 'myAction', 'Myplugin'); $this->assertInstanceOf('\\Kanboard\\Plugin\\Myplugin\\Controller\\FakeController', $dispatcher->dispatch()); $this->assertEquals('FakeController', $dispatcher->getController()); $this->assertEquals('myAction', $dispatcher->getAction()); $this->assertEquals('Myplugin', $dispatcher->getPlugin()); $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); $this->assertEquals('123', $this->container['request']->getStringParam('param')); }