test: fix the P9/P14 backup wording of every VisibleEdits caller (ruling Q17 M3)

VisibleEditsTest asserts the exact refusal messages (no unfiltered_html,
trash disabled) and the keepingBackup() hints for rolled-back and partial
failures with each caller's label and entry. The callers' own tests drive
GlobalEdits, ThemeBuilderEdits (through DiviWriter) and make-global with
revisions off and assert the same sentences.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-27 23:03:05 +02:00
co-authored by Claude Opus 5.5
parent 43dc3fb889
commit 79f2fdbda6
5 changed files with 165 additions and 10 deletions
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Pages;
use Brain\Monkey\Functions;
use LIT\MCP\Abilities\Errors;
use LIT\MCP\Abilities\WriteFailed;
use LIT\MCP\Integrations\Divi\Pages\VisibleEdits;
use LIT\MCP\Tests\Unit\TestCase;
use WP_Post;
/**
* The P9/P14 wording VisibleEdits builds from each caller's label and entry (review I-3, ruling Q17 M3). The
* callers' own tests (GlobalEditsTest, ThemeBuilderEditsTest, DiviWriterThemeBuilderTest,
* LibraryMakeGlobalAbilityTest) drive the real callers with the same sentences.
*/
final class VisibleEditsTest extends TestCase
{
public const UNFAITHFUL = 'Revisionen sind für %s abgeschaltet, und die Sicherungskopie wäre für dieses Konto nicht '
. 'verlustfrei (WordPress filtert HTML); nichts wurde gespeichert.';
public const NO_TRASH = 'Revisionen sind für %s abgeschaltet, und der Papierkorb ist deaktiviert '
. '(EMPTY_TRASH_DAYS = 0) – die Sicherungskopie würde sofort gelöscht; nichts wurde gespeichert.';
public const KEPT = 'Sicherung %d liegt im Papierkorb (vorheriger Stand %s, in WordPress wiederherstellbar).';
/** The hint of keepingBackup() after a clean rollback. */
public static function keptRolledBack(int $backupId, string $entry): string
{
return sprintf(self::KEPT, $backupId, $entry) . ' Den Aufruf erst nach Prüfung mit lit-divi-outline wiederholen.';
}
/** The hint of keepingBackup() after a partial write. */
public static function keptPartial(int $backupId, string $entry): string
{
return 'Den Aufruf nicht einfach wiederholen. ' . sprintf(self::KEPT, $backupId, $entry)
. ' Zuerst den Stand mit lit-divi-outline prüfen und dem Nutzer Bescheid geben.';
}
/** @return array<string, array{string, string}> Label and entry of each caller. */
public static function callers(): array
{
return [
'library entry (GlobalEdits)' => ['Bibliothekseintrag 1059', 'des Bibliothekseintrags'],
'Theme Builder layout (ThemeBuilderEdits)' => ['Theme-Builder-Layout 1062', 'des Theme-Builder-Layouts'],
'page (lit/library-make-global)' => ['Seite 8', 'der Seite'],
];
}
/** @dataProvider callers */
public function testTheBackupRefusalsNameTheEntryAndTheCallersHint(string $label, string $entry): void
{
$post = new WP_Post(['ID' => 1]);
Functions\when('wp_revisions_enabled')->justReturn(false);
Functions\when('current_user_can')->alias(static fn (string $cap): bool => $cap !== 'unfiltered_html');
$visible = new VisibleEdits(static fn (WP_Post $post): int => 1071, static fn (): bool => false);
$unfaithful = $visible->backupRefusal($post, $label, 'Was stattdessen.');
self::assertToolError($unfaithful, 'unsupported');
self::assertSame(sprintf(self::UNFAITHFUL, $label), Errors::clientMessage($unfaithful));
self::assertSame('Was stattdessen.', $unfaithful->get_error_data()['hint']);
Functions\when('current_user_can')->justReturn(true);
$noTrash = $visible->backupRefusal($post, $label, 'Was stattdessen.');
self::assertSame(sprintf(self::NO_TRASH, $label), Errors::clientMessage($noTrash));
self::assertSame('Was stattdessen.', $noTrash->get_error_data()['hint']);
Functions\when('wp_revisions_enabled')->justReturn(true);
self::assertNull($visible->backupRefusal($post, $label, 'Was stattdessen.'));
}
/** @dataProvider callers */
public function testAFailureAfterTheBackupNamesItAndTheEntry(string $label, string $entry): void
{
$rolledBack = VisibleEdits::keepingBackup(WriteFailed::rolledBack('Grund.'), 1071, $entry)->toError();
self::assertToolError($rolledBack, 'write_failed');
self::assertSame(
'Speichern fehlgeschlagen: Grund. ' . Errors::notSavedKeeping('Sicherung 1071 im Papierkorb'),
Errors::clientMessage($rolledBack)
);
self::assertSame(self::keptRolledBack(1071, $entry), $rolledBack->get_error_data()['hint']);
self::assertSame(1071, $rolledBack->get_error_data()['backup_id']);
$partial = VisibleEdits::keepingBackup(WriteFailed::partial('Grund.', postId: 5), 1071, $entry)->toError();
self::assertToolError($partial, 'partial_write');
self::assertSame(self::keptPartial(1071, $entry), $partial->get_error_data()['hint']);
self::assertSame(1071, $partial->get_error_data()['backup_id']);
$withoutBackup = WriteFailed::rolledBack('Grund.');
self::assertSame($withoutBackup, VisibleEdits::keepingBackup($withoutBackup, null, $entry));
}
}