Files
WP-LIT-MCP/tests/Unit/Integrations/Divi/Schema/DiviCatalogAbilityTest.php
T
janniclas.loosenandClaude Opus 5.5 10c98cd3c6 docs: Divi guides shortform/placeholders, hints name the write tools; test: Divi write end-to-end; version 0.3.0
- Hints (PostPresenter::DIVI_NOTE, outline, catalog) and server instructions (tree_rev rule)
  name the Divi write tools; guides divi-shortform and divi-placeholders, additions to
  divi-structure, divi-attrs, overview (tool groups, 'nur lesen'), workflows, content-types.
- D7 wording and the S7 exception in readme, guides and spec 1.3/5.2; readme 0.3.0.
- ToolNamingTest: every referenced guide topic exists; overview lists exactly the topics.
- tests/Integration/divi-write-smoke.sh: all write tools via OAuth, editor without
  unfiltered_html with benign probes (S6), Divi's own save filters on the new fixture
  synthetic-divi-filters.html (S7); admin-render.php accepts the new wrap class.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
2026-09-26 17:13:59 +02:00

88 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Schema;
use Brain\Monkey\Functions;
use LIT\MCP\Integrations\Divi\Schema\DiviCatalogAbility;
use LIT\MCP\Integrations\Divi\Schema\DiviModules;
use LIT\MCP\Tests\Unit\TestCase;
use Mockery;
final class DiviCatalogAbilityTest extends TestCase
{
private function ability(): DiviCatalogAbility
{
$modules = Mockery::mock(DiviModules::class);
$modules->allows('catalog')->andReturn(ModuleCatalogTest::sampleCatalog());
return new DiviCatalogAbility($modules);
}
public function testListsModulesWithShortformFlag(): void
{
$result = $this->ability()->execute([]);
$button = array_values(array_filter($result['modules'], static fn (array $m): bool => $m['name'] === 'divi/button'));
self::assertSame(
[['name' => 'divi/button', 'title' => 'Button', 'category' => 'module', 'children' => [], 'shortform' => true]],
$button
);
$header = array_values(array_filter(
$result['modules'],
static fn (array $m): bool => $m['name'] === 'divi/fullwidth-header'
));
self::assertFalse($header[0]['shortform']);
self::assertSame(DiviCatalogAbility::CODE_NOTE, $result['notes'][0]);
self::assertStringContainsString('"divi-shortform"', $result['notes'][1]);
self::assertStringContainsString('"divi-attrs"', $result['notes'][1]);
}
public function testDetailOfOneModule(): void
{
$result = $this->ability()->execute(['module' => 'Accordion']);
self::assertSame('divi/accordion', $result['module']['name']);
self::assertSame(['divi/accordion-item'], $result['module']['children']);
self::assertSame('accordion-item', $result['module']['item_type']);
self::assertContains('title.decoration.font.font', $result['module']['paths']);
$button = $this->ability()->execute(['module' => 'divi/button'])['module'];
self::assertSame('linkUrl', $button['shortform']['url']['sub']);
}
public function testDetailExposesTheAttributePathKindsForSanitizationRouting(): void
{
$button = $this->ability()->execute(['module' => 'divi/button'])['module'];
self::assertSame('text', $button['path_kinds']['module.meta.adminLabel']);
self::assertArrayNotHasKey('no.such.path', $button['path_kinds']);
// Composite ("group") paths are left out rather than guessing a single kind.
self::assertArrayNotHasKey('button.innerContent', $button['path_kinds']);
}
/** A composite path (several named sub-fields under one attribute path) surfaces as a
* subName => kind map, not a single guessed string (spec §5.6, ruling F1 #1). */
public function testDetailExposesCompositePathKindsAsASubNameMap(): void
{
$header = $this->ability()->execute(['module' => 'divi/fullwidth-header'])['module'];
self::assertSame(
['text' => 'text', 'linkUrl' => 'url'],
$header['path_kinds']['buttonOne.innerContent']
);
self::assertSame(['src' => 'image'], $header['path_kinds']['image.innerContent']);
}
public function testUnknownModuleAndPermission(): void
{
self::assertSame('lit_not_found', $this->ability()->execute(['module' => 'slider-pro'])->get_error_code());
Functions\when('current_user_can')->justReturn(false);
self::assertSame('lit_forbidden', $this->ability()->permission([])->get_error_code());
self::assertTrue($this->ability()->annotations()['readonly']);
self::assertTrue($this->ability()->isDirect());
}
}