121 lines
5.1 KiB
PHP
121 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Pages and assets that belong to one platform can be switched off or replaced by another platform
|
|
* running the same code: the Android app, local group pages in the footer, email logos and favicons.
|
|
*/
|
|
class PlatformBrandingTest extends TestCase
|
|
{
|
|
private function platformConfig(array $values): void
|
|
{
|
|
$platform = config('app.timebank_config');
|
|
foreach ($values as $key => $value) {
|
|
config(["{$platform}.{$key}" => $value]);
|
|
}
|
|
}
|
|
|
|
public function test_the_app_version_check_names_the_configured_apk(): void
|
|
{
|
|
$this->platformConfig(['android_app.enabled' => true, 'android_app.apk_file' => 'myorg-{version}.apk']);
|
|
|
|
$this->getJson('/app/version')
|
|
->assertOk()
|
|
->assertJsonPath('apkUrl', url('storage/apk/myorg-' . \App\Http\Controllers\AppVersionController::latest()['versionName'] . '.apk'));
|
|
}
|
|
|
|
public function test_the_android_app_is_off_when_disabled(): void
|
|
{
|
|
$this->platformConfig(['android_app.enabled' => false]);
|
|
|
|
$this->get('/app/version')->assertNotFound();
|
|
$this->get(route('static-android-app'))->assertNotFound();
|
|
}
|
|
|
|
public function test_the_android_app_page_names_the_platform(): void
|
|
{
|
|
$this->platformConfig(['android_app.enabled' => true, 'platform_translations.en.platform_name' => 'Example Timebank']);
|
|
|
|
$this->get(route('static-android-app'))
|
|
->assertOk()
|
|
->assertDontSee('Timebank.cc Android')
|
|
->assertSee('Example Timebank Android');
|
|
}
|
|
|
|
public function test_the_footer_leaves_out_links_to_routes_this_platform_does_not_register(): void
|
|
{
|
|
$this->platformConfig(['footer.sections' => [[
|
|
'title' => 'Community', 'order' => 1, 'visible' => true,
|
|
'links' => [
|
|
['route' => 'static-events', 'title' => 'Events', 'order' => 1, 'visible' => true],
|
|
['route' => 'static-switched-off-page', 'title' => 'Switched off page', 'order' => 2, 'visible' => true],
|
|
],
|
|
]]]);
|
|
|
|
$html = Blade::render('<x-footer />');
|
|
|
|
$this->assertStringContainsString(route('static-events'), $html);
|
|
$this->assertStringNotContainsString('Switched off page', $html);
|
|
}
|
|
|
|
public function test_without_its_own_email_logo_a_platform_gets_a_text_logo_with_its_name(): void
|
|
{
|
|
$name = 'Test Platform ' . uniqid();
|
|
$this->platformConfig(['platform_translations.' . app()->getLocale() . '.platform_name' => $name]);
|
|
config([
|
|
'themes.active' => 'uuro',
|
|
'themes.themes.uuro.logos.email_logo' => 'app-images/does-not-exist.png',
|
|
'themes.themes.uuro.logos.email_logo_inverted' => 'app-images/does-not-exist.png',
|
|
]);
|
|
|
|
$paths = [theme_email_logo(), theme_email_logo(true)];
|
|
|
|
try {
|
|
foreach ($paths as $path) {
|
|
$this->assertStringStartsWith('app-images/generated/test-platform-', $path);
|
|
$size = getimagesize(storage_path('app/public/' . $path));
|
|
$this->assertSame([900, 700, 'image/png'], [$size[0], $size[1], $size['mime']]);
|
|
}
|
|
$this->assertNotSame($paths[0], $paths[1]);
|
|
|
|
// Cached: asking again gives the same file
|
|
$this->assertSame($paths[0], theme_email_logo());
|
|
} finally {
|
|
foreach ($paths as $path) {
|
|
@unlink(storage_path('app/public/' . $path));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_the_timebank_cc_theme_falls_back_to_its_own_logo_and_an_uploaded_logo_wins(): void
|
|
{
|
|
// The tracked app_mail_logo.png is the Timebank.cc logo, part of the timebank_cc theme
|
|
config(['themes.active' => 'timebank_cc', 'themes.themes.timebank_cc.logos.email_logo' => 'app-images/does-not-exist.png']);
|
|
$this->assertSame('app-images/app_mail_logo.png', theme_email_logo());
|
|
|
|
// An uploaded theme logo is used, whatever the theme
|
|
config(['themes.active' => 'uuro', 'themes.themes.uuro.logos.email_logo' => 'app-images/app_mail_logo_inverted.png']);
|
|
$this->assertSame('app-images/app_mail_logo_inverted.png', theme_email_logo());
|
|
}
|
|
|
|
public function test_favicons_come_from_the_theme_folder_only_when_it_holds_the_file(): void
|
|
{
|
|
config(['themes.active' => 'uuro', 'themes.themes.uuro.logos.favicon_dir' => null]);
|
|
$this->assertSame(asset('favicon.ico'), theme_favicon('favicon.ico'));
|
|
|
|
// public/ itself holds favicon.ico, so use it as an existing "theme folder" and a missing one
|
|
config(['themes.themes.uuro.logos.favicon_dir' => '/']);
|
|
$this->assertSame(asset('favicon.ico'), theme_favicon('favicon.ico'));
|
|
|
|
config(['themes.themes.uuro.logos.favicon_dir' => 'build']);
|
|
$this->assertSame(asset('favicon.ico'), theme_favicon('favicon.ico'));
|
|
|
|
config(['themes.themes.uuro.logos.favicon_dir' => 'storage/app-images']);
|
|
$this->assertSame(asset('storage/app-images/app_logo.svg'), theme_favicon('app_logo.svg'));
|
|
}
|
|
}
|