87 lines
2.6 KiB
PHP
87 lines
2.6 KiB
PHP
<?php
|
|
|
|
use App\Enums\Portal;
|
|
use App\Models\Company;
|
|
use App\Models\PressRelease;
|
|
use Tests\TestCase;
|
|
|
|
test('press release slug is unique within portal and language scope', function () {
|
|
/** @var TestCase $this */
|
|
$base = (new PressRelease)->generateUniqueSlug('Test Mitteilung', [
|
|
'portal' => Portal::Presseecho->value,
|
|
'language' => 'de',
|
|
]);
|
|
|
|
expect($base)->toBe('test-mitteilung');
|
|
|
|
PressRelease::factory()->create([
|
|
'portal' => Portal::Presseecho->value,
|
|
'language' => 'de',
|
|
'slug' => 'test-mitteilung',
|
|
]);
|
|
|
|
$next = (new PressRelease)->generateUniqueSlug('Test Mitteilung', [
|
|
'portal' => Portal::Presseecho->value,
|
|
'language' => 'de',
|
|
]);
|
|
|
|
expect($next)->toBe('test-mitteilung-2');
|
|
|
|
// Same slug allowed in another portal
|
|
$foreign = (new PressRelease)->generateUniqueSlug('Test Mitteilung', [
|
|
'portal' => Portal::Businessportal24->value,
|
|
'language' => 'de',
|
|
]);
|
|
|
|
expect($foreign)->toBe('test-mitteilung');
|
|
|
|
// Same slug allowed in another language
|
|
$en = (new PressRelease)->generateUniqueSlug('Test Mitteilung', [
|
|
'portal' => Portal::Presseecho->value,
|
|
'language' => 'en',
|
|
]);
|
|
|
|
expect($en)->toBe('test-mitteilung');
|
|
});
|
|
|
|
test('press release editing keeps own slug stable', function () {
|
|
/** @var TestCase $this */
|
|
$pr = PressRelease::factory()->create([
|
|
'portal' => Portal::Presseecho->value,
|
|
'language' => 'de',
|
|
'slug' => 'meine-mitteilung',
|
|
]);
|
|
|
|
$regenerated = $pr->generateUniqueSlug('Meine Mitteilung', [
|
|
'portal' => Portal::Presseecho->value,
|
|
'language' => 'de',
|
|
]);
|
|
|
|
expect($regenerated)->toBe('meine-mitteilung');
|
|
});
|
|
|
|
test('company slug is unique within portal scope', function () {
|
|
/** @var TestCase $this */
|
|
Company::factory()->create([
|
|
'portal' => Portal::Presseecho->value,
|
|
'slug' => 'acme-gmbh',
|
|
]);
|
|
|
|
$slug = (new Company)->generateUniqueSlug('Acme GmbH', ['portal' => Portal::Presseecho->value]);
|
|
expect($slug)->toBe('acme-gmbh-2');
|
|
|
|
$other = (new Company)->generateUniqueSlug('Acme GmbH', ['portal' => Portal::Businessportal24->value]);
|
|
expect($other)->toBe('acme-gmbh');
|
|
});
|
|
|
|
test('blank source falls back to model defined fallback', function () {
|
|
/** @var TestCase $this */
|
|
$prSlug = (new PressRelease)->generateUniqueSlug('---', [
|
|
'portal' => Portal::Presseecho->value,
|
|
'language' => 'de',
|
|
]);
|
|
expect($prSlug)->toBe('pressemitteilung');
|
|
|
|
$coSlug = (new Company)->generateUniqueSlug('!!!', ['portal' => Portal::Presseecho->value]);
|
|
expect($coSlug)->toBe('company');
|
|
});
|