Files
librenms-librenms/tests/AlertingTest.php
T

71 lines
2.3 KiB
PHP
Raw Normal View History

<?php
/**
* AlertingTest.php
*
* Tests for alerting functionality.
*
* 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 <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2016 Neil Lathwood
* @author Neil Lathwood <neil@lathwood.co.uk>
*/
namespace LibreNMS\Tests;
2018-07-21 13:34:59 -06:00
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RecursiveRegexIterator;
use RegexIterator;
class AlertTest extends TestCase
{
public function testJsonAlertCollection()
{
$rules = get_rules_from_json();
$this->assertIsArray($rules);
foreach ($rules as $rule) {
$this->assertIsArray($rule);
}
}
2018-07-21 13:34:59 -06:00
public function testTransports()
{
foreach ($this->getTransportFiles() as $file => $_unused) {
$parts = explode('/', $file);
$transport = ucfirst(str_replace('.php', '', array_pop($parts)));
$class = 'LibreNMS\\Alert\\Transport\\'.$transport;
if (!class_exists($class)) {
$this->assertTrue(false, "The transport $transport does not exist");
} else {
$methods = ['deliverAlert', 'configTemplate', 'contact'.$transport];
foreach ($methods as $method) {
if (!method_exists($class, $method)) {
$this->assertTrue(false, "The transport $transport does not have the method $method");
}
}
}
}
$this->expectNotToPerformAssertions();
2018-07-21 13:34:59 -06:00
}
private function getTransportFiles()
{
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('LibreNMS/Alert/Transport'));
return new RegexIterator($iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
}
}