1<?php 2 3/* 4 ------------------------------------------------------------------------ 5 FusionInventory 6 Copyright (C) 2010-2016 by the FusionInventory Development Team. 7 8 http://www.fusioninventory.org/ http://forge.fusioninventory.org/ 9 ------------------------------------------------------------------------ 10 11 LICENSE 12 13 This file is part of FusionInventory project. 14 15 FusionInventory is free software: you can redistribute it and/or modify 16 it under the terms of the GNU Affero General Public License as published by 17 the Free Software Foundation, either version 3 of the License, or 18 (at your option) any later version. 19 20 FusionInventory is distributed in the hope that it will be useful, 21 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 GNU Affero General Public License for more details. 24 25 You should have received a copy of the GNU Affero General Public License 26 along with FusionInventory. If not, see <http://www.gnu.org/licenses/>. 27 28 ------------------------------------------------------------------------ 29 30 @package FusionInventory 31 @author David Durieux 32 @co-author 33 @copyright Copyright (c) 2010-2016 FusionInventory team 34 @license AGPL License 3.0 or (at your option) any later version 35 http://www.gnu.org/licenses/agpl-3.0-standalone.html 36 @link http://www.fusioninventory.org/ 37 @link http://forge.fusioninventory.org/projects/fusioninventory-for-glpi/ 38 @since 2013 39 40 ------------------------------------------------------------------------ 41 */ 42 43class CollectRuleTest extends RestoreDatabase_TestCase { 44 45 var $rules_id = 0; 46 var $ruleactions_id = 0; 47 48 /** 49 * @test 50 */ 51 public function prepareDB() { 52 global $DB; 53 54 $DB->connect(); 55 56 $_SESSION['glpiactive_entity'] = 0; 57 $_SESSION["plugin_fusioninventory_entity"] = 0; 58 $_SESSION["glpiname"] = 'Plugin_FusionInventory'; 59 60 $rule = new Rule(); 61 $ruleCriteria = new RuleCriteria(); 62 $ruleAction = new RuleAction(); 63 64 // * computer model assign 65 $input = array( 66 'entities_id' => 0, 67 'sub_type' => 'PluginFusioninventoryCollectRule', 68 'name' => 'computer model', 69 'match' => 'AND' 70 ); 71 $rules_id = $rule->add($input); 72 73 $input = array( 74 'rules_id' => $rules_id, 75 'criteria' => 'filename', 76 'condition' => 6, 77 'pattern' => "/latitude(.*)/" 78 ); 79 $ruleCriteria->add($input); 80 81 $input = array( 82 'rules_id' => $rules_id, 83 'action_type' => 'assign', 84 'field' => 'computermodels_id', 85 'value' => 1 86 ); 87 $this->ruleactions_id = $ruleAction->add($input); 88 89 90 // * computer model regex 91 $input = array( 92 'entities_id' => 0, 93 'sub_type' => 'PluginFusioninventoryCollectRule', 94 'name' => 'computer model 2', 95 'match' => 'AND' 96 ); 97 $rules_id = $rule->add($input); 98 99 $input = array( 100 'rules_id' => $rules_id, 101 'criteria' => 'filename', 102 'condition' => 6, 103 'pattern' => "/longitude(.*)/" 104 ); 105 $ruleCriteria->add($input); 106 107 $input = array( 108 'rules_id' => $rules_id, 109 'action_type' => 'regex_result', 110 'field' => 'computermodels_id', 111 'value' => '#0' 112 ); 113 $this->ruleactions_id = $ruleAction->add($input); 114 115 116 // * user regex 117 $input = array( 118 'entities_id' => 0, 119 'sub_type' => 'PluginFusioninventoryCollectRule', 120 'name' => 'user', 121 'match' => 'AND' 122 ); 123 $rules_id = $rule->add($input); 124 125 $input = array( 126 'rules_id' => $rules_id, 127 'criteria' => 'filename', 128 'condition' => 6, 129 'pattern' => "/user (.*)/" 130 ); 131 $ruleCriteria->add($input); 132 133 $input = array( 134 'rules_id' => $rules_id, 135 'action_type' => 'regex_result', 136 'field' => 'user', 137 'value' => '#0' 138 ); 139 $this->ruleactions_id = $ruleAction->add($input); 140 141 142 // * softwareversion regex 143 $input = array( 144 'entities_id' => 0, 145 'sub_type' => 'PluginFusioninventoryCollectRule', 146 'name' => 'softwareversion 3.0', 147 'match' => 'AND' 148 ); 149 $rules_id = $rule->add($input); 150 151 $input = array( 152 'rules_id' => $rules_id, 153 'criteria' => 'filename', 154 'condition' => 6, 155 'pattern' => "/version (.*)/" 156 ); 157 $ruleCriteria->add($input); 158 159 $input = array( 160 'rules_id' => $rules_id, 161 'action_type' => 'regex_result', 162 'field' => 'softwareversion', 163 'value' => '#0' 164 ); 165 $this->ruleactions_id = $ruleAction->add($input); 166 167 168 // * otherserial regex 169 $input = array( 170 'entities_id' => 0, 171 'sub_type' => 'PluginFusioninventoryCollectRule', 172 'name' => 'otherserial', 173 'match' => 'AND' 174 ); 175 $rules_id = $rule->add($input); 176 177 $input = array( 178 'rules_id' => $rules_id, 179 'criteria' => 'filename', 180 'condition' => 6, 181 'pattern' => "/other (.*)/" 182 ); 183 $ruleCriteria->add($input); 184 185 $input = array( 186 'rules_id' => $rules_id, 187 'action_type' => 'regex_result', 188 'field' => 'otherserial', 189 'value' => '#0' 190 ); 191 $this->ruleactions_id = $ruleAction->add($input); 192 193 194 // * otherserial regex 195 $input = array( 196 'entities_id' => 0, 197 'sub_type' => 'PluginFusioninventoryCollectRule', 198 'name' => 'otherserial assign', 199 'match' => 'AND' 200 ); 201 $rules_id = $rule->add($input); 202 203 $input = array( 204 'rules_id' => $rules_id, 205 'criteria' => 'filename', 206 'condition' => 6, 207 'pattern' => "/serial (.*)/" 208 ); 209 $ruleCriteria->add($input); 210 211 $input = array( 212 'rules_id' => $rules_id, 213 'action_type' => 'assign', 214 'field' => 'otherserial', 215 'value' => 'ttuujj' 216 ); 217 $this->ruleactions_id = $ruleAction->add($input); 218 219 220 // * create items 221 $computerModel = new ComputerModel(); 222 $input = array( 223 'name' => '6430u' 224 ); 225 $computerModel->add($input); 226 227 } 228 229 230 231 /** 232 * @test 233 */ 234 public function getComputerModelAssign() { 235 global $DB; 236 237 $DB->connect(); 238 239 $_SESSION['glpiactive_entity'] = 0; 240 $_SESSION["plugin_fusioninventory_entity"] = 0; 241 $_SESSION["glpiname"] = 'Plugin_FusionInventory'; 242 243 $pfCollectRuleCollection = new PluginFusioninventoryCollectRuleCollection(); 244 245 $res_rule = $pfCollectRuleCollection->processAllRules( 246 array( 247 "filename" => 'latitude 6430u', 248 "filepath" => '/tmp', 249 "size" => 1000 250 ) 251 ); 252 253 $this->assertEquals(1, $res_rule['computermodels_id']); 254 } 255 256 257 258 /** 259 * @test 260 */ 261 public function getComputerModelRegexCreate() { 262 global $DB; 263 264 $DB->connect(); 265 266 $_SESSION['glpiactive_entity'] = 0; 267 $_SESSION["plugin_fusioninventory_entity"] = 0; 268 $_SESSION["glpiname"] = 'Plugin_FusionInventory'; 269 270 $pfCollectRuleCollection = new PluginFusioninventoryCollectRuleCollection(); 271 272 $res_rule = $pfCollectRuleCollection->processAllRules( 273 array( 274 "filename" => 'longitude 6431u', 275 "filepath" => '/tmp', 276 "size" => 1000 277 ) 278 ); 279 280 $this->assertEquals(2, $res_rule['computermodels_id']); 281 } 282 283 284 285 /** 286 * @test 287 */ 288 public function getComputerModelRegex() { 289 global $DB; 290 291 $DB->connect(); 292 293 $_SESSION['glpiactive_entity'] = 0; 294 $_SESSION["plugin_fusioninventory_entity"] = 0; 295 $_SESSION["glpiname"] = 'Plugin_FusionInventory'; 296 297 $pfCollectRuleCollection = new PluginFusioninventoryCollectRuleCollection(); 298 299 $res_rule = $pfCollectRuleCollection->processAllRules( 300 array( 301 "filename" => 'longitude 6430u', 302 "filepath" => '/tmp', 303 "size" => 1000 304 ) 305 ); 306 307 $this->assertEquals(1, $res_rule['computermodels_id']); 308 } 309 310 311 312 /** 313 * @test 314 */ 315 public function getUserRegex() { 316 global $DB; 317 318 $DB->connect(); 319 320 $_SESSION['glpiactive_entity'] = 0; 321 $_SESSION["plugin_fusioninventory_entity"] = 0; 322 $_SESSION["glpiname"] = 'Plugin_FusionInventory'; 323 324 $pfCollectRuleCollection = new PluginFusioninventoryCollectRuleCollection(); 325 326 $res_rule = $pfCollectRuleCollection->processAllRules( 327 array( 328 "filename" => 'user david', 329 "filepath" => '/tmp', 330 "size" => 1000 331 ) 332 ); 333 334 $this->assertEquals('david', $res_rule['user']); 335 } 336 337 338 339 /** 340 * @test 341 */ 342 public function getSoftwareVersionRegex() { 343 global $DB; 344 345 $DB->connect(); 346 347 $_SESSION['glpiactive_entity'] = 0; 348 $_SESSION["plugin_fusioninventory_entity"] = 0; 349 $_SESSION["glpiname"] = 'Plugin_FusionInventory'; 350 351 $pfCollectRuleCollection = new PluginFusioninventoryCollectRuleCollection(); 352 353 $res_rule = $pfCollectRuleCollection->processAllRules( 354 array( 355 "filename" => 'version 3.2.0', 356 "filepath" => '/tmp', 357 "size" => 1000 358 ) 359 ); 360 361 $this->assertEquals('3.2.0', $res_rule['softwareversion']); 362 } 363 364 365 366 /** 367 * @test 368 */ 369 public function getOtherserialRegex() { 370 global $DB; 371 372 $DB->connect(); 373 374 $_SESSION['glpiactive_entity'] = 0; 375 $_SESSION["plugin_fusioninventory_entity"] = 0; 376 $_SESSION["glpiname"] = 'Plugin_FusionInventory'; 377 378 $pfCollectRuleCollection = new PluginFusioninventoryCollectRuleCollection(); 379 380 $res_rule = $pfCollectRuleCollection->processAllRules( 381 array( 382 "filename" => 'other xxyyzz', 383 "filepath" => '/tmp', 384 "size" => 1000 385 ) 386 ); 387 388 $this->assertEquals('xxyyzz', $res_rule['otherserial']); 389 } 390 391 392 393 /** 394 * @test 395 */ 396 public function getOtherserialAssign() { 397 global $DB; 398 399 $DB->connect(); 400 401 $_SESSION['glpiactive_entity'] = 0; 402 $_SESSION["plugin_fusioninventory_entity"] = 0; 403 $_SESSION["glpiname"] = 'Plugin_FusionInventory'; 404 405 $pfCollectRuleCollection = new PluginFusioninventoryCollectRuleCollection(); 406 407 $res_rule = $pfCollectRuleCollection->processAllRules( 408 array( 409 "filename" => 'serial clic', 410 "filepath" => '/tmp', 411 "size" => 1000 412 ) 413 ); 414 415 $this->assertEquals('ttuujj', $res_rule['otherserial']); 416 } 417 418} 419?> 420