Commit bf1f5bfc by Damien Moulard

Test prestataire creation from the admin

Covers the encrypted IBAN storage and the creation of a user linked to
the new prestataire (MLCEvents::REGISTRATION_PRESTATAIRE).
parent e9ec6c0d
...@@ -144,6 +144,11 @@ FOSUserBundle ne supporte pas Symfony 8, et SonataUserBundle 4 dépend de FOSUse ...@@ -144,6 +144,11 @@ FOSUserBundle ne supporte pas Symfony 8, et SonataUserBundle 4 dépend de FOSUse
Ces tests ont été exécutés avec succès sur l'ancien code (avec FOSUserBundle) et sur le nouveau. Ces tests ont été exécutés avec succès sur l'ancien code (avec FOSUserBundle) et sur le nouveau.
Tests ajoutés après l'étape 1b, dans le même fichier :
- création d'un adhérent depuis l'admin ;
- création d'un prestataire depuis l'admin, avec un IBAN (vérifie qu'il est enregistré chiffré puis affiché en clair dans l'admin) et un nouvel utilisateur rattaché ;
- absence de clé de traduction brute sur les pages d'admin des utilisateurs et des groupes.
### Commits ### Commits
- Formatage seul (php-cs-fixer) des fichiers touchés, isolé pour faciliter la relecture. - Formatage seul (php-cs-fixer) des fichiers touchés, isolé pour faciliter la relecture.
......
...@@ -154,6 +154,47 @@ class UserAccountTest extends WebTestCase ...@@ -154,6 +154,47 @@ class UserAccountTest extends WebTestCase
} }
/** /**
* Creating a prestataire with an IBAN (stored encrypted) and a new user (MLCEvents::REGISTRATION_PRESTATAIRE).
*/
public function testAdminCreatesPrestataire(): void
{
$admin = json_decode(file_get_contents(__DIR__ . '/urls.json'), true)['users']['super_admin'];
$client = $this->loggedInClient($admin, SmokeTest::PASSWORD);
$crawler = $client->request('GET', '/admin/prestataire/create');
self::assertSame(200, $client->getResponse()->getStatusCode());
$form = $this->formWithField($crawler, '[raison]');
$raison = 'Smoke presta ' . bin2hex(random_bytes(4));
$iban = 'FR7630001007941234567890185';
$email = 'smoke.presta-' . bin2hex(random_bytes(4)) . '@example.org';
$form[$this->fieldName($form, '[raison]')] = $raison;
$form[$this->fieldName($form, '[iban]')] = $iban;
// The "new users" collection is filled in javascript in the browser: post its fields directly.
$values = $form->getPhpValues();
$uniqid = array_key_first(array_filter($values, 'is_array'));
$values[$uniqid]['newusers'] = [['email' => $email, 'firstname' => 'Smoke', 'lastname' => 'Presta']];
$client->request($form->getMethod(), $form->getUri(), $values, $form->getPhpFiles());
self::assertTrue($client->getResponse()->isRedirect(), 'Prestataire creation failed with status ' . $client->getResponse()->getStatusCode() . ': ' . $this->pageErrors($client));
$stmt = $this->db()->prepare('SELECT id, iban FROM prestataire WHERE raison = ?');
$stmt->execute([$raison]);
$presta = $stmt->fetch(\PDO::FETCH_ASSOC);
self::assertNotFalse($presta, 'The prestataire must be created');
self::assertStringEndsWith('<ENC>', $presta['iban'], 'The IBAN must be stored encrypted');
self::assertStringNotContainsString($iban, $presta['iban']);
$stmt = $this->db()->prepare('SELECT COUNT(*) FROM user u JOIN prestataire_user pu ON pu.user_id = u.id WHERE u.email = ? AND pu.prestataire_id = ?');
$stmt->execute([$email, $presta['id']]);
self::assertSame('1', (string) $stmt->fetchColumn(), 'The new user must be created and linked to the prestataire');
// The IBAN is decrypted when displayed in the admin
$client->request('GET', '/admin/prestataire/' . $presta['id'] . '/edit');
self::assertSame(200, $client->getResponse()->getStatusCode());
self::assertStringContainsString($iban, $client->getResponse()->getContent());
}
/**
* The labels of the user and group admins come from the former SonataUserBundle translations. * The labels of the user and group admins come from the former SonataUserBundle translations.
*/ */
public function testUserAdminLabelsAreTranslated(): void public function testUserAdminLabelsAreTranslated(): void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment