Skip to content

Added submitSymfonyForm function #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2020
Merged

Added submitSymfonyForm function #32

merged 2 commits into from
Nov 16, 2020

Conversation

TavoNiievez
Copy link
Member

While testing forms in Symfony it is very common to have to repeat the form name in different places in the method to comply with the Symfony naming format:

	$I->submitForm('form[name={form_name}]', [
		'{form_name}[{field_key}]' => '{field_value}',
		'{form_name}[{field_key}]' => '{field_value}'
	], '{form_name}_submit');

However this ruins the readability of the test and makes the code much more verbose:

	$I->submitForm('form[name=user_update_password_form]', [
		'user_update_password_form[oldPassword]'      => '123456',
		'user_update_password_form[password][first]'  => '654321',
		'user_update_password_form[password][second]' => '654321'
	], 'user_update_password_form_submit');

That is why i write this function that allows you to take advantage of the fact that the naming format is always the same, and allows you to simplify the action of submitting a form:

	$I->submitSymfonyForm('user_update_password_form', [
		'[oldPassword]'      => '123456',
		'[password][first]'  => '654321',
		'[password][second]' => '654321'
	]);

For the few who do edit this format in their applications and create something super-custom there is always the option to use the base ->submitForm() function, so this is basically a shortcut alias function.

The improvement in readability is significant.

@@ -965,6 +965,35 @@ public function seeAuthentication($remembered = false)
$this->assertTrue($security->isGranted($role), 'There is no authenticated user');
}

/**
* Submits the given Symfony Form on the page, with the given form values.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from this description it is not clear when should I use submitSimfonyForm and submitForm
so a small description why you would need to use this method over submitForm is required

@TavoNiievez TavoNiievez merged commit bed4c5a into Codeception:master Nov 16, 2020
@TavoNiievez TavoNiievez deleted the submitSymfonyForm branch November 16, 2020 16:04
@TavoNiievez TavoNiievez added this to the 1.3.0 milestone Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants