refactor: GlobalUsages sucht über UsageQuery – Bibliothekssuche als LibraryUsageQuery
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
3fe83e39d3
commit
454116851e
@@ -282,4 +282,34 @@ final class GlobalUsagesTest extends TestCase
|
||||
self::assertFalse($report->blocks());
|
||||
self::assertSame(['affected', 'affected_count'], array_keys($report->listing()));
|
||||
}
|
||||
|
||||
public function testRowsForUsesTheConditionAndMatcherOfTheQuery(): void
|
||||
{
|
||||
$db = Mockery::mock(\wpdb::class)->makePartial();
|
||||
$queries = [];
|
||||
$db->allows('get_results')->andReturnUsing(static function (string $sql) use (&$queries): array {
|
||||
$queries[] = $sql;
|
||||
|
||||
return str_contains($sql, 'post_content FROM')
|
||||
? [['ID' => '5', 'post_content' => 'treffer'], ['ID' => '6', 'post_content' => 'nichts']]
|
||||
: [['ID' => '5', 'post_status' => 'draft', 'post_type' => 'page'],
|
||||
['ID' => '6', 'post_status' => 'draft', 'post_type' => 'page']];
|
||||
});
|
||||
$query = new class implements \LIT\MCP\Integrations\Divi\Library\UsageQuery {
|
||||
public function candidateCondition(\wpdb $db): string
|
||||
{
|
||||
return '(MARKER)';
|
||||
}
|
||||
|
||||
public function matches(string $content): bool
|
||||
{
|
||||
return $content === 'treffer';
|
||||
}
|
||||
};
|
||||
|
||||
$rows = (new GlobalUsages($db))->rowsFor($query);
|
||||
|
||||
self::assertSame([['id' => 5, 'status' => 'draft', 'type' => 'page']], $rows);
|
||||
self::assertStringContainsString('WHERE (MARKER) AND post_type', $queries[0]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user