/**
  * @test
  */
 public function PeripheralUniqueSerialimport()
 {
     global $DB;
     $DB->connect();
     self::restore_database();
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $_SESSION["glpiname"] = 'Plugin_FusionInventory';
     $pfConfig = new PluginFusioninventoryConfig();
     $pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
     $computer = new Computer();
     $GLPIlog = new GLPIlogs();
     $pxml = @simplexml_load_string($this->a_computer1_XML, 'SimpleXMLElement', LIBXML_NOCDATA);
     $arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($pxml);
     $agent = new PluginFusioninventoryAgent();
     $agents_id = $agent->importToken($arrayinventory);
     $_SESSION['plugin_fusioninventory_agents_id'] = $agents_id;
     $pfInventoryComputerInventory = new PluginFusioninventoryInventoryComputerInventory();
     $pfInventoryComputerInventory->import('deviceid', $arrayinventory['CONTENT'], $arrayinventory);
     $computer->getFromDB(1);
     $this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly');
     $a_ref = array(1 => array('name' => 'Périphérique USB composite', 'id' => '1', 'serial' => '10075973', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '2', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0'), 2 => array('name' => 'H5321 gw Mobile Broadband Device', 'id' => '2', 'serial' => '187A047919938CM0', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '7', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0'), 3 => array('name' => 'Périphérique d’entrée USB', 'id' => '3', 'serial' => 'STM32_EMOTION2', 'peripheraltypes_id' => '0', 'peripheralmodels_id' => '0', 'manufacturers_id' => '8', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'is_dynamic' => '0'));
     $a_db_peripherals = getAllDatasFromTable('glpi_peripherals');
     foreach ($a_db_peripherals as $id => $data) {
         $data_temp = array('name' => $data['name'], 'id' => $data['id'], 'serial' => $data['serial'], 'peripheraltypes_id' => $data['peripheraltypes_id'], 'peripheralmodels_id' => $data['peripheralmodels_id'], 'manufacturers_id' => $data['manufacturers_id'], 'is_global' => $data['is_global'], 'is_deleted' => $data['is_deleted'], 'is_template' => $data['is_template'], 'is_dynamic' => $data['is_dynamic']);
         $a_db_peripherals[$id] = $data_temp;
     }
     $this->assertEquals($a_ref, $a_db_peripherals, 'List of peripherals');
     // Update computer and may not have new values in glpi_logs
     $query = "SELECT * FROM `glpi_logs`\n         ORDER BY `id` DESC LIMIT 1";
     $result = $DB->query($query);
     $data = $DB->fetch_assoc($result);
     $last_id = $data['id'];
     $pfInventoryComputerInventory->import('deviceid', $arrayinventory['CONTENT'], $arrayinventory);
     $data = getAllDatasFromTable('glpi_logs', "`id`>'" . $last_id . "'");
     $this->assertEquals(array(), $data, 'On update peripherals, may not have new lines in glpi_logs');
 }
 /**
  * @test
  * @dataProvider dataprovider
  */
 public function AddComputer($data)
 {
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION['glpiactiveentities_string'] = 0;
     $_SESSION['glpishowallentities'] = 1;
     $_SESSION['glpiname'] = 'glpi';
     $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory();
     $inventory = array();
     $inventory['CONTENT'] = $data['inventory']['CONTENT'];
     // ** Add agent
     $pfAgent = new PluginFusioninventoryAgent();
     $agent_name = $data['inventory']['AGENT']['name'];
     $computer_name = $data['inventory']['CONTENT']['HARDWARE']['NAME'];
     $agents_id = $pfAgent->add($data['inventory']['AGENT']);
     $_SESSION['plugin_fusioninventory_agents_id'] = $agents_id;
     // ** Add
     $pfiComputerInv->import($data['inventory']['AGENT']['device_id'], "", $inventory);
     // creation
     $this->CountSoftwares($data);
     $this->CountVersions($data);
 }
 /**
  * @test
  */
 public function AddComputerStep3()
 {
     global $DB;
     $this->mark_incomplete();
     return;
     // TODO: recode this test
     $DB->connect();
     $DB->query("UPDATE `glpi_entities`\n         SET `entities_id_software` = '-2'\n         WHERE `id`='1'");
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION['glpiactiveentities_string'] = 0;
     $_SESSION['glpishowallentities'] = 1;
     $_SESSION['glpiname'] = 'glpi';
     $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory();
     $computer = new Computer();
     $software = new Software();
     $input = array('id' => 1, 'is_recursive' => 0);
     $software->update($input);
     $computer->add(array('name' => 'pc2', 'entities_id' => 1));
     $a_inventory = array();
     $a_inventory['CONTENT']['HARDWARE'] = array('NAME' => 'pc2');
     $a_inventory['CONTENT']['SOFTWARES'][] = array('COMMENTS' => "Non-interactive tool to get files from FTP, GOPHER, HTTP(S)", 'NAME' => "curl", 'VERSION' => "7.24.0_1");
     // ** Add agent
     $pfAgent = new PluginFusioninventoryAgent();
     $a_agents_id = $pfAgent->add(array('name' => 'pc-2013-02-13', 'device_id' => 'pc-2013-02-13'));
     $_SESSION['plugin_fusioninventory_agents_id'] = $a_agents_id;
     // ** Add
     $pfiComputerInv->import("pc2-2013-02-13", "", $a_inventory);
     // creation
     $computer->getFromDB(2);
     $this->assertEquals(1, $computer->fields['entities_id'], 'Add computer');
     $nbSoftwares = countElementsInTable("glpi_softwares");
     $softs = getAllDatasFromTable("glpi_softwares");
     $this->assertEquals(2, $nbSoftwares, 'Nb softwares ' . print_r($softs, true));
     $software->getFromDB(2);
     $this->assertEquals(1, $software->fields['entities_id'], "May be on entity 1");
     // Software not in same entity as computer, may be recursive
     $this->assertEquals(0, $software->fields['is_recursive'], 'Software may have recursive = 0');
 }
 /**
  * Update computer with restrict entity (in this case computer added)
  *
  * @test
  */
 public function updateaddComputerRestrictEntity()
 {
     global $DB;
     $DB->connect();
     $computer = new Computer();
     $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory();
     // Disable all rules
     $DB->query("UPDATE `glpi_rules`\n         SET `is_active`='0'\n         WHERE `sub_type`='PluginFusioninventoryInventoryRuleImport'");
     // Add rule name + restrict entity search
     $rulecollection = new PluginFusioninventoryInventoryRuleImportCollection();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Computer name + restrict';
     $input['match'] = 'AND';
     $input['sub_type'] = 'PluginFusioninventoryInventoryRuleImport';
     $input['ranking'] = 1;
     $rule_id = $rulecollection->add($input);
     // Add criteria
     $rule = $rulecollection->getRuleClass();
     $rulecriteria = new RuleCriteria(get_class($rule));
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "name";
     $input['pattern'] = 1;
     $input['condition'] = 10;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "name";
     $input['pattern'] = 1;
     $input['condition'] = 8;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "entityrestrict";
     $input['pattern'] = '';
     $input['condition'] = 202;
     $rulecriteria->add($input);
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "itemtype";
     $input['pattern'] = 'Computer';
     $input['condition'] = 0;
     $rulecriteria->add($input);
     // Add action
     $ruleaction = new RuleAction(get_class($rule));
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['action_type'] = 'assign';
     $input['field'] = '_fusion';
     $input['value'] = '1';
     $ruleaction->add($input);
     $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(2, countElementsInTable('glpi_computers'), 'Must have only 2 computer');
     $computer->getFromDB(2);
     $this->assertEquals(1, $computer->fields['entities_id'], 'Second computer added');
 }
 /**
  * @test
  * computer inventory
  */
 public function IgnoreComputerImport()
 {
     global $DB;
     $DB->connect();
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION['glpiactiveentities_string'] = 0;
     $_SESSION['glpishowallentities'] = 1;
     $_SESSION['glpiname'] = 'glpi';
     $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory();
     $computer = new Computer();
     $pfUnmanaged = new PluginFusioninventoryUnmanaged();
     $pfIgnoredimportdevice = new PluginFusioninventoryIgnoredimportdevice();
     $a_inventory = array();
     $a_inventory['CONTENT']['HARDWARE'] = array('NAME' => 'pc1');
     $a_inventory['CONTENT']['SOFTWARES'][] = array();
     // ** Add agent
     $pfAgent = new PluginFusioninventoryAgent();
     $a_agents_id = $pfAgent->add(array('name' => 'pc-2013-02-13', 'device_id' => 'pc-2013-02-13'));
     $_SESSION['plugin_fusioninventory_agents_id'] = $a_agents_id;
     $pfiComputerInv->import("pc-2013-02-13", "", $a_inventory);
     // creation
     $a_computers = $computer->find();
     $this->assertEquals(0, count($a_computers), 'Computer may not be added');
     $a_unknown = $pfUnmanaged->find();
     $this->assertEquals(0, count($a_unknown), 'Unmanaged may not be added');
     $a_ignored = $pfIgnoredimportdevice->find();
     $this->assertEquals(1, count($a_ignored), 'May have only one ignored device import');
     $a_ignore = current($a_ignored);
     $a_reference = array('id' => '1', 'name' => 'pc1', 'itemtype' => 'Computer', 'entities_id' => '0', 'ip' => NULL, 'mac' => NULL, 'rules_id' => '48', 'method' => 'inventory', 'serial' => '', 'uuid' => '');
     unset($a_ignore['date']);
     $this->assertEquals($a_ignore, $a_reference, 'Ignored import computer');
     $pfIgnoredimportdevice->delete($a_ignore);
 }