fix: final review minors m-1 to m-8

- m-1: the no-change Divi result carries preview_url/edit_url too
- m-2: overview names replace-text's per-page tree_rev
- m-3: divi-shortform documents validation_failed vs not_found for unknown IDs
- m-4: DiviWriter/DiviPageLoader final (no mocks left), neutral NewDraft
  log detail, snapshots are Etappe 4
- m-5: Tested up to 7.1, changelog completed
- m-6: content-create warns when the extras changed the stored layout
- m-7: deleting a whole section outlines nothing instead of the next one
- m-8: uninstall removes the user meta lit_mcp_log_per_page; readme lists it

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-26 19:35:24 +02:00
co-authored by Claude Opus 5.5
parent b24eb6c3e9
commit 097fef2e32
15 changed files with 136 additions and 21 deletions
@@ -105,10 +105,43 @@ final class DiviWriterTest extends TestCase
$writer = $this->writer($saver, FakeChangeLog::forbidden());
$page = $writer->page(['post_id' => 7, 'tree_rev' => Rev::of($content)]);
Functions\when('get_preview_post_link')->justReturn('https://kunde.test/?page_id=7&preview=true');
$result = $writer->save('lit/divi-update', $page, new DiviChange('nichts'), []);
self::assertSame(Rev::of($content), $result['tree_rev']);
self::assertStringStartsWith('Keine Änderung', $result['summary']);
// Review m-1: the same result shape as a save, URLs included.
self::assertSame('https://kunde.test/?page_id=7&et_fb=1', $result['edit_url']);
self::assertSame('https://kunde.test/?page_id=7&preview=true', $result['preview_url']);
}
/** Review m-7: a deleted whole section has no section left to outline (its ID now names the next one). */
public function testDeletingAWholeSectionOutlinesNothing(): void
{
$content = DiviFixtures::markup('synthetic-basic.html');
DiviFixtures::givenPost($content);
$saver = Mockery::mock(DiviSaver::class);
$saver->allows('save')->andReturnUsing(static function (WP_Post $post, string $new): array {
DiviFixtures::givenPost($new);
return ['revision_id' => 811, 'warnings' => []];
});
$input = ['post_id' => 7, 'tree_rev' => Rev::of($content)];
Functions\when('do_action')->justReturn(null);
Functions\when('get_preview_post_link')->justReturn('https://kunde.test/?page_id=7&preview=true');
$writer = $this->writer($saver, new FakeChangeLog(55));
$page = $writer->page($input);
$section = $page->index->find('s0');
$page->document->children()[0]->removeChild($section);
$result = $writer->save('lit/divi-delete', $page, (new DiviChange('gelöscht'))->removed('s0', $section), $input);
self::assertNull($result['outline']);
self::assertSame([['s0', 'divi/section', 'deleted']], array_map(
static fn (array $c): array => [$c['id'], $c['type'], $c['action']],
$result['changed']
));
}
public function testSavesAndReportsChangedNodesOutlineAndTheNewTreeRev(): void
@@ -123,6 +123,46 @@ final class ContentCreateDiviTest extends TestCase
self::assertArrayHasKey('divi', $this->ability(null)->inputSchema()['properties']);
}
/**
* Review m-6: the extras are written after the layout; if that re-saves the entry (e.g. Pods
* object fields call wp_update_post, a save_post listener) and the layout changes, say so.
*/
public function testALayoutChangedByTheExtrasIsReported(): void
{
$composer = $this->composer();
$composer->allows('write')->andReturn(['warnings' => [], 'outline' => 's0 divi/section']);
Functions\when('wp_insert_post')->justReturn(42);
$this->stubStoredDraft();
$writer = Mockery::mock(PostWriter::class);
$writer->allows('prepare')->andReturn(['fields' => [], 'terms' => [], 'warnings' => []]);
$writer->allows('postData')->andReturn(['post_title' => 'Start']);
$writer->allows('deniedMeta')->andReturn([]);
$writer->expects('writeExtras')->andReturnUsing(static function (): void {
Functions\when('get_post')->justReturn(new WP_Post([
'ID' => 42, 'post_title' => 'Start', 'post_type' => 'page', 'post_status' => 'draft',
'post_content' => '<!-- wp:divi/placeholder /-->',
]));
});
$result = $this->ability($composer, $writer)->execute(self::INPUT + ['fields' => ['role' => 'x']]);
self::assertSame(Rev::of('<!-- wp:divi/placeholder /-->'), $result['tree_rev'], 'the stored state');
self::assertContains(ContentCreateAbility::LAYOUT_CHANGED, $result['warnings']);
$this->stubStoredDraft();
$unchanged = $this->ability($this->composerWriting(), $this->writer())->execute(self::INPUT);
self::assertNotContains(ContentCreateAbility::LAYOUT_CHANGED, $unchanged['warnings']);
}
/** @return ContentComposer&MockInterface */
private function composerWriting(): ContentComposer
{
$composer = $this->composer();
$composer->allows('write')->andReturn(['warnings' => [], 'outline' => null]);
return $composer;
}
public function testWithoutDiviTheComposerIsNotUsed(): void
{
$composer = Mockery::mock(ContentComposer::class);
@@ -33,7 +33,7 @@ final class NewDraftTest extends TestCase
self::assertSame(42, $e->postId);
self::assertSame('Grund für den Client.', $e->reason);
self::assertSame(
'Extras of new post 42 could not be written: layout kaputt; rollback: term 15 bleibt; '
'Writing new post 42 failed after the insert: layout kaputt; rollback: term 15 bleibt; '
. 'draft 42 could not be deleted: delete_post hook kaputt [rollback incomplete]',
$e->getMessage()
);
+1
View File
@@ -35,6 +35,7 @@ final class UninstallTest extends TestCase
Functions\expect('restore_current_blog')->twice();
Functions\expect('delete_transient')->twice()->with(ConnectionStatus::ENDPOINT_TRANSIENT);
Functions\expect('wp_clear_scheduled_hook')->twice()->with(ChangeLogCleanup::HOOK);
Functions\expect('delete_metadata')->once()->with('user', 0, 'lit_mcp_log_per_page', '', true);
$deleted = [];
Functions\when('delete_option')->alias(static function (string $option) use (&$deleted): bool {
$deleted[] = $option;
+4
View File
@@ -8,6 +8,7 @@ use Brain\Monkey\Functions;
use LIT\MCP\Abilities\ExposurePolicy;
use LIT\MCP\Access;
use LIT\MCP\Admin\ConnectionStatus;
use LIT\MCP\Admin\LogTab;
use LIT\MCP\ChangeLog\ChangeLogCleanup;
use LIT\MCP\ChangeLog\ChangeLogInstaller;
use LIT\MCP\Limits;
@@ -37,6 +38,8 @@ final class UninstallerTest extends TestCase
Functions\expect('restore_current_blog')->never();
Functions\expect('delete_transient')->once()->with(ConnectionStatus::ENDPOINT_TRANSIENT);
Functions\expect('wp_clear_scheduled_hook')->once()->with(ChangeLogCleanup::HOOK);
// Review m-8: the Protokoll screen option is user meta (network-wide): removed once.
Functions\expect('delete_metadata')->once()->with('user', 0, LogTab::PER_PAGE_OPTION, '', true);
$deleted = [];
Functions\when('delete_option')->alias(static function (string $option) use (&$deleted): bool {
$deleted[] = $option;
@@ -62,6 +65,7 @@ final class UninstallerTest extends TestCase
Functions\expect('restore_current_blog')->twice();
Functions\expect('delete_transient')->twice()->with(ConnectionStatus::ENDPOINT_TRANSIENT);
Functions\expect('wp_clear_scheduled_hook')->twice()->with(ChangeLogCleanup::HOOK);
Functions\expect('delete_metadata')->once()->with('user', 0, LogTab::PER_PAGE_OPTION, '', true);
Functions\when('delete_option')->justReturn(true);
Uninstaller::run();