mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-21 12:35:01 +00:00
zip unit testing
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Domain\Zip\Actions;
|
namespace Domain\Zip\Actions;
|
||||||
|
|
||||||
|
use STS\ZipStream\ZipStream;
|
||||||
use Domain\Sharing\Models\Share;
|
use Domain\Sharing\Models\Share;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
@@ -27,14 +28,14 @@ class ZipFilesAction
|
|||||||
if (Storage::exists($filePath)) {
|
if (Storage::exists($filePath)) {
|
||||||
// local disk
|
// local disk
|
||||||
if (is_storage_driver('local')) {
|
if (is_storage_driver('local')) {
|
||||||
$zip->add(storage_path("app/files/$file->user_id/$file->basename"), $file->name);
|
$zip->add(Storage::path($filePath), $file->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// s3 client
|
// s3 client
|
||||||
if (is_storage_driver('s3')) {
|
if (is_storage_driver('s3')) {
|
||||||
$bucketName = config('filesystems.disks.s3.bucket');
|
$bucketName = config('filesystems.disks.s3.bucket');
|
||||||
|
|
||||||
$zip->add("s3://$bucketName/files/$file->user_id/$file->basename", $file->name);
|
$zip->add("s3://$bucketName/$filePath", $file->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ class ZipFolderAction
|
|||||||
|
|
||||||
// local disk
|
// local disk
|
||||||
if (is_storage_driver('local')) {
|
if (is_storage_driver('local')) {
|
||||||
$zip->add(storage_path("app/files/$user_id/{$file['basename']}"), $zipDestination);
|
$zip->add(Storage::path($filePath), $zipDestination);
|
||||||
}
|
}
|
||||||
|
|
||||||
// s3 client
|
// s3 client
|
||||||
if (is_storage_driver('s3')) {
|
if (is_storage_driver('s3')) {
|
||||||
$bucketName = config('filesystems.disks.s3.bucket');
|
$bucketName = config('filesystems.disks.s3.bucket');
|
||||||
|
|
||||||
$zip->add("s3://$bucketName/files/$user_id/{$file['basename']}", $zipDestination);
|
$zip->add("s3://$bucketName/$filePath", $zipDestination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ namespace Tests\Domain\Zip;
|
|||||||
use Storage;
|
use Storage;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use App\Users\Models\User;
|
use App\Users\Models\User;
|
||||||
use Domain\Zip\Models\Zip;
|
|
||||||
use Laravel\Sanctum\Sanctum;
|
use Laravel\Sanctum\Sanctum;
|
||||||
use Domain\Files\Models\File;
|
use Domain\Files\Models\File;
|
||||||
use Domain\Folders\Models\Folder;
|
use Domain\Folders\Models\Folder;
|
||||||
@@ -35,20 +34,14 @@ class UserZippingTest extends TestCase
|
|||||||
])->assertStatus(201);
|
])->assertStatus(201);
|
||||||
});
|
});
|
||||||
|
|
||||||
$file_ids = File::all()->pluck('id');
|
$file_ids = File::all()->pluck('id')->toArray();
|
||||||
|
|
||||||
$this->postJson('/api/zip/files', [
|
$ids = implode(',', $file_ids);
|
||||||
'items' => $file_ids,
|
|
||||||
])->assertStatus(201);
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('zips', [
|
$this
|
||||||
'user_id' => $user->id,
|
->getJson("/api/zip/files?ids=$ids")
|
||||||
]);
|
->assertStatus(200)
|
||||||
|
->assertHeader('content-type', 'application/x-zip');
|
||||||
Storage::disk('local')
|
|
||||||
->assertExists(
|
|
||||||
'zip/' . Zip::first()->basename
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,15 +73,7 @@ class UserZippingTest extends TestCase
|
|||||||
});
|
});
|
||||||
|
|
||||||
$this->getJson("/api/zip/folder/$folder->id")
|
$this->getJson("/api/zip/folder/$folder->id")
|
||||||
->assertStatus(201);
|
->assertStatus(200)
|
||||||
|
->assertHeader('content-type', 'application/x-zip');
|
||||||
$this->assertDatabaseHas('zips', [
|
|
||||||
'user_id' => $user->id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
Storage::disk('local')
|
|
||||||
->assertExists(
|
|
||||||
'zip/' . Zip::first()->basename
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -25,6 +25,6 @@ abstract class TestCase extends BaseTestCase
|
|||||||
|
|
||||||
resolve(CreateDiskDirectoriesAction::class)();
|
resolve(CreateDiskDirectoriesAction::class)();
|
||||||
|
|
||||||
//$this->withoutExceptionHandling();
|
$this->withoutExceptionHandling();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user