65 lines
2.5 KiB
PHP
65 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use Symfony\Component\Process\Process;
|
|
use Tests\TestCase;
|
|
|
|
class AppearanceTest extends TestCase
|
|
{
|
|
#[DataProvider('appearanceCookies')]
|
|
public function test_initial_render_uses_a_validated_theme(?string $cookie, string $expected): void
|
|
{
|
|
if ($cookie !== null) {
|
|
$this->withUnencryptedCookie('appearance', $cookie);
|
|
}
|
|
|
|
$response = $this->get(route('home'));
|
|
$response->assertOk()
|
|
->assertSee('data-appearance="'.$expected.'"', false)
|
|
->assertInertia(fn (Assert $page) => $page->where('appearance', $expected))
|
|
->assertDontSee('fonts.bunny.net', false)
|
|
->assertDontSee('Instrument Sans', false)
|
|
->assertSee('fonts/inter/InterVariable.woff2', false);
|
|
|
|
preg_match('/<html[^>]+>/', $response->getContent(), $matches);
|
|
$this->assertSame($expected === 'dark', str_contains($matches[0], 'class="dark"'));
|
|
$this->assertStringContainsString(file_get_contents(resource_path('css/theme.css')), $response->getContent());
|
|
}
|
|
|
|
/** @return array<string, array{?string, string}> */
|
|
public static function appearanceCookies(): array
|
|
{
|
|
return [
|
|
'default' => [null, 'system'],
|
|
'light' => ['light', 'light'],
|
|
'dark' => ['dark', 'dark'],
|
|
'system' => ['system', 'system'],
|
|
'invalid' => ['invalid', 'system'],
|
|
'empty' => ['', 'system'],
|
|
'malformed' => ['</script><script>alert(1)</script>', 'system'],
|
|
];
|
|
}
|
|
|
|
public function test_theme_behaviour_and_contrast(): void
|
|
{
|
|
$process = new Process(['node', 'tests/Fixtures/appearance.mjs'], base_path());
|
|
$process->setTimeout(60);
|
|
$process->run();
|
|
|
|
$this->assertTrue($process->isSuccessful(), $process->getOutput().$process->getErrorOutput());
|
|
$this->assertStringContainsString('Appearance behavior checks passed.', $process->getOutput());
|
|
}
|
|
|
|
public function test_inter_is_bundled_with_its_license(): void
|
|
{
|
|
foreach (['InterVariable.woff2', 'InterVariable-Italic.woff2'] as $font) {
|
|
$this->assertSame('wOF2', file_get_contents(public_path('fonts/inter/'.$font), false, null, 0, 4));
|
|
}
|
|
|
|
$this->assertStringContainsString('SIL OPEN FONT LICENSE', file_get_contents(public_path('fonts/inter/LICENSE.txt')));
|
|
}
|
|
}
|