feat(tenant): add site title and favicon support for tenants and website types
This commit is contained in:
@@ -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