本文介绍了如何使用cakePHP和SimpleTest测试需要认证的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写需要验证的WebTestCase视图。是否可以?如何通过验证?

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';


推荐答案

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

这篇关于如何使用cakePHP和SimpleTest测试需要认证的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 14:14