feat: lit/divi-move, lit/divi-delete, lit/divi-duplicate-node
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:
@@ -21,7 +21,7 @@ Direkt sichtbar: `lit-guide`, `lit-site-status`, `lit-content-types`, `lit-conte
|
|||||||
`lit-content-get`, `lit-content-create`, `lit-content-update`, `lit-post-publish`, `lit-media-search`,
|
`lit-content-get`, `lit-content-create`, `lit-content-update`, `lit-post-publish`, `lit-media-search`,
|
||||||
`lit-media-preview`, `lit-media-download`, `lit-media-upload-from-url`, `lit-page-render-summary`,
|
`lit-media-preview`, `lit-media-download`, `lit-media-upload-from-url`, `lit-page-render-summary`,
|
||||||
`lit-divi-outline`, `lit-divi-node-get`, `lit-divi-catalog`, `lit-divi-design-system`, `lit-divi-insert`,
|
`lit-divi-outline`, `lit-divi-node-get`, `lit-divi-catalog`, `lit-divi-design-system`, `lit-divi-insert`,
|
||||||
`lit-divi-update`.
|
`lit-divi-update`, `lit-divi-move`, `lit-divi-delete`.
|
||||||
|
|
||||||
Welche Tools direkt sichtbar sind, lässt sich unter Einstellungen → LIT MCP → Tools ändern (außer bei
|
Welche Tools direkt sichtbar sind, lässt sich unter Einstellungen → LIT MCP → Tools ändern (außer bei
|
||||||
`lit-guide`, das immer direkt bleibt).
|
`lit-guide`, das immer direkt bleibt).
|
||||||
@@ -32,7 +32,7 @@ Status (`lit/post-unpublish`, `lit/post-schedule`, `lit/post-trash`), Kopien (`l
|
|||||||
`lit/post-replace-with-copy`), Revisionen (`lit/revisions-list`, `lit/revision-restore`), Menüs
|
`lit/post-replace-with-copy`), Revisionen (`lit/revisions-list`, `lit/revision-restore`), Menüs
|
||||||
(`lit/menu-list`, `lit/menu-get`, `lit/menu-create`, `lit/menu-set-items`, `lit/menu-assign-location`),
|
(`lit/menu-list`, `lit/menu-get`, `lit/menu-create`, `lit/menu-set-items`, `lit/menu-assign-location`),
|
||||||
Einstellungen (`lit/wp-settings-get`, `lit/wp-settings-update`), Medien (`lit/media-get`, `lit/media-upload`,
|
Einstellungen (`lit/wp-settings-get`, `lit/wp-settings-update`), Medien (`lit/media-get`, `lit/media-upload`,
|
||||||
`lit/media-update`, `lit/media-delete`).
|
`lit/media-update`, `lit/media-delete`), Divi (`lit/divi-duplicate-node`).
|
||||||
|
|
||||||
Die `lit-divi-…`-Werkzeuge gibt es nur, wenn der Divi-5-Builder aktiv ist.
|
Die `lit-divi-…`-Werkzeuge gibt es nur, wenn der Divi-5-Builder aktiv ist.
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ use LIT\MCP\ChangeLog\ChangeLog;
|
|||||||
use LIT\MCP\Integrations\Divi\Design\DesignSystemReader;
|
use LIT\MCP\Integrations\Divi\Design\DesignSystemReader;
|
||||||
use LIT\MCP\Integrations\Divi\Design\DiviDesignSystemAbility;
|
use LIT\MCP\Integrations\Divi\Design\DiviDesignSystemAbility;
|
||||||
use LIT\MCP\Integrations\Divi\Pages\DiviComposition;
|
use LIT\MCP\Integrations\Divi\Pages\DiviComposition;
|
||||||
|
use LIT\MCP\Integrations\Divi\Pages\DiviDeleteAbility;
|
||||||
|
use LIT\MCP\Integrations\Divi\Pages\DiviDuplicateNodeAbility;
|
||||||
use LIT\MCP\Integrations\Divi\Pages\DiviInsertAbility;
|
use LIT\MCP\Integrations\Divi\Pages\DiviInsertAbility;
|
||||||
|
use LIT\MCP\Integrations\Divi\Pages\DiviMoveAbility;
|
||||||
use LIT\MCP\Integrations\Divi\Pages\DiviNodeGetAbility;
|
use LIT\MCP\Integrations\Divi\Pages\DiviNodeGetAbility;
|
||||||
use LIT\MCP\Integrations\Divi\Pages\DiviOutlineAbility;
|
use LIT\MCP\Integrations\Divi\Pages\DiviOutlineAbility;
|
||||||
use LIT\MCP\Integrations\Divi\Pages\DiviPageLoader;
|
use LIT\MCP\Integrations\Divi\Pages\DiviPageLoader;
|
||||||
@@ -59,6 +62,9 @@ final class DiviIntegration implements Integration
|
|||||||
new DiviDesignSystemAbility($this->design),
|
new DiviDesignSystemAbility($this->design),
|
||||||
new DiviInsertAbility($writer),
|
new DiviInsertAbility($writer),
|
||||||
new DiviUpdateAbility($writer),
|
new DiviUpdateAbility($writer),
|
||||||
|
new DiviMoveAbility($writer),
|
||||||
|
new DiviDeleteAbility($writer),
|
||||||
|
new DiviDuplicateNodeAbility($writer),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace LIT\MCP\Integrations\Divi\Pages;
|
||||||
|
|
||||||
|
use LIT\MCP\Abilities\Ability;
|
||||||
|
use LIT\MCP\Abilities\Errors;
|
||||||
|
use LIT\MCP\Abilities\ToolResult;
|
||||||
|
use LIT\MCP\Integrations\Divi\BlockTree\Block;
|
||||||
|
use LIT\MCP\Integrations\Divi\BlockTree\NodeSummary;
|
||||||
|
use WP_Error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lit/divi-delete: removes nodes with everything inside (spec §5.7, destructive). Needs
|
||||||
|
* confirm: true after asking the user; without it the answer lists what would be removed –
|
||||||
|
* nodes inside another node that is deleted anyway do not count twice. The revision in the
|
||||||
|
* result allows undoing it (lit/revision-restore).
|
||||||
|
*/
|
||||||
|
final class DiviDeleteAbility implements Ability
|
||||||
|
{
|
||||||
|
public function __construct(private DiviWriter $writer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function name(): string
|
||||||
|
{
|
||||||
|
return 'lit/divi-delete';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return 'Divi-Knoten löschen';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function description(): string
|
||||||
|
{
|
||||||
|
return 'Entfernt Divi-Knoten samt Inhalt. Erst nach Rückfrage beim Nutzer mit confirm: true; ohne confirm '
|
||||||
|
. 'nennt die Antwort, was entfernt würde. Rückgängig über die Revision in revision_id. tree_rev ist '
|
||||||
|
. 'Pflicht.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function inputSchema(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type' => 'object',
|
||||||
|
'properties' => array_merge(DiviWriter::inputProperties(), [
|
||||||
|
'ids' => [
|
||||||
|
'type' => 'array',
|
||||||
|
'minItems' => 1,
|
||||||
|
'maxItems' => 20,
|
||||||
|
'items' => ['type' => 'string'],
|
||||||
|
'description' => 'Pfad-IDs der zu löschenden Knoten (aus lit-divi-outline).',
|
||||||
|
],
|
||||||
|
'confirm' => ['type' => 'boolean', 'description' => 'true erst nach Rückfrage beim Nutzer.'],
|
||||||
|
]),
|
||||||
|
'required' => ['post_id', 'tree_rev', 'ids'],
|
||||||
|
'additionalProperties' => false,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function outputSchema(): ?array
|
||||||
|
{
|
||||||
|
return ToolResult::schema(['tree_rev' => ['type' => 'string']], ['tree_rev']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function annotations(): array
|
||||||
|
{
|
||||||
|
return ['readonly' => false, 'destructive' => true, 'idempotent' => false];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDirect(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function permission(array $input): bool|WP_Error
|
||||||
|
{
|
||||||
|
$page = $this->writer->page($input);
|
||||||
|
|
||||||
|
return $page instanceof WP_Error ? $page : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(array $input): mixed
|
||||||
|
{
|
||||||
|
$page = $this->writer->page($input);
|
||||||
|
if ($page instanceof WP_Error) {
|
||||||
|
return $page;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var array<string, Block> $nodes */
|
||||||
|
$nodes = [];
|
||||||
|
foreach (is_array($input['ids'] ?? null) ? $input['ids'] : [] as $id) {
|
||||||
|
$node = is_string($id) ? $page->index->find($id) : null;
|
||||||
|
if ($node === null) {
|
||||||
|
return DiviPageLoader::unknownNode((string) $id, $page->post);
|
||||||
|
}
|
||||||
|
$nodes[$id] = $node;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A node inside another node that is deleted anyway needs no own removal.
|
||||||
|
$nodes = array_filter(
|
||||||
|
$nodes,
|
||||||
|
static fn (Block $node, string $id): bool => array_filter(
|
||||||
|
array_keys($nodes),
|
||||||
|
static fn (string $other): bool => $other !== $id && str_starts_with($id, $other . '.')
|
||||||
|
) === [],
|
||||||
|
ARRAY_FILTER_USE_BOTH
|
||||||
|
);
|
||||||
|
|
||||||
|
if (($input['confirm'] ?? false) !== true) {
|
||||||
|
return Errors::confirmRequired(
|
||||||
|
sprintf('%d Divi-Knoten würden samt Inhalt entfernt: %s.', count($nodes), $this->describe($nodes)),
|
||||||
|
['nodes' => array_keys($nodes)]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$editor = $this->writer->composition($page)->editor();
|
||||||
|
$change = new DiviChange(sprintf('%d Divi-Knoten gelöscht', count($nodes)));
|
||||||
|
foreach ($nodes as $id => $node) {
|
||||||
|
$change->removed((string) $id, $node);
|
||||||
|
$editor->remove($page->index, $node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->writer->save($this->name(), $page, $change, $input);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param array<string, Block> $nodes */
|
||||||
|
private function describe(array $nodes): string
|
||||||
|
{
|
||||||
|
$parts = [];
|
||||||
|
foreach ($nodes as $id => $node) {
|
||||||
|
$label = NodeSummary::label($node);
|
||||||
|
$parts[] = sprintf(
|
||||||
|
'%s %s%s (%d Kind-Knoten)',
|
||||||
|
$id,
|
||||||
|
$node->shortName(),
|
||||||
|
$label === '' ? '' : ' "' . $label . '"',
|
||||||
|
count($node->children())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(', ', $parts);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace LIT\MCP\Integrations\Divi\Pages;
|
||||||
|
|
||||||
|
use LIT\MCP\Abilities\Ability;
|
||||||
|
use LIT\MCP\Abilities\ToolResult;
|
||||||
|
use LIT\MCP\Integrations\Divi\BlockTree\AttrMap;
|
||||||
|
use LIT\MCP\Integrations\Divi\BlockTree\NodeSummary;
|
||||||
|
use WP_Error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lit/divi-duplicate-node: copies a node with everything inside right behind the original
|
||||||
|
* (spec §5.7). The copy's admin label gets " (Kopie)"; read-only nodes (global modules,
|
||||||
|
* foreign blocks) are copied unchanged, as a whole, byte-identical reference.
|
||||||
|
*/
|
||||||
|
final class DiviDuplicateNodeAbility implements Ability
|
||||||
|
{
|
||||||
|
public function __construct(private DiviWriter $writer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function name(): string
|
||||||
|
{
|
||||||
|
return 'lit/divi-duplicate-node';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return 'Divi-Knoten duplizieren';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function description(): string
|
||||||
|
{
|
||||||
|
return 'Dupliziert einen Divi-Knoten samt Inhalt direkt hinter das Original; das Admin-Label der Kopie endet '
|
||||||
|
. 'auf „(Kopie)“. tree_rev aus lit-divi-outline ist Pflicht.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function inputSchema(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type' => 'object',
|
||||||
|
'properties' => array_merge(DiviWriter::inputProperties(), [
|
||||||
|
'id' => ['type' => 'string', 'description' => 'Pfad-ID des zu duplizierenden Knotens.'],
|
||||||
|
]),
|
||||||
|
'required' => ['post_id', 'tree_rev', 'id'],
|
||||||
|
'additionalProperties' => false,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function outputSchema(): ?array
|
||||||
|
{
|
||||||
|
return ToolResult::schema(['tree_rev' => ['type' => 'string']], ['tree_rev']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function annotations(): array
|
||||||
|
{
|
||||||
|
return ['readonly' => false, 'destructive' => false, 'idempotent' => false];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDirect(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function permission(array $input): bool|WP_Error
|
||||||
|
{
|
||||||
|
$page = $this->writer->page($input);
|
||||||
|
|
||||||
|
return $page instanceof WP_Error ? $page : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(array $input): mixed
|
||||||
|
{
|
||||||
|
$page = $this->writer->page($input);
|
||||||
|
if ($page instanceof WP_Error) {
|
||||||
|
return $page;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = is_string($input['id'] ?? null) ? $input['id'] : '';
|
||||||
|
$node = $page->index->find($id);
|
||||||
|
if ($node === null) {
|
||||||
|
return DiviPageLoader::unknownNode($id, $page->post);
|
||||||
|
}
|
||||||
|
|
||||||
|
$copy = $this->writer->composition($page)->editor()->duplicate($page->index, $node);
|
||||||
|
if ($copy->isDivi() && ! $copy->isOpaque()) {
|
||||||
|
$label = NodeSummary::label($node);
|
||||||
|
$copy->setAttrs(AttrMap::set($copy->attrs(), 'module.meta.adminLabel', [
|
||||||
|
'desktop' => ['value' => ($label === '' ? $node->shortName() : $label) . ' (Kopie)'],
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
$change = (new DiviChange(sprintf('Knoten %s dupliziert', $id)))->changed($copy, 'duplicated');
|
||||||
|
|
||||||
|
return $this->writer->save($this->name(), $page, $change, $input);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace LIT\MCP\Integrations\Divi\Pages;
|
||||||
|
|
||||||
|
use LIT\MCP\Abilities\Ability;
|
||||||
|
use LIT\MCP\Abilities\Errors;
|
||||||
|
use LIT\MCP\Abilities\ToolResult;
|
||||||
|
use WP_Error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lit/divi-move: moves a node (with everything inside) to parent / before / after – also into
|
||||||
|
* another row or section, as long as the structure rules allow it (spec §5.7). Read-only
|
||||||
|
* nodes (global modules, foreign blocks) move as a whole, unchanged.
|
||||||
|
*/
|
||||||
|
final class DiviMoveAbility implements Ability
|
||||||
|
{
|
||||||
|
public function __construct(private DiviWriter $writer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function name(): string
|
||||||
|
{
|
||||||
|
return 'lit/divi-move';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return 'Divi-Knoten verschieben';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function description(): string
|
||||||
|
{
|
||||||
|
return 'Verschiebt einen Divi-Knoten samt Inhalt an eine neue Stelle (parent, before oder after; auch in '
|
||||||
|
. 'andere Zeilen oder Abschnitte). tree_rev aus lit-divi-outline ist Pflicht.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function inputSchema(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type' => 'object',
|
||||||
|
'properties' => array_merge(
|
||||||
|
DiviWriter::inputProperties(),
|
||||||
|
['id' => ['type' => 'string', 'description' => 'Pfad-ID des zu verschiebenden Knotens.']],
|
||||||
|
DiviWriter::positionProperties()
|
||||||
|
),
|
||||||
|
'required' => ['post_id', 'tree_rev', 'id'],
|
||||||
|
'additionalProperties' => false,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function outputSchema(): ?array
|
||||||
|
{
|
||||||
|
return ToolResult::schema(['tree_rev' => ['type' => 'string']], ['tree_rev']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function annotations(): array
|
||||||
|
{
|
||||||
|
return ['readonly' => false, 'destructive' => false, 'idempotent' => false];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDirect(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function permission(array $input): bool|WP_Error
|
||||||
|
{
|
||||||
|
$page = $this->writer->page($input);
|
||||||
|
|
||||||
|
return $page instanceof WP_Error ? $page : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(array $input): mixed
|
||||||
|
{
|
||||||
|
$page = $this->writer->page($input);
|
||||||
|
if ($page instanceof WP_Error) {
|
||||||
|
return $page;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = is_string($input['id'] ?? null) ? $input['id'] : '';
|
||||||
|
$node = $page->index->find($id);
|
||||||
|
if ($node === null) {
|
||||||
|
return DiviPageLoader::unknownNode($id, $page->post);
|
||||||
|
}
|
||||||
|
|
||||||
|
$editor = $this->writer->composition($page)->editor();
|
||||||
|
$position = $editor->position($page->index, $input);
|
||||||
|
if (is_string($position)) {
|
||||||
|
return Errors::invalidInput('Ungültige Position; nichts wurde gespeichert.', ['position' => $position]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$problem = $editor->move($page->index, $node, $position);
|
||||||
|
if ($problem !== null) {
|
||||||
|
return Errors::invalidInput(
|
||||||
|
'Verschieben nicht möglich; nichts wurde gespeichert.',
|
||||||
|
['position' => $problem]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$change = (new DiviChange(sprintf('Knoten %s verschoben', $id)))->changed($node, 'moved');
|
||||||
|
|
||||||
|
return $this->writer->save($this->name(), $page, $change, $input);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,9 @@ final class DiviIntegrationTest extends TestCase
|
|||||||
'lit/divi-design-system',
|
'lit/divi-design-system',
|
||||||
'lit/divi-insert',
|
'lit/divi-insert',
|
||||||
'lit/divi-update',
|
'lit/divi-update',
|
||||||
|
'lit/divi-move',
|
||||||
|
'lit/divi-delete',
|
||||||
|
'lit/divi-duplicate-node',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function testProvidesTheDiviAbilitiesOnlyWithDivi5(): void
|
public function testProvidesTheDiviAbilitiesOnlyWithDivi5(): void
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ use LIT\MCP\Integrations\Divi\BlockTree\NodeIndex;
|
|||||||
use LIT\MCP\Integrations\Divi\BlockTree\Parser;
|
use LIT\MCP\Integrations\Divi\BlockTree\Parser;
|
||||||
use LIT\MCP\Integrations\Divi\Design\DesignSystemReader;
|
use LIT\MCP\Integrations\Divi\Design\DesignSystemReader;
|
||||||
use LIT\MCP\Integrations\Divi\Pages\DiviComposition;
|
use LIT\MCP\Integrations\Divi\Pages\DiviComposition;
|
||||||
|
use LIT\MCP\Integrations\Divi\Pages\DiviDeleteAbility;
|
||||||
|
use LIT\MCP\Integrations\Divi\Pages\DiviDuplicateNodeAbility;
|
||||||
use LIT\MCP\Integrations\Divi\Pages\DiviInsertAbility;
|
use LIT\MCP\Integrations\Divi\Pages\DiviInsertAbility;
|
||||||
|
use LIT\MCP\Integrations\Divi\Pages\DiviMoveAbility;
|
||||||
use LIT\MCP\Integrations\Divi\Pages\DiviPageLoader;
|
use LIT\MCP\Integrations\Divi\Pages\DiviPageLoader;
|
||||||
use LIT\MCP\Integrations\Divi\Pages\DiviSaver;
|
use LIT\MCP\Integrations\Divi\Pages\DiviSaver;
|
||||||
use LIT\MCP\Integrations\Divi\Pages\DiviUpdateAbility;
|
use LIT\MCP\Integrations\Divi\Pages\DiviUpdateAbility;
|
||||||
@@ -83,6 +86,21 @@ final class DiviWriteAbilitiesTest extends TestCase
|
|||||||
return new DiviUpdateAbility($this->writer);
|
return new DiviUpdateAbility($this->writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function move(): DiviMoveAbility
|
||||||
|
{
|
||||||
|
return new DiviMoveAbility($this->writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function delete(): DiviDeleteAbility
|
||||||
|
{
|
||||||
|
return new DiviDeleteAbility($this->writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function duplicate(): DiviDuplicateNodeAbility
|
||||||
|
{
|
||||||
|
return new DiviDuplicateNodeAbility($this->writer);
|
||||||
|
}
|
||||||
|
|
||||||
/** @return array<string, mixed> The structured error the client sees (message JSON, spec §8.2). */
|
/** @return array<string, mixed> The structured error the client sees (message JSON, spec §8.2). */
|
||||||
private static function clientError(WP_Error $error): array
|
private static function clientError(WP_Error $error): array
|
||||||
{
|
{
|
||||||
@@ -236,6 +254,40 @@ final class DiviWriteAbilitiesTest extends TestCase
|
|||||||
self::assertSame([], $this->saved);
|
self::assertSame([], $this->saved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Ruling S14: move there and back restores the exact bytes; delete of the copy too. */
|
||||||
|
public function testMoveDuplicateAndDelete(): void
|
||||||
|
{
|
||||||
|
$moved = $this->move()->execute([
|
||||||
|
'post_id' => 7, 'tree_rev' => $this->treeRev(), 'id' => 's0.r0.c1.m2', 'parent' => 's1.r0.c0',
|
||||||
|
]);
|
||||||
|
self::assertSame([['id' => 's1.r0.c0.m1', 'type' => 'divi/button', 'action' => 'moved', 'label' => 'Hero – Button']], $moved['changed']);
|
||||||
|
|
||||||
|
$back = $this->move()->execute([
|
||||||
|
'post_id' => 7, 'tree_rev' => Rev::of($this->saved[0]), 'id' => 's1.r0.c0.m1', 'parent' => 's0.r0.c1',
|
||||||
|
]);
|
||||||
|
self::assertSame([['id' => 's0.r0.c1.m2', 'type' => 'divi/button', 'action' => 'moved', 'label' => 'Hero – Button']], $back['changed']);
|
||||||
|
self::assertSame($this->original, $this->saved[1], 'move there and back restores the exact bytes (S14)');
|
||||||
|
|
||||||
|
$duplicated = $this->duplicate()->execute([
|
||||||
|
'post_id' => 7, 'tree_rev' => $this->treeRev(), 'id' => 's1',
|
||||||
|
]);
|
||||||
|
self::assertSame('s2', $duplicated['changed'][0]['id']);
|
||||||
|
self::assertSame('Leistungen (Kopie)', $duplicated['changed'][0]['label']);
|
||||||
|
|
||||||
|
$delete = $this->delete();
|
||||||
|
$ask = $delete->execute(['post_id' => 7, 'tree_rev' => Rev::of($this->saved[2]), 'ids' => ['s2', 's2.r0']]);
|
||||||
|
self::assertSame('lit_confirm_required', $ask->get_error_code());
|
||||||
|
self::assertSame(
|
||||||
|
'1 Divi-Knoten würden samt Inhalt entfernt: s2 section "Leistungen (Kopie)" (1 Kind-Knoten).',
|
||||||
|
json_decode($ask->get_error_message(), true)['message']
|
||||||
|
);
|
||||||
|
|
||||||
|
$deleted = $delete->execute(['post_id' => 7, 'tree_rev' => Rev::of($this->saved[2]), 'ids' => ['s2'], 'confirm' => true]);
|
||||||
|
self::assertSame([['id' => 's2', 'type' => 'divi/section', 'action' => 'deleted', 'label' => 'Leistungen (Kopie)']], $deleted['changed']);
|
||||||
|
self::assertSame($this->saved[1], $this->saved[3], 'deleting the copy restores the exact bytes');
|
||||||
|
self::assertTrue($delete->annotations()['destructive']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testReadOnlyNodesCannotBeUpdated(): void
|
public function testReadOnlyNodesCannotBeUpdated(): void
|
||||||
{
|
{
|
||||||
$this->post->post_content = DiviPageLoaderTest::fixture('synthetic-mixed.html');
|
$this->post->post_content = DiviPageLoaderTest::fixture('synthetic-mixed.html');
|
||||||
|
|||||||
Reference in New Issue
Block a user