how can I test view where authentication is required, with cakePHP and SimpleTest
-
26-10-2019 - |
Question
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';
Solution
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:");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow