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('')); self::assertFalse($query->matches('')); } 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('')); } public function testNeedsATarget(): void { $this->expectException(\InvalidArgumentException::class); new PresetUsageQuery([]); } }