Skip to content

Instantly share code, notes, and snippets.

@MrTrick
Created August 8, 2012 13:26
Show Gist options
  • Save MrTrick/3295006 to your computer and use it in GitHub Desktop.
Save MrTrick/3295006 to your computer and use it in GitHub Desktop.
Expected behaviour for splat routes
<?
/**
* My_Router: Routing splats, more edge cases
*/
public function testRoutingMoreSplats() {
$router = new My_Router();
$router->on('route',array($this, 'onRoute'));
$router->route('foo/*bar', 'foo');
$this->assertTrue( $router('foo/bar/baz') );
$this->assertEquals(array('bar/baz'), $this->lastArgs, 'Doesn\'t pick up an extra / from somewhere');
$this->assertTrue( $router('foo/bar/baz/') );
$this->assertEquals(array('bar/baz'), $this->lastArgs, 'Loses the trailing slash if present');
$this->assertTrue( $router('foo/') );
$this->assertEquals(array(''), $this->lastArgs, 'Matches empty url');
$this->assertTrue( $router('foo') );
$this->assertEquals(array(''), $this->lastArgs, 'Matches empty even without /');
$this->assertFalse( $router('food'), 'Won\'t match if the preceding component is extended' );
$this->assertFalse( $router('fo'), 'Won\'t match if the preceding component is shortened' );
$router = new My_Router();
$router->on('route',array($this, 'onRoute'));
$router->route('foo*bar', 'foo');
$this->assertTrue( $router('foo/bar/baz') );
$this->assertEquals(array('/bar/baz'), $this->lastArgs, 'Picks up slash if starting rest');
$this->assertTrue( $router('foo/') );
$this->assertEquals(array(''), $this->lastArgs, 'Won\'t pick up trailing slash at end (will be trimmed)');
$this->assertTrue( $router('food') );
$this->assertEquals(array('d'), $this->lastArgs, 'Will match if the preceding component is extended');
$this->assertFalse( $router('fo'), 'Won\'t match if the preceding component is shortened' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment