From aafc8996c113af38706e005b73b9c385f33e2568 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 27 Jun 2025 12:18:54 +0100 Subject: [PATCH] phpcbf fixes Signed-off-by: snipe --- app/Helpers/StorageHelper.php | 25 ++++--- .../Api/UploadedFilesController.php | 55 +++++++------- app/Http/Requests/UploadFileRequest.php | 4 +- app/Presenters/UploadedFilesPresenter.php | 1 + .../Accessories/Api/AccessoryFilesTest.php | 75 ++++++++++++------- .../AssetModels/Api/AssetModelFilesTest.php | 75 ++++++++++++------- tests/Feature/Assets/Api/AssetFilesTest.php | 21 ++++-- .../Components/Api/ComponentFileTest.php | 75 ++++++++++++------- .../Consumables/Api/ConsumableFileTest.php | 75 ++++++++++++------- .../Licenses/Api/LicenseUploadTest.php | 75 ++++++++++++------- .../Locations/Api/LocationFileTest.php | 75 ++++++++++++------- tests/Feature/Users/Api/UserFileTest.php | 75 ++++++++++++------- 12 files changed, 410 insertions(+), 221 deletions(-) diff --git a/app/Helpers/StorageHelper.php b/app/Helpers/StorageHelper.php index 38a5769f1e..5c17a9fb4d 100644 --- a/app/Helpers/StorageHelper.php +++ b/app/Helpers/StorageHelper.php @@ -16,14 +16,14 @@ class StorageHelper $disk = config('filesystems.default'); } switch (config("filesystems.disks.$disk.driver")) { - case 'local': - return response()->download(Storage::disk($disk)->path($filename)); //works for PRIVATE or public?! + case 'local': + return response()->download(Storage::disk($disk)->path($filename)); //works for PRIVATE or public?! - case 's3': - return redirect()->away(Storage::disk($disk)->temporaryUrl($filename, now()->addMinutes(5))); //works for private or public, I guess? + case 's3': + return redirect()->away(Storage::disk($disk)->temporaryUrl($filename, now()->addMinutes(5))); //works for private or public, I guess? - default: - return Storage::disk($disk)->download($filename); + default: + return Storage::disk($disk)->download($filename); } } @@ -33,11 +33,12 @@ class StorageHelper * to determine that they are safe to display inline. * * @author [ - * @since v7.0.14 - * @param $file_with_path + * @since v7.0.14 + * @param $file_with_path * @return bool */ - public static function allowSafeInline($file_with_path) { + public static function allowSafeInline($file_with_path) + { $allowed_inline = [ 'pdf', @@ -60,7 +61,8 @@ class StorageHelper } - public static function getFiletype($file_with_path) { + public static function getFiletype($file_with_path) + { // The file exists and is allowed to be displayed inline if (Storage::exists($file_with_path)) { @@ -75,7 +77,8 @@ class StorageHelper /** * Decide whether to show the file inline or download it. */ - public static function showOrDownloadFile($file, $filename) { + public static function showOrDownloadFile($file, $filename) + { $headers = []; diff --git a/app/Http/Controllers/Api/UploadedFilesController.php b/app/Http/Controllers/Api/UploadedFilesController.php index 52d8471208..7725418c0b 100644 --- a/app/Http/Controllers/Api/UploadedFilesController.php +++ b/app/Http/Controllers/Api/UploadedFilesController.php @@ -67,10 +67,10 @@ class UploadedFilesController extends Controller /** * List files for an object * - * @param \App\Http\Requests\UploadFileRequest $request - * @param string $object_type the type of object to upload the file to - * @param int $id the ID of the object to list files for - * @since [v8.1.17] + * @param \App\Http\Requests\UploadFileRequest $request + * @param string $object_type the type of object to upload the file to + * @param int $id the ID of the object to list files for + * @since [v8.1.17] * @author [A. Gianotto ] */ public function index(Request $request, $object_type, $id) : JsonResponse | array @@ -105,10 +105,12 @@ class UploadedFilesController extends Controller // And we generally won't need that here if ($request->filled('search')) { - $uploads->where(function ($query) use ($request) { - $query->where('filename', 'LIKE', '%' . $request->input('search') . '%') - ->orWhere('note', 'LIKE', '%' . $request->input('search') . '%'); - }); + $uploads->where( + function ($query) use ($request) { + $query->where('filename', 'LIKE', '%' . $request->input('search') . '%') + ->orWhere('note', 'LIKE', '%' . $request->input('search') . '%'); + } + ); } $uploads = $uploads->skip($offset)->take($limit)->orderBy($sort, $order)->get(); @@ -119,10 +121,10 @@ class UploadedFilesController extends Controller /** * Accepts a POST to upload a file to the server. * - * @param \App\Http\Requests\UploadFileRequest $request - * @param string $object_type the type of object to upload the file to - * @param int $id the ID of the object to store so we can check permisisons - * @since [v8.1.17] + * @param \App\Http\Requests\UploadFileRequest $request + * @param string $object_type the type of object to upload the file to + * @param int $id the ID of the object to store so we can check permisisons + * @since [v8.1.17] * @author [A. Gianotto ] */ public function store(UploadFileRequest $request, $object_type, $id) : JsonResponse @@ -145,7 +147,7 @@ class UploadedFilesController extends Controller if ($request->hasFile('file')) { // Loop over the attached files and add them to the object foreach ($request->file('file') as $file) { - $file_name = $request->handleFile(self::$map_storage_path[$object_type],self::$map_file_prefix[$object_type].'-'.$object->id, $file); + $file_name = $request->handleFile(self::$map_storage_path[$object_type], self::$map_file_prefix[$object_type].'-'.$object->id, $file); $files[] = $file_name; $object->logUpload($file_name, $request->get('notes')); } @@ -167,13 +169,13 @@ class UploadedFilesController extends Controller /** * Check for permissions and display the file. * - * @param \App\Http\Requests\UploadFileRequest $request - * @param string $object_type the type of object to upload the file to - * @param int $id the ID of the object to delete from so we can check permisisons - * @param $file_id the ID of the file to delete from the action_logs table - * @since [v8.1.17] + * @param \App\Http\Requests\UploadFileRequest $request + * @param string $object_type the type of object to upload the file to + * @param int $id the ID of the object to delete from so we can check permisisons + * @param $file_id the ID of the file to delete from the action_logs table + * @since [v8.1.17] * @author [A. Gianotto ] - */ + */ public function show($object_type, $id, $file_id) : JsonResponse | StreamedResponse | Storage | StorageHelper | BinaryFileResponse { // Check the permissions to make sure the user can view the object @@ -186,9 +188,8 @@ class UploadedFilesController extends Controller // Check that the file being requested exists for the asset - if (! $log = Actionlog::whereNotNull('filename') - ->where('item_type', AssetModel::class) - ->where('item_id', $object->id)->find($file_id)) { + if (! $log = Actionlog::whereNotNull('filename')->where('item_type', AssetModel::class)->where('item_id', $object->id)->find($file_id) + ) { return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.file_upload_status.invalid_id')), 200); } @@ -211,11 +212,11 @@ class UploadedFilesController extends Controller /** * Delete the associated file * - * @param \App\Http\Requests\UploadFileRequest $request - * @param string $object_type the type of object to upload the file to - * @param int $id the ID of the object to delete from so we can check permisisons - * @param $file_id the ID of the file to delete from the action_logs table - * @since [v8.1.17] + * @param \App\Http\Requests\UploadFileRequest $request + * @param string $object_type the type of object to upload the file to + * @param int $id the ID of the object to delete from so we can check permisisons + * @param $file_id the ID of the file to delete from the action_logs table + * @since [v8.1.17] * @author [A. Gianotto ] */ public function destroy($object_type, $id, $file_id) : JsonResponse diff --git a/app/Http/Requests/UploadFileRequest.php b/app/Http/Requests/UploadFileRequest.php index 1150107f2f..91c5ef512a 100644 --- a/app/Http/Requests/UploadFileRequest.php +++ b/app/Http/Requests/UploadFileRequest.php @@ -60,7 +60,8 @@ class UploadFileRequest extends Request return $file_name; } - public function handleSVG($file) { + public function handleSVG($file) + { $sanitizer = new Sanitizer(); $dirtySVG = file_get_contents($file->getRealPath()); return $sanitizer->sanitize($dirtySVG); @@ -71,6 +72,7 @@ class UploadFileRequest extends Request * Get the validation error messages that apply to the request, but * replace the attribute name with the name of the file that was attempted and failed * to make it clearer to the user which file is the bad one. + * * @return array */ public function attributes(): array diff --git a/app/Presenters/UploadedFilesPresenter.php b/app/Presenters/UploadedFilesPresenter.php index 26614def56..b46367c257 100644 --- a/app/Presenters/UploadedFilesPresenter.php +++ b/app/Presenters/UploadedFilesPresenter.php @@ -9,6 +9,7 @@ class UploadsPresenter extends Presenter { /** * Json Column Layout for bootstrap table + * * @return string */ public static function dataTableLayout($object) diff --git a/tests/Feature/Accessories/Api/AccessoryFilesTest.php b/tests/Feature/Accessories/Api/AccessoryFilesTest.php index 1287eb38bc..9e5088082b 100644 --- a/tests/Feature/Accessories/Api/AccessoryFilesTest.php +++ b/tests/Feature/Accessories/Api/AccessoryFilesTest.php @@ -24,7 +24,8 @@ class AccessoryFilesTest extends TestCase ->post( route('api.files.store', ['object_type' => 'accessories', 'id' => $accessory->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); } @@ -41,12 +42,15 @@ class AccessoryFilesTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'accessories', 'id' => $accessory->id])) + route('api.files.index', ['object_type' => 'accessories', 'id' => $accessory->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'rows', 'total', - ]); + ] + ); } public function testAccessoryFailsIfInvalidTypePassedInUrl() @@ -62,7 +66,8 @@ class AccessoryFilesTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $accessory->id])) + route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $accessory->id]) + ) ->assertStatus(404); } @@ -79,7 +84,8 @@ class AccessoryFilesTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'accessories', 'id' => 100000])) + route('api.files.index', ['object_type' => 'accessories', 'id' => 100000]) + ) ->assertOk() ->assertStatusMessageIs('error'); } @@ -99,12 +105,15 @@ class AccessoryFilesTest extends TestCase ->post( route('api.files.store', ['object_type' => 'accessories', 'id' => $accessory->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // Upload a file with notes $this->actingAsForApi($user) @@ -112,19 +121,24 @@ class AccessoryFilesTest extends TestCase route('api.files.store', ['object_type' => 'accessories', 'id' => $accessory->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], 'notes' => 'manual' - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'accessories', 'id' => $accessory->id])) + route('api.files.index', ['object_type' => 'accessories', 'id' => $accessory->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'total', 'rows'=>[ '*' => [ @@ -138,18 +152,22 @@ class AccessoryFilesTest extends TestCase 'available_actions' ] ] - ]) - ->assertJsonPath('rows.0.note',null) - ->assertJsonPath('rows.1.note','manual'); + ] + ) + ->assertJsonPath('rows.0.note', null) + ->assertJsonPath('rows.1.note', 'manual'); // Get the file $this->actingAsForApi($user) ->get( - route('api.files.show', [ + route( + 'api.files.show', [ 'object_type' => 'accessories', 'id' => $accessory->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk(); } @@ -168,27 +186,34 @@ class AccessoryFilesTest extends TestCase ->post( route('api.files.store', ['object_type' => 'accessories', 'id' => $accessory->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'accessories', 'id' => $accessory->id])) + route('api.files.index', ['object_type' => 'accessories', 'id' => $accessory->id]) + ) ->assertOk(); // Delete the file $this->actingAsForApi($user) ->delete( - route('api.files.destroy', [ + route( + 'api.files.destroy', [ 'object_type' => 'accessories', 'id' => $accessory->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); } } \ No newline at end of file diff --git a/tests/Feature/AssetModels/Api/AssetModelFilesTest.php b/tests/Feature/AssetModels/Api/AssetModelFilesTest.php index 93eeca386b..79e5786a48 100644 --- a/tests/Feature/AssetModels/Api/AssetModelFilesTest.php +++ b/tests/Feature/AssetModels/Api/AssetModelFilesTest.php @@ -24,7 +24,8 @@ class AssetModelFilesTest extends TestCase ->post( route('api.files.store', ['object_type' => 'models', 'id' => $model->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); } @@ -41,12 +42,15 @@ class AssetModelFilesTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'models', 'id' => $model->id])) + route('api.files.index', ['object_type' => 'models', 'id' => $model->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'rows', 'total', - ]); + ] + ); } public function testAssetModelFailsIfInvalidTypePassedInUrl() @@ -62,7 +66,8 @@ class AssetModelFilesTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $model->id])) + route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $model->id]) + ) ->assertStatus(404); } @@ -79,7 +84,8 @@ class AssetModelFilesTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'models', 'id' => 100000])) + route('api.files.index', ['object_type' => 'models', 'id' => 100000]) + ) ->assertOk() ->assertStatusMessageIs('error'); } @@ -99,12 +105,15 @@ class AssetModelFilesTest extends TestCase ->post( route('api.files.store', ['object_type' => 'models', 'id' => $model->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // Upload a file with notes $this->actingAsForApi($user) @@ -112,19 +121,24 @@ class AssetModelFilesTest extends TestCase route('api.files.store', ['object_type' => 'models', 'id' => $model->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], 'notes' => 'manual' - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'models', 'id' => $model->id])) + route('api.files.index', ['object_type' => 'models', 'id' => $model->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'total', 'rows'=>[ '*' => [ @@ -138,18 +152,22 @@ class AssetModelFilesTest extends TestCase 'available_actions' ] ] - ]) - ->assertJsonPath('rows.0.note',null) - ->assertJsonPath('rows.1.note','manual'); + ] + ) + ->assertJsonPath('rows.0.note', null) + ->assertJsonPath('rows.1.note', 'manual'); // Get the file $this->actingAsForApi($user) ->get( - route('api.files.show', [ + route( + 'api.files.show', [ 'object_type' => 'models', 'id' => $model->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk(); } @@ -168,27 +186,34 @@ class AssetModelFilesTest extends TestCase ->post( route('api.files.store', ['object_type' => 'models', 'id' => $model->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'models', 'id' => $model->id])) + route('api.files.index', ['object_type' => 'models', 'id' => $model->id]) + ) ->assertOk(); // Delete the file $this->actingAsForApi($user) ->delete( - route('api.files.destroy', [ + route( + 'api.files.destroy', [ 'object_type' => 'models', 'id' => $model->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); } } \ No newline at end of file diff --git a/tests/Feature/Assets/Api/AssetFilesTest.php b/tests/Feature/Assets/Api/AssetFilesTest.php index 251480338d..ff87958170 100644 --- a/tests/Feature/Assets/Api/AssetFilesTest.php +++ b/tests/Feature/Assets/Api/AssetFilesTest.php @@ -24,7 +24,8 @@ class AssetFilesTest extends TestCase ->post( route('api.files.store', ['object_type' => 'assets', 'id' => $asset->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); } @@ -42,10 +43,12 @@ class AssetFilesTest extends TestCase $this->actingAsForApi($user) ->getJson(route('api.files.index', ['object_type' => 'assets', 'id' => $asset->id])) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'rows', 'total', - ]); + ] + ); } public function testAssetApiDownloadsFile() @@ -60,9 +63,11 @@ class AssetFilesTest extends TestCase //Upload a file $this->actingAsForApi($user) - ->post(route('api.files.store', ['object_type' => 'assets', 'id' => $asset->id]), [ + ->post( + route('api.files.store', ['object_type' => 'assets', 'id' => $asset->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); // List the files to get the file ID @@ -86,13 +91,15 @@ class AssetFilesTest extends TestCase ->post( route('api.files.store', ['object_type' => 'assets', 'id' => $asset->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'assets', 'id' => $asset->id])) + route('api.files.index', ['object_type' => 'assets', 'id' => $asset->id]) + ) ->assertOk(); } diff --git a/tests/Feature/Components/Api/ComponentFileTest.php b/tests/Feature/Components/Api/ComponentFileTest.php index 5b13659fa5..c8bc8b6fe9 100644 --- a/tests/Feature/Components/Api/ComponentFileTest.php +++ b/tests/Feature/Components/Api/ComponentFileTest.php @@ -22,7 +22,8 @@ class ComponentFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'components', 'id' => $component->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); } @@ -39,12 +40,15 @@ class ComponentFileTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'components', 'id' => $component->id])) + route('api.files.index', ['object_type' => 'components', 'id' => $component->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'rows', 'total', - ]); + ] + ); } public function testComponentFailsIfInvalidTypePassedInUrl() @@ -60,7 +64,8 @@ class ComponentFileTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $component->id])) + route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $component->id]) + ) ->assertStatus(404); } @@ -77,7 +82,8 @@ class ComponentFileTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'components', 'id' => 100000])) + route('api.files.index', ['object_type' => 'components', 'id' => 100000]) + ) ->assertOk() ->assertStatusMessageIs('error'); } @@ -97,12 +103,15 @@ class ComponentFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'components', 'id' => $component->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // Upload a file with notes $this->actingAsForApi($user) @@ -110,19 +119,24 @@ class ComponentFileTest extends TestCase route('api.files.store', ['object_type' => 'components', 'id' => $component->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], 'notes' => 'manual' - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'components', 'id' => $component->id])) + route('api.files.index', ['object_type' => 'components', 'id' => $component->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'total', 'rows'=>[ '*' => [ @@ -136,18 +150,22 @@ class ComponentFileTest extends TestCase 'available_actions' ] ] - ]) - ->assertJsonPath('rows.0.note',null) - ->assertJsonPath('rows.1.note','manual'); + ] + ) + ->assertJsonPath('rows.0.note', null) + ->assertJsonPath('rows.1.note', 'manual'); // Get the file $this->actingAsForApi($user) ->get( - route('api.files.show', [ + route( + 'api.files.show', [ 'object_type' => 'components', 'id' => $component->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk(); } @@ -166,27 +184,34 @@ class ComponentFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'components', 'id' => $component->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'components', 'id' => $component->id])) + route('api.files.index', ['object_type' => 'components', 'id' => $component->id]) + ) ->assertOk(); // Delete the file $this->actingAsForApi($user) ->delete( - route('api.files.destroy', [ + route( + 'api.files.destroy', [ 'object_type' => 'components', 'id' => $component->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); } } \ No newline at end of file diff --git a/tests/Feature/Consumables/Api/ConsumableFileTest.php b/tests/Feature/Consumables/Api/ConsumableFileTest.php index c515c64d5c..7fc2bc10cb 100644 --- a/tests/Feature/Consumables/Api/ConsumableFileTest.php +++ b/tests/Feature/Consumables/Api/ConsumableFileTest.php @@ -24,7 +24,8 @@ class ConsumableFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'consumables', 'id' => $consumable->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); } @@ -41,12 +42,15 @@ class ConsumableFileTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'consumables', 'id' => $consumable->id])) + route('api.files.index', ['object_type' => 'consumables', 'id' => $consumable->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'rows', 'total', - ]); + ] + ); } public function testConsumableFailsIfInvalidTypePassedInUrl() @@ -62,7 +66,8 @@ class ConsumableFileTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $consumable->id])) + route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $consumable->id]) + ) ->assertStatus(404); } @@ -79,7 +84,8 @@ class ConsumableFileTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'consumables', 'id' => 100000])) + route('api.files.index', ['object_type' => 'consumables', 'id' => 100000]) + ) ->assertOk() ->assertStatusMessageIs('error'); } @@ -99,12 +105,15 @@ class ConsumableFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'consumables', 'id' => $consumable->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // Upload a file with notes $this->actingAsForApi($user) @@ -112,19 +121,24 @@ class ConsumableFileTest extends TestCase route('api.files.store', ['object_type' => 'consumables', 'id' => $consumable->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], 'notes' => 'manual' - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'consumables', 'id' => $consumable->id])) + route('api.files.index', ['object_type' => 'consumables', 'id' => $consumable->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'total', 'rows'=>[ '*' => [ @@ -138,18 +152,22 @@ class ConsumableFileTest extends TestCase 'available_actions' ] ] - ]) - ->assertJsonPath('rows.0.note',null) - ->assertJsonPath('rows.1.note','manual'); + ] + ) + ->assertJsonPath('rows.0.note', null) + ->assertJsonPath('rows.1.note', 'manual'); // Get the file $this->actingAsForApi($user) ->get( - route('api.files.show', [ + route( + 'api.files.show', [ 'object_type' => 'consumables', 'id' => $consumable->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk(); } @@ -168,27 +186,34 @@ class ConsumableFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'consumables', 'id' => $consumable->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'consumables', 'id' => $consumable->id])) + route('api.files.index', ['object_type' => 'consumables', 'id' => $consumable->id]) + ) ->assertOk(); // Delete the file $this->actingAsForApi($user) ->delete( - route('api.files.destroy', [ + route( + 'api.files.destroy', [ 'object_type' => 'consumables', 'id' => $consumable->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); } } \ No newline at end of file diff --git a/tests/Feature/Licenses/Api/LicenseUploadTest.php b/tests/Feature/Licenses/Api/LicenseUploadTest.php index a35151074f..ed46f7d199 100644 --- a/tests/Feature/Licenses/Api/LicenseUploadTest.php +++ b/tests/Feature/Licenses/Api/LicenseUploadTest.php @@ -24,7 +24,8 @@ class LicenseUploadTest extends TestCase ->post( route('api.files.store', ['object_type' => 'licenses', 'id' => $license->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); } @@ -41,12 +42,15 @@ class LicenseUploadTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'licenses', 'id' => $license->id])) + route('api.files.index', ['object_type' => 'licenses', 'id' => $license->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'rows', 'total', - ]); + ] + ); } public function testLicenseFailsIfInvalidTypePassedInUrl() @@ -62,7 +66,8 @@ class LicenseUploadTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $license->id])) + route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $license->id]) + ) ->assertStatus(404); } @@ -79,7 +84,8 @@ class LicenseUploadTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'licenses', 'id' => 100000])) + route('api.files.index', ['object_type' => 'licenses', 'id' => 100000]) + ) ->assertOk() ->assertStatusMessageIs('error'); } @@ -99,12 +105,15 @@ class LicenseUploadTest extends TestCase ->post( route('api.files.store', ['object_type' => 'licenses', 'id' => $license->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // Upload a file with notes $this->actingAsForApi($user) @@ -112,19 +121,24 @@ class LicenseUploadTest extends TestCase route('api.files.store', ['object_type' => 'licenses', 'id' => $license->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], 'notes' => 'manual' - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'licenses', 'id' => $license->id])) + route('api.files.index', ['object_type' => 'licenses', 'id' => $license->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'total', 'rows'=>[ '*' => [ @@ -138,18 +152,22 @@ class LicenseUploadTest extends TestCase 'available_actions' ] ] - ]) - ->assertJsonPath('rows.0.note',null) - ->assertJsonPath('rows.1.note','manual'); + ] + ) + ->assertJsonPath('rows.0.note', null) + ->assertJsonPath('rows.1.note', 'manual'); // Get the file $this->actingAsForApi($user) ->get( - route('api.files.show', [ + route( + 'api.files.show', [ 'object_type' => 'licenses', 'id' => $license->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk(); } @@ -168,27 +186,34 @@ class LicenseUploadTest extends TestCase ->post( route('api.files.store', ['object_type' => 'licenses', 'id' => $license->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'licenses', 'id' => $license->id])) + route('api.files.index', ['object_type' => 'licenses', 'id' => $license->id]) + ) ->assertOk(); // Delete the file $this->actingAsForApi($user) ->delete( - route('api.files.destroy', [ + route( + 'api.files.destroy', [ 'object_type' => 'licenses', 'id' => $license->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); } } \ No newline at end of file diff --git a/tests/Feature/Locations/Api/LocationFileTest.php b/tests/Feature/Locations/Api/LocationFileTest.php index 370446d321..bf4680ffff 100644 --- a/tests/Feature/Locations/Api/LocationFileTest.php +++ b/tests/Feature/Locations/Api/LocationFileTest.php @@ -22,7 +22,8 @@ class LocationFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'locations', 'id' => $location->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); } @@ -39,12 +40,15 @@ class LocationFileTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'locations', 'id' => $location->id])) + route('api.files.index', ['object_type' => 'locations', 'id' => $location->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'rows', 'total', - ]); + ] + ); } public function testLocationFailsIfInvalidTypePassedInUrl() @@ -60,7 +64,8 @@ class LocationFileTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $location->id])) + route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $location->id]) + ) ->assertStatus(404); } @@ -77,7 +82,8 @@ class LocationFileTest extends TestCase // List the files $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'locations', 'id' => 100000])) + route('api.files.index', ['object_type' => 'locations', 'id' => 100000]) + ) ->assertOk() ->assertStatusMessageIs('error'); } @@ -97,12 +103,15 @@ class LocationFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'locations', 'id' => $location->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // Upload a file with notes $this->actingAsForApi($user) @@ -110,19 +119,24 @@ class LocationFileTest extends TestCase route('api.files.store', ['object_type' => 'locations', 'id' => $location->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], 'notes' => 'manual' - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'locations', 'id' => $location->id])) + route('api.files.index', ['object_type' => 'locations', 'id' => $location->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'total', 'rows'=>[ '*' => [ @@ -136,18 +150,22 @@ class LocationFileTest extends TestCase 'available_actions' ] ] - ]) - ->assertJsonPath('rows.0.note',null) - ->assertJsonPath('rows.1.note','manual'); + ] + ) + ->assertJsonPath('rows.0.note', null) + ->assertJsonPath('rows.1.note', 'manual'); // Get the file $this->actingAsForApi($user) ->get( - route('api.files.show', [ + route( + 'api.files.show', [ 'object_type' => 'locations', 'id' => $location->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk(); } @@ -166,27 +184,34 @@ class LocationFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'locations', 'id' => $location->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); // List the files to get the file ID $result = $this->actingAsForApi($user) ->getJson( - route('api.files.index', ['object_type' => 'locations', 'id' => $location->id])) + route('api.files.index', ['object_type' => 'locations', 'id' => $location->id]) + ) ->assertOk(); // Delete the file $this->actingAsForApi($user) ->delete( - route('api.files.destroy', [ + route( + 'api.files.destroy', [ 'object_type' => 'locations', 'id' => $location->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); } } \ No newline at end of file diff --git a/tests/Feature/Users/Api/UserFileTest.php b/tests/Feature/Users/Api/UserFileTest.php index e7a43e0c27..85528706ca 100644 --- a/tests/Feature/Users/Api/UserFileTest.php +++ b/tests/Feature/Users/Api/UserFileTest.php @@ -21,7 +21,8 @@ class UserFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'users', 'id' => $user->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); } @@ -38,12 +39,15 @@ class UserFileTest extends TestCase // List the files $this->actingAsForApi($admin) ->getJson( - route('api.files.index', ['object_type' => 'users', 'id' => $user->id])) + route('api.files.index', ['object_type' => 'users', 'id' => $user->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'rows', 'total', - ]); + ] + ); } public function testUserFailsIfInvalidTypePassedInUrl() @@ -59,7 +63,8 @@ class UserFileTest extends TestCase // List the files $this->actingAsForApi($admin) ->getJson( - route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $user->id])) + route('api.files.index', ['object_type' => 'shibboleeeeeet', 'id' => $user->id]) + ) ->assertStatus(404); } @@ -76,7 +81,8 @@ class UserFileTest extends TestCase // List the files $this->actingAsForApi($admin) ->getJson( - route('api.files.index', ['object_type' => 'users', 'id' => 100000])) + route('api.files.index', ['object_type' => 'users', 'id' => 100000]) + ) ->assertOk() ->assertStatusMessageIs('error'); } @@ -96,12 +102,15 @@ class UserFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'users', 'id' => $user->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // Upload a file with notes $this->actingAsForApi($admin) @@ -109,19 +118,24 @@ class UserFileTest extends TestCase route('api.files.store', ['object_type' => 'users', 'id' => $user->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)], 'notes' => 'manual' - ]) + ] + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); // List the files to get the file ID $result = $this->actingAsForApi($admin) ->getJson( - route('api.files.index', ['object_type' => 'users', 'id' => $user->id])) + route('api.files.index', ['object_type' => 'users', 'id' => $user->id]) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'total', 'rows'=>[ '*' => [ @@ -135,18 +149,22 @@ class UserFileTest extends TestCase 'available_actions' ] ] - ]) - ->assertJsonPath('rows.0.note',null) - ->assertJsonPath('rows.1.note','manual'); + ] + ) + ->assertJsonPath('rows.0.note', null) + ->assertJsonPath('rows.1.note', 'manual'); // Get the file $this->actingAsForApi($admin) ->get( - route('api.files.show', [ + route( + 'api.files.show', [ 'object_type' => 'users', 'id' => $user->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk(); } @@ -165,27 +183,34 @@ class UserFileTest extends TestCase ->post( route('api.files.store', ['object_type' => 'users', 'id' => $user->id]), [ 'file' => [UploadedFile::fake()->create("test.jpg", 100)] - ]) + ] + ) ->assertOk(); // List the files to get the file ID $result = $this->actingAsForApi($admin) ->getJson( - route('api.files.index', ['object_type' => 'users', 'id' => $user->id])) + route('api.files.index', ['object_type' => 'users', 'id' => $user->id]) + ) ->assertOk(); // Delete the file $this->actingAsForApi($admin) ->delete( - route('api.files.destroy', [ + route( + 'api.files.destroy', [ 'object_type' => 'users', 'id' => $user->id, 'file_id' => $result->decodeResponseJson()->json()["rows"][0]["id"], - ])) + ] + ) + ) ->assertOk() - ->assertJsonStructure([ + ->assertJsonStructure( + [ 'status', 'messages', - ]); + ] + ); } } \ No newline at end of file