How to create CSRF token for Cakephp 3 PHPunit testing? -
i trying unit tests working again after enabling csrf tokens , ssl in cakephp 3 app.
how create or generate token test following? or disable 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']); }
the official documentation has approach since version 3.1.2.
you have call $this->enablecsrftoken();
and/or $this->enablesecuritytoken();
before post able perform request token.
as official example shows:
public function testadd() { $this->enablecsrftoken(); $this->enablesecuritytoken(); $this->post('/posts/add', ['title' => 'exciting news!']); }
Comments
Post a Comment