Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Dec 5, 2023
1 parent 6dd37d0 commit 3e35570
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Tags/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Tests\Tags;

use Facades\Tests\Factories\EntryFactory;
use Illuminate\Support\Facades\Storage;
use Statamic\Facades\Asset;
use Statamic\Facades\AssetContainer;
use Statamic\Facades\Parse;
use Statamic\Facades\Search;
use Statamic\Search\QueryBuilder;
Expand Down Expand Up @@ -61,4 +64,30 @@ public function it_outputs_results_using_alias()
)
);
}

/** @test */
public function it_outputs_results_where_there_are_no_statuses()
{
Storage::fake('images');
AssetContainer::make('images')->disk('images')->save();

$entryA = EntryFactory::id('a')->collection('test')->data(['title' => 'entry a'])->create();
$entryB = EntryFactory::id('b')->collection('test')->data(['title' => 'entry b'])->create();
$assetA = tap(Asset::make()->container('images')->path('a.jpg')->data(['title' => 'asset a']))->save();

$builder = $this->mock(QueryBuilder::class);
$builder->shouldReceive('ensureExists', 'search', 'withData', 'limit', 'offset', 'where')->andReturnSelf();
$builder->shouldReceive('get')->andReturn(collect([$entryA, $entryB, $assetA]));

Search::shouldReceive('index')->with(null)->once()->andReturn($builder);

$this->get('/whatever?q=foo'); // just a way to get a query param into the request(). the url is irrelevant.

$this->assertEquals(
'<entry a><entry b><asset a>',
$this->tag(
'{{ search:results }}{{ if no_results }}No results{{ else }}<{{ title }}>{{ /if }}{{ /search:results }}'
)
);
}
}

0 comments on commit 3e35570

Please sign in to comment.