fix: FontInstaller prüft Divis Schriftenliste vor font_add; leere Installation ist ein sauberer Rollback

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-19 18:27:02 +02:00
co-authored by Claude Sonnet 5.5
parent 901179de62
commit 2b45f1bdd3
4 changed files with 51 additions and 1 deletions
@@ -464,6 +464,24 @@ final class DiviFontsUploadAbilityTest extends TestCase
$this->assertTempFilesRemoved();
}
public function testAnInstallThatStoredNothingIsACleanRollback(): void
{
$installer = self::installer();
$installer->allows('install')->andReturn([]);
$installer->expects('remove')->never();
$log = FakeChangeLog::partialsOnly();
try {
$this->ability($installer, $log)->execute(self::input(['confirm' => true]));
self::fail('WriteFailed expected');
} catch (WriteFailed $e) {
self::assertTrue($e->rolledBack);
$error = self::assertToolError($e->toError(), 'write_failed');
self::assertStringContainsString('nichts gespeichert', $error['message']);
}
self::assertSame([], $log->partials);
}
public function testAPartialInstallThatCannotBeRemovedIsAPartialWrite(): void
{
$installer = self::installer();
@@ -37,6 +37,7 @@ final class FontInstallerTest extends TestCase
protected function setUp(): void
{
parent::setUp();
Functions\when('get_option')->justReturn([]);
Functions\when('sanitize_file_name')->alias(static fn (string $name): string => str_replace(' ', '-', $name));
}
@@ -83,6 +84,7 @@ final class FontInstallerTest extends TestCase
);
self::assertSame('AiAgentImageUtility::install_to_custom_fonts()', $manifest->mirrors[0]->label());
self::assertSame([DiviFeature::FontUpload], $manifest->features);
self::assertSame(['et_uploaded_fonts'], $manifest->keys);
}
public function testInstallNeedsAReleasedDivi(): void
@@ -204,6 +206,21 @@ final class FontInstallerTest extends TestCase
);
}
/** @runInSeparateProcess */
public function testACorruptFontListStopsTheInstallBeforeFontAdd(): void
{
$woff2 = $this->tempFile('wOF2DATA');
Functions\when('get_option')->justReturn('kaputt');
Mockery::mock('alias:' . self::HOOKS)->allows('check_filetype_and_ext_font')
->andReturn(['ext' => 'woff2', 'type' => 'font/woff2', 'proper_filename' => 'Inter.woff2']);
Mockery::mock('alias:' . self::FONTS)->expects('font_add')->never();
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('et_uploaded_fonts');
(new FontInstaller())->install('Inter', ['woff2' => $woff2], 'all', 'sans-serif');
}
/** @runInSeparateProcess */
public function testAFileDivisTypeCheckRefusesStopsTheInstallBeforeFontAdd(): void
{