Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
66 lines
2.7 KiB
PHP
66 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Library;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Integrations\Divi\Library\GlobalUsages;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use Mockery;
|
|
|
|
final class GlobalUsagesTest extends TestCase
|
|
{
|
|
public function testFindsInstancesLikeDiviAndHidesUnreadableTitles(): void
|
|
{
|
|
$db = Mockery::mock(\wpdb::class)->makePartial();
|
|
$queries = [];
|
|
$db->allows('get_var')->andReturnUsing(static function (string $sql) use (&$queries): string {
|
|
$queries[] = $sql;
|
|
|
|
return '3';
|
|
});
|
|
$db->allows('get_results')->andReturnUsing(static function (string $sql) use (&$queries): array {
|
|
$queries[] = $sql;
|
|
|
|
return [
|
|
['ID' => '1053', 'post_title' => 'Globale Instanzen', 'post_status' => 'draft', 'post_type' => 'page'],
|
|
['ID' => '1061', 'post_title' => 'Geheim', 'post_status' => 'private', 'post_type' => 'et_header_layout'],
|
|
];
|
|
});
|
|
Functions\when('current_user_can')->alias(static fn (string $cap, int $id): bool => $id !== 1061);
|
|
|
|
$usages = (new GlobalUsages($db))->of(1058);
|
|
|
|
self::assertSame(3, $usages['count']);
|
|
self::assertSame(
|
|
[
|
|
['post_id' => 1053, 'title' => 'Globale Instanzen', 'status' => 'draft', 'type' => 'page'],
|
|
['post_id' => 1061, 'title' => '(nicht lesbar)', 'status' => 'private', 'type' => 'et_header_layout'],
|
|
],
|
|
$usages['items']
|
|
);
|
|
self::assertStringContainsString("LIKE '%\"globalModule\":\"1058\"%'", $queries[0]);
|
|
self::assertStringContainsString("post_status NOT IN ('trash', 'auto-draft', 'inherit')", $queries[1]);
|
|
self::assertStringContainsString('LIMIT 50', $queries[1]);
|
|
}
|
|
|
|
/** Ruling P8a: every live (published, private, scheduled) post showing the entry, beyond the listing limit. */
|
|
public function testLiveIdsAreUnlimited(): void
|
|
{
|
|
$db = Mockery::mock(\wpdb::class)->makePartial();
|
|
$queries = [];
|
|
$db->allows('get_col')->andReturnUsing(static function (string $sql) use (&$queries): array {
|
|
$queries[] = $sql;
|
|
|
|
return ['1053', '1080'];
|
|
});
|
|
|
|
self::assertSame([1053, 1080], (new GlobalUsages($db))->liveIds(1059));
|
|
self::assertStringContainsString("LIKE '%\"globalModule\":\"1059\"%'", $queries[0]);
|
|
self::assertStringContainsString("post_status IN ('publish', 'private', 'future')", $queries[0]);
|
|
self::assertStringContainsString("post_type <> 'revision'", $queries[0]);
|
|
self::assertStringNotContainsString('LIMIT', $queries[0]);
|
|
}
|
|
}
|