How to test response of successful form submit in presenter test

Notice: This thread is very old.
josef.sabl
Backer | 153
+
0
-

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
	}
Azathoth
Member | 506
+
+1
-

I think you could use selenium for that.

Comments

josef.sabl:

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?

5 years ago
Azathoth:

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

5 years ago
jvit
Member | 2
+
+1
-

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.