feat(tenant): add site title and favicon support for tenants and website types
This commit is contained in:
@@ -36,6 +36,11 @@ class CreateDesfilePuraTendenciaTenantTest extends TestCase
|
||||
);
|
||||
$footerBackgroundMigration->up();
|
||||
|
||||
$browserBrandingMigration = require database_path(
|
||||
'migrations/2026_08_14_010000_set_seeded_tenant_browser_branding.php'
|
||||
);
|
||||
$browserBrandingMigration->up();
|
||||
|
||||
$this->assertDatabaseHas('tenants', [
|
||||
'codigo' => 'desfile_pura_tendencia',
|
||||
'nombre' => 'Desfile Pura Tendencia',
|
||||
@@ -52,8 +57,25 @@ class CreateDesfilePuraTendenciaTenantTest extends TestCase
|
||||
'footer_bg_color' => '#D4441C',
|
||||
'display_categories' => false,
|
||||
'display_seach_bar' => false,
|
||||
'site_title' => 'Desfile Pura Tendencia',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('tenants', [
|
||||
'codigo' => 'fiesta_futbol_infantil',
|
||||
'site_title' => 'Fiesta Fútbol Infantil',
|
||||
]);
|
||||
|
||||
foreach ([
|
||||
'fiesta_futbol_infantil' => 'futbol_infantil_favicon.png',
|
||||
'desfile_pura_tendencia' => 'pura_tendencia_favicon.png',
|
||||
] as $tenantCode => $faviconFilename) {
|
||||
$faviconId = DB::table('tenants')->where('codigo', $tenantCode)->value('favicon_id');
|
||||
$favicon = DB::table('attachments')->where('id', $faviconId)->sole();
|
||||
|
||||
$this->assertSame($faviconFilename, $favicon->filename);
|
||||
Storage::disk('s3')->assertExists($favicon->path);
|
||||
}
|
||||
|
||||
$eventDate = DB::table('event_dates')
|
||||
->where('tenant_code', 'desfile_pura_tendencia')
|
||||
->sole();
|
||||
@@ -104,6 +126,7 @@ class CreateDesfilePuraTendenciaTenantTest extends TestCase
|
||||
'desfile_pura_tendencia_footer.png',
|
||||
'desfile_pura_tendencia_hero.png',
|
||||
'desfile_pura_tendencia_footer_background.png',
|
||||
'pura_tendencia_favicon.png',
|
||||
'entrada_pasarela.png',
|
||||
] as $filename) {
|
||||
$path = DB::table('attachments')->where('filename', $filename)->value('path');
|
||||
|
||||
@@ -127,6 +127,62 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
->assertJsonPath('data.dominio', 'acme.com');
|
||||
}
|
||||
|
||||
public function test_it_resolves_browser_branding_from_the_tenant_before_the_website_type(): void
|
||||
{
|
||||
$typeFavicon = Attachment::query()->create([
|
||||
'key' => (string) Str::uuid(),
|
||||
'path' => 'website-types/type-favicon.png',
|
||||
'filename' => 'type-favicon.png',
|
||||
'type' => AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
$tenantFavicon = Attachment::query()->create([
|
||||
'key' => (string) Str::uuid(),
|
||||
'path' => 'tenants/tenant-favicon.png',
|
||||
'filename' => 'tenant-favicon.png',
|
||||
'type' => AttachmentType::Image,
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
$websiteType = WebsiteType::query()->create([
|
||||
'codigo' => 'store',
|
||||
'nombre' => 'Tienda',
|
||||
'site_title' => 'Website type title',
|
||||
'favicon_id' => $typeFavicon->id,
|
||||
]);
|
||||
$tenant = $this->createTenant([
|
||||
'website_type_code' => $websiteType->codigo,
|
||||
]);
|
||||
|
||||
$typeResponse = $this->getJson('/api/tenants/bootstrap/acme.com');
|
||||
|
||||
$typeResponse
|
||||
->assertOk()
|
||||
->assertJsonPath('data.site_title', 'Website type title');
|
||||
$this->assertStringContainsString($typeFavicon->key, $typeResponse->json('data.favicon'));
|
||||
|
||||
$tenant->update([
|
||||
'site_title' => 'Tenant title',
|
||||
'favicon_id' => $tenantFavicon->id,
|
||||
]);
|
||||
|
||||
$tenantResponse = $this->getJson('/api/tenants/bootstrap/acme.com');
|
||||
|
||||
$tenantResponse
|
||||
->assertOk()
|
||||
->assertJsonPath('data.site_title', 'Tenant title');
|
||||
$this->assertStringContainsString($tenantFavicon->key, $tenantResponse->json('data.favicon'));
|
||||
}
|
||||
|
||||
public function test_it_uses_default_browser_branding_when_none_is_configured(): void
|
||||
{
|
||||
$this->createTenant();
|
||||
|
||||
$this->getJson('/api/tenants/bootstrap/acme.com')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.site_title', 'ShopitFront')
|
||||
->assertJsonPath('data.favicon', null);
|
||||
}
|
||||
|
||||
public function test_it_returns_only_the_tenant_categories_in_the_bootstrap(): void
|
||||
{
|
||||
$tenant = $this->createTenant();
|
||||
@@ -755,21 +811,28 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
'footer_bg_color' => '#444444',
|
||||
'header_logo' => $base64Image,
|
||||
'footer_logo' => $ftrUuid,
|
||||
'site_title' => 'Acme Store',
|
||||
'favicon' => $base64Image,
|
||||
]);
|
||||
|
||||
$response->assertCreated();
|
||||
|
||||
$tenant = Tenant::query()->with('headerLogo')->where('codigo', 'acme')->firstOrFail();
|
||||
$tenant = Tenant::query()->with(['headerLogo', 'favicon'])->where('codigo', 'acme')->firstOrFail();
|
||||
|
||||
$this->assertNotNull($tenant->header_logo_id);
|
||||
$this->assertNotNull($tenant->favicon_id);
|
||||
|
||||
$headerUrl = $response->json('data.header_logo');
|
||||
$faviconUrl = $response->json('data.favicon');
|
||||
|
||||
$response->assertJsonPath('data.site_title', 'Acme Store');
|
||||
$this->assertStringContainsString($tenant->headerLogo->key, $headerUrl);
|
||||
$this->assertStringContainsString($tenant->favicon->key, $faviconUrl);
|
||||
$this->assertTrue(
|
||||
str_contains($headerUrl, 'Expires=') || str_contains($headerUrl, 'expiration=') || str_contains($headerUrl, 'X-Amz-Expires=')
|
||||
);
|
||||
|
||||
$this->assertDatabaseHas('attachments', ['key' => $tenant->headerLogo->key]);
|
||||
$this->assertDatabaseHas('attachments', ['key' => $tenant->favicon->key]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,20 +32,26 @@ class WebsiteTypeServiceTest extends TestCase
|
||||
'background_color' => '#f8f8f8',
|
||||
'border_color' => '#dddddd',
|
||||
'login_header_footer_color' => '#333333',
|
||||
'site_title' => 'Marketplace Central',
|
||||
'site_logo' => UploadedFile::fake()->image('site-logo.png'),
|
||||
'footer_logo' => UploadedFile::fake()->image('footer-logo.png'),
|
||||
'favicon' => UploadedFile::fake()->image('favicon.png', 32, 32),
|
||||
]);
|
||||
|
||||
$siteLogo = $websiteType->siteLogo()->firstOrFail();
|
||||
$footerLogo = $websiteType->footerLogo()->firstOrFail();
|
||||
$favicon = $websiteType->favicon()->firstOrFail();
|
||||
|
||||
$this->assertSame('marketplace', $websiteType->codigo);
|
||||
$this->assertSame($siteLogo->id, $websiteType->site_logo);
|
||||
$this->assertSame($footerLogo->id, $websiteType->footer_logo);
|
||||
$this->assertSame($favicon->id, $websiteType->favicon_id);
|
||||
$this->assertStringStartsWith('website-types/', $siteLogo->path);
|
||||
$this->assertStringStartsWith('website-types/', $footerLogo->path);
|
||||
$this->assertStringStartsWith('website-types/', $favicon->path);
|
||||
Storage::disk('s3')->assertExists($siteLogo->path);
|
||||
Storage::disk('s3')->assertExists($footerLogo->path);
|
||||
Storage::disk('s3')->assertExists($favicon->path);
|
||||
$this->assertDatabaseHas('website_type', [
|
||||
'codigo' => 'marketplace',
|
||||
'dominio' => 'marketplace.test',
|
||||
@@ -57,8 +63,10 @@ class WebsiteTypeServiceTest extends TestCase
|
||||
'background_color' => '#f8f8f8',
|
||||
'border_color' => '#dddddd',
|
||||
'login_header_footer_color' => '#333333',
|
||||
'site_title' => 'Marketplace Central',
|
||||
'site_logo' => $siteLogo->id,
|
||||
'footer_logo' => $footerLogo->id,
|
||||
'favicon_id' => $favicon->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user