@@ -2673,6 +2673,154 @@ public function testImportStackedNetworkEquipment()
26732673 $ this ->integer (count ($ iterator ))->isIdenticalTo (43 );
26742674 }
26752675
2676+ public function testImportStackedNetworkEquipment2 ()
2677+ {
2678+ $ xml = file_get_contents (GLPI_ROOT . '/tests/fixtures/inventories/stacked_switch_name.xml ' );
2679+
2680+ $ date_now = date ('Y-m-d H:i:s ' );
2681+ $ _SESSION ['glpi_currenttime ' ] = $ date_now ;
2682+ $ inventory = $ this ->doInventory ($ xml , true );
2683+
2684+ //check inventory metadata
2685+ $ metadata = $ inventory ->getMetadata ();
2686+
2687+ $ this ->array ($ metadata )->hasSize (5 )
2688+ ->string ['deviceid ' ]->isIdenticalTo ('it-2024-05-11-14-34-10 ' )
2689+ ->string ['version ' ]->isIdenticalTo ('6.1 ' )
2690+ ->string ['itemtype ' ]->isIdenticalTo ('NetworkEquipment ' )
2691+ ->variable ['port ' ]->isIdenticalTo (null )
2692+ ->string ['action ' ]->isIdenticalTo ('netinventory ' );
2693+
2694+ global $ DB ;
2695+ //check created agent
2696+ $ agenttype = $ DB ->request (['FROM ' => \AgentType::getTable (), 'WHERE ' => ['name ' => 'Core ' ]])->current ();
2697+ $ this ->array ($ inventory ->getAgent ()->fields )
2698+ ->string ['deviceid ' ]->isIdenticalTo ('it-2024-05-11-14-34-10 ' )
2699+ ->string ['name ' ]->isIdenticalTo ('it-2024-05-11-14-34-10 ' )
2700+ ->string ['itemtype ' ]->isIdenticalTo ('NetworkEquipment ' )
2701+ ->integer ['agenttypes_id ' ]->isIdenticalTo ($ agenttype ['id ' ]);
2702+
2703+ //get model, manufacturer, ...
2704+ $ autoupdatesystems = $ DB ->request (['FROM ' => \AutoupdateSystem::getTable (), 'WHERE ' => ['name ' => 'GLPI Native Inventory ' ]])->current ();
2705+ $ this ->array ($ autoupdatesystems );
2706+ $ autoupdatesystems_id = $ autoupdatesystems ['id ' ];
2707+
2708+ $ cmodels = $ DB ->request (['FROM ' => \NetworkEquipmentModel::getTable (), 'WHERE ' => ['name ' => 'JG937A ' ]])->current ();
2709+ $ this ->array ($ cmodels );
2710+ $ models_id = $ cmodels ['id ' ];
2711+
2712+ $ ctypes = $ DB ->request (['FROM ' => \NetworkEquipmentType::getTable (), 'WHERE ' => ['name ' => 'Networking ' ]])->current ();
2713+ $ this ->array ($ ctypes );
2714+ $ types_id = $ ctypes ['id ' ];
2715+
2716+ $ cmanuf = $ DB ->request (['FROM ' => \Manufacturer::getTable (), 'WHERE ' => ['name ' => 'Hewlett-Packard ' ]])->current ();
2717+ $ this ->array ($ cmanuf );
2718+ $ manufacturers_id = $ cmanuf ['id ' ];
2719+
2720+ $ cloc = $ DB ->request (['FROM ' => \Location::getTable (), 'WHERE ' => ['name ' => 'office ' ]])->current ();
2721+ $ this ->array ($ cloc );
2722+ $ locations_id = $ cloc ['id ' ];
2723+
2724+ //check created equipments
2725+ $ expected_eq_count = 2 ;
2726+ $ iterator = $ DB ->request ([
2727+ 'FROM ' => \NetworkEquipment::getTable (),
2728+ 'WHERE ' => ['is_dynamic ' => 1 ]
2729+ ]);
2730+ $ this ->integer (count ($ iterator ))->isIdenticalTo ($ expected_eq_count );
2731+
2732+ $ main_expected = [
2733+ 'id ' => null ,
2734+ 'entities_id ' => 0 ,
2735+ 'is_recursive ' => 0 ,
2736+ 'name ' => 'SW00Test - 5130EI ' ,
2737+ 'ram ' => null ,
2738+ 'serial ' => 'CX15GXXX99 ' ,
2739+ 'otherserial ' => null ,
2740+ 2741+ 'contact_num ' => null ,
2742+ 'users_id_tech ' => 0 ,
2743+ 'groups_id_tech ' => 0 ,
2744+ 'date_mod ' => null ,
2745+ 'comment ' => null ,
2746+ 'locations_id ' => $ locations_id ,
2747+ 'networks_id ' => 0 ,
2748+ 'networkequipmenttypes_id ' => $ types_id ,
2749+ 'networkequipmentmodels_id ' => $ models_id ,
2750+ 'manufacturers_id ' => $ manufacturers_id ,
2751+ 'is_deleted ' => 0 ,
2752+ 'is_template ' => 0 ,
2753+ 'template_name ' => null ,
2754+ 'users_id ' => 0 ,
2755+ 'groups_id ' => 0 ,
2756+ 'states_id ' => 0 ,
2757+ 'ticket_tco ' => '0.0000 ' ,
2758+ 'is_dynamic ' => 1 ,
2759+ 'uuid ' => null ,
2760+ 'date_creation ' => null ,
2761+ 'autoupdatesystems_id ' => $ autoupdatesystems_id ,
2762+ 'sysdescr ' => null ,
2763+ 'cpu ' => 0 ,
2764+ 'uptime ' => '22 days, 00:08:54.24 ' ,
2765+ 'last_inventory_update ' => $ date_now ,
2766+ 'snmpcredentials_id ' => 0 ,
2767+ ];
2768+
2769+ $ stacks = [
2770+ 1 => [
2771+ 'name ' => 'SW00Test - 5130EI - 1 ' ,
2772+ 'serial ' => 'CX15GXXX99 ' ,
2773+ 'connections ' => 0
2774+ ],
2775+ 2 => [
2776+ 'name ' => 'SW00Test - 5130EI - 2 ' ,
2777+ 'serial ' => 'CN15CN123456 ' ,
2778+ 'connections ' => 1
2779+ ]
2780+ ];
2781+
2782+ foreach ($ iterator as $ row ) {
2783+ $ expected = $ main_expected ;
2784+ $ equipments_id = $ row ['id ' ];
2785+ $ expected ['id ' ] = $ equipments_id ;
2786+ $ equipment = new \NetworkEquipment ();
2787+ $ this ->boolean ($ equipment ->getFromDB ($ equipments_id ))->isTrue ();
2788+ $ expected ['date_mod ' ] = $ row ['date_mod ' ];
2789+ $ expected ['date_creation ' ] = $ row ['date_creation ' ];
2790+ $ stack_id = preg_replace ('/.+ - (\d)/ ' , '$1 ' , $ row ['name ' ]);
2791+ $ this ->array ($ stacks )->hasKey ($ stack_id );
2792+ $ expected ['name ' ] .= ' - ' . $ stack_id ;
2793+ $ expected ['serial ' ] = $ stacks [$ stack_id ]['serial ' ];
2794+ $ this ->array ($ row )->isIdenticalTo ($ expected );
2795+ }
2796+
2797+ //check matchedlogs
2798+ $ mlogs = new \RuleMatchedLog ();
2799+ $ found = $ mlogs ->find ();
2800+ $ this ->array ($ found )->hasSize (2 );
2801+
2802+ $ mrules_criteria = [
2803+ 'FROM ' => \RuleMatchedLog::getTable (),
2804+ 'LEFT JOIN ' => [
2805+ \Rule::getTable () => [
2806+ 'ON ' => [
2807+ \RuleMatchedLog::getTable () => 'rules_id ' ,
2808+ \Rule::getTable () => 'id '
2809+ ]
2810+ ]
2811+ ],
2812+ 'WHERE ' => []
2813+ ];
2814+
2815+ $ neteq_criteria = $ mrules_criteria ;
2816+ $ neteq_criteria ['WHERE ' ][] = ['itemtype ' => \NetworkEquipment::getType ()];
2817+ $ iterator = $ DB ->request ($ neteq_criteria );
2818+ $ this ->integer (count ($ iterator ))->isIdenticalTo ($ expected_eq_count );
2819+ foreach ($ iterator as $ neteq ) {
2820+ $ this ->string ($ neteq ['name ' ])->isIdenticalTo ('NetworkEquipment import (by serial) ' );
2821+ $ this ->string ($ neteq ['method ' ])->isIdenticalTo (\Glpi \Inventory \Request::INVENT_QUERY );
2822+ }
2823+ }
26762824 public function testImportNetworkEquipmentMultiConnections ()
26772825 {
26782826 $ json = json_decode (file_get_contents (self ::INV_FIXTURES . 'networkequipment_3.json ' ));
0 commit comments