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);
 }
Example #2
0
 public function test_get_routes()
 {
     $router = new Router(StandardDefinition::factory());
     $router->add(RouteFactory::build("article", "/article/:int/:slug"));
     $router->add(RouteFactory::build("product", "/product/:int/:slug"));
     $routes = $router->getRoutes();
     $this->assertEquals("article", $routes["article"]->getName());
     $this->assertEquals("product", $routes["product"]->getName());
 }