UploadedFile::fake()->image('test.png'), "alts" => ['1', '2', '3'], "description" => 'lfjdsklfslfsdlfasdfsfhgsfgsdf', "public" => 1 ]; $collection = Collection::factory()->create([ 'tmp_support' => false ]); $response = $this->postJson(route('api.files.store', ['collection_name' => $collection->name]), $data); $response->assertForbidden(); } public function test_tmp_false_and_collection_is_full_forbidden() { $randomCount = rand(2, 10); $collection = Collection::factory()->createQuietly([ 'tmp_support' => false, 'count' => $randomCount ]); for ($i = $randomCount; $i > 0; $i--) { $uuid = app()->uuid; $this->one(File::class, [ 'uuid' => $uuid, 'user_id' => auth()->id(), 'collection_id' => $collection->id, 'server_path' => '/' . date('y') . '/' . date('m') . '/' . $uuid . '.' . $collection->ext, ]); } $data = [ "file" => UploadedFile::fake()->image('test.png'), "alts" => ['1', '2', '3'], "description" => 'lfjdsklfslfsdlfasdfsfhgsfgsdf', "public" => 1 ]; $response = $this->postJson(route('api.files.store', ['collection_name' => $collection->name]), $data); $response->assertForbidden(); } public function test_file_is_not_isset_forbidden() { $collection = Collection::factory()->create([ 'tmp_support' => true ]); $data = [ "file" => app()->uuid, "alts" => ['1', '2', '3'], "description" => 'lfjdsklfslfsdlfasdfsfhgsfgsdf', "public" => 1 ]; $response = $this->postJson(route('api.files.store', ['collection_name' => $collection->name]), $data); $response->assertForbidden(); } public function test_user_can_not_access_not_ownered_files() { $collection = Collection::factory()->createQuietly(); $uuid = app()->uuid; $file = File::factory()->createQuietly([ 'uuid' => $uuid, 'user_id' => auth()->id() + 1234, 'server_path' => '/' . date('y') . '/' . date('m') . '/', 'collection_id' => $collection->id ]); $data = [ "file" => $file->uuid, "public" => 1 ]; $response = $this->postJson(route('api.files.store', ['collection_name' => $collection->name]), $data); $response->assertForbidden(); } /** * @dataProvider storeValidationTestProvider */ public function test_store_dynamic_validation_unprocessable($collectionFields, $dataFields) { $collection = Collection::factory()->create($collectionFields); $response = $this->postJson(route('api.files.store', ['collection_name' => $collection->name]), $dataFields); $response->assertUnprocessable(); } // /** // * @testWith // * ['email:gt'] // * ['email:gt'] // * ['email:gt'] // * ['email:gt'] // * ['email:gt'] // */ // public function test_store_static_validation_unprocessable($key) // { // File::factory()->smash($key); // } /** * @dataProvider storeValidationTestProvider */ public function test_store_dynamic_validation_stored_file_unprocessable($collectionFields) { $collection = Collection::factory()->createQuietly($collectionFields); $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 = [ "file" => $file->uuid, "public" => 1 ]; $response = $this->postJson(route('api.files.store', ['collection_name' => $collection->name]), $data); $response->assertUnprocessable(); } public function test_user_can_store_sent_file_count_multiple_without_image_processor_ok() { $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; $this->one(File::class, [ 'uuid' => $uuid, 'user_id' => auth()->id(), 'collection_id' => $collection->id, 'server_path' => '/' . date('y') . '/' . date('m') . '/', ]); $data = [ "file" => UploadedFile::fake()->image('test.png'), "public" => 1 ]; $response = $this->postJson(route('api.files.store', ['collection_name' => $collection->name]), $data); $response->assertCreated(); } public function test_user_can_store_sent_file_uuid_count_multiple_without_image_processor_ok() { $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 = [ "file" => $file->uuid, "public" => 1 ]; $response = $this->postJson(route('api.files.store', ['collection_name' => $collection->name]), $data); $response->assertCreated(); } public function test_user_can_store_sent_file_count_one_without_image_processor_ok() { $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 = [ "file" => $file->uuid, "public" => 1 ]; $response = $this->postJson(route('api.files.store', ['collection_name' => $collection->name]), $data); $response->assertCreated(); } public function test_user_can_store_sent_file_uuid_count_one_without_image_processor_ok() { $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 = [ "file" => $file->uuid, "public" => 1 ]; $response = $this->postJson(route('api.files.store', ['collection_name' => $collection->name]), $data); $response->assertCreated(); } }