认证集在cakephp 3.x单元测试用例

时间:2016-02-23 05:53:43

标签: cakephp phpunit cakephp-3.0

这里我正在编写cakephp 3.x中更改密码的测试用例,因为我已经在测试用例中设置了用于身份验证检查的会话,但是它无效。

我的代码是

public function setUserSession() {
    $auth = [
        'Auth' => [
            'user' => [
                'id' => 2,
                'email' => 'testemail1@test.ie',
                'firstname' => 'testfastname',
                'lastname' => 'testlastname',
                'gender' => 'male',
                'active' => 1,
                'created' => '2016-02-19 11:54:47',
                'modified' => '2016-02-19 11:54:47'
            ]
        ]
    ];
    return $auth;
}
 /**
 * Test register method
 *
 * @return void
 */
public function testpassword()
{


   $data = [ 
        'current_password' => '123456',
        'new_password'=>'12345678',
        'repeat_password'=>'12345678',
    ];
   $this->session($this->setUserSession());

   $this->post('/Customers/password', $data);

   $this->assertResponseSuccess();
    //echo "Ser"; exit;
   // $users = TableRegistry::get('customers');
    //$query = $users->find()->where(['email' => $data['email']]);
    //$this->assertEquals(1, $query->count());

}

像这样检查客户控制器但是没有工作。

   $id = $this->Auth->user('id');

    if (!$this->Customers->exists(['id' => $id])) {
        $this->Flash->error('You have been logged out');
        return $this->redirect(array('action' => 'login'));
    }

0 个答案:

没有答案