refactor: GlobalUsages sucht über UsageQuery – Bibliothekssuche als LibraryUsageQuery

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-16 17:36:21 +02:00
co-authored by Claude Sonnet 5.5
parent 3fe83e39d3
commit 454116851e
5 changed files with 171 additions and 43 deletions
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Library;
use LIT\MCP\Integrations\Divi\Library\LibraryUsageQuery;
use LIT\MCP\Tests\Unit\TestCase;
use Mockery;
final class LibraryUsageQueryTest extends TestCase
{
public function testConditionIsTheFormerCandidateFilter(): void
{
$db = Mockery::mock(\wpdb::class);
$db->allows('esc_like')->andReturnUsing(static fn (string $text): string => $text);
$db->expects('prepare')
->with(
'(LOWER(post_content) LIKE %s OR LOWER(post_content) LIKE %s OR post_content REGEXP %s)',
'%globalmodule%',
'%global_module%',
'\\\\u00[4-7][0-9a-fA-F]'
)
->andReturn('(prepared)');
self::assertSame('(prepared)', (new LibraryUsageQuery(12))->candidateCondition($db));
}
public function testMatchesThroughTheUsageMatcher(): void
{
$query = new LibraryUsageQuery(12);
self::assertTrue($query->matches('<!-- wp:divi/section {"globalModule":"12"} /-->'));
self::assertFalse($query->matches('<!-- wp:divi/section {"globalModule":"13"} /-->'));
}
}