From c9b38105f9bc722fa48a1daaa2ea41bb80257a8b Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Sat, 7 Nov 2020 16:38:14 -0500 Subject: [PATCH 1/2] Added submitSymfonyForm function --- src/Codeception/Module/Symfony.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index 37fb938a..773e2584 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -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. + * If you customized the CSS selectors or field names use ->submitForm() instead. + * + * ```php + * submitSymfonyForm('login_form', [ + * '[email]' => 'john_doe@gmail.com', + * '[password]' => 'secretForest' + * ]); + * ``` + * + * @param string $name + * @param string[] $fields + */ + public function submitSymfonyForm($name, $fields) + { + $selector = sprintf('form[name=%s]', $name); + + $params = []; + foreach ($fields as $key => $value) { + $fixedKey = sprintf('%s%s', $name, $key); + $params[$fixedKey] = $value; + } + $button = sprintf('%s_submit', $name); + + $this->submitForm($selector, $params, $button); + } + /** * Check that the current user has a role * From 6c8c0cb5a14b234a99f1bc957f8ac529d3d0a47a Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Mon, 16 Nov 2020 10:52:58 -0500 Subject: [PATCH 2/2] Added a more descriptive message for submitSymfonyForm --- src/Codeception/Module/Symfony.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index 773e2584..7697f19d 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -966,8 +966,10 @@ public function seeAuthentication($remembered = false) } /** - * Submits the given Symfony Form on the page, with the given form values. - * If you customized the CSS selectors or field names use ->submitForm() instead. + * Submit a form specifying the form name only once. + * + * Use this function instead of $I->submitForm() to avoid repeating the form name in the field selectors. + * If you customized the names of the field selectors use $I->submitForm() for full control. * * ```php *