Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
2.0 KiB
PHP
Raw Permalink 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
2021-02-09 00:29:04 +01:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
2021-02-09 00:29:04 +01:00
* @link https://www.librenms.org
2021-09-10 20:09:53 +02:00
*
* @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;
2020-04-03 17:13:18 -05:00
class AlertingTest 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;
2021-10-06 07:29:47 -05:00
$this->assertTrue(class_exists($class), "The transport $transport does not exist");
$this->assertInstanceOf(\LibreNMS\Interfaces\Alert\Transport::class, new $class);
2018-07-21 13:34:59 -06:00
}
}
private function getTransportFiles()
{
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('LibreNMS/Alert/Transport'));
2020-09-21 14:54:51 +02:00
2018-07-21 13:34:59 -06:00
return new RegexIterator($iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
}
}