From 25480293dc3f31435c7b5a792cf05175075a8063 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 30 Apr 2024 18:03:26 -0500 Subject: [PATCH] change keys to values, add test --- .../Assets/BulkAssetsController.php | 2 +- resources/views/hardware/bulk.blade.php | 4 +-- tests/Feature/Assets/AssetsBulkEditTest.php | 33 +++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/Assets/AssetsBulkEditTest.php diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 561e13b200..d60507527f 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -214,7 +214,7 @@ class BulkAssetsController extends Controller } - $assets = Asset::whereIn('id', array_keys($request->input('ids')))->get(); + $assets = Asset::whereIn('id', $request->input('ids'))->get(); diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index fa4680e2e8..d4f0544851 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -196,8 +196,8 @@ @include("models/custom_fields_form_bulk_edit",["models" => $models]) - @foreach ($assets as $key => $value) - + @foreach($assets as $asset) + @endforeach diff --git a/tests/Feature/Assets/AssetsBulkEditTest.php b/tests/Feature/Assets/AssetsBulkEditTest.php new file mode 100644 index 0000000000..7054b36da6 --- /dev/null +++ b/tests/Feature/Assets/AssetsBulkEditTest.php @@ -0,0 +1,33 @@ +count(10)->create(['purchase_date' => '2023-01-01']); + + $id_array = $assets->pluck('id')->toArray(); + + $response = $this->actingAs(User::factory()->editAssets()->create())->post(route('hardware/bulksave'), [ + 'ids' => array_values($id_array), + 'purchase_date' => '2024-01-01' + ]) + ->assertStatus(302) + ->assertSessionHasNoErrors(); + + Asset::findMany($id_array)->each(function (Asset $asset) { + $this->assertEquals('2024-01-01', $asset->purchase_date->format('Y-m-d')); + }); + + $this->assertDatabaseHas('assets', [ + 'purchase_date' => '2024-01-01' + ]); + } +}