presseportale/tests/Feature/SyncCompanyLogosTest.php
Kevin Adametz 5b8bdf4182
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
12-05-2026 Frontend dev
2026-05-12 18:32:33 +02:00

107 lines
3.6 KiB
PHP

<?php
use App\Enums\Portal;
use App\Models\Company;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
test('legacy company logos are copied to normalized storage and linked in database', function () {
/** @var TestCase $this */
Storage::fake('public');
Storage::disk('public')->put('presseecho/company/logo-a.jpg', 'logo-a');
Storage::disk('public')->put('presseecho/company/unused.jpg', 'unused');
$company = Company::factory()->create([
'portal' => Portal::Presseecho->value,
'legacy_portal' => Portal::Presseecho->value,
'legacy_id' => 123,
'logo_path' => 'logo-a.jpg',
]);
$this->artisan('legacy:sync-company-logos', [
'--portal' => Portal::Presseecho->value,
])
->assertSuccessful()
->expectsOutputToContain('presseecho: referenziert 1, kopiert 1, DB-Updates 1')
->expectsOutputToContain('ungenutzt 1');
$company->refresh();
expect($company->logo_path)->toBe("company-logos/presseecho/{$company->id}/logo-a.jpg");
expect(Storage::disk('public')->exists($company->logo_path))->toBeTrue();
});
test('legacy company logo sync dry run does not copy or update records', function () {
/** @var TestCase $this */
Storage::fake('public');
Storage::disk('public')->put('businessportal24/company/logo-b.png', 'logo-b');
$company = Company::factory()->create([
'portal' => Portal::Businessportal24->value,
'legacy_portal' => Portal::Businessportal24->value,
'legacy_id' => 456,
'logo_path' => 'logo-b.png',
]);
$this->artisan('legacy:sync-company-logos', [
'--portal' => Portal::Businessportal24->value,
'--dry-run' => true,
])
->assertSuccessful()
->expectsOutputToContain('(Dry-Run)');
$company->refresh();
expect($company->logo_path)->toBe('logo-b.png');
expect(Storage::disk('public')->exists("company-logos/businessportal24/{$company->id}/logo-b.png"))->toBeFalse();
});
test('legacy company logo sync reports missing referenced files', function () {
/** @var TestCase $this */
Storage::fake('public');
Company::factory()->create([
'portal' => Portal::Presseecho->value,
'legacy_portal' => Portal::Presseecho->value,
'legacy_id' => 789,
'logo_path' => 'missing.jpg',
]);
$this->artisan('legacy:sync-company-logos', [
'--portal' => Portal::Presseecho->value,
])
->assertFailed()
->expectsOutputToContain('Fehlt: presseecho/company/missing.jpg');
});
test('company logo url resolves normalized local legacy logo before external legacy url', function () {
/** @var TestCase $this */
Storage::fake('public');
$company = Company::factory()->create([
'portal' => Portal::Businessportal24->value,
'legacy_portal' => Portal::Businessportal24->value,
'legacy_id' => 321,
'logo_path' => 'https://legacy.example/company/logo-c.png',
]);
Storage::disk('public')->put("company-logos/businessportal24/{$company->id}/logo-c.png", 'logo-c');
expect($company->logoUrl())->toBe(asset("storage/company-logos/businessportal24/{$company->id}/logo-c.png"));
});
test('company logo url resolves storage-prefixed local path', function () {
/** @var TestCase $this */
Storage::fake('public');
$company = Company::factory()->create([
'portal' => Portal::Presseecho->value,
'logo_path' => '/storage/company-logos/presseecho/99/logo-d.png',
]);
Storage::disk('public')->put('company-logos/presseecho/99/logo-d.png', 'logo-d');
expect($company->logoUrl())->toBe(asset('storage/company-logos/presseecho/99/logo-d.png'));
});