icingaweb2/test/php/library/Icinga/Application/Hook/AuditHookTest.php
Eric Lippmann 662de28f85 License source files as GPL-3.0-or-later
Add SPDX license headers and mark source files as GPL-3.0-or-later to
preserve the option to relicense under later GPL versions.
2026-03-26 17:49:26 +01:00

57 lines
1.8 KiB
PHP

<?php
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Tests\Icinga\Application\Hook;
use Icinga\Application\Hook\AuditHook;
use Icinga\Test\BaseTestCase;
class TestAuditHook extends AuditHook
{
public function logMessage($time, $identity, $type, $message, ?array $data = null)
{
// TODO: Implement logMessage() method.
}
}
class AuditHookTest extends BaseTestCase
{
public function testFormatMessageResolvesFirstLevelParameters()
{
$this->assertEquals('foo', (new TestAuditHook())->formatMessage('{{test}}', ['test' => 'foo']));
}
public function testFormatMessageResolvesNestedLevelParameters()
{
$this->assertEquals('foo', (new TestAuditHook())->formatMessage('{{te.st}}', ['te' => ['st' => 'foo']]));
}
public function testFormatMessageResolvesParametersWithSingleBraces()
{
$this->assertEquals('foo', (new TestAuditHook())->formatMessage('{{t{e}st}}', ['t{e}st' => 'foo']));
$this->assertEquals('foo', (new TestAuditHook())->formatMessage('{{te{.}st}}', ['te{' => ['}st' => 'foo']]));
}
public function testFormatMessageComplainsAboutUnresolvedParameters()
{
$this->expectException(\InvalidArgumentException::class);
(new TestAuditHook())->formatMessage('{{missing}}', []);
}
public function testFormatMessageComplainsAboutNonScalarParameters()
{
$this->expectException(\InvalidArgumentException::class);
(new TestAuditHook())->formatMessage('{{test}}', ['test' => ['foo' => 'bar']]);
}
public function testFormatMessageComplainsAboutNonArrayParameters()
{
$this->expectException(\InvalidArgumentException::class);
(new TestAuditHook())->formatMessage('{{test.foo}}', ['test' => 'foo']);
}
}