<?php /** * PortsTest.php * * Tests for ports * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * @package LibreNMS * @link http://librenms.org * @copyright 2017 Neil Lathwood * @author Neil Lathwood */ namespace LibreNMS\Tests; class PortsTest extends \PHPUnit_Framework_TestCase { public function testIsPortValid() { global $config; $device['os'] = 'linux'; $port['ifType'] = 'ethernetCsmacd'; $port['ifName'] = 'eth0'; $port['ifAlias'] = 'eth0'; $port['ifDescr'] = 'voip-null'; $this->assertFalse(is_port_valid($port, $device), 'Port ifDescr bad_if should not be valid' ); $port['ifDescr'] = 'Valid-port'; $this->assertTrue(is_port_valid($port, $device), 'Port ifDescr bad_if should be valid' ); $port['ifDescr'] = 'ng8'; $this->assertFalse(is_port_valid($port, $device), 'Port ifDescr bad_if_regexp should not be valid' ); $port['ifDescr'] = 'ngValid'; $this->assertTrue(is_port_valid($port, $device), 'Port ifDescr bad_if_regexp should be valid' ); $port['ifType'] = 'voiceEncap'; $this->assertFalse(is_port_valid($port, $device), 'Port ifType bad_iftype should not be valid' ); $port['ifType'] = 'voiceValid'; $this->assertTrue(is_port_valid($port, $device), 'Port ifType bad_iftype should be valid' ); $config['bad_ifname_regexp'][] = '/eth[0-9]+/'; $this->assertFalse(is_port_valid($port, $device), 'Port ifName bad_ifname_regexp should not be valid' ); $port['ifName'] = 'ethValid'; $this->assertTrue(is_port_valid($port, $device), 'Port ifName bad_ifname_regexp should be valid' ); $config['bad_ifalias_regexp'][] = '/eth[0-9]+/'; $this->assertFalse(is_port_valid($port, $device), 'Port ifName bad_ifalias_regexp should not be valid' ); $port['ifAlias'] = 'ethValid'; $this->assertTrue(is_port_valid($port, $device), 'Port ifName bad_ifalias_regexp should be valid' ); } }