feat: normalize email addresses to lowercase on write

This commit is contained in:
2026-09-21 12:20:55 +02:00
parent d6327f033e
commit af46c57bd1
7 changed files with 102 additions and 4 deletions
+31
View File
@@ -200,6 +200,37 @@ class UserDataHandlerTest extends TestCase
$this->assertSame(['team' => ['selected' => true]], $teamer->getCrmSelections());
}
/**
* BusPro compares addresses case-insensitively and MyE&P lowercases them on login, so a
* mixed-case address coming back from the API must land lowercased on both the user and
* the teamer - otherwise the login identity and the mailing address drift apart.
*/
public function testUpdateLocalUserNormalizesTheAddressBusProReports(): void
{
$user = (new User())
->setFirstName('Old')
->setLastName('Name')
->setEmail('[email protected]')
->setBusProAddressId(1)
->setBusProPersonId(2)
;
$teamer = (new Teamer())
->setCommunication((new Communication())->setEmail('[email protected]'))
;
$user->setTeamer($teamer);
$profileResponse = $this->createProfileResponse()
->setCommunication((new BusProCommunication())->setEmail('[email protected]'))
;
$handler = new UserDataHandler($this->entityManager, $this->logger);
$handler->updateLocalUser($user, $profileResponse, true, [], ['ROLE_TEAMER'], []);
$this->assertSame('[email protected]', $user->getEmail());
$this->assertSame('[email protected]', $teamer->getCommunication()?->getEmail());
}
/**
* @dataProvider pendingRolesProvider
*/
+22
View File
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace App\Tests\Entity;
use App\Entity\Contact;
use PHPUnit\Framework\TestCase;
class ContactTest extends TestCase
{
/**
* Office contacts are normalized the same way User::setEmail() normalizes, so that every
* stored address has one shape regardless of which form wrote it.
*/
public function testSetEmailNormalizesCaseAndSurroundingWhitespace(): void
{
$contact = (new Contact())->setEmail(' [email protected] ');
$this->assertSame('[email protected]', $contact->getEmail());
}
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace App\Tests\Entity\Embeddable;
use App\Entity\Embeddable\Communication;
use PHPUnit\Framework\TestCase;
/**
* Pins the lowercasing of the teamer's contact address. This is the address the profile form
* writes and the one toPayload() pushes back to BusPro, so a mixed-case value entered here
* would otherwise diverge from the login identity stored in User::email.
*/
class CommunicationTest extends TestCase
{
public function testSetEmailNormalizesCaseAndSurroundingWhitespace(): void
{
$communication = (new Communication())->setEmail(' [email protected] ');
$this->assertSame('[email protected]', $communication->getEmail());
}
public function testSetEmailKeepsNull(): void
{
$communication = (new Communication())->setEmail(null);
$this->assertNull($communication->getEmail());
}
/**
* The outbound BusPro payload must carry the normalized form, not the raw input.
*/
public function testPayloadCarriesTheNormalizedAddress(): void
{
$communication = (new Communication())
->setEmail('[email protected]')
->setMobile('0170 1234567')
;
$this->assertSame('[email protected]', $communication->toPayload()['email']);
}
}