Skip to content

Commit c9b3810

Browse files
committed
Added submitSymfonyForm function
1 parent 6c521ba commit c9b3810

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/Codeception/Module/Symfony.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,35 @@ public function seeAuthentication($remembered = false)
965965
$this->assertTrue($security->isGranted($role), 'There is no authenticated user');
966966
}
967967

968+
/**
969+
* Submits the given Symfony Form on the page, with the given form values.
970+
* If you customized the CSS selectors or field names use ->submitForm() instead.
971+
*
972+
* ```php
973+
* <?php
974+
* $I->submitSymfonyForm('login_form', [
975+
* '[email]' => 'john_doe@gmail.com',
976+
* '[password]' => 'secretForest'
977+
* ]);
978+
* ```
979+
*
980+
* @param string $name
981+
* @param string[] $fields
982+
*/
983+
public function submitSymfonyForm($name, $fields)
984+
{
985+
$selector = sprintf('form[name=%s]', $name);
986+
987+
$params = [];
988+
foreach ($fields as $key => $value) {
989+
$fixedKey = sprintf('%s%s', $name, $key);
990+
$params[$fixedKey] = $value;
991+
}
992+
$button = sprintf('%s_submit', $name);
993+
994+
$this->submitForm($selector, $params, $button);
995+
}
996+
968997
/**
969998
* Check that the current user has a role
970999
*

0 commit comments

Comments
 (0)