Skip to content

A free open source IT asset/license management system

Updated tests

snipe02bb0356a62f
diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php
index 10a0925864..1d7615e158 100644
--- a/app/Importer/ItemImporter.php
+++ b/app/Importer/ItemImporter.php
@@ -182,7 +182,14 @@ class ItemImporter extends Importer
if (method_exists($model, 'adjustQuantity')) {
if (array_key_exists('qty', $sanitized)) {
- $qtyRequested = (int) $sanitized['qty'];
+ // Empty CSV cell (present but blank) means "don't touch qty"
+ // on update — not "set qty to 0". Casting '' straight to (int)
+ // 0 produced a delta of -currentQty and silently drained
+ // inventory on any import row that included an empty
+ // quantity column.
+ if ($sanitized['qty'] !== '' && $sanitized['qty'] !== null) {
+ $qtyRequested = (int) $sanitized['qty'];
+ }
unset($sanitized['qty']);
}
if (array_key_exists('order_number', $sanitized)) {
diff --git a/database/migrations/2026_07_29_000001_index_order_number_on_action_logs.php b/database/migrations/2026_07_29_000001_index_order_number_on_action_logs.php
index 8a6c3ae276..450ed92dde 100644
--- a/database/migrations/2026_07_29_000001_index_order_number_on_action_logs.php
+++ b/database/migrations/2026_07_29_000001_index_order_number_on_action_logs.php
@@ -17,6 +17,7 @@ return new class extends Migration
{
Schema::table('action_logs', function (Blueprint $table) {
$table->index('order_number');
+ $table->index(['item_type', 'item_id', 'quantity']);
});
}
diff --git a/tests/Feature/Assets/Ui/EncryptedCustomFieldFormDisclosureTest.php b/tests/Feature/Assets/Ui/EncryptedCustomFieldFormDisclosureTest.php
index 302badf144..ac8807a7ba 100644
--- a/tests/Feature/Assets/Ui/EncryptedCustomFieldFormDisclosureTest.php
+++ b/tests/Feature/Assets/Ui/EncryptedCustomFieldFormDisclosureTest.php
@@ -8,6 +8,7 @@ use App\Models\CustomField;
use App\Models\CustomFieldset;
use App\Models\User;
use Illuminate\Support\Facades\Crypt;
+use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;
/**
@@ -24,9 +25,7 @@ use Tests\TestCase;
*/
class EncryptedCustomFieldFormDisclosureTest extends TestCase
{
- /**
- * @dataProvider elementTypeProvider
- */
+ #[DataProvider('elementTypeProvider')]
public function test_edit_form_masks_encrypted_custom_field_for_user_without_view_encrypted(array $fieldAttributes, string $secret): void
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
@@ -42,9 +41,7 @@ class EncryptedCustomFieldFormDisclosureTest extends TestCase
->assertSee(strtoupper(trans('admin/custom_fields/general.encrypted')), false);
}
- /**
- * @dataProvider elementTypeProvider
- */
+ #[DataProvider('elementTypeProvider')]
public function test_edit_form_shows_encrypted_custom_field_plaintext_for_superuser(array $fieldAttributes, string $secret): void
{
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
diff --git a/tests/Feature/Importing/Api/ImportAccessoriesTest.php b/tests/Feature/Importing/Api/ImportAccessoriesTest.php
index b4051a061b..decf50c786 100644
--- a/tests/Feature/Importing/Api/ImportAccessoriesTest.php
+++ b/tests/Feature/Importing/Api/ImportAccessoriesTest.php
@@ -408,10 +408,15 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio
// Import a CSV that only has the identity field (name) plus one
// updated column. All other Accessory fields are absent from the
- // CSV, so their DB values must be preserved on update.
+ // CSV, so their DB values must be preserved on update. We update
+ // model_number here as the "one changed field" proxy instead of
+ // order_number, because Accessory (like Consumable/Component)
+ // hides its parent-level order_number behind an accessor that
+ // returns null — reads via $accessory->order_number can't verify
+ // the write. model_number is a plain readable column.
$partialFile = new ImportFileBuilder([[
'itemName' => $accessory->name,
- 'orderNumber' => 'UPDATED-ORDER',
+ 'modelNumber' => 'UPDATED-MODEL-NUMBER',
]]);
$partialImport = Import::factory()->accessory()->create([
'file_path' => $partialFile->saveToImportsDirectory(),
@@ -423,7 +428,7 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio
])->assertOk();
$accessory->refresh();
- $this->assertEquals('UPDATED-ORDER', $accessory->order_number);
+ $this->assertEquals('UPDATED-MODEL-NUMBER', $accessory->model_number);
$this->assertEquals($originalNotes, $accessory->notes);
$this->assertEquals($originalPurchaseDate, $accessory->purchase_date?->toDateString());
}
diff --git a/tests/Feature/Importing/Api/ImportComponentsTest.php b/tests/Feature/Importing/Api/ImportComponentsTest.php
index f4780fba07..2451ea193a 100644
--- a/tests/Feature/Importing/Api/ImportComponentsTest.php
+++ b/tests/Feature/Importing/Api/ImportComponentsTest.php
@@ -260,18 +260,22 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission
{
$this->actingAsForApi(User::factory()->superuser()->create());
+ // purchase_date is the sole proxy for the "empty CSV cell clears
+ // the DB column" behavior here. order_number is not exercised
+ // because Component / Accessory / Consumable all hide the
+ // parent-level order_number behind an accessor that returns null
+ // (see Component::getOrderNumberAttribute) — reads via
+ // $component->order_number would be null regardless of the DB
+ // state and would give a false green for this test.
$component = Component::factory()->create([
- 'order_number' => 'PRE-EXISTING-ORDER',
'purchase_date' => '2022-01-01',
])->refresh();
$this->assertNotNull($component->purchase_date);
- $this->assertNotEmpty($component->order_number);
$row = ImportFileBuilder::new()->definition();
$row['itemName'] = $component->name;
$row['serialNumber'] = $component->serial;
- $row['orderNumber'] = '';
$row['purchaseDate'] = '';
$importFileBuilder = new ImportFileBuilder([$row]);
@@ -285,7 +289,6 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission
])->assertOk();
$component->refresh();
- $this->assertNull($component->order_number);
$this->assertNull($component->purchase_date);
}
diff --git a/tests/Feature/Importing/Api/ImportConsumablesTest.php b/tests/Feature/Importing/Api/ImportConsumablesTest.php
index 15d6ec09e2..9d7f9573a8 100644
--- a/tests/Feature/Importing/Api/ImportConsumablesTest.php
+++ b/tests/Feature/Importing/Api/ImportConsumablesTest.php
@@ -283,17 +283,21 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio
{
$this->actingAsForApi(User::factory()->superuser()->create());
+ // purchase_date is the sole proxy for the "empty CSV cell clears
+ // the DB column" behavior here. order_number is not exercised
+ // because Consumable / Accessory / Component all hide the
+ // parent-level order_number behind an accessor that returns null
+ // (see Consumable::getOrderNumberAttribute) — reads via
+ // $consumable->order_number would be null regardless of the DB
+ // state and would give a false green for this test.
$consumable = Consumable::factory()->create([
- 'order_number' => 'PRE-EXISTING-ORDER',
'purchase_date' => '2022-01-01',
])->refresh();
$this->assertNotNull($consumable->purchase_date);
- $this->assertNotEmpty($consumable->order_number);
$row = ImportFileBuilder::new()->definition();
$row['itemName'] = $consumable->name;
- $row['orderNumber'] = '';
$row['purchaseDate'] = '';
$importFileBuilder = new ImportFileBuilder([$row]);
@@ -307,7 +311,6 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio
])->assertOk();
$consumable->refresh();
- $this->assertNull($consumable->order_number);
$this->assertNull($consumable->purchase_date);
}