/** * @test */ public function PrinterCartridge() { global $DB; $DB->connect(); $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $a_printer = array(); $a_printer['INFO'] = array('ID' => '54', 'NAME' => 'ARC12-B09-N', 'TYPE' => 'PRINTER'); $a_printer['CARTRIDGES'] = array('CARTRIDGEBLACK' => 90, 'CARTRIDGECYAN' => '', 'CARTRIDGEMAGENTA' => 'OK', 'CARTRIDGEYELLOW' => '30pages'); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $pfMapping = new PluginFusioninventoryMapping(); $a_return = $pfFormatconvert->printerInventoryTransformation($a_printer); $a_reference = array(); $a_id = $pfMapping->get("Printer", strtolower('CARTRIDGEBLACK')); $a_reference[$a_id['id']] = 90; $a_id = $pfMapping->get("Printer", strtolower('CARTRIDGEMAGENTA')); $a_reference[$a_id['id']] = 100000; $a_id = $pfMapping->get("Printer", strtolower('CARTRIDGEYELLOW')); $a_reference[$a_id['id']] = -30; $this->assertEquals($a_reference, $a_return['cartridge']); }
/** * Import the content (where have all devices) *@param $p_content CONTENT code to import * *@return errors string to be alimented if import ko / '' if ok **/ function importContent($arrayinventory) { PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkInventory->importContent().'); $pfAgent = new PluginFusioninventoryAgent(); $errors = ''; $nbDevices = 0; foreach ($arrayinventory as $childname => $child) { PluginFusioninventoryCommunication::addLog($childname); switch ($childname) { case 'DEVICE': $a_devices = array(); if (is_int(key($child))) { $a_devices = $child; } else { $a_devices[] = $child; } $xml_num = 0; foreach ($a_devices as $dchild) { $_SESSION['plugin_fusioninventory_xmlnum'] = $xml_num; $a_inventory = array(); if (isset($dchild['INFO'])) { if ($dchild['INFO']['TYPE'] == "NETWORKING") { $a_inventory = PluginFusioninventoryFormatconvert::networkequipmentInventoryTransformation($dchild); } else { if ($dchild['INFO']['TYPE'] == "PRINTER") { $a_inventory = PluginFusioninventoryFormatconvert::printerInventoryTransformation($dchild); } } } if (isset($dchild['ERROR'])) { $itemtype = ""; if ($dchild['ERROR']['TYPE'] == "NETWORKING") { $itemtype = "NetworkEquipment"; } else { if ($dchild['ERROR']['TYPE'] == "PRINTER") { $itemtype = "Printer"; } } $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] ' . $dchild['ERROR']['MESSAGE'] . ' [[' . $itemtype . '::' . $dchild['ERROR']['ID'] . ']]'; $this->addtaskjoblog(); } else { if ($a_inventory['PluginFusioninventory' . $a_inventory['itemtype']]['sysdescr'] == '' && $a_inventory[$a_inventory['itemtype']]['name'] == '' && $a_inventory[$a_inventory['itemtype']]['serial'] == '') { $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] No informations [[' . $a_inventory['itemtype'] . '::' . $dchild['INFO']['ID'] . ']]'; $this->addtaskjoblog(); } else { if (count($a_inventory) > 0) { $errors .= $this->sendCriteria($a_inventory); $nbDevices++; } } } $xml_num++; } break; case 'AGENT': if (isset($this->arrayinventory['CONTENT']['AGENT']['AGENTVERSION'])) { $agent = $pfAgent->InfosByKey($this->arrayinventory['DEVICEID']); $agent['fusioninventory_agent_version'] = $this->arrayinventory['CONTENT']['AGENT']['AGENTVERSION']; $agent['last_agent_update'] = date("Y-m-d H:i:s"); $pfAgent->update($agent); } break; case 'PROCESSNUMBER': break; case 'MODULEVERSION': break; default: $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '[==detail==] ' . __('Unattended element in', 'fusioninventory') . ' CONTENT : ' . $childname; $this->addtaskjoblog(); } } return $errors; }