cakephp 4需要身份验证的测试操作

时间:2020-03-08 18:44:23

标签: authentication testing cakephp cakephp-4.x

需要身份验证的测试操作无法按照cakephp manual中所述进行操作。

我找到了这个解决方案,是正确的吗?

use App\Model\Entity\User;
...
public function testLogout()
{
    $user=new User();
    $user->id=1;

    $this->session(['Auth' => $user]);

    $this->get ( '/Users/logout' );
    $this->assertRedirect(['controller' => 'Users', 'action' => 'login']);
}

1 个答案:

答案 0 :(得分:0)

解决方案是(感谢ndm):

import numpy as np

picture_0 = np.random.randint(0, 256, (100, 100, 3))
picture_1 = np.copy(picture_0)
picture_2 = picture_1[10:-10, 10:-10]
picture_1_mod = np.copy(picture_0)+1 # mod means modified.
picture_2_mod = picture_1_mod[10:-10, 10:-10]

print(picture_2.base == picture_0) # Array of Trues
print(picture_2_mod.base == picture_0) # Array of Falses