UploadedFile::fake()->image('test.png'), "alts" => ['1', '2', '3'], "description" => 'lfjdsklfslfsdlfasdfsfhgsfgsdf', "public" => 1 ]; $collection = Collection::factory()->create([ 'tmp_support' => false ]); $response = $this->loginAs('dick')->postJson(route('api.file.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->loginAs('dick')->postJson(route('api.file.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->loginAs('dick')->postJson(route('api.file.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->loginAs('dick')->postJson(route('api.file.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); // } public function test_store_dynamic_validation_stored_file_unprocessable() { $collection = Collection::factory()->create([ '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()->createImage(storage_path('app/' . date('y') . '/' . date('m') . '/' . $uuid . '.' . $collection->ext))->create([ 'uuid' => $uuid, 'server_path' => '/' . date('y') . '/' . date('m') . '/', 'collection_id' => $collection->id ]); $data = [ "file" => $file->uuid, "alts" => ['1', '2', '3'], "description" => 'lfjdsklfslfsdlfasdfsfhgsfgsdf', "public" => 1 ]; $response = $this->loginAs('dick')->postJson(route('api.file.store', ['collection_name' => $collection->name]), $data); $response->assertUnprocessable(); } }