feat: Fundstellen eines Presets (PresetUsageMatcher, PresetUsageQuery)
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
454116851e
commit
bfd3840eb1
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\Design\PresetScope;
|
||||
use LIT\MCP\Integrations\Divi\Design\PresetUsageQuery;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use Mockery;
|
||||
|
||||
final class PresetUsageQueryTest extends TestCase
|
||||
{
|
||||
public function testCandidatesContainAnIdOrAJsonEscape(): void
|
||||
{
|
||||
$db = Mockery::mock(\wpdb::class);
|
||||
$db->allows('esc_like')->andReturnUsing(static fn (string $text): string => $text);
|
||||
$db->expects('prepare')
|
||||
->with(
|
||||
'(post_content LIKE %s OR post_content LIKE %s OR post_content REGEXP %s)',
|
||||
'%aaaaaaaaaa%',
|
||||
'%gggggggggg%',
|
||||
'\\\\u00[4-7][0-9a-fA-F]'
|
||||
)
|
||||
->andReturn('(prepared)');
|
||||
|
||||
$query = new PresetUsageQuery([
|
||||
['scope' => new PresetScope('module', 'divi/button'), 'id' => 'aaaaaaaaaa', 'default' => false],
|
||||
['scope' => new PresetScope('group', 'divi/font-body'), 'id' => 'gggggggggg', 'default' => false],
|
||||
]);
|
||||
|
||||
self::assertSame('(prepared)', $query->candidateCondition($db));
|
||||
self::assertTrue($query->matches('<!-- wp:divi/text {"groupPreset":{"content.decoration.bodyFont":'
|
||||
. '{"presetId":["gggggggggg"],"groupName":"divi/font-body"}}} /-->'));
|
||||
self::assertFalse($query->matches('<!-- wp:divi/text {} /-->'));
|
||||
}
|
||||
|
||||
public function testADefaultModulePresetLooksForTheModule(): void
|
||||
{
|
||||
$db = Mockery::mock(\wpdb::class);
|
||||
$db->allows('esc_like')->andReturnUsing(static fn (string $text): string => $text);
|
||||
$db->expects('prepare')
|
||||
->with(
|
||||
'(post_content LIKE %s OR post_content LIKE %s OR post_content REGEXP %s)',
|
||||
'%dddddddddd%',
|
||||
'%wp:divi/button %',
|
||||
'\\\\u00[4-7][0-9a-fA-F]'
|
||||
)
|
||||
->andReturn('(prepared)');
|
||||
|
||||
$query = new PresetUsageQuery([
|
||||
['scope' => new PresetScope('module', 'divi/button'), 'id' => 'dddddddddd', 'default' => true],
|
||||
]);
|
||||
|
||||
self::assertSame('(prepared)', $query->candidateCondition($db));
|
||||
self::assertTrue($query->matches('<!-- wp:divi/button {} /-->'));
|
||||
}
|
||||
|
||||
public function testNeedsATarget(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
new PresetUsageQuery([]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user