From bc120ac3cf0e01b3cf29686531163fee2bb1c467 Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 5 Sep 2024 11:21:40 +0200 Subject: [PATCH] Add units tests --- .../Glpi/Inventory/InventoryTest.php | 174 +++++++----------- phpunit/functional/RuleImportAssetTest.php | 2 +- 2 files changed, 65 insertions(+), 111 deletions(-) diff --git a/phpunit/functional/Glpi/Inventory/InventoryTest.php b/phpunit/functional/Glpi/Inventory/InventoryTest.php index bf758e68770..1bf3156359d 100644 --- a/phpunit/functional/Glpi/Inventory/InventoryTest.php +++ b/phpunit/functional/Glpi/Inventory/InventoryTest.php @@ -8591,73 +8591,75 @@ public function testRuleRefuseImportComputerVirtualMachines() public function testRuleRefuseUpdateComputerVirtualMachines() { - //change config to import vms as computers + // Helper function to create JSON string + function createJsonString($versionClient) + { + return <<login(); $conf = new \Glpi\Inventory\Conf(); $this->assertTrue($conf->saveConf(['vm_as_computer' => 1])); $this->logout(); - $json_str = <<content->virtualmachines); $nb_computers = countElementsInTable(\Computer::getTable()); $this->doInventory($json); - //check created vms + // Check created VMs $this->assertSame($count_vms, countElementsInTable(\ItemVirtualMachine::getTable())); - $this->assertSame($nb_computers + 3, countElementsInTable(\Computer::getTable())); + $this->assertSame($nb_computers + 2, countElementsInTable(\Computer::getTable())); + $computer = new \Computer(); + $computer->getFromDBByCrit(['name' => 'mailpit_update']); + // Create Docker VM type $nb_vm = countElementsInTable(\VirtualMachineType::getTable()); $docker_vm = $this->createItems( \VirtualMachineType::class, @@ -8665,10 +8667,9 @@ public function testRuleRefuseUpdateComputerVirtualMachines() ['name' => 'docker'], ] ); - $this->assertGreaterThan($nb_vm, countElementsInTable(\VirtualMachineType::getTable())); - //IMPORT rule to refuse "db" virtual machine + // Import rule to refuse "docker" virtual machine $criteria = [ [ 'condition' => 0, @@ -8723,62 +8724,15 @@ public function testRuleRefuseUpdateComputerVirtualMachines() $nb_computers = countElementsInTable(\Computer::getTable()); - $json_str = <<doInventory($json); - //check created vms + // Check created VMs $this->assertSame($count_vms, countElementsInTable(\ItemVirtualMachine::getTable())); $this->assertSame($nb_computers, countElementsInTable(\Computer::getTable())); + $c_update = new \Computer(); + $c_update->getFromDBByCrit(['name' => 'mailpit_update']); + $this->assertSame($c_update->fields['date_mod'], $computer->fields['date_mod']); } } diff --git a/phpunit/functional/RuleImportAssetTest.php b/phpunit/functional/RuleImportAssetTest.php index 8d07fe6ceac..a7a10abb452 100644 --- a/phpunit/functional/RuleImportAssetTest.php +++ b/phpunit/functional/RuleImportAssetTest.php @@ -1010,7 +1010,7 @@ public function testMaxActionsCount() public function testGetCriteria() { $instance = new \RuleImportAsset(); - $this->assertSame(23, count($instance->getCriterias())); + $this->assertSame(24, count($instance->getCriterias())); } public function testGetActions()