CakePHP 2.3 - Testowanie jednostek Logowanie użytkownika
Pomyślałem, że muszę tutaj poprosić o pomoc w moim problemie. Spędziłem z tym cały wieczór. Mam metodę logowania wUsersController
lubię to:
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' );
}
}
}
Próbuję to przetestowaćPHPUnit, więc mogę być pewien, że tylko poprawni użytkownicy mogą się zalogować → po pomyślnym zalogowaniu zostaną przekierowani na określoną stronę. Oto mojatestLogin
metoda wUsersControllerTest
klasa:
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' );
}
Nadal uczę się podstaw testów jednostkowych za pomocą CakePHP. Dostaję ten błąd:
PHPUNIT_FRAMEWORK_ERROR_NOTICE
Undefined index: Location
Test case: UsersControllerTest(testLogin)
Nie mam pojęcia, co to powoduje ... Co jest nie tak z moją metodą testową i jak powinno być napisane?
Dzięki!