How to test response of successful form submit in presenter test

Backer | 146

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' => '',
        'password' => 'superSecret123',

    $pt = $this->getPresenterTester()

    $response = $pt->run();

    Assert::true($response instanceof Nette\Application\Responses\RedirectResponse);

    //TODO test that flashMessage: 'login successful' is displayed on final page
Member | 506

I think you could use selenium for that.



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?

4 years ago

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

4 years ago
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.