Search code examples
unit-testingcakephpcakephp-1.3simpletest

how can I test view where authentication is required, with cakePHP and SimpleTest


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:");
        }