【问题标题】:how can I test view where authentication is required, with cakePHP and SimpleTest如何使用 cakePHP 和 SimpleTest 测试需要身份验证的视图
【发布时间】:2011-03-17 10:42:49
【问题描述】:

我想编写需要身份验证的视图的 WebTestCase。可能吗?我怎样才能通过认证?

我尝试在会话中编写基本身份验证,但它不起作用。

    $_SESSION['Auth']['User']['id'] = 1;
    $_SESSION['Auth']['User']['username'] = 'nico';

【问题讨论】:

    标签: unit-testing cakephp cakephp-1.3 simpletest


    【解决方案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:");
        }
    

    【讨论】:

    • 非常感谢。当人们看到解决方案时,它看起来如此明显。 Web测试是从用户的角度进行测试。我是新来的测试,我没有很好的反应。
    猜你喜欢
    • 2015-07-30
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多