/** * @test */ public function prepareDB() { global $DB; $DB->connect(); $_SESSION['glpiactive_entity'] = 0; $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $query = "INSERT INTO `glpi_entities` " . " (`id`, `name`, `entities_id`, `level`) " . " VALUES ('1', 'ent1', '0', '2')"; $DB->query($query); $entities_id = 1; $pfAgent = new PluginFusioninventoryAgent(); $input = array('name' => 'toto', 'entities_id' => $entities_id, 'device_id' => 'toto-device'); $agents_id = $pfAgent->add($input); $config = new PluginFusioninventoryConfig(); $config->loadCache(); $pfEntity = new PluginFusioninventoryEntity(); $input = array('id' => 1, 'entities_id' => 0, 'agent_base_url' => 'http://127.0.0.1/glpi085'); $pfEntity->update($input); $input = array('entities_id' => $entities_id, 'agent_base_url' => 'http://10.0.2.2/glpi085'); $pfEntity->add($input); // active all modules $query = "UPDATE `glpi_plugin_fusioninventory_agentmodules`" . " SET `is_active`='1'"; $DB->query($query); }
------------------------------------------------------------------------ @package FusionInventory @author David Durieux @co-author @copyright Copyright (c) 2010-2014 FusionInventory team @license AGPL License 3.0 or (at your option) any later version http://www.gnu.org/licenses/agpl-3.0-standalone.html @link http://www.fusioninventory.org/ @link http://forge.fusioninventory.org/projects/fusioninventory-for-glpi/ @since 2014 ------------------------------------------------------------------------ */ include "../../../inc/includes.php"; $pfEntity = new PluginFusioninventoryEntity(); if (isset($_POST["add"])) { $pfEntity->add($_POST); Html::back(); } else { if (isset($_POST["update"])) { $pfEntity->update($_POST); Html::back(); } else { if (isset($_REQUEST["purge"])) { $pfEntity->delete($_POST); Html::back(); } } }
/** * Update computer to not change entity (transfer not allowed) * * @test */ public function updateComputerNoTranfer() { global $DB; $DB->connect(); $transfer = new Transfer(); $computer = new Computer(); $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory(); $pfEntity = new PluginFusioninventoryEntity(); // Manual transfer computer to entity 2 $transfer->getFromDB(1); $item_to_transfer = array("Computer" => array(1 => 1)); $transfer->moveItems($item_to_transfer, 2, $transfer->fields); $computer->getFromDB(1); $this->assertEquals(2, $computer->fields['entities_id'], 'Transfer move computer'); $this->AgentEntity(1, 2, 'Transfer computer on entity 2'); // Define entity 2 not allowed to transfer $ents_id = $pfEntity->add(array('entities_id' => 2, 'transfers_id_auto' => 0)); $this->assertEquals(2, $ents_id, 'Entity 2 defined with no transfer'); // Update computer and computer must not be transfered (keep in entoty 2) $a_inventory = array(); $a_inventory['CONTENT']['HARDWARE'] = array('NAME' => 'pc1'); $a_inventory['CONTENT']['BIOS'] = array('SSN' => 'xxyyzz'); $pfiComputerInv->import("pc-2013-02-13", "", $a_inventory); // Update $this->assertEquals(1, countElementsInTable('glpi_computers'), 'Must have only 1 computer'); $computer->getFromDB(1); $this->assertEquals(2, $computer->fields['entities_id'], 'Computer must not be transfered'); $this->AgentEntity(1, 2, 'Agent must stay with entity 2'); }