b2in/tests/Feature/WhatsappNumberSeederTest.php
Kevin Adametz 07816dce19 Kontaktdaten: Telefon +49 521 986 20 100, E-Mail interior@b2in.eu
Lang-Dateien (Kontaktformular, Impressum, Datenschutz, de/en), Support-Link im Partnerportal,
WhatsApp-Schreibweise und Platzhalter im Admin. ContactDetailsSeeder ersetzt die alten Werte in
den gespeicherten CMS-Einträgen (beide Sprachen), Marken und Magazin; Display-Folien und
Info-Tablet (CABINET-Showroom) bleiben unberührt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 13:29:34 +00:00

88 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
use Database\Seeders\WhatsappNumberSeeder;
use FluxCms\Core\Models\CmsContent;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
function contactWhatsapp(string $locale = 'de'): string
{
$row = CmsContent::query()->where('group', 'global')->where('key', 'contact')->firstOrFail();
return (string) ($row->getTranslation('value', $locale)['whatsapp'] ?? '');
}
it('creates the contact entry with the business number when it is missing', function () {
$this->seed(WhatsappNumberSeeder::class);
expect(contactWhatsapp('de'))->toBe('+49 521 986 20 100')
->and(contactWhatsapp('en'))->toBe('+49 521 986 20 100')
->and(whatsapp_link())->toBe('https://wa.me/4952198620100');
});
it('replaces the placeholder number from the first setup', function () {
CmsContent::create([
'group' => 'global',
'key' => 'contact',
'type' => 'json',
'value' => ['de' => ['whatsapp' => '+49 151 00000000'], 'en' => ['whatsapp' => '+49 151 00000000']],
'order' => 0,
]);
$this->seed(WhatsappNumberSeeder::class);
expect(contactWhatsapp('de'))->toBe('+49 521 986 20 100')
->and(contactWhatsapp('en'))->toBe('+49 521 986 20 100');
});
it('corrects the wrong number that was seeded on 23.09.', function () {
CmsContent::create([
'group' => 'global',
'key' => 'contact',
'type' => 'json',
'value' => ['de' => ['whatsapp' => '+49 521 98610020'], 'en' => ['whatsapp' => '+49 521 98610020']],
'order' => 0,
]);
$this->seed(WhatsappNumberSeeder::class);
expect(contactWhatsapp('de'))->toBe('+49 521 986 20 100')
->and(contactWhatsapp('en'))->toBe('+49 521 986 20 100');
});
it('keeps a number that was maintained in the admin', function () {
CmsContent::create([
'group' => 'global',
'key' => 'contact',
'type' => 'json',
'value' => ['de' => ['whatsapp' => '+49 170 1234567', 'phone' => '0521 1'], 'en' => []],
'order' => 0,
]);
$this->seed(WhatsappNumberSeeder::class);
$row = CmsContent::query()->where('group', 'global')->where('key', 'contact')->firstOrFail();
expect(contactWhatsapp('de'))->toBe('+49 170 1234567')
->and($row->getTranslation('value', 'de')['phone'])->toBe('0521 1')
->and(contactWhatsapp('en'))->toBe('+49 521 986 20 100');
});
it('is idempotent', function () {
$this->seed(WhatsappNumberSeeder::class);
$this->seed(WhatsappNumberSeeder::class);
expect(CmsContent::query()->where('group', 'global')->where('key', 'contact')->count())->toBe(1)
->and(contactWhatsapp('de'))->toBe('+49 521 986 20 100');
});
it('shows the business number on the site after seeding', function () {
$this->seed(WhatsappNumberSeeder::class);
$html = $this->get('/')->assertSuccessful()->getContent();
expect($html)->toContain('4952198620100');
});