Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Renderer url handler fails with empty params #973

Closed
tefra opened this Issue Jun 9, 2013 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

tefra commented Jun 9, 2013

There is a difference when using the renderer url handler and directly the router::match method with empty url params.

\tests\cases\template\view\RendererTest.php

    public function testUrlHelperWithEmptyParams() {
        Router::reset();
        Router::connect('/', 'List::home',  array('persist' => array('controller',  'action')));
        Router::connect('/{:controller}/{:action}', 'Hello::world', array('persist' => array('controller',  'action')));
        $request = Router::process(new Request(array('url' => '/', 'base' => '')));
        $renderer = new Simple(compact('request'));

        // Fail
        $this->assertEqual('/', $renderer->url(array()));
        // Ok
        $this->assertEqual('/', Router::match(array(), $request));
    }

Shouldn't the results match ?

davidpersson added a commit that referenced this issue Aug 3, 2014

Showing difference between renderer url and router match methods.
- Adding tests to prove behavior using empty array as first parameter
  differs.

- Adding documentation for renderer handlers.

Refs #973.
Owner

davidpersson commented Aug 3, 2014

Actually the assertions in the example code provided return the inverse for me. Renderer's url handler will convert any falsey value to an empty string and passing that to Router::match() which in turn returns '/'. Using match directly with an empty will show different behavior as match works entirely different using string URLs in contrast to routable array URLs. Consider match to be more restrictive and explicit and the renderer's url handler to be more convenient and conceptually implicit. I've documented the behavior nonetheless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment