|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Assets; |
| 4 | + |
| 5 | +use Illuminate\Database\Events\QueryExecuted; |
| 6 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 7 | +use Illuminate\Support\Facades\Storage; |
| 8 | +use PHPUnit\Framework\Attributes\Test; |
| 9 | +use Statamic\Facades; |
| 10 | +use Tests\TestCase; |
| 11 | + |
| 12 | +class AssetContainerTest extends TestCase |
| 13 | +{ |
| 14 | + use RefreshDatabase; |
| 15 | + |
| 16 | + private $container; |
| 17 | + |
| 18 | + protected function setUp(): void |
| 19 | + { |
| 20 | + parent::setUp(); |
| 21 | + |
| 22 | + Storage::fake('test', ['url' => '/assets']); |
| 23 | + |
| 24 | + $this->container = tap(Facades\AssetContainer::make('test')->disk('test'))->save(); |
| 25 | + |
| 26 | + Storage::disk('test')->put('a.jpg', ''); |
| 27 | + Facades\Asset::make()->container('test')->path('a.jpg')->save(); |
| 28 | + |
| 29 | + Storage::disk('test')->put('b.txt', ''); |
| 30 | + Facades\Asset::make()->container('test')->path('b.txt')->save(); |
| 31 | + |
| 32 | + Storage::disk('test')->put('c.txt', ''); |
| 33 | + Facades\Asset::make()->container('test')->path('c.txt')->save(); |
| 34 | + |
| 35 | + Storage::disk('test')->put('d.jpg', ''); |
| 36 | + Facades\Asset::make()->container('test')->path('d.jpg')->save(); |
| 37 | + |
| 38 | + Storage::disk('test')->put('e.jpg', ''); |
| 39 | + Facades\Asset::make()->container('test')->path('e.jpg')->save(); |
| 40 | + |
| 41 | + Storage::disk('test')->put('f.jpg', ''); |
| 42 | + Facades\Asset::make()->container('test')->path('f.jpg')->save(); |
| 43 | + } |
| 44 | + |
| 45 | + #[Test] |
| 46 | + public function calling_folders_uses_eloquent_asset_container_contents() |
| 47 | + { |
| 48 | + $this->expectsDatabaseQueryCount(1); |
| 49 | + |
| 50 | + $queryExecuted = false; |
| 51 | + \DB::listen(function (QueryExecuted $query) use (&$queryExecuted) { |
| 52 | + $queryExecuted = str_contains($query->sql, 'select distinct "folder" from "assets_meta"'); |
| 53 | + }); |
| 54 | + |
| 55 | + $this->container->folders(); |
| 56 | + |
| 57 | + $this->assertTrue($queryExecuted); |
| 58 | + } |
| 59 | +} |
0 commit comments