Skip to content

Commit bed4c5a

Browse files
authored
Added submitSymfonyForm function
2 parents d558d48 + 6c8c0cb commit bed4c5a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Codeception/Module/Symfony.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,37 @@ public function seeAuthentication($remembered = false)
980980
$this->assertTrue($security->isGranted($role), 'There is no authenticated user');
981981
}
982982

983+
/**
984+
* Submit a form specifying the form name only once.
985+
*
986+
* Use this function instead of $I->submitForm() to avoid repeating the form name in the field selectors.
987+
* If you customized the names of the field selectors use $I->submitForm() for full control.
988+
*
989+
* ```php
990+
* <?php
991+
* $I->submitSymfonyForm('login_form', [
992+
* '[email]' => 'john_doe@gmail.com',
993+
* '[password]' => 'secretForest'
994+
* ]);
995+
* ```
996+
*
997+
* @param string $name
998+
* @param string[] $fields
999+
*/
1000+
public function submitSymfonyForm($name, $fields)
1001+
{
1002+
$selector = sprintf('form[name=%s]', $name);
1003+
1004+
$params = [];
1005+
foreach ($fields as $key => $value) {
1006+
$fixedKey = sprintf('%s%s', $name, $key);
1007+
$params[$fixedKey] = $value;
1008+
}
1009+
$button = sprintf('%s_submit', $name);
1010+
1011+
$this->submitForm($selector, $params, $button);
1012+
}
1013+
9831014
/**
9841015
* Check that the current user has a role
9851016
*

0 commit comments

Comments
 (0)