-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use database to build asset folder list (#311)
* Use database to build asset folder list * Fix bug with adding folders * Remove debugging * Test coverage * 🍺
- Loading branch information
1 parent
1cd16ac
commit 8172d10
Showing
3 changed files
with
97 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace Tests\Assets; | ||
|
||
use Illuminate\Http\UploadedFile; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Facades\AssetContainer; | ||
use Statamic\Testing\Concerns\PreventsSavingStacheItemsToDisk; | ||
use Tests\TestCase; | ||
|
||
class AssetContainerContentsTest extends TestCase | ||
{ | ||
use PreventsSavingStacheItemsToDisk; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
config(['filesystems.disks.test' => [ | ||
'driver' => 'local', | ||
'root' => __DIR__.'/tmp', | ||
]]); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
app('files')->deleteDirectory(__DIR__.'/tmp'); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
#[Test] | ||
public function it_gets_a_folder_listing() | ||
{ | ||
$container = tap(AssetContainer::make('test')->disk('test'))->save(); | ||
$container->makeAsset('one/one.txt')->upload(UploadedFile::fake()->create('one.txt')); | ||
$container->makeAsset('two/two.txt')->upload(UploadedFile::fake()->create('two.txt')); | ||
|
||
$this->assertSame([ | ||
[ | ||
'path' => 'one', | ||
'type' => 'dir', | ||
], | ||
[ | ||
'path' => 'two', | ||
'type' => 'dir', | ||
], | ||
], $container->contents()->directories()->all()); | ||
} | ||
|
||
#[Test] | ||
public function it_adds_to_a_folder_listing() | ||
{ | ||
$container = tap(AssetContainer::make('test')->disk('test'))->save(); | ||
$container->makeAsset('one/one.txt')->upload(UploadedFile::fake()->create('one.txt')); | ||
$container->makeAsset('two/two.txt')->upload(UploadedFile::fake()->create('two.txt')); | ||
|
||
$this->assertCount(2, $container->contents()->directories()->all()); | ||
|
||
$container->contents()->add('three'); | ||
|
||
$this->assertCount(3, $container->contents()->directories()->all()); | ||
} | ||
|
||
#[Test] | ||
public function it_forgets_a_folder_listing() | ||
{ | ||
$container = tap(AssetContainer::make('test')->disk('test'))->save(); | ||
$container->makeAsset('one/one.txt')->upload(UploadedFile::fake()->create('one.txt')); | ||
$container->makeAsset('two/two.txt')->upload(UploadedFile::fake()->create('two.txt')); | ||
|
||
$this->assertCount(2, $container->contents()->directories()->all()); | ||
|
||
$container->contents()->forget('one'); | ||
|
||
$this->assertCount(1, $container->contents()->directories()->all()); | ||
} | ||
|
||
#[Test] | ||
public function it_creates_parent_folders_where_they_dont_exist() | ||
{ | ||
$container = tap(AssetContainer::make('test')->disk('test'))->save(); | ||
$container->makeAsset('one/two/three/file.txt')->upload(UploadedFile::fake()->create('one.txt')); | ||
|
||
$this->assertCount(3, $container->contents()->filteredDirectoriesIn('', true)); | ||
} | ||
} |