Esempio n. 1
1
 public function testInstall()
 {
     global $DB;
     $query = "SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'VIEW'";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         $DB->query("DROP VIEW " . $data[0]);
     }
     $query = "SHOW TABLES";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         $DB->query("DROP TABLE " . $data[0]);
     }
     include_once GLPI_ROOT . "/inc/dbmysql.class.php";
     include_once GLPI_CONFIG_DIR . "/config_db.php";
     // Install a fresh 0.80.5 DB
     $DB = new DB();
     $res = $DB->runFile(GLPI_ROOT . "/install/mysql/glpi-0.80.3-empty.sql");
     $this->assertTrue($res, "Fail: SQL Error during install");
     // update default language
     $query = "UPDATE `glpi_configs`\n                SET `language` = 'en_GB'";
     $this->assertTrue($DB->query($query), "Fail: can't set default language");
     $query = "UPDATE `glpi_users`\n                SET `language` = 'en_GB'";
     $this->assertTrue($DB->query($query), "Fail: can't set users language");
     $GLPIlog = new GLPIlogs();
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
 }
 /**
  * @depends GLPIInstallTest::installDatabase
  */
 public function testInstall()
 {
     global $DB;
     $DB->connect();
     $this->assertTrue($DB->connected, "Problem connecting to the Database");
     // Delete if Table of FusionInventory or Tracker yet in DB
     $query = "SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'VIEW'";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         if (strstr($data[0], "fusi")) {
             $DB->query("DROP VIEW " . $data[0]);
         }
     }
     $query = "SHOW TABLES";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         if (strstr($data[0], "tracker") or strstr($data[0], "fusi")) {
             $DB->query("DROP TABLE " . $data[0]);
         }
     }
     $output = array();
     $returncode = 0;
     exec("php -f " . FUSINV_ROOT . "/scripts/cli_install.php -- --as-user 'glpi'", $output, $returncode);
     $this->assertEquals(0, $returncode, "Error when installing plugin in CLI mode\n" . implode("\n", $output));
     $GLPIlog = new GLPIlogs();
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
     $FusinvDBTest = new FusinvDB();
     $FusinvDBTest->checkInstall("fusioninventory", "install new version");
     PluginFusioninventoryConfig::loadCache();
 }
 /**
  * @test
  */
 public function AddComputer()
 {
     global $DB;
     $DB->connect();
     $_SESSION['plugin_fusioninventory_classrulepassed'] = '';
     $date = date('Y-m-d H:i:s');
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION['glpiactiveentities_string'] = 0;
     $_SESSION['glpishowallentities'] = 1;
     $_SESSION["glpiname"] = 'Plugin_FusionInventory';
     $a_inventory = array('fusioninventorycomputer' => array('winowner' => 'test', 'wincompany' => 'siprossii', 'operatingsystem_installationdate' => '2012-10-16 08:12:56', 'last_fusioninventory_update' => $date), 'soundcard' => array(), 'graphiccard' => array(), 'controller' => array(), 'processor' => array(), 'computerdisk' => array(), 'memory' => array(), 'monitor' => array(), 'printer' => array(), 'peripheral' => array(), 'networkport' => array(), 'SOFTWARES' => array(), 'harddrive' => array(), 'virtualmachine' => array(), 'antivirus' => array(), 'storage' => array(), 'licenseinfo' => array(), 'networkcard' => array(), 'drive' => array(), 'batteries' => array(), 'itemtype' => 'Computer');
     $a_inventory['Computer'] = array('name' => 'pc', 'users_id' => 0, 'operatingsystems_id' => 'freebsd', 'operatingsystemversions_id' => '9.1-RELEASE', 'uuid' => '68405E00-E5BE-11DF-801C-B05981201220', 'domains_id' => 'mydomain.local', 'os_licenseid' => '', 'os_license_number' => '', 'operatingsystemservicepacks_id' => 'GENERIC ()root@farrell.cse.buffalo.edu', 'manufacturers_id' => '', 'computermodels_id' => '', 'serial' => 'XB63J7D', 'computertypes_id' => 'Notebook', 'is_dynamic' => 1, 'contact' => 'ddurieux');
     $a_inventory['processor'] = array(array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'serial' => '', 'frequency' => 2400, 'frequence' => 2400, 'nbthreads' => 2, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'serial' => '', 'frequency' => 2400, 'frequence' => 2400, 'nbthreads' => 2, 'frequency_default' => 2400), array('nbcores' => 4, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'serial' => '', 'frequency' => 2405, 'frequence' => 2405, 'nbthreads' => 4, 'frequency_default' => 2405), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'serial' => '', 'frequency' => 2600, 'frequence' => 2600, 'nbthreads' => 4, 'frequency_default' => 2600));
     $a_inventory['memory'] = array(array('size' => 2048, 'serial' => '98F6FF18', 'frequence' => '1067 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 1), array('size' => 2048, 'serial' => '95F1833E', 'frequence' => '1067 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 2), array('size' => 2048, 'serial' => '95F1833G', 'frequence' => '1066 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 3), array('size' => 2048, 'serial' => '95F1833H', 'frequence' => '1333 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 4));
     $a_inventory['monitor'] = array(array('name' => 'ThinkPad Display 1280x800', 'serial' => 'UBYVUTFYEIUI', 'manufacturers_id' => 'Lenovo'));
     $a_inventory['printer'] = array(array('name' => 'HP Deskjet 5700 Series', 'serial' => 'MY47L1W1JHEB6', 'have_usb' => 1));
     $a_inventory['networkport'] = array('em0-00:23:18:cf:0d:93' => array('name' => 'em0', 'netmask' => '255.255.255.0', 'subnet' => '192.168.30.0', 'mac' => '00:23:18:cf:0d:93', 'instantiation_type' => 'NetworkPortEthernet', 'virtualdev' => 0, 'ssid' => '', 'gateway' => '', 'dhcpserver' => '', 'logical_number' => 1, 'ipaddress' => array('192.168.30.198')), 'lo0-' => array('name' => 'lo0', 'virtualdev' => 1, 'mac' => '', 'instantiation_type' => 'NetworkPortLocal', 'subnet' => '', 'ssid' => '', 'gateway' => '', 'netmask' => '', 'dhcpserver' => '', 'logical_number' => 0, 'ipaddress' => array('::1', 'fe80::1', '127.0.0.1')));
     $a_inventory['software'] = array('gentiumbasic$$$$110$$$$1$$$$0' => array('name' => 'GentiumBasic', 'version' => 110, 'manufacturers_id' => 1, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0), 'imagemagick$$$$6.8.0.7_1$$$$2$$$$0' => array('name' => 'ImageMagick', 'version' => '6.8.0.7_1', 'manufacturers_id' => 2, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0), 'orbit2$$$$2.14.19$$$$3$$$$0' => array('name' => 'ORBit2', 'version' => '2.14.19', 'manufacturers_id' => 3, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0));
     $pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
     $computer = new Computer();
     $pfFormatconvert = new PluginFusioninventoryFormatconvert();
     $a_inventory = $pfFormatconvert->replaceids($a_inventory);
     $serialized = gzcompress(serialize($a_inventory));
     $a_inventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized);
     $this->items_id = $computer->add(array('serial' => 'XB63J7D', 'entities_id' => 0));
     $this->assertGreaterThan(0, $this->items_id, FALSE);
     $pfiComputerLib->updateComputer($a_inventory, $this->items_id, FALSE);
     // To be sure not have 2 same informations
     $pfiComputerLib->updateComputer($a_inventory, $this->items_id, FALSE);
     $GLPIlog = new GLPIlogs();
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
 }
 /**
  * @test
  */
 public function AddComputer()
 {
     global $DB;
     $DB->connect();
     $date = date('Y-m-d H:i:s');
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION['glpiactiveentities_string'] = 0;
     $_SESSION['glpishowallentities'] = 1;
     $_SESSION["glpiname"] = 'Plugin_FusionInventory';
     $a_inventory = $this->computer_inventory;
     $pfiComputerLib = new PluginFusioninventoryInventoryComputerLib();
     $computer = new Computer();
     $pfFormatconvert = new PluginFusioninventoryFormatconvert();
     $a_inventory = $pfFormatconvert->replaceids($a_inventory);
     $serialized = gzcompress(serialize($a_inventory));
     $a_inventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized);
     $this->items_id = $computer->add(array('serial' => 'XB63J7D', 'entities_id' => 0));
     $this->assertGreaterThan(0, $this->items_id, FALSE);
     $pfiComputerLib->updateComputer($a_inventory, $this->items_id, TRUE);
     // To be sure not have 2 same informations
     $pfiComputerLib->updateComputer($a_inventory, $this->items_id, FALSE);
     $GLPIlog = new GLPIlogs();
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
 }
Esempio n. 5
0
 public function testInstall($verify = 1)
 {
     global $DB;
     $DB->connect();
     if (file_exists("save.sql") and $verify == '0') {
         $query = "SHOW TABLES";
         $result = $DB->query($query);
         while ($data = $DB->fetch_array($result)) {
             $DB->query("DROP TABLE " . $data[0]);
         }
         $res = $DB->runFile("save.sql");
         $this->assertTrue($res, "Fail: SQL Error during import saved GLPI DB");
         echo "======= Import save.sql file =======\n";
         $TimelineticketInstall = new TimelineticketInstall();
         $TimelineticketInstall->testDB(TRUE);
     } else {
         $query = "SHOW TABLES";
         $result = $DB->query($query);
         while ($data = $DB->fetch_array($result)) {
             if (strstr($data[0], "timelineticket")) {
                 $DB->query("DROP TABLE " . $data[0]);
             }
         }
         passthru("cd ../tools && /usr/local/bin/php -f cli_install.php");
         Session::loadLanguage("en_GB");
         $TimelineticketInstall = new TimelineticketInstall();
         $TimelineticketInstall->testDB(TRUE);
         passthru("mysqldump -h " . $DB->dbhost . " -u " . $DB->dbuser . " -p" . $DB->dbpassword . " " . $DB->dbdefault . " > save.sql");
     }
     $GLPIlog = new GLPIlogs();
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
 }
Esempio n. 6
0
 function Update($version = '')
 {
     global $DB;
     if ($version == '') {
         return;
     }
     echo "#####################################################\n\n            ######### Update from version " . $version . "###############\n\n            #####################################################\n";
     $GLPIInstall = new GLPIInstall();
     $GLPIInstall->testInstall();
     $query = "SHOW TABLES";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         if (strstr($data[0], "timelineticket")) {
             $DB->query("DROP TABLE " . $data[0]);
         }
     }
     $query = "DELETE FROM `glpi_displaypreferences` \n         WHERE `itemtype` LIKE 'PluginTimelineticket%'";
     $DB->query($query);
     // ** Insert in DB
     $res = $DB->runFile(GLPI_ROOT . "/plugins/timelineticket/phpunit/TimelineticketInstall/Update/mysql/i-" . $version . ".sql");
     $this->assertTrue($res, "Fail: SQL Error during insert version " . $version);
     passthru("cd ../tools/ && /usr/local/bin/php -f cli_install.php");
     $TimelineticketInstall = new TimelineticketInstall();
     $TimelineticketInstall->testDB(TRUE);
     $GLPIlog = new GLPIlogs();
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
 }
 /**
  * @dataProvider provider
  * @runInSeparateProcess
  * @preserveGlobalState disabled
  * @test
  */
 function update($version = '', $verify = FALSE, $nbrules = 0)
 {
     self::restore_database();
     global $DB;
     $DB->connect();
     if ($version == '') {
         return;
     }
     $query = "SHOW TABLES";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         if (strstr($data[0], "tracker") or strstr($data[0], "fusi")) {
             $DB->query("DROP TABLE " . $data[0]);
         }
     }
     $query = "DELETE FROM `glpi_displaypreferences`\n         WHERE `itemtype` LIKE 'PluginFus%'";
     $DB->query($query);
     $sqlfile = GLPI_ROOT . "/plugins/fusioninventory/phpunit/0_Install/mysql/i-" . $version . ".sql";
     // Load specific FusionInventory version in database
     $result = load_mysql_file($DB->dbuser, $DB->dbhost, $DB->dbdefault, $DB->dbpassword, $sqlfile);
     $this->assertEquals(0, $result['returncode'], "Failed to install Fusioninventory " . $sqlfile . ":\n" . implode("\n", $result['output']));
     $output = array();
     $returncode = 0;
     exec("php -f " . FUSINV_ROOT . "/scripts/cli_install.php -- --as-user 'glpi'", $output, $returncode);
     $this->assertEquals(0, $returncode, implode("\n", $output));
     $GLPIlog = new GLPIlogs();
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
     $FusinvDB = new FusinvDB();
     $FusinvDB->checkInstall("fusioninventory", "upgrade from " . $version);
     $this->verifyEntityRules($nbrules);
     if ($verify) {
         $this->verifyConfig();
     }
 }
Esempio n. 8
0
 public function testInstall($verify = 1)
 {
     global $DB;
     // Delete if Table of Monitoring yet in DB
     $query = "SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'VIEW'";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         if (strstr($data[0], "monitoring")) {
             $DB->query("DROP VIEW " . $data[0]);
         }
     }
     $query = "SHOW TABLES";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         if (strstr($data[0], "monitoring")) {
             $DB->query("DROP TABLE " . $data[0]);
         }
     }
     passthru("cd ../tools && /usr/local/bin/php -f cli_install.php");
     $_SESSION['glpi_use_mode'] = 2;
     $_SESSION["glpiID"] = 2;
     Plugin::load("monitoring");
     loadLanguage("en_GB");
     if ($verify == '1') {
         $MonitoringInstall = new MonitoringInstall();
         $MonitoringInstall->testDB("monitoring");
     }
     $GLPIlog = new GLPIlogs();
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
 }
 /**
  * @test
  */
 public function updatePrinterFromNetdiscovery()
 {
     global $DB;
     $DB->connect();
     $pfCNetworkDiscovery = new PluginFusioninventoryCommunicationNetworkDiscovery();
     $GLPIlog = new GLPIlogs();
     $networkName = new NetworkName();
     $iPAddress = new IPAddress();
     $_SESSION['SOURCE_XMLDEVICE'] = array('AUTHSNMP' => '1', 'DESCRIPTION' => 'Photosmart D7200 series', 'ENTITY' => '0', 'FIRMWARE' => '', 'IP' => '192.168.20.102', 'MAC' => '00:21:5a:0b:bb:c4', 'MANUFACTURER' => 'Hewlett-Packard', 'MODEL' => '', 'MODELSNMP' => 'Printer0093', 'NETBIOSNAME' => 'HP00215A0BBBC4', 'SERIAL' => 'MY89AQG0V9050N', 'SNMPHOSTNAME' => 'HP0BBBC4new', 'TYPE' => 'PRINTER');
     $printer = new Printer();
     $a_printers = $printer->find("`serial`='MY89AQG0V9050N'");
     $a_printer = current($a_printers);
     $printers_id = $a_printer['id'];
     $printer->getFromDB($printers_id);
     $pfCNetworkDiscovery->importDevice($printer);
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
     $printer->getFromDB($printers_id);
     $this->assertEquals('HP0BBBC4new', $printer->fields['name'], 'Name must be updated');
     $a_printerextends = getAllDatasFromTable('glpi_plugin_fusioninventory_printers', "`printers_id`='" . $printers_id . "'");
     $this->assertEquals('1', count($a_printerextends), 'May have one printer extend line for this printer');
     $a_printerextend = current($a_printerextends);
     $this->assertEquals('1', $a_printerextend['plugin_fusioninventory_configsecurities_id'], 'SNMPauth may be with id 1');
     $this->assertEquals('Photosmart D7200 series', $a_printerextend['sysdescr'], 'Sysdescr not updated correctly');
     // Check mac
     $networkPort = new NetworkPort();
     $a_ports = $networkPort->find("`itemtype`='Printer' AND `items_id`='" . $printers_id . "'");
     $this->assertEquals('1', count($a_ports), 'May have one network port');
     $a_port = current($a_ports);
     $this->assertEquals('00:21:5a:0b:bb:c4', $a_port['mac'], 'Mac address');
     // check ip
     $a_networknames = $networkName->find("`itemtype`='NetworkPort'\n         AND `items_id`='" . $a_port['id'] . "'");
     $this->assertEquals('1', count($a_networknames), 'May have one networkname');
     $a_networkname = current($a_networknames);
     $a_ipaddresses = $iPAddress->find("`itemtype`='NetworkName'\n         AND `items_id`='" . $a_networkname['id'] . "'");
     $this->assertEquals('1', count($a_ipaddresses), 'May have one IP address');
     $a_ipaddress = current($a_ipaddresses);
     $this->assertEquals('192.168.20.102', $a_ipaddress['name'], 'IP address');
 }
    /**
     * @test
     */
    function DiscoveryDeviceConvert()
    {
        global $DB;
        $DB->connect();
        $sxml = '<?xml version="1.0" encoding="UTF-8" ?>
<REQUEST>
  <CONTENT>
    <DEVICE>
      <AUTHSNMP>1</AUTHSNMP>
      <DESCRIPTION>Eaton 5PX 1500</DESCRIPTION>
      <IP>192.168.20.196</IP>
      <MAC>00:20:85:f5:2d:19</MAC>
      <MANUFACTURER>Eaton</MANUFACTURER>
      <SNMPHOSTNAME>ups25</SNMPHOSTNAME>
      <TYPE>NETWORKING</TYPE>
    </DEVICE>
    <MODULEVERSION>2.2.0</MODULEVERSION>
    <PROCESSNUMBER>11</PROCESSNUMBER>
  </CONTENT>
  <DEVICEID>port004.bureau.siprossii.com-2012-12-20-16-27-27</DEVICEID>
  <QUERY>NETDISCOVERY</QUERY>
</REQUEST>';
        $xml = @simplexml_load_string($sxml, 'SimpleXMLElement', LIBXML_NOCDATA);
        PluginFusioninventoryFormatconvert::XMLtoArray($xml);
        $GLPIlog = new GLPIlogs();
        $GLPIlog->testSQLlogs();
        $GLPIlog->testPHPlogs();
    }
    /**
     * @test
     */
    public function NetworkEquipmentConnectionMac()
    {
        global $DB;
        $DB->connect();
        $_SESSION["plugin_fusioninventory_entity"] = 0;
        $_SESSION["glpiname"] = 'Plugin_FusionInventory';
        $a_inventory = array();
        $a_inventory['INFO'] = array('COMMENTS' => 'Cisco IOS Software, C3750 Software (C3750-IPSERVICESK9-M), Version 12.2(55)SE, RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2010 by Cisco Systems, Inc.
Compiled Sat 07-Aug-10 22:45 by prod_rel_team', 'ID' => '55', 'MAC' => '00:1b:2b:20:40:80', 'NAME' => 'sw1.siprossii.com', 'SERIAL' => 'CAT1109RGVK', 'TYPE' => 'NETWORKING');
        $a_inventory['PORTS']['PORT'][1] = array('CONNECTIONS' => array('CONNECTION' => array('MAC' => array('00:0f:fe:0d:30:70'))), 'IFNAME' => 'Fa0/1', 'IFNUMBER' => 1, 'IFTYPE' => 6, 'MAC' => 'b4:39:d6:3a:7f:3a');
        $a_inventory['PORTS']['PORT'][2] = array('CONNECTIONS' => array('CONNECTION' => array('MAC' => array('00:0f:fe:0d:30:76', '00:0f:fe:0d:30:77', '00:0f:fe:0d:30:78'))), 'IFNAME' => 'Fa0/2', 'IFNUMBER' => 2, 'IFTYPE' => 6, 'MAC' => 'b4:39:d6:3a:7f:3e');
        $pfFormatconvert = new PluginFusioninventoryFormatconvert();
        $a_return = $pfFormatconvert->networkequipmentInventoryTransformation($a_inventory);
        $a_reference = array('00:0f:fe:0d:30:70');
        $this->assertEquals($a_reference, $a_return['connection-mac'][1]);
        $a_reference = array();
        $a_reference = array('00:0f:fe:0d:30:76', '00:0f:fe:0d:30:77', '00:0f:fe:0d:30:78');
        $this->assertEquals($a_reference, $a_return['connection-mac'][2]);
        $GLPIlog = new GLPIlogs();
        $GLPIlog->testSQLlogs();
        $GLPIlog->testPHPlogs();
    }
 /**
  * @test
  */
 public function addEntryForTwoDaysYetAdded()
 {
     $pfTimeslotEntry = new PluginFusioninventoryTimeslotEntry();
     $input = array('timeslots_id' => 1, 'beginday' => 2, 'lastday' => 3, 'beginhours' => 60, 'lasthours' => 36015);
     $pfTimeslotEntry->addEntry($input);
     $references = array('3' => array('id' => '3', 'entities_id' => '0', 'plugin_fusioninventory_timeslots_id' => '1', 'is_recursive' => '0', 'day' => '3', 'begin' => '0', 'end' => '86400'), '4' => array('id' => '4', 'entities_id' => '0', 'plugin_fusioninventory_timeslots_id' => '1', 'is_recursive' => '0', 'day' => '1', 'begin' => '0', 'end' => '86400'), '5' => array('id' => '5', 'entities_id' => '0', 'plugin_fusioninventory_timeslots_id' => '1', 'is_recursive' => '0', 'day' => '2', 'begin' => '0', 'end' => '86400'), '6' => array('id' => '6', 'entities_id' => '0', 'plugin_fusioninventory_timeslots_id' => '1', 'is_recursive' => '0', 'day' => '4', 'begin' => '0', 'end' => '36000'));
     $db = getAllDatasFromTable('glpi_plugin_fusioninventory_timeslotentries');
     $this->assertEquals($references, $db, "May have 4 entries " . print_r($db, true));
     $GLPIlog = new GLPIlogs();
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
 }
 protected function tearDown()
 {
     $GLPIlog = new GLPIlogs();
     $GLPIlog->testSQLlogs();
     $GLPIlog->testPHPlogs();
 }
Esempio n. 14
0
 private function manageTicket($closed = true)
 {
     global $DB, $CFG_GLPI;
     $DB->connect();
     $_SESSION['glpiactive_entity'] = 0;
     $CFG_GLPI['root_doc'] = "http://127.0.0.1/fusion0.83/";
     $plugin = new Plugin();
     $plugin->getFromDBbyDir("timelineticket");
     $plugin->activate($plugin->fields['id']);
     Plugin::load("timelineticket");
     Session::loadLanguage("en_GB");
     $ticket = new Ticket();
     $group = new Group();
     $group_ticket = new Group_Ticket();
     $GLPIlog = new GLPIlogs();
     $ticket_User = new Ticket_User();
     $_SESSION['plugin_timelineticket_date'] = array();
     $group->add(array('name' => 'grtech1'));
     $group->add(array('name' => 'grtech2'));
     // * 01/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate = array('1' => $_SESSION["glpi_currenttime"]);
     $input = array();
     $input['name'] = 'Pb with the ticket';
     $input['content'] = 'I have a problem with the ticket';
     $tickets_id = $ticket->add($input);
     $GLPIlog->testSQLlogs('01/');
     $GLPIlog->testPHPlogs('01/');
     // * 02/
     sleep(2);
     // * 03/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[3] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 1;
     $ticket->update($input);
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('03/');
     $GLPIlog->testPHPlogs('03/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[1] = array('id' => '1', 'tickets_id' => '1', 'groups_id' => '1', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to group1');
     $a_db = getAllDatasFromTable('glpi_tickets_users');
     $a_ref = array();
     $a_ref[1] = array('id' => '1', 'tickets_id' => '1', 'users_id' => '2', 'type' => '1', 'use_notification' => '1', 'alternative_email' => '');
     $a_ref[2] = array('id' => '2', 'tickets_id' => '1', 'users_id' => '2', 'type' => '2', 'use_notification' => '1', 'alternative_email' => '');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to user 2 (glpi)');
     // * 04/
     sleep(2);
     // * 05/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[5] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::WAITING;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('05/');
     $GLPIlog->testPHPlogs('05/');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], 'May have status waiting');
     // * 06/
     sleep(1);
     // * 07/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[7] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = 2;
     $input['itickets_id'] = $tickets_id;
     $ticket_User->check($input['id'], 'w');
     $ticket_User->delete($input);
     $input = array();
     $input['id'] = 1;
     $input['itickets_id'] = $tickets_id;
     $group_ticket->check($input['id'], 'w');
     $group_ticket->delete($input);
     $GLPIlog->testSQLlogs('07/');
     $GLPIlog->testPHPlogs('07/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $this->assertEquals(array(), $a_db, 'May have no group assigned');
     // * 08/
     sleep(1);
     // * 09/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[9] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('09/');
     $GLPIlog->testPHPlogs('09/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[2] = array('id' => '2', 'tickets_id' => '1', 'groups_id' => '2', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, 'May have ticket assigned to group2');
     $ticket->getFromDB(1);
     $this->assertEquals('assign', $ticket->fields['status'], '(09/) Status is assign');
     // * 10/
     sleep(1);
     // * 11/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[11] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::WAITING;
     $ticket->update($input);
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 4;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('11/');
     $GLPIlog->testPHPlogs('11/');
     // * 12/
     sleep(1);
     // * 13/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[13] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['_itil_assign']['_type'] = 'group';
     $input['_itil_assign']['groups_id'] = 1;
     $ticket->update($input);
     $input['_itil_assign']['_type'] = 'user';
     $input['_itil_assign']['users_id'] = 2;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('13/');
     $GLPIlog->testPHPlogs('13/');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], '(13/)May have always status waiting');
     // * 14/
     $input = array();
     $input['id'] = 2;
     $input['itickets_id'] = $tickets_id;
     $group_ticket->check($input['id'], 'w');
     $group_ticket->delete($input);
     $GLPIlog->testSQLlogs('14/');
     $GLPIlog->testPHPlogs('14/');
     $a_db = getAllDatasFromTable('glpi_groups_tickets');
     $a_ref = array();
     $a_ref[3] = array('id' => '3', 'tickets_id' => '1', 'groups_id' => '1', 'type' => '2');
     $this->assertEquals($a_ref, $a_db, '(14/) May have ticket assigned to group1');
     $ticket->getFromDB(1);
     $this->assertEquals('waiting', $ticket->fields['status'], '(14/) Status is waiting');
     // * 15/
     sleep(2);
     // * 16/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[16] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['status'] = Ticket::ASSIGNED;
     $ticket->update($input);
     $GLPIlog->testSQLlogs('16/');
     $GLPIlog->testPHPlogs('16/');
     // * 17/
     sleep(1);
     // * 18/
     $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
     $a_storedate[18] = $_SESSION["glpi_currenttime"];
     $input = array();
     $input['id'] = $tickets_id;
     $input['solution'] = "solution";
     $ticket->update($input);
     $GLPIlog->testSQLlogs('18/');
     $GLPIlog->testPHPlogs('18/');
     $ticket->getFromDB(1);
     $this->assertEquals('solved', $ticket->fields['status'], '(18/) Status is solved');
     if ($closed) {
         // * 19/
         sleep(1);
         // * 20/
         $_SESSION["glpi_currenttime"] = date("Y-m-d H:i:s");
         $a_storedate[20] = $_SESSION["glpi_currenttime"];
         $fup = new TicketFollowup();
         $input = array();
         $input['tickets_id'] = $tickets_id;
         $input['add_close'] = 'add_close';
         $fup->add($input);
         $GLPIlog->testSQLlogs('20/');
         $GLPIlog->testPHPlogs('20/');
         $ticket->getFromDB(1);
         $this->assertEquals('closed', $ticket->fields['status'], '(19/) Status is closed');
     }
     self::$storedate = $a_storedate;
 }