public function testRouteMatch() { $Router = new Router(array('about' => 'pages/about', 'help' => 'pages/help')); // using $this->uri $this->assertTrue($Router->routeMatch('tools/util/router')); $this->assertFalse($Router->routeMatch('/tools/util/router')); $this->assertFalse($Router->routeMatch('tools/util/router/')); $this->assertFalse($Router->routeMatch('/tools/util/router/')); $this->assertFalse($Router->routeMatch('tools/util')); // specifc $uri $this->assertTrue($Router->routeMatch('tools/([0-9]+)', 'tools/123')); $this->assertFalse($Router->routeMatch('tools/[0-9]+', 'tools/util')); }
public function testFilterWithChildren() { $_SERVER['REQUEST_URI'] = '/test/area/55'; $_SERVER['REQUEST_METHOD'] = 'GET'; $t = false; $child = false; $id = 0; Router::filter('/test/{*}')->to(function () use(&$t) { $t = true; })->children(array('area/{id}' => array('type' => 'get', 'action' => function ($param) use(&$child, &$id) { $id = $param; $child = true; return false; }, 'where' => array('id' => 'integer_positive'))))->process(); $this->assertTrue($t); $this->assertTrue($child); $this->assertEquals(55, $id); $this->assertFalse(Router::routeMatch()); $_SERVER['REQUEST_URI'] = '/double/testing/create'; $_SERVER['REQUEST_METHOD'] = 'POST'; $child = false; $action = ''; Router::filter('/double/testing/{*}')->children(array('{action}' => array('type' => 'post', 'action' => function ($param) use(&$child, &$action) { $action = $param; $child = true; return false; }, 'where' => array('action' => 'alpha_numeric'))))->process(); $this->assertTrue($child); $this->assertEquals('create', $action); $this->assertFalse(Router::routeMatch()); }