feat: Divi tools write library entries; global ones with dry run, confirm and backup (E2, F2)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -127,15 +127,28 @@ final class DiviPageLoaderTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testLibraryItemsAreNotWritableYet(): void
|
||||
public function testLibraryItemsAreWritableWhateverTheBuilderSettingOfTheirType(): void
|
||||
{
|
||||
LibraryFixtures::given([LibraryFixtures::item(1058)]);
|
||||
LibraryFixtures::given([LibraryFixtures::item(1057)]);
|
||||
$loader = new DiviPageLoader(DiviFixtures::schema(false), new Parser(), LibraryFixtures::access());
|
||||
|
||||
$page = $loader->loadWritable(1057);
|
||||
|
||||
self::assertInstanceOf(DiviPage::class, $page);
|
||||
self::assertTrue($page->isLibraryItem());
|
||||
}
|
||||
|
||||
public function testWritingALibraryItemNeedsTheLibraryAccessAndItsEditRights(): void
|
||||
{
|
||||
LibraryFixtures::given([LibraryFixtures::item(1057)]);
|
||||
$schema = Mockery::mock(ContentSchema::class);
|
||||
$schema->allows('isManaged')->with('et_pb_layout')->andReturn(false);
|
||||
|
||||
$result = (new DiviPageLoader($schema, new Parser(), LibraryFixtures::access()))->load(1058, true);
|
||||
|
||||
self::assertToolError($result, 'not_found');
|
||||
self::assertToolError((new DiviPageLoader($schema))->loadWritable(1057), 'not_found');
|
||||
self::assertToolError(
|
||||
(new DiviPageLoader($schema, new Parser(), LibraryFixtures::access([], false)))->loadWritable(1057),
|
||||
'forbidden'
|
||||
);
|
||||
}
|
||||
|
||||
/** Ruling P9: the group "Divi-Bibliothek" disabled hides library entries from the Divi read tools. */
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace LIT\MCP\Tests\Unit\Integrations\Divi\Pages;
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Abilities\WriteFailed;
|
||||
use LIT\MCP\Integrations\Divi\Pages\DiviSaver;
|
||||
use LIT\MCP\Integrations\Divi\Pages\SaveScope;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use RuntimeException;
|
||||
use WP_Error;
|
||||
@@ -267,4 +268,36 @@ final class DiviSaverTest extends TestCase
|
||||
$this->expectException(RuntimeException::class);
|
||||
(new DiviSaver())->saveNew(42, 'NEU');
|
||||
}
|
||||
|
||||
public function testLibraryItemsGetNoDiviFlagsAndGlobalOnesClearEveryPage(): void
|
||||
{
|
||||
\ET_Core_PageResource::$removed = [];
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
Functions\when('wp_update_post')->justReturn(7);
|
||||
Functions\when('get_post')->justReturn(new WP_Post(['ID' => 7, 'post_content' => 'NEU']));
|
||||
$cleared = [];
|
||||
Functions\when('et_theme_builder_clear_wp_cache')->alias(static function (string $what) use (&$cleared): void {
|
||||
$cleared[] = $what;
|
||||
});
|
||||
|
||||
(new DiviSaver())->save($this->post, 'NEU', SaveScope::LibraryItem);
|
||||
self::assertSame([], array_filter($this->calls, static fn (string $call): bool => str_starts_with($call, 'meta:')));
|
||||
self::assertSame([[7, 'all', true]], \ET_Core_PageResource::$removed);
|
||||
self::assertSame([], $cleared);
|
||||
|
||||
\ET_Core_PageResource::$removed = [];
|
||||
(new DiviSaver())->save($this->post, 'NEU', SaveScope::GlobalItem);
|
||||
self::assertSame([[7, 'all', true], ['all', 'all', true]], \ET_Core_PageResource::$removed);
|
||||
self::assertSame(['all'], $cleared);
|
||||
}
|
||||
|
||||
public function testSaveNewOfALibraryItemSetsNoFlags(): void
|
||||
{
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
Functions\when('wp_update_post')->justReturn(42);
|
||||
Functions\when('get_post')->justReturn(new WP_Post(['ID' => 42, 'post_content' => 'NEU']));
|
||||
|
||||
self::assertSame([], (new DiviSaver())->saveNew(42, 'NEU', SaveScope::LibraryItem));
|
||||
self::assertSame([], array_filter($this->calls, static fn (string $call): bool => str_starts_with($call, 'meta:')));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user