Introduce test AuditHookTest

refs #2584
This commit is contained in:
Johannes Meyer 2018-04-18 08:57:08 +02:00 committed by Eric Lippmann
parent cece9d7e65
commit 1f7d9def73
1 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,58 @@
<?php
/* Icinga Web 2 | (c) 2018 Icinga Development Team | GPLv2+ */
namespace Tests\Icinga\Application\Hook;
use Icinga\Application\Hook\AuditHook;
use Icinga\Test\BaseTestCase;
class TestAuditHook extends AuditHook
{
public function logMessage($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']]));
}
/**
* @expectedException \InvalidArgumentException
*/
public function testFormatMessageComplainsAboutUnresolvedParameters()
{
(new TestAuditHook())->formatMessage('{{missing}}', []);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testFormatMessageComplainsAboutNonScalarParameters()
{
(new TestAuditHook())->formatMessage('{{test}}', ['test' => ['foo' => 'bar']]);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testFormatMessageComplainsAboutNonArrayParameters()
{
(new TestAuditHook())->formatMessage('{{test.foo}}', ['test' => 'foo']);
}
}