Skip to content

Commit 5329e56

Browse files
Lainowstonebuzz
andauthored
Fix inventory_lockable_objects list (#19692)
* Fix inventory_lockable_objects list * Fix lint * Fix lint * Update phpunit/functional/LockedfieldTest.php Co-authored-by: Stanislas <skita@teclib.com> * Fix units tests --------- Co-authored-by: Stanislas <skita@teclib.com>
1 parent f97e0b0 commit 5329e56

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

inc/define.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@
496496
'Item_DeviceControl', 'Item_DeviceDrive', 'Item_DeviceFirmware', 'Item_DeviceGeneric', 'Item_DeviceGraphicCard',
497497
'Item_DeviceHardDrive', 'Item_DeviceMemory', 'Item_DeviceMotherboard', 'Item_DeviceNetworkCard', 'Item_DevicePci',
498498
'Item_DevicePowerSupply', 'Item_DeviceProcessor', 'Item_DeviceSensor', 'Item_DeviceSimcard', 'Item_DeviceSoundCard',
499-
'DatabaseInstance', 'Item_RemoteManagement','Monitor', 'Domain_Item',
499+
'DatabaseInstance', 'Item_RemoteManagement','Monitor', 'Domain_Item', 'Peripheral', 'Unmanaged', 'Database',
500+
'Item_DeviceCamera', 'Item_DeviceCamera_ImageFormat', 'Item_DeviceCamera_ImageResolution',
500501
];
501502

502503
$CFG_GLPI["kb_types"] = ['Budget', 'Change', 'Computer',

phpunit/functional/LockedfieldTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,4 +924,49 @@ public function testReplaceLockedField()
924924
$this->assertTrue($computer->getFromDB($cid));
925925
$this->assertEquals($computer->fields['locations_id'], 0);
926926
}
927+
928+
public function testCheckAllInventoryLockableObjects()
929+
{
930+
$this->login('glpi', 'glpi');
931+
932+
/** @var \DBmysql $DB */
933+
global $DB;
934+
935+
/** @var array $CFG_GLPI */
936+
global $CFG_GLPI;
937+
foreach ($CFG_GLPI['inventory_lockable_objects'] as $itemtype) {
938+
$this->assertTrue($DB->fieldExists($itemtype::getTable(), 'is_dynamic'), "$itemtype does not have is_dynamic field");
939+
}
940+
941+
942+
// Excluded type with is_dynamic field but not in inventory_lockable_objects
943+
$excluded = [
944+
'UserEmail',
945+
'Group_User',
946+
'Profile_User',
947+
];
948+
949+
$global_inventory_type = array_merge(
950+
$CFG_GLPI['inventory_lockable_objects'],
951+
$CFG_GLPI['inventory_types']
952+
);
953+
954+
$tables = $DB->listTables();
955+
foreach ($tables as $table_data) {
956+
$table = $table_data['TABLE_NAME'];
957+
958+
if ($DB->fieldExists($table, 'is_dynamic')) {
959+
$itemtype = getItemTypeForTable($table);
960+
if (in_array($itemtype, $excluded)) {
961+
continue;
962+
}
963+
964+
$this->assertContains(
965+
$itemtype,
966+
$global_inventory_type,
967+
"$itemtype is not in inventory_lockable_objects or inventory_types"
968+
);
969+
}
970+
}
971+
}
927972
}

phpunit/functional/MassiveActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function actionsProvider()
7272
], [
7373
'itemtype' => 'Peripheral',
7474
'items_id' => '_test_peripheral_1',
75-
'allcount' => 18,
75+
'allcount' => 20,
7676
'singlecount' => 12,
7777
], [
7878
'itemtype' => 'Printer',

0 commit comments

Comments
 (0)