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

大憨熊 提交于 2019-12-23 05:22:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!