Example #1
0
 public function testHost()
 {
     $route = new Route("/");
     $this->assertEquals("", $route->getHost());
     $route->setHost("example.com");
     $this->assertEquals("example.com", $route->getHost());
     $route->setHost(null);
     $this->assertEquals("", $route->getHost());
     // TODO: this should throw an exception
     // $route->setHost("http://example.com/users/list?page=1");
     // $this->assertEquals("example.com", $route->getHost());
     $route->setHost("sub.example.com");
     $this->assertEquals("sub.example.com", $route->getHost());
 }
Example #2
0
 public function testHostVariablesWithRequisites()
 {
     $route = new Route("/");
     $route->setHost("{lang}.example.com");
     $route->setRequisites(array("lang" => "en|bg"));
     // ok
     $this->assertTrue($route->match(Request::custom("http://en.example.com/")));
     $this->assertTrue($route->match(Request::custom("http://bg.example.com/")));
     // fail
     $this->assertFalse($route->match(Request::custom("http://example.com/")));
     $this->assertFalse($route->match(Request::custom("http://.example.com/")));
     $this->assertFalse($route->match(Request::custom("http://ru.example.com/")));
     $this->assertFalse($route->match(Request::custom("http://ru.example.com/")));
     $this->assertFalse($route->match(Request::custom("http://www.en.example.com/")));
     $this->assertFalse($route->match(Request::custom("http://english.example.com/")));
     // with default value
     $route->setDefaults(array("lang" => "en"));
     // ok
     $this->assertTrue($route->match(Request::custom("http://example.com/")));
     // fails
     $this->assertFalse($route->match(Request::custom("http://ru.example.com/")));
 }