fix: media search also matches file names
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Media;
|
||||
|
||||
use Brain\Monkey\Filters;
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Abilities\Cursor;
|
||||
use LIT\MCP\Integrations\Media\MediaPresenter;
|
||||
@@ -149,6 +150,39 @@ final class MediaSearchAbilityTest extends TestCase
|
||||
(new MediaSearchAbility($this->presenter(), Mockery::mock(MediaUsageFinder::class)))->execute([]);
|
||||
}
|
||||
|
||||
public function testASearchTermAlsoMatchesFileNames(): void
|
||||
{
|
||||
$this->unrestrictedPostType();
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
Filters\expectAdded('wp_allow_query_attachment_by_filename')->once()->with('__return_true');
|
||||
Functions\expect('get_posts')->once()->with(
|
||||
Mockery::on(static fn (array $args): bool => ($args['s'] ?? null) === 'logo')
|
||||
)->andReturn([]);
|
||||
|
||||
(new MediaSearchAbility($this->presenter(), Mockery::mock(MediaUsageFinder::class)))->execute(['search' => 'logo']);
|
||||
}
|
||||
|
||||
public function testTheUnusedScanAlsoMatchesFileNames(): void
|
||||
{
|
||||
$this->unrestrictedPostType();
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
Filters\expectAdded('wp_allow_query_attachment_by_filename')->once()->with('__return_true');
|
||||
Functions\when('get_posts')->justReturn([]);
|
||||
|
||||
(new MediaSearchAbility($this->presenter(), Mockery::mock(MediaUsageFinder::class)))
|
||||
->execute(['search' => 'logo', 'unused' => true]);
|
||||
}
|
||||
|
||||
public function testNoFileNameFilterWithoutASearchTerm(): void
|
||||
{
|
||||
$this->unrestrictedPostType();
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
Filters\expectAdded('wp_allow_query_attachment_by_filename')->never();
|
||||
Functions\when('get_posts')->justReturn([]);
|
||||
|
||||
(new MediaSearchAbility($this->presenter(), Mockery::mock(MediaUsageFinder::class)))->execute([]);
|
||||
}
|
||||
|
||||
public function testUnusedFiltersThroughTheUsageFinder(): void
|
||||
{
|
||||
Functions\when('get_posts')->justReturn($this->attachments(1, 2, 3));
|
||||
|
||||
Reference in New Issue
Block a user