fix: guard revision-restore follow-ups, mark divi revisions
RevisionRestoreAbility now wraps the after-save action and change-log write in FollowUp::run() and reports failures as warnings instead of letting them turn a saved restore into an error response, matching ContentUpdateAbility; a failed wp_restore_post_revision() is now Errors::writeFailed() (nothing was changed) instead of unsupported(). RevisionsListAbility marks each item divi (reusing PostPresenter::usesDivi()/DIVI_HINT) since a Divi/block revision's excerpt is stripped markup, not prose. 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:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\WordPress\Revisions;
|
||||
|
||||
use Brain\Monkey\Actions;
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Abilities\Rev;
|
||||
use LIT\MCP\ChangeLog\ChangeLog;
|
||||
@@ -11,6 +12,7 @@ use LIT\MCP\Integrations\WordPress\Revisions\RevisionRestoreAbility;
|
||||
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use Mockery;
|
||||
use RuntimeException;
|
||||
use WP_Post;
|
||||
|
||||
final class RevisionRestoreAbilityTest extends TestCase
|
||||
@@ -111,5 +113,56 @@ final class RevisionRestoreAbilityTest extends TestCase
|
||||
self::assertSame(813, $result['revision_id']);
|
||||
self::assertSame('restored', $result['changed'][0]['action']);
|
||||
self::assertStringContainsString('2026-09-20 10:00:00', $result['summary']);
|
||||
self::assertStringContainsString('Status unverändert: publish', $result['summary']);
|
||||
self::assertSame([], $result['warnings']);
|
||||
}
|
||||
|
||||
public function testRestoreFailureIsWriteFailed(): void
|
||||
{
|
||||
Functions\when('wp_save_post_revision')->justReturn(813);
|
||||
Functions\when('wp_get_post_revisions')->justReturn([813 => new WP_Post(['ID' => 813])]);
|
||||
Functions\when('wp_restore_post_revision')->justReturn(false);
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->expects('record')->never();
|
||||
|
||||
$result = $this->ability($log)->execute([
|
||||
'revision_id' => 810,
|
||||
'confirm' => true,
|
||||
'rev' => $this->currentRev(),
|
||||
]);
|
||||
|
||||
self::assertSame('lit_write_failed', $result->get_error_code());
|
||||
}
|
||||
|
||||
public function testFailuresAfterTheWriteOnlyAddWarnings(): void
|
||||
{
|
||||
Functions\when('wp_save_post_revision')->justReturn(813);
|
||||
Functions\when('wp_get_post_revisions')->justReturn([813 => new WP_Post(['ID' => 813])]);
|
||||
Functions\when('wp_restore_post_revision')->justReturn(5);
|
||||
Functions\when('get_preview_post_link')->justReturn('');
|
||||
Functions\when('get_edit_post_link')->justReturn('');
|
||||
Actions\expectDone('lit_mcp_after_save')->once()->whenHappen(static function (): void {
|
||||
throw new RuntimeException('listener kaputt');
|
||||
});
|
||||
$log = Mockery::mock(ChangeLog::class);
|
||||
$log->expects('record')->andThrow(new RuntimeException('db weg'));
|
||||
$file = (string) tempnam(sys_get_temp_dir(), 'lit-mcp-log');
|
||||
$previous = ini_set('error_log', $file);
|
||||
|
||||
try {
|
||||
$result = $this->ability($log)->execute([
|
||||
'revision_id' => 810,
|
||||
'confirm' => true,
|
||||
'rev' => $this->currentRev(),
|
||||
]);
|
||||
} finally {
|
||||
ini_set('error_log', (string) $previous);
|
||||
}
|
||||
|
||||
self::assertTrue($result['ok']);
|
||||
self::assertNull($result['log_id']);
|
||||
self::assertCount(2, $result['warnings']);
|
||||
self::assertStringContainsString('listener kaputt', (string) file_get_contents($file));
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user