feat: Divi read tools accept library entries (library access, E1/E3)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-27 01:02:25 +02:00
co-authored by Claude Opus 5.5
parent 2700fd615a
commit 48ecc627aa
13 changed files with 487 additions and 13 deletions
@@ -7,6 +7,11 @@ namespace LIT\MCP\Tests\Unit\Integrations\Divi\Pages;
use LIT\MCP\Integrations\Divi\Pages\DiviPage;
use LIT\MCP\Integrations\Divi\Pages\DiviPageLoader;
use LIT\MCP\Tests\Support\DiviFixtures;
use LIT\MCP\Integrations\Divi\BlockTree\Parser;
use LIT\MCP\Integrations\Divi\Library\LibraryAccess;
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
use LIT\MCP\Tests\Support\LibraryFixtures;
use Mockery;
use LIT\MCP\Tests\Unit\TestCase;
use WP_Error;
@@ -96,4 +101,49 @@ final class DiviPageLoaderTest extends TestCase
DiviFixtures::givenPost("<!-- wp:paragraph -->\n<p>Gutenberg</p>\n<!-- /wp:paragraph -->");
self::assertToolError($loader->loadWritable(7), 'unsupported');
}
public function testLoadsALibraryItemForReading(): void
{
LibraryFixtures::given([LibraryFixtures::item(1058)]);
$page = LibraryFixtures::loader()->load(1058, false);
self::assertInstanceOf(DiviPage::class, $page);
self::assertTrue($page->isLibraryItem());
self::assertSame('divi/section', $page->index->find('s0')?->name());
self::assertSame('https://kunde.test/wp-admin/post.php?post=1058&action=edit', $page->editUrl());
}
public function testLibraryItemsNeedTheLibraryAccess(): void
{
LibraryFixtures::given([LibraryFixtures::item(1058)]);
$schema = Mockery::mock(ContentSchema::class);
$schema->allows('isManaged')->with('et_pb_layout')->andReturn(false);
self::assertToolError((new DiviPageLoader($schema))->load(1058, false), 'not_found');
self::assertToolError(
(new DiviPageLoader($schema, new Parser(), LibraryFixtures::access(['divi_library'])))->load(1058, false),
'forbidden'
);
}
public function testLibraryItemsAreNotWritableYet(): void
{
LibraryFixtures::given([LibraryFixtures::item(1058)]);
$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');
}
/** Ruling P9: the group "Divi-Bibliothek" disabled hides library entries from the Divi read tools. */
public function testAHiddenLibraryLeavesLibraryItemsNotFound(): void
{
LibraryFixtures::given([LibraryFixtures::item(1058)]);
$hidden = new LibraryAccess(LibraryFixtures::store(), LibraryFixtures::roles(), null, static fn (): bool => false);
self::assertToolError(LibraryFixtures::loader($hidden)->load(1058, false), 'not_found');
}
}