From 1f7d9def7359db6b72127385f18a01fe37f921b3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 18 Apr 2018 08:57:08 +0200 Subject: [PATCH] Introduce test AuditHookTest refs #2584 --- .../Icinga/Application/Hook/AuditHookTest.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/php/library/Icinga/Application/Hook/AuditHookTest.php diff --git a/test/php/library/Icinga/Application/Hook/AuditHookTest.php b/test/php/library/Icinga/Application/Hook/AuditHookTest.php new file mode 100644 index 000000000..3ef35806b --- /dev/null +++ b/test/php/library/Icinga/Application/Hook/AuditHookTest.php @@ -0,0 +1,58 @@ +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']); + } +}