public function testBasicRouteRegex() { $collection = new RouteCollection(); $collection->add('category', new Route('/category/{name}')); $collection->add('page', Route::create('/page/{page}.{ext}')->setRequirement('ext', 'htm|html')->setRequirement('page', '[a-z]+')); $collection->add('profile', Route::create('/profile/{username}')->setDefault('username', 'me')); $collection->add('read', RouteFactory::createHttpGet('/read/{slug}')->setRequirement('slug', '[a-z\\-]+')); $this->assertTrue((bool) preg_match($collection->get('category')->getRegex()->getRegexPattern(), '/category/music')); $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index.html')); $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index.htm')); $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index05.html') === false); $this->assertTrue((bool) preg_match($collection->get('page')->getRegex()->getRegexPattern(), '/page/index.php') === false); $this->assertTrue((bool) preg_match($collection->get('profile')->getRegex()->getRegexPattern(), '/profile') === true); $this->assertTrue((bool) preg_match($collection->get('profile')->getRegex()->getRegexPattern(), '/profile/danu') === true); $this->assertTrue((bool) preg_match($collection->get('read')->getRegex()->getRegexPattern(), '/read/welcome-to-the-jungle') === true); $this->assertTrue((bool) preg_match($collection->get('read')->getRegex()->getRegexPattern(), '/read/WELCOME-TO-THE') === false); }
public function testRouteHandler() { $handler = function () { return "welcome"; }; $collection = new RouteCollection(); $route = Route::create('/view/{id}'); $route->getDefaultBag()->set('id', 5); $route->getRequirementBag()->set('id', '\\d+'); $route->getMethod()->replace(array('GET')); $route->handleWith($handler); $collection->add('view', $route); $this->assertArrayHasKey('view', $collection->all()); $this->assertTrue($collection->get('view')->getRequirementBag()->has('id')); $this->assertTrue($collection->get('view')->getDefaultBag()->has('id')); $this->assertTrue($collection->get('view')->getMethod()->has('GET')); $this->assertTrue($collection->get('view')->getHandler() === $handler); $this->assertTrue(call_user_func($collection->get('view')->getHandler()) === 'welcome'); }