问题
I'd like to write WebTestCase of views that requires authentification. Is it possible? How can I pass authentification?
I tried with writing basic authentification in the session but it doesn't work.
$_SESSION['Auth']['User']['id'] = 1;
$_SESSION['Auth']['User']['username'] = 'nico';
回答1:
function login() {
$this->get($this->host_name."/users/login/");
$this->assertText("Login");
$this->setField("data[User][username]",'xxxx');
$this->setField("data[User][password]",'xxxx');
$this->assertClickable("login");
$this->clickSubmit("login");
$this->assertNoText("Error:");
}
来源:https://stackoverflow.com/questions/5337934/how-can-i-test-view-where-authentication-is-required-with-cakephp-and-simpletes