feat: Divi adapters for roles and library with a live compatibility check
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\DiviCompatibility;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RuntimeException;
|
||||
|
||||
final class DiviCompatibilityTest extends TestCase
|
||||
{
|
||||
public function testListsFailedAndThrowingChecks(): void
|
||||
{
|
||||
$compatibility = new DiviCompatibility([
|
||||
'A' => static fn (): bool => true,
|
||||
'B' => static fn (): bool => false,
|
||||
'C' => static function (): bool {
|
||||
throw new RuntimeException('Divi changed');
|
||||
},
|
||||
]);
|
||||
|
||||
self::assertSame(['B', 'C'], $compatibility->problems());
|
||||
}
|
||||
|
||||
public function testDefaultsCoverTheDiviInternalsInUse(): void
|
||||
{
|
||||
self::assertSame(
|
||||
[
|
||||
'ModuleRegistration (Modul-Katalog)',
|
||||
'DynamicContentOptions (Dynamic Content)',
|
||||
'et_pb_is_allowed (Divi-Rollen)',
|
||||
'Post-Typ et_pb_layout (Bibliothek)',
|
||||
'Taxonomien scope, layout_type, module_width (Bibliothek)',
|
||||
'GlobalLayout::is_global_layout_template (globale Module)',
|
||||
'ET_Core_PageResource (CSS-Cache)',
|
||||
],
|
||||
array_keys(DiviCompatibility::defaults())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Library;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Integrations\Divi\Library\DiviLibraryStore;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use WP_Post;
|
||||
use WP_Term;
|
||||
|
||||
final class DiviLibraryStoreTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$terms = [
|
||||
1058 => [
|
||||
'scope' => [new WP_Term(['slug' => 'global', 'name' => 'global'])],
|
||||
'layout_type' => [new WP_Term(['slug' => 'section', 'name' => 'section'])],
|
||||
'layout_category' => [new WP_Term(['slug' => 'kopf', 'name' => 'Kopfbereiche'])],
|
||||
],
|
||||
1055 => [
|
||||
'scope' => [new WP_Term(['slug' => 'non_global', 'name' => 'non_global'])],
|
||||
'layout_type' => [new WP_Term(['slug' => 'section', 'name' => 'section'])],
|
||||
],
|
||||
1057 => [],
|
||||
];
|
||||
Functions\when('get_the_terms')->alias(
|
||||
static fn (int $id, string $taxonomy): array|false => $terms[$id][$taxonomy] ?? false
|
||||
);
|
||||
Functions\when('get_post_meta')->alias(
|
||||
static fn (int $id, string $key): string => $id === 1057 && $key === '_et_pb_module_type' ? 'divi/blurb' : ''
|
||||
);
|
||||
}
|
||||
|
||||
public function testGlobalScopeAndLayoutTypeFromTheTerms(): void
|
||||
{
|
||||
$store = new DiviLibraryStore();
|
||||
|
||||
self::assertTrue($store->isGlobal(1058));
|
||||
self::assertFalse($store->isGlobal(1055));
|
||||
self::assertSame('section', $store->layoutType(1058));
|
||||
self::assertNull($store->layoutType(1057));
|
||||
self::assertSame(['Kopfbereiche'], $store->termNames(1058, 'layout_category'));
|
||||
}
|
||||
|
||||
public function testDescribesAnEntry(): void
|
||||
{
|
||||
$post = new WP_Post([
|
||||
'ID' => 1057, 'post_type' => 'et_pb_layout', 'post_title' => '[Fixture] Library-Modul',
|
||||
'post_modified_gmt' => '2026-09-26 20:56:29',
|
||||
]);
|
||||
|
||||
self::assertSame(
|
||||
[
|
||||
'id' => 1057, 'title' => '[Fixture] Library-Modul', 'layout_type' => null, 'scope' => 'normal',
|
||||
'module_type' => 'divi/blurb', 'categories' => [], 'tags' => [], 'modified' => '2026-09-26 20:56:29',
|
||||
],
|
||||
(new DiviLibraryStore())->describe($post)
|
||||
);
|
||||
}
|
||||
|
||||
public function testFindQueriesPublishedEntriesWithFilters(): void
|
||||
{
|
||||
$captured = [];
|
||||
Functions\when('get_posts')->alias(static function (array $args) use (&$captured): array {
|
||||
$captured = $args;
|
||||
|
||||
return [];
|
||||
});
|
||||
|
||||
(new DiviLibraryStore())->find(
|
||||
['layout_type' => 'section', 'scope' => 'normal', 'search' => 'Kopf', 'category' => 'Kopfbereiche'],
|
||||
20,
|
||||
40
|
||||
);
|
||||
|
||||
self::assertSame('et_pb_layout', $captured['post_type']);
|
||||
self::assertSame('publish', $captured['post_status']);
|
||||
self::assertSame(21, $captured['posts_per_page']);
|
||||
self::assertSame(40, $captured['offset']);
|
||||
self::assertSame('Kopf', $captured['s']);
|
||||
self::assertSame(
|
||||
[
|
||||
'relation' => 'AND',
|
||||
['taxonomy' => 'layout_type', 'field' => 'slug', 'terms' => ['section']],
|
||||
['taxonomy' => 'scope', 'field' => 'slug', 'terms' => ['global'], 'operator' => 'NOT IN'],
|
||||
['taxonomy' => 'layout_category', 'field' => 'name', 'terms' => ['Kopfbereiche']],
|
||||
],
|
||||
$captured['tax_query']
|
||||
);
|
||||
}
|
||||
|
||||
public function testReportsMissingTaxonomies(): void
|
||||
{
|
||||
Functions\when('taxonomy_exists')->alias(static fn (string $taxonomy): bool => $taxonomy !== 'scope');
|
||||
|
||||
self::assertSame(['scope'], (new DiviLibraryStore())->missingTaxonomies());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Library;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\Library\DiviRoles;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
|
||||
final class DiviRolesTest extends TestCase
|
||||
{
|
||||
public function testAsksTheCheckAndExplainsARefusal(): void
|
||||
{
|
||||
$roles = new DiviRoles(static fn (string $cap): bool => $cap !== 'edit_global_library');
|
||||
|
||||
self::assertTrue($roles->allows('divi_library'));
|
||||
self::assertNull($roles->refusal('divi_library'));
|
||||
$refusal = $roles->refusal('edit_global_library');
|
||||
self::assertToolError($refusal, 'forbidden');
|
||||
self::assertStringContainsString('Globale Bibliothekselemente bearbeiten', $refusal->get_error_message());
|
||||
self::assertStringContainsString('Rollen-Editor', $refusal->get_error_message());
|
||||
}
|
||||
|
||||
public function testWithoutDiviNothingIsAllowed(): void
|
||||
{
|
||||
// Unit tests have no et_pb_is_allowed(): a missing Divi function never means "allowed".
|
||||
self::assertFalse((new DiviRoles())->allows('divi_library'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user