- tests/UploadTest.php prüft den SVG-Filter (Skripte, Event-Handler, javascript:-Verweise) und Upload::isLocal gegen Pfad-Tricks - tests/UiTest.php prüft Versionsstempel, Media-Pfade und die Branding-Overrides inklusive Abweisung ungültiger Farbwerte - PHPStan analysiert jetzt auch includes/Ui.php und includes/Upload.php - CI vergleicht die Sprachdateien (gleiche Schlüsselmenge) und prüft, dass jeder im Code verwendete Schlüssel existiert Dabei aufgefallen und behoben: Upload.php rief __() direkt auf und wäre außerhalb einer Seite mit geladener I18n mit einem Fatal Error abgebrochen; jetzt gibt es einen Fallback auf die deutsche Meldung. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
93 lines
2.8 KiB
PHP
93 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
require_once __DIR__ . '/../includes/Ui.php';
|
|
|
|
/**
|
|
* Sehr einfache Datenbank-Attrappe: liefert nur Einstellungen zurueck.
|
|
*/
|
|
class FakeSettings
|
|
{
|
|
/** @var array<string, string> */
|
|
private array $values;
|
|
|
|
/** @param array<string, string> $values */
|
|
public function __construct(array $values = [])
|
|
{
|
|
$this->values = $values;
|
|
}
|
|
|
|
public function getSetting(string $key, $default = null)
|
|
{
|
|
return $this->values[$key] ?? $default;
|
|
}
|
|
}
|
|
|
|
class UiTest extends TestCase
|
|
{
|
|
public function testAssetUrlCarriesVersionStamp(): void
|
|
{
|
|
$url = \Ui::asset('assets/global.css');
|
|
|
|
$this->assertStringStartsWith('assets/global.css?v=', $url);
|
|
$this->assertMatchesRegularExpression('/\?v=\d+$/', $url);
|
|
}
|
|
|
|
public function testAssetUrlRespectsBasePath(): void
|
|
{
|
|
$this->assertStringStartsWith('../assets/global.css?v=', \Ui::asset('assets/global.css', '../'));
|
|
}
|
|
|
|
public function testBrandingStyleIsEmptyForDefaults(): void
|
|
{
|
|
$db = new FakeSettings([
|
|
'brand_accent' => \Ui::DEFAULT_ACCENT,
|
|
'brand_accent_dark' => \Ui::DEFAULT_ACCENT_DARK,
|
|
'brand_gradient_from' => \Ui::DEFAULT_GRADIENT_FROM,
|
|
'brand_gradient_to' => \Ui::DEFAULT_GRADIENT_TO,
|
|
'brand_radius' => (string)\Ui::DEFAULT_RADIUS,
|
|
]);
|
|
|
|
$this->assertSame('', \Ui::brandingStyle($db));
|
|
$this->assertSame('', \Ui::brandingStyle(null));
|
|
}
|
|
|
|
public function testBrandingStyleUsesCustomColour(): void
|
|
{
|
|
$style = \Ui::brandingStyle(new FakeSettings(['brand_accent' => '#0F766E']));
|
|
|
|
$this->assertStringContainsString('--accent:#0f766e', $style);
|
|
$this->assertStringContainsString('[data-theme="dark"]', $style);
|
|
}
|
|
|
|
public function testBrandingStyleIgnoresInvalidColour(): void
|
|
{
|
|
$style = \Ui::brandingStyle(new FakeSettings(['brand_accent' => 'rot; background:url(x)']));
|
|
|
|
$this->assertSame('', $style, 'Ungueltige Farben duerfen keinen Override erzeugen');
|
|
}
|
|
|
|
public function testBrandingRadiusIsClamped(): void
|
|
{
|
|
$style = \Ui::brandingStyle(new FakeSettings(['brand_radius' => '999']));
|
|
|
|
$this->assertStringContainsString('--r-lg:28px', $style);
|
|
}
|
|
|
|
public function testMediaUrlKeepsAbsoluteAddresses(): void
|
|
{
|
|
$this->assertSame('https://cdn.example.com/logo.svg', \Ui::mediaUrl('https://cdn.example.com/logo.svg', '../'));
|
|
$this->assertSame('/logo.svg', \Ui::mediaUrl('/logo.svg', '../'));
|
|
$this->assertSame('', \Ui::mediaUrl('', '../'));
|
|
}
|
|
|
|
public function testMediaUrlPrefixesUploads(): void
|
|
{
|
|
$this->assertSame('../uploads/logo.png', \Ui::mediaUrl('uploads/logo.png', '../'));
|
|
}
|
|
}
|