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 OR post_content REGEXP %s)', '%gcid-holz000001%', '%gvid-radius0001%', 'g[cv]id\\\\u002[dD]', '\\\\u00[4-7][0-9a-fA-F]' ) ->andReturn('(prepared)'); $query = new ReferenceUsageQuery(['gcid-holz000001', 'gvid-radius0001', 'gcid-holz000001']); self::assertSame('(prepared)', $query->candidateCondition($db)); } public function testNeedsAnId(): void { $this->expectException(InvalidArgumentException::class); new ReferenceUsageQuery(['']); } public function testFindsAReferenceInTheAttributesOfAnyBlock(): void { $query = new ReferenceUsageQuery(['gcid-holz000001', 'gvid-radius0001']); self::assertTrue($query->matches('')); self::assertTrue($query->matches('')); self::assertFalse($query->matches('')); self::assertFalse($query->matches('')); self::assertFalse($query->matches('

Keine Verweise

')); } public function testFindsAnIdWrittenWithJsonEscapesAlsoInsideGlobalModules(): void { $query = new ReferenceUsageQuery(['gcid-holz000001']); self::assertTrue($query->matches('')); self::assertTrue($query->matches('' . '')); self::assertFalse($query->matches('')); // Escaped letter, nested two levels deep inside a global module: only decoded attributes reveal the ID. $nested = ''; self::assertStringNotContainsString('gcid-holz000001', $nested); self::assertTrue($query->matches($nested)); } public function testUnreadableMarkupAndDivi4ContentCount(): void { $query = new ReferenceUsageQuery(['gcid-holz000001']); self::assertTrue($query->matches(''), 'never closed'); self::assertTrue($query->matches(''), 'attrs no JSON'); self::assertTrue($query->matches(''), 'no JSON, no raw ID'); self::assertTrue($query->matches('[et_pb_text background_color="gcid-holz000001"]x[/et_pb_text]'), 'Divi 4'); } public function testMentionsLooksIntoNestedStrings(): void { self::assertTrue(ReferenceUsageQuery::mentions(['a' => ['b' => 'x gvid-radius0001 y']], ['gvid-radius0001'])); self::assertFalse(ReferenceUsageQuery::mentions(['gvid-radius0001' => 1], ['gvid-radius0001']), 'keys'); self::assertFalse(ReferenceUsageQuery::mentions(12, ['gvid-radius0001'])); } }