下面是cakephp unittest用户sontroller中的代码。我正在使用Cake \ Auth \ DefaultPasswordHasher;
我想看看我是否在发布后成功登录。会话没有设置。如果我预定义会话然后返回true(注释行).assertSession给出错误。如何设置会话?我可以在提交帖子后查看url onload吗?
public function testLogin()
{
$this->enableCsrfToken();
$this->enableSecurityToken();
//$this->session(
[
'Auth.User.id' => 2,
'Auth.User.username' => 'amol'
]
);
$this->post('/', [
'username' => 'amol',
'password' => 'abcdef'
]);
$expected = [
'id' => 2,
'username' => 'amol'
];
debug($this->post('/users/login/', [
'username' => 'amol',
'password' => 'testing123'
]));
$this->assertSession($expected, 'Auth.User');
$this->assertResponseCode(200);
//if($this->debug) debug($this->_requestSession->read());
}