public function test_defiition_custom_rule()
 {
     $languages = array("pt", "pt-br", "en");
     $definition = StandardDefinition::factory();
     $definition->addRule(':lang', function ($input) use($languages) {
         return in_array($input, $languages);
     });
     $this->assertTrue($definition->rules[':lang']("pt-br"));
     $this->assertFalse($definition->rules[':lang']("fr"));
     $router = new Router($definition);
     $router->add(RouteFactory::build("article", "/article/:lang/:slug"));
     $route = $router->match("/article/pt-br/this-is-a-slug");
     $this->assertInstanceof("Melody\\Router\\Route", $route);
     $route = $router->match("/article/en/this-is-another-slug");
     $this->assertInstanceof("Melody\\Router\\Route", $route);
     $route = $router->match("/article/fr/this-is-another-slug");
     $this->assertFalse($route instanceof Melody\Router\Route);
 }
예제 #2
0
 public function test_get_not_found_route()
 {
     $router = new Router(StandardDefinition::factory());
     $this->assertFalse($router->get("not-found-route"));
 }