Skip to content

A free open source IT asset/license management system

cleanup and test

spencerrlongg12d5e4f7d27c
diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php
index f70d40e5d8..88ba51bf78 100644
--- a/app/Http/Controllers/Assets/BulkAssetsController.php
+++ b/app/Http/Controllers/Assets/BulkAssetsController.php
@@ -201,7 +201,6 @@ class BulkAssetsController extends Controller
*/
public function update(Request $request) : RedirectResponse
{
- //dd($request->all());
$this->authorize('update', Asset::class);
$has_errors = 0;
$error_array = array();
@@ -296,7 +295,6 @@ class BulkAssetsController extends Controller
$this->conditionallyAddItem($custom_field_column);
}
foreach ($custom_fields_to_null as $key => $custom_field_to_null) {
- //dd($key);
$this->conditionallyAddItem($key);
}
diff --git a/tests/Feature/Assets/Ui/BulkEditAssetsTest.php b/tests/Feature/Assets/Ui/BulkEditAssetsTest.php
index 44e9052482..58f7a11598 100644
--- a/tests/Feature/Assets/Ui/BulkEditAssetsTest.php
+++ b/tests/Feature/Assets/Ui/BulkEditAssetsTest.php
@@ -197,6 +197,47 @@ class BulkEditAssetsTest extends TestCase
});
}
+ public function testBulkEditAssetsNullsCustomFieldsIfSelected()
+ {
+ $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
+
+ CustomField::factory()->ram()->create();
+ CustomField::factory()->cpu()->create();
+ CustomField::factory()->phone()->create();
+
+ // when getting the custom field directly from the factory the field has not been fully created yet
+ // so we have to do a query afterwards to get the actual model :shrug:
+
+ $ram = CustomField::where('name', 'RAM')->first();
+ $cpu = CustomField::where('name', 'CPU')->first();
+ $phone = CustomField::where('name', 'Phone Number')->first();
+
+ $assets = Asset::factory()->count(10)->hasMultipleCustomFields([$ram, $cpu])->create([
+ $ram->db_column => 8,
+ $cpu->db_column => '2.1',
+ ]);
+
+ $id_array = $assets->pluck('id')->toArray();
+
+ $this->actingAs(User::factory()->editAssets()->create())->post(route('hardware/bulksave'), [
+ 'ids' => $id_array,
+ $ram->db_column => 16,
+ $cpu->db_column => '4.1',
+ 'null'.$phone->db_column => '8304997586',
+ ])->assertStatus(302);
+
+ $this->actingAs(User::factory()->editAssets()->create())->post(route('hardware/bulksave'), [
+ 'ids' => $id_array,
+ null.$phone->db_column => 1,
+ ]);
+
+ Asset::findMany($id_array)->each(function (Asset $asset) use ($ram, $cpu, $phone) {
+ $this->assertEquals(16, $asset->{$ram->db_column});
+ $this->assertEquals('4.1', $asset->{$cpu->db_column});
+ $this->assertEquals(null, $asset->{$phone->db_column});
+ });
+ }
+
public function testBulkEditAssetsAcceptsAndUpdatesEncryptedCustomFields()
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');