You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
3.0 KiB
82 lines
3.0 KiB
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Image\ImageProcessor;
|
|
use App\Models\Collection;
|
|
use App\Models\File;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\Feature\Traits\FileTraits;
|
|
use Tests\TestCase;
|
|
|
|
class FileUpdateTest extends TestCase
|
|
{
|
|
use FileTraits;
|
|
public function test_user_can_not_access_update_without_permission()
|
|
{
|
|
$this->assertFalse("it's not mohammad's fault, I'm waiting for dynamic policy");
|
|
}
|
|
|
|
public function test_user_update_not_exits_files_not_found()
|
|
{
|
|
$data = [
|
|
"original_name" => 'original name is very bad',
|
|
"description" => 'this is a description for file and has beed updated',
|
|
];
|
|
|
|
$response = $this->loginAs()->putJson(route('api.files.update', ['collection_name' => 'not_exits', 'uuid' => app()->uuid, 'extention' => 'jpg']), $data);
|
|
$response->assertNotFound();
|
|
}
|
|
|
|
|
|
// /**
|
|
// * @dataProvider updateValidationTestProvider
|
|
// */
|
|
// public function test_user_send_unproccable_fileds($collectionFields, $dataFields)
|
|
// {
|
|
// $collection = Collection::factory()->create($collectionFields);
|
|
// $uuid = app()->uuid;
|
|
// $file = File::factory()->createQuietly([
|
|
// 'uuid' => $uuid,
|
|
// 'server_path' => '/' . date('y') . '/' . date('m') . '/',
|
|
// 'user_id' => auth()->id(),
|
|
// 'collection_id' => $collection->id
|
|
// ]);
|
|
|
|
// $response = $this->loginAs()->postJson(route('api.files.update', ['collection_name' => $collection->name, 'uuid' => $file->uuid, 'ext' => $collection->ext]), $dataFields);
|
|
// $response->assertUnprocessable();
|
|
// }
|
|
|
|
public function test_user_can_update_file()
|
|
{
|
|
$collection = Collection::factory()->createQuietly([
|
|
'alt_required' => false,
|
|
'description_required' => false,
|
|
'tmp_support' => true,
|
|
'max_width' => 2000,
|
|
'max_height' => 2000,
|
|
'min_width' => 1,
|
|
'min_height' => 1,
|
|
'min_file_size' => 0
|
|
]);
|
|
$uuid = app()->uuid;
|
|
$file = File::factory()->createQuietly([
|
|
'uuid' => $uuid,
|
|
'server_path' => '/' . date('y') . '/' . date('m') . '/',
|
|
'user_id' => auth()->id(),
|
|
'collection_id' => $collection->id
|
|
]);
|
|
$imageProcessor = new ImageProcessor;
|
|
$imageProcessor->createFakeImage(storage_path('stub') . '/image.png', Storage::disk($collection->disk)->path($file->server_path . $uuid . '.' . $collection->ext));
|
|
|
|
$data = [
|
|
"original_name" => 'original name is very bad',
|
|
"description" => 'this is a description for file and has beed updated',
|
|
];
|
|
|
|
$response = $this->loginAs()->putJson(route('api.files.update', ['collection_name' => $collection->name, 'uuid' => $file->uuid, 'extention' => $collection->ext]), $data);
|
|
$response->assertok()->assertJson(['data' => $data]);
|
|
}
|
|
}
|