public function testCookies() { $req = Request::custom("", "GET", array(), array("cookiename" => "cookievalue", "foo" => "bar")); // cookies array $this->assertInternalType("array", $req->cookie->all()); // cookie $this->assertEquals("cookievalue", $req->cookie->get("cookiename")); // cookie2 $this->assertEquals("bar", $req->cookie->get("foo", "foobar")); // notexisting cookie $this->assertSame(null, $req->cookie->get("notexisting")); // defualt value $this->assertEquals("default", $req->cookie->get("notexistsing", "default")); }
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/"))); }