File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -40,10 +40,20 @@ public function directories()
4040 }
4141
4242 $ this ->folders = Cache::remember ($ this ->key (), $ this ->ttl (), function () {
43- return $ this ->query ()->select (['folder ' ])
44- ->distinct ()
45- ->get ()
46- ->map (fn ($ model ) => ['path ' => $ model ->folder , 'type ' => 'dir ' ]);
43+ return
44+ collect (
45+ $ this ->query ()->select (['folder ' ])
46+ ->distinct ()
47+ ->get ()
48+ ->map (fn ($ model ) => ['path ' => $ model ->folder , 'type ' => 'dir ' ])
49+ )
50+ ->merge (
51+ collect ($ this ->container ->disk ()->getFolders ('/ ' , true )
52+ ->filter (fn ($ folder ) => ! Str::startsWith ($ folder , '. ' ))
53+ )
54+ ->map (fn ($ folder ) => ['path ' => $ folder , 'type ' => 'dir ' ])
55+ )
56+ ->unique ();
4757 });
4858
4959 return $ this ->folders ;
Original file line number Diff line number Diff line change 33namespace Tests \Assets ;
44
55use Illuminate \Http \UploadedFile ;
6+ use Illuminate \Support \Facades \Cache ;
7+ use Illuminate \Support \Facades \Storage ;
68use PHPUnit \Framework \Attributes \Test ;
79use Statamic \Facades \AssetContainer ;
10+ use Statamic \Facades \Blink ;
811use Statamic \Testing \Concerns \PreventsSavingStacheItemsToDisk ;
912use Tests \TestCase ;
1013
@@ -98,4 +101,20 @@ public function it_doesnt_nest_folders_that_start_with_the_same_name()
98101 $ this ->assertCount (1 , $ filtered );
99102 $ this ->assertSame ($ filtered ->keys ()->all (), ['one/two ' ]);
100103 }
104+
105+ #[Test]
106+ public function it_includes_empty_folders_in_the_directory_listing ()
107+ {
108+ $ container = tap (AssetContainer::make ('test ' )->disk ('test ' ))->save ();
109+ $ container ->makeAsset ('one-two/file.txt ' )->upload (UploadedFile::fake ()->create ('one.txt ' ));
110+
111+ $ this ->assertCount (1 , $ container ->contents ()->directories ());
112+
113+ Cache::flush ();
114+ Blink::flush ();
115+
116+ Storage::disk ('test ' )->makeDirectory ('another ' );
117+
118+ $ this ->assertCount (2 , $ container ->contents ()->directories ());
119+ }
101120}
You can’t perform that action at this time.
0 commit comments