diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index 37fb938a..7697f19d 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -965,6 +965,37 @@ public function seeAuthentication($remembered = false) $this->assertTrue($security->isGranted($role), 'There is no authenticated user'); } + /** + * 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 + * 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 *