@@ -1238,6 +1238,70 @@ public function it_doesnt_lowercase_moved_files_when_configured()
12381238 ], $ container ->assets ('/ ' , true )->map ->path ()->all ());
12391239 }
12401240
1241+ #[Test]
1242+ public function it_can_be_moved_to_another_folder_with_a_unique_filename_when_conflict_exists ()
1243+ {
1244+ Storage::fake ('local ' );
1245+ $ disk = Storage::disk ('local ' );
1246+ $ disk ->put ('old/asset.txt ' , 'The asset contents ' );
1247+ $ disk ->put ('new/asset.txt ' , 'Existing asset ' );
1248+ $ disk ->put ('new/asset-1.txt ' , 'Another existing asset ' );
1249+ $ container = Facades \AssetContainer::make ('test ' )->disk ('local ' );
1250+ Facades \AssetContainer::shouldReceive ('save ' )->with ($ container );
1251+ Facades \AssetContainer::shouldReceive ('findByHandle ' )->with ('test ' )->andReturn ($ container );
1252+ $ asset = $ container ->makeAsset ('old/asset.txt ' )->data (['foo ' => 'bar ' ]);
1253+ $ asset ->save ();
1254+
1255+ $ return = $ asset ->move ('new ' , null , true );
1256+
1257+ $ this ->assertEquals ($ asset , $ return );
1258+ $ disk ->assertMissing ('old/asset.txt ' );
1259+ $ disk ->assertExists ('new/asset-2.txt ' );
1260+ $ this ->assertEquals ('new/asset-2.txt ' , $ asset ->path ());
1261+ }
1262+
1263+ #[Test]
1264+ public function it_can_be_moved_to_another_folder_with_a_unique_filename_without_renaming_when_no_conflict ()
1265+ {
1266+ Storage::fake ('local ' );
1267+ $ disk = Storage::disk ('local ' );
1268+ $ disk ->put ('old/asset.txt ' , 'The asset contents ' );
1269+ $ container = Facades \AssetContainer::make ('test ' )->disk ('local ' );
1270+ Facades \AssetContainer::shouldReceive ('save ' )->with ($ container );
1271+ Facades \AssetContainer::shouldReceive ('findByHandle ' )->with ('test ' )->andReturn ($ container );
1272+ $ asset = $ container ->makeAsset ('old/asset.txt ' )->data (['foo ' => 'bar ' ]);
1273+ $ asset ->save ();
1274+
1275+ $ return = $ asset ->move ('new ' , null , true );
1276+
1277+ $ this ->assertEquals ($ asset , $ return );
1278+ $ disk ->assertMissing ('old/asset.txt ' );
1279+ $ disk ->assertExists ('new/asset.txt ' );
1280+ $ this ->assertEquals ('new/asset.txt ' , $ asset ->path ());
1281+ }
1282+
1283+ #[Test]
1284+ public function it_does_not_ensure_unique_filename_when_moving_by_default ()
1285+ {
1286+ Storage::fake ('local ' );
1287+ $ disk = Storage::disk ('local ' );
1288+ $ disk ->put ('old/asset.txt ' , 'The asset contents ' );
1289+ $ disk ->put ('new/asset.txt ' , 'Existing asset ' );
1290+ $ container = Facades \AssetContainer::make ('test ' )->disk ('local ' );
1291+ Facades \AssetContainer::shouldReceive ('save ' )->with ($ container );
1292+ Facades \AssetContainer::shouldReceive ('findByHandle ' )->with ('test ' )->andReturn ($ container );
1293+ $ asset = $ container ->makeAsset ('old/asset.txt ' )->data (['foo ' => 'bar ' ]);
1294+ $ asset ->save ();
1295+
1296+ $ return = $ asset ->move ('new ' );
1297+
1298+ $ this ->assertEquals ($ asset , $ return );
1299+ $ disk ->assertMissing ('old/asset.txt ' );
1300+ // Without unique flag, it overwrites the existing file
1301+ $ disk ->assertExists ('new/asset.txt ' );
1302+ $ this ->assertEquals ('new/asset.txt ' , $ asset ->path ());
1303+ }
1304+
12411305 #[Test]
12421306 public function it_renames ()
12431307 {
0 commit comments