我有一个适用于 authentication 2 的登录方法。
我需要编写登录方法的集成测试,但失败并显示 FAILURE_IDENTITY_NOT_FOUND
测试如下:
public function testLoginOk()
{
$this->enableCsrfToken();
$this->enableSecurityToken();
$this->enableRetainFlashMessages();
$this->post('/users/login', [
'user_login' => 'user1',
'password' => 'P!tU!i!ZIMI&',
]);
$this->assertFlashMessage(__('You are connected'));
}
在fixture中,user1密码if hashed [
'id' => 1,
'user_login' => 'user1',
'user_pass' => 'e430ff579ef1db71e654852e548e0f327b0e3d18', # P!tU!i!ZIMI&
'user_status' => 1,
...
在 Application.php 中
$fields = [
'username' => 'user_login',
'password' => 'password'
];
// Load the authenticators, you want session first
$service->loadAuthenticator('Authentication.Session');
$service->loadAuthenticator('Authentication.Cookie');
$service->loadAuthenticator('Authentication.Form', [
'fields' => $fields,
'loginUrl' => '/users/login'
]);
我不明白为什么测试不起作用,有什么想法吗? 谢谢