summaryrefslogtreecommitdiffstats
path: root/test/php/library/Director/Restriction/MatchingFilterTest.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/php/library/Director/Restriction/MatchingFilterTest.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/php/library/Director/Restriction/MatchingFilterTest.php b/test/php/library/Director/Restriction/MatchingFilterTest.php
new file mode 100644
index 0000000..cd1b57e
--- /dev/null
+++ b/test/php/library/Director/Restriction/MatchingFilterTest.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Tests\Icinga\Module\Director\Restriction;
+
+use Icinga\Module\Director\Restriction\MatchingFilter;
+use Icinga\Module\Director\Test\BaseTestCase;
+use Icinga\User;
+
+class MatchingFilterTest extends BaseTestCase
+{
+ public function testUserWithNoRestrictionHasNoFilter()
+ {
+ $user = new User('dummy');
+ $this->assertEquals(
+ '',
+ (string) MatchingFilter::forUser($user, 'some/name', 'prop')
+ );
+ }
+
+ public function testSimpleRestrictionRendersCorrectly()
+ {
+ $this->assertEquals(
+ 'prop = a*',
+ (string) MatchingFilter::forPatterns(['a*'], 'prop')
+ );
+ }
+
+ public function testMultipleRestrictionsAreCombinedWithOr()
+ {
+ $this->assertEquals(
+ 'prop = a* | prop = *b',
+ (string) MatchingFilter::forPatterns(['a*', '*b'], 'prop')
+ );
+ }
+
+ public function testUserWithMultipleRestrictionsWorksFine()
+ {
+ $user = new User('dummy');
+ $user->setRestrictions([
+ 'some/name' => ['a*', '*b'],
+ 'some/thing' => ['else']
+ ]);
+ $this->assertEquals(
+ 'prop = a* | prop = *b',
+ (string) MatchingFilter::forUser($user, 'some/name', 'prop')
+ );
+ }
+
+ public function testSingleRestrictionAllowsForPipes()
+ {
+ $this->assertEquals(
+ 'prop = a* | prop = *b',
+ (string) MatchingFilter::forPatterns(['a*|*b'], 'prop')
+ );
+ }
+}