diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
commit | f66ab8dae2f3d0418759f81a3a64dc9517a62449 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /test/php/library/Director/PropertyModifier/PropertyModifierArrayFilterTest.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.tar.xz icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.zip |
Adding upstream version 1.10.2.upstream/1.10.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/php/library/Director/PropertyModifier/PropertyModifierArrayFilterTest.php | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/test/php/library/Director/PropertyModifier/PropertyModifierArrayFilterTest.php b/test/php/library/Director/PropertyModifier/PropertyModifierArrayFilterTest.php new file mode 100644 index 0000000..e50a45d --- /dev/null +++ b/test/php/library/Director/PropertyModifier/PropertyModifierArrayFilterTest.php @@ -0,0 +1,120 @@ +<?php + +namespace Tests\Icinga\Module\Director\Objects; + +use Icinga\Module\Director\PropertyModifier\PropertyModifierArrayFilter; +use Icinga\Module\Director\Test\BaseTestCase; + +class PropertyModifierArrayFilterTest extends BaseTestCase +{ + /** + * Allowed settings: + * + * filter_method: wildcard, regex + * filter_string + * + * policy: keep, reject + * when_empty: empty_array, null + */ + + /** @var array */ + private $testArray = array( + 'www.example.com', + 'example.com', + 'www', + 'wwexample.com', + 'example.www', + '', + ); + + public function testKeepMatchingWildcards() + { + $modifier = new PropertyModifierArrayFilter(); + $modifier->setSettings(array( + 'filter_method' => 'wildcard', + 'filter_string' => 'www*', + 'policy' => 'keep', + 'when_empty' => 'empty_array', + )); + + $this->assertEquals( + array('www.example.com', 'www'), + $modifier->transform($this->testArray) + ); + } + + public function testRejectMatchingWildcards() + { + $modifier = new PropertyModifierArrayFilter(); + $modifier->setSettings(array( + 'filter_method' => 'wildcard', + 'filter_string' => 'www*', + 'policy' => 'reject', + 'when_empty' => 'empty_array', + )); + + $this->assertEquals( + array('example.com', 'wwexample.com', 'example.www', ''), + $modifier->transform($this->testArray) + ); + } + + public function testKeepMatchingRegularExpression() + { + $modifier = new PropertyModifierArrayFilter(); + $modifier->setSettings(array( + 'filter_method' => 'regex', + 'filter_string' => '/^w{3}.*/', + 'policy' => 'keep', + 'when_empty' => 'empty_array', + )); + + $this->assertEquals( + array('www.example.com', 'www'), + $modifier->transform($this->testArray) + ); + } + + public function testRejectMatchingRegularExpression() + { + $modifier = new PropertyModifierArrayFilter(); + $modifier->setSettings(array( + 'filter_method' => 'regex', + 'filter_string' => '/^w{3}.*/', + 'policy' => 'reject', + 'when_empty' => 'empty_array', + )); + + $this->assertEquals( + array('example.com', 'wwexample.com', 'example.www', ''), + $modifier->transform($this->testArray) + ); + } + + public function testGivesEmptyArrayOrNullAccordingToConfig() + { + $modifier = new PropertyModifierArrayFilter(); + $modifier->setSettings(array( + 'filter_method' => 'wildcard', + 'filter_string' => 'no-match', + 'policy' => 'keep', + 'when_empty' => 'empty_array', + )); + + $this->assertEquals( + array(), + $modifier->transform($this->testArray) + ); + + $modifier->setSetting('when_empty', 'null'); + $this->assertNull( + $modifier->transform($this->testArray) + ); + } + + public function testAnnouncesArraySupport() + { + $modifier = new PropertyModifierArrayFilter(); + $this->assertTrue($modifier->hasArraySupport()); + } +} |