CakePHP 2.3 - Unit Testing Benutzer Login
Ich dachte, ich muss hier etwas Hilfe zu meinem Problem fragen. Ich habe den ganzen Abend damit verbracht. Ich habe eine Anmeldemethode inUsersController
so was:
public function login() {
if ( $this->request->is( 'post' ) ) {
if ( $this->Auth->login() ) {
$this->redirect( array( 'controller' => 'reservations', 'action' => 'index' ) );
} else {
$this->Session->setFlash( __( 'Login error.' ), 'flashError' );
}
}
}
Ich versuche das mit zu testenPHPUnitIch kann also sicher sein, dass sich nur gültige Benutzer anmelden können → nach einer erfolgreichen Anmeldung werden sie auf eine bestimmte Seite weitergeleitet. Hier ist meinstestLogin
Methode inUsersControllerTest
Klasse:
function testLogin() {
$UsersController = $this->generate( 'Users', array(
'components' => array(
'Auth' => array( 'user' )
),
)
);
$UsersController->Auth->expects( $this->any() )
->method( 'user' )
->with( 'id' )
->will( $this->returnValue( 2 ) );
$data = array( 'User' => array(
'student_number' => 1111111,
'password' => 'qwerty'
) );
//$UsersController->Auth->login( $data['User'] );
$this->testAction( '/users/login', array( 'data' => $data, 'method' => 'get' ) );
$url = parse_url( $this->headers['Location'] );
$this->assertEquals( $url['path'], '/reservations' );
}
Ich lerne immer noch die Grundlagen des Unit-Testens mit CakePHP. Ich erhalte diesen Fehler:
PHPUNIT_FRAMEWORK_ERROR_NOTICE
Undefined index: Location
Test case: UsersControllerTest(testLogin)
Ich habe keine Ahnung, woran das liegt ... Was ist falsch an meiner Testmethode und wie soll sie geschrieben werden?
Vielen Dank!