0

When I use the Security component in Cake3 I always get the error message: "The request has been black-holed" in my controller tests. It works as expected because the request is really black-holed in that case but I need a possibility to test my code anyway.

I found the following post about the same issue but in Cake2. Unfortunately I was not able to transfer it to Cake3 and maybe it's not possible to use the same approach here.

This is how my test case looks:

        $data = [
        'first_name' => 'Test First Name',
        'last_name' => 'Test Last Name',
        'gender' => Gender::MALE,
        'role_id' => Role::ADMIN,
        'email' => 'test@test.com',
        'password' => '',
        'status' => Status::ACTIVE,
        'birthday' => '2015-01-01',
    ];
    $this->post(['prefix' => 'admin', 'controller' => 'users', 'action' => 'edit', 1], $data);

Same problem occurs also for Csrf component but the solution should be quite similar so I will figure this out afterwards.

Community
  • 1
  • 1
Stefan D.
  • 287
  • 4
  • 9
  • possible duplicate of [CakePHP - Controller testing failed because of Security component](http://stackoverflow.com/questions/30680800/cakephp-controller-testing-failed-because-of-security-component) – ndm Jul 12 '15 at 20:30
  • Also see http://stackoverflow.com/q/31119078/1392379 – ndm Jul 12 '15 at 20:31

1 Answers1

0

Your test must to extend IntegrationTestCase and before doing the post you could use:

    $this->enableCsrfToken();
    $this->enableSecurityToken();
yeliparra
  • 11
  • 1