Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Search/Searchables/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function provide(): Collection|LazyCollection
->map->reference();
}

$query->whereStatus('published');
if ($this->index->handle() !== 'cp') {
$query->whereStatus('published');
}

return $query->pluck('reference');
}
Expand All @@ -66,7 +68,7 @@ public function contains($searchable): bool

$query = Entry::query()->where('id', $searchable->id());

if (! $filter) {
if (! $filter && $this->index->handle() !== 'cp') {
$query->whereStatus('published');
}

Expand Down
22 changes: 19 additions & 3 deletions tests/Search/Searchables/EntriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,35 @@ public function it_can_use_a_query_scope_and_a_custom_filter()
$this->assertFalse($provider->contains($c));
}

private function makeProvider($locale, $config)
#[Test]
public function it_includes_unpublished_entries_in_the_cp_index()
{
Collection::make('blog')->save();
$a = EntryFactory::collection('blog')->id('a')->create();
$b = EntryFactory::collection('blog')->id('b')->published(false)->create();

$provider = $this->makeProvider(null, ['searchables' => 'content'], 'cp');

$this->assertEquals(['entry::a', 'entry::b'], $provider->provide()->all());

$this->assertTrue($provider->contains($a));
$this->assertTrue($provider->contains($b));
}

private function makeProvider($locale, $config, $handle = 'default')
{
$index = $this->makeIndex($locale, $config);
$index = $this->makeIndex($locale, $config, $handle);

$keys = $this->normalizeSearchableKeys($config['searchables'] ?? null);

return (new Entries)->setIndex($index)->setKeys($keys);
}

private function makeIndex($locale, $config)
private function makeIndex($locale, $config, $handle)
{
$index = $this->mock(\Statamic\Search\Index::class);

$index->shouldReceive('handle')->andReturn($handle);
$index->shouldReceive('config')->andReturn($config);
$index->shouldReceive('locale')->andReturn($locale);

Expand Down
Loading