feat: E.164 phone validation and storage with libphonenumber

- Add giggsey/libphonenumber-for-php, PhoneNumberNormalizer, ValidPhoneNumber rule

- Store subscribers as E.164; mutator normalizes on save; optional phone required from form block

- Migration to normalize legacy subscriber phones; Mailwizz/search/UI/tests updated

- Add run-deploy-from-local.sh and PREREGISTER_DEFAULT_PHONE_REGION in .env.example

Made-with: Cursor
This commit is contained in:
2026-04-04 14:25:52 +02:00
parent 5a67827c23
commit 17e784fee7
21 changed files with 476 additions and 18 deletions

View File

@@ -170,7 +170,7 @@ class PublicPageTest extends TestCase
$response->assertJsonValidationErrors(['phone']);
}
public function test_subscribe_normalizes_phone_to_digits(): void
public function test_subscribe_stores_phone_as_e164(): void
{
$page = $this->makePage([
'start_date' => now()->subHour(),
@@ -189,7 +189,7 @@ class PublicPageTest extends TestCase
$this->assertDatabaseHas('subscribers', [
'preregistration_page_id' => $page->id,
'email' => 'phoneuser@example.com',
'phone' => '31612345678',
'phone' => '+31612345678',
]);
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Tests\Feature;
use App\Jobs\SyncSubscriberToMailwizz;
use App\Models\MailwizzConfig;
use App\Models\PreregistrationPage;
use App\Models\Subscriber;
@@ -91,6 +92,47 @@ class SyncSubscriberToMailwizzTest extends TestCase
$this->assertTrue($subscriber->synced_to_mailwizz);
}
public function test_mailwizz_sync_sends_phone_with_e164_plus_prefix(): void
{
Http::fake(function (Request $request) {
$url = $request->url();
if (str_contains($url, 'search-by-email')) {
return Http::response(['status' => 'error']);
}
if ($request->method() === 'POST' && preg_match('#/lists/[^/]+/subscribers$#', $url) === 1) {
$body = $request->body();
$this->assertStringContainsString('PHONE', $body);
$this->assertTrue(
str_contains($body, '+31612345678') || str_contains($body, '%2B31612345678'),
'Expected E.164 phone with + in Mailwizz request body'
);
return Http::response(['status' => 'success']);
}
return Http::response(['status' => 'error'], 500);
});
$page = $this->makePageWithMailwizz([
'field_phone' => 'PHONE',
]);
$page->update(['phone_enabled' => true]);
$subscriber = Subscriber::query()->create([
'preregistration_page_id' => $page->id,
'first_name' => 'Test',
'last_name' => 'User',
'email' => 'phone-e164@example.com',
'phone' => '+31612345678',
'synced_to_mailwizz' => false,
]);
SyncSubscriberToMailwizz::dispatchSync($subscriber);
$subscriber->refresh();
$this->assertTrue($subscriber->synced_to_mailwizz);
}
/**
* @param array<string, mixed> $configOverrides
*/