lundi 29 juin 2015

How to create CSRF token for Cakephp 3 PHPunit testing?

I am trying to get my unit tests working again after enabling CSRF tokens and SSL in my CakePHP 3 app.

How do I create or generate a token for a test like the following? Or do I just disable it for testing purposes?

public function testLogin() {
    $this->get('/login');
    $this->assertResponseOk();

    $data = [
        'email' => 'info@example.com',
        'password' => 'secret'
    ];
    $this->post('/login', $data);

    $this->assertResponseSuccess();
    $this->assertRedirect(['controller' => 'Users', 'action' => 'dashboard']);
}

Aucun commentaire:

Enregistrer un commentaire