CakePHP Test Logon

I want to test the login function, if it works, and allows only valid and active users.

My custom fixture contains:

array( 'password' => '*emptyPasswordHash*', // empty password 'username' => 'Lorem', 'balance' => 0, 'currency' => 'USD', 'id' => 1, 'user_group_id' => 3, //Customer 'active' => 1, 'hash' => 'LoremHash' ), 

My test function looks like this:

 function testLogin() { //test valid login $result = $this->testAction('/users/login', array( 'data' => array( 'User' => array( 'username' => 'Lorem', 'pass' => '', 'remember' => true )), 'method' => 'post', 'return' => 'view' )); debug($result); 

}

The login form has 3 inputs: username , password and remember

I set $this->Auth->autoRedirect = false; in UsersController::beforeFilter and I do some cookie settings

when i debug($this->data); in UsersController::login() , it shows the same data when testing and when normalizing the log. But when checking the login, the crash fails, and I get the message $this->Auth->loginError instead of logging in.

How can I check the login action?

+6
php login simpletest
source share
2 answers

if you use the Aake cake component and do not crack it, you do not need ...

https://github.com/cakephp/cakephp/blob/master/cake/tests/cases/libs/controller/components/auth.test.php#L545

and if you really want it, see how pro does it :)

+1
source share

You also set your custom function as described in the CakePHP Guide :

Typically, AuthComponent will try to verify that the login credentials you entered are more accurate by comparing them with those that were stored in your user model. However, there are times when you may need additional work in determining the proper credentials. From setting this variable to one of several different values, you can do different things.

0
source share

All Articles