Some checks are pending
CI / PHP Lint (push) Waiting to run
CI / PHP Lint-1 (push) Waiting to run
CI / Unit Tests & Static Analysis (push) Waiting to run
CI / PHP Lint (pull_request) Successful in 35s
CI / PHP Lint-1 (pull_request) Successful in 46s
CI / Unit Tests & Static Analysis (pull_request) Successful in 37s
Die Lizenzhinweise standen bisher nur in den Dateien. Unter Integration & Wartung gibt es jetzt eine Karte "Über diese Installation" mit Version, PHP-Version, Lizenz, Entwickler und Quellcode sowie einer Tabelle der mitgelieferten Komponenten Dritter, die direkt auf die ausgelieferten Lizenztexte verlinkt. Die Liste kommt aus Ui::thirdParty(), damit Oberfläche und THIRD-PARTY-NOTICES.md nicht auseinanderlaufen; drei Tests prüfen, dass jede gelistete Komponente ihren Lizenztext wirklich mitliefert, in den Notices auftaucht und LICENSE vorhanden ist. Außerdem: - docker-publish.yml entfernt – der Workflow veröffentlichte nach ghcr.io und stammte noch aus der GitHub-Zeit - Readme: der Actions-Runner läuft jetzt, entsprechende Hinweise angepasst; Test-Badge durch das echte CI-Badge der Forgejo-Instanz ersetzt Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
131 lines
4.2 KiB
PHP
131 lines
4.2 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', '../'));
|
|
}
|
|
|
|
/**
|
|
* Die Uebersicht in der Administration und THIRD-PARTY-NOTICES.md duerfen
|
|
* nicht auseinanderlaufen: jede gelistete Komponente muss ihren
|
|
* Lizenztext wirklich mitliefern.
|
|
*/
|
|
public function testEveryThirdPartyComponentShipsItsLicence(): void
|
|
{
|
|
$root = dirname(__DIR__);
|
|
|
|
foreach (\Ui::thirdParty() as $component) {
|
|
$this->assertFileExists(
|
|
$root . '/' . $component['license_file'],
|
|
'Lizenztext fehlt fuer ' . $component['name']
|
|
);
|
|
$this->assertNotSame('', trim($component['license']), 'Lizenz fehlt fuer ' . $component['name']);
|
|
$this->assertNotSame('', trim($component['version']), 'Version fehlt fuer ' . $component['name']);
|
|
}
|
|
}
|
|
|
|
public function testThirdPartyComponentsAreListedInTheNotices(): void
|
|
{
|
|
$notices = (string)file_get_contents(dirname(__DIR__) . '/THIRD-PARTY-NOTICES.md');
|
|
|
|
foreach (\Ui::thirdParty() as $component) {
|
|
$this->assertStringContainsString(
|
|
$component['name'],
|
|
$notices,
|
|
$component['name'] . ' fehlt in THIRD-PARTY-NOTICES.md'
|
|
);
|
|
}
|
|
}
|
|
|
|
public function testProjectLicenceFileExists(): void
|
|
{
|
|
$this->assertFileExists(dirname(__DIR__) . '/LICENSE');
|
|
$this->assertStringContainsString('MIT License', (string)file_get_contents(dirname(__DIR__) . '/LICENSE'));
|
|
}
|
|
}
|