How to test response of successful form submit in presenter test
- josef.sabl
- Member | 153
I want to test the sign in presenter action with form submit and correct response in redirect. E.g. I want to test that after correct login, user is redirected somewhere and flash message with text “login successful” is displayed.
In all the examples the only way to test correct form behavior is to test that I get RedirectResponse (see below). Isn't that too little? How to do the test I describe? Is it even possible?
function testSignUpSuccess()
{
$post = [
'identity' => 'john.doe@gmail.com',
'password' => 'superSecret123',
];
$pt = $this->getPresenterTester()
->setPresenter('Sign')
->setAction('up')
->setHandle('signUpForm-submit')
->setPost($post);
$response = $pt->run();
Assert::true($response instanceof Nette\Application\Responses\RedirectResponse);
//TODO test that flashMessage: 'login successful' is displayed on final page
}
- josef.sabl
- Member | 153
Ok, I know Selenium but I am interested in testing this with nette/tester. Does you answer mean that it is not possible with tester or are you just suggesting alternative method?
- jvit
- Member | 2
To get your flash message you could:
- extract _fid parameter from redirect response url and find flash text in session
- override flashMessage method in your BasePresenter class so that it stores messages when called from test enviroment and then retrieve it later from wherever you stored it.
- Azathoth
- Member | 495
I my optinion, using selenium would be best option. But maybe I just don't
know aby better solution.
There is couple of extensions integrating selenium to nette/tester, such as kdyby/selenium or flame.org/tester-selenium