Dealing with Security component in a CakePHP 2 test case

前端 未结 1 352
暖寄归人
暖寄归人 2021-01-26 17:11

I am trying to test a CakePHP action that deals with a signup form secured with the Security component. I have configured the component in a UsersController like th

相关标签:
1条回答
  • 2021-01-26 18:14

    The solution is to mock the Users controller and the User model and make expectations for the Security::_validatePost() method:

    $this->Users = $this->generate(
      'Users',
      array(
        'components' => array(
          'Security' => array('_validatePost'),
        ),
        'models' => array('User' => true),
      )
    );
    $this->Users->Security->expects($this->any())
      ->method('_validatePost')
      ->will($this->returnValue(true));
    
    0 讨论(0)
提交回复
热议问题