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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <?php
* $I->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
*
Expand Down