fix: Task 7 review round 1 - copy the raw admin label verbatim on duplicate

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-26 16:02:33 +02:00
co-authored by Claude Opus 5.5
parent 17402549c5
commit ede0221b50
2 changed files with 65 additions and 5 deletions
@@ -7,6 +7,7 @@ namespace LIT\MCP\Tests\Unit\Integrations\Divi\Pages;
use Brain\Monkey\Functions;
use LIT\MCP\Abilities\Rev;
use LIT\MCP\ChangeLog\ChangeLog;
use LIT\MCP\Integrations\Divi\BlockTree\AttrMap;
use LIT\MCP\Integrations\Divi\BlockTree\NodeIndex;
use LIT\MCP\Integrations\Divi\BlockTree\Parser;
use LIT\MCP\Integrations\Divi\Design\DesignSystemReader;
@@ -458,6 +459,60 @@ final class DiviWriteAbilitiesTest extends TestCase
self::assertSame(str_replace($globalRow, $globalRow . $globalRow, $mixed), $this->saved[0]);
}
/**
* Fix round 1 (Important-1): the copy's admin label must be the raw stored desktop value
* plus " (Kopie)" – never NodeSummary::label()'s display-shortened text (80-char limit).
*/
public function testDuplicateCopiesALongAdminLabelVerbatim(): void
{
$long = str_repeat('Ausführliche Beschriftung, ', 4) . 'Ende';
self::assertGreaterThan(80, strlen($long), 'precondition: longer than the NodeSummary::label() display limit');
$content = str_replace(
'"module":{"meta":{"adminLabel":{"desktop":{"value":"Hero – Button"}}}}',
'"module":{"meta":{"adminLabel":{"desktop":{"value":"' . $long . '"}}}}',
$this->original
);
self::assertNotSame($content, $this->original, 'precondition: replaced exactly once');
$this->post->post_content = $content;
$result = $this->duplicate()->execute(['post_id' => 7, 'tree_rev' => Rev::of($content), 'id' => 's0.r0.c1.m2']);
self::assertTrue($result['ok'], (string) json_encode($result));
$index = NodeIndex::build((new Parser())->parse($this->saved[0]));
$copy = $index->find('s0.r0.c1.m3');
self::assertNotNull($copy, 'the duplicate sits right after the original module');
self::assertSame(
$long . ' (Kopie)',
AttrMap::desktop($copy->attrs(), 'module.meta.adminLabel'),
'stored verbatim, not shortened/ellipsised for display'
);
}
public function testDuplicateCopiesALabelWithNewlinesAndMultipleSpacesVerbatim(): void
{
$messy = "Erste Zeile mit viel Leerraum\nZweite Zeile";
$encoded = substr((string) json_encode($messy, JSON_UNESCAPED_UNICODE), 1, -1);
$content = str_replace(
'"module":{"meta":{"adminLabel":{"desktop":{"value":"Hero – Button"}}}}',
'"module":{"meta":{"adminLabel":{"desktop":{"value":"' . $encoded . '"}}}}',
$this->original
);
self::assertNotSame($content, $this->original, 'precondition: replaced exactly once');
$this->post->post_content = $content;
$result = $this->duplicate()->execute(['post_id' => 7, 'tree_rev' => Rev::of($content), 'id' => 's0.r0.c1.m2']);
self::assertTrue($result['ok'], (string) json_encode($result));
$index = NodeIndex::build((new Parser())->parse($this->saved[0]));
$copy = $index->find('s0.r0.c1.m3');
self::assertNotNull($copy, 'the duplicate sits right after the original module');
self::assertSame(
$messy . ' (Kopie)',
AttrMap::desktop($copy->attrs(), 'module.meta.adminLabel'),
'whitespace/newlines kept verbatim, not collapsed'
);
}
/** Permission denied (edit_post false) for all three new abilities. */
public function testPermissionDeniedWhenNotEditable(): void
{