From 3c52bd683ae04e2ebaec74f090bc91931b4e62fc Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Mon, 14 Mar 2022 22:04:38 +0100 Subject: [PATCH] Add unit tests --- .../lib/Auth/Process/AttributeAlterTest.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/modules/core/lib/Auth/Process/AttributeAlterTest.php b/tests/modules/core/lib/Auth/Process/AttributeAlterTest.php index 5227e0f67..9652c22ae 100644 --- a/tests/modules/core/lib/Auth/Process/AttributeAlterTest.php +++ b/tests/modules/core/lib/Auth/Process/AttributeAlterTest.php @@ -81,6 +81,34 @@ class AttributeAlterTest extends TestCase } + /** + * Test the most basic functionality with merging strategy. + */ + public function testMergeWithTarget(): void + { + $config = [ + 'subject' => 'test', + 'target' => 'test2', + 'pattern' => '/wrong/', + 'replacement' => 'right', + '%merge' + ]; + + $request = [ + 'Attributes' => [ + 'test' => ['wrong'], + 'test2' => ['somethingelse'], + ], + ]; + + $result = self::processFilter($config, $request); + $attributes = $result['Attributes']; + $this->assertArrayHasKey('test2', $attributes); + $this->assertEquals($attributes['test'], ['wrong']); + $this->assertEquals($attributes['test2'], ['right', 'somethingelse']); + } + + /** * Module is a no op if subject attribute is not present. */ @@ -155,6 +183,31 @@ class AttributeAlterTest extends TestCase } + /** + * Test replacing attribute value with merging strategy. + */ + public function testReplaceMergeMatchWithTarget(): void + { + $config = [ + 'subject' => 'source', + 'pattern' => '/wrong/', + 'replacement' => 'right', + 'target' => 'test', + '%replace', + '%merge', + ]; + $request = [ + 'Attributes' => [ + 'source' => ['wrong'], + 'test' => ['wrong', 'somethingelse'], + ], + ]; + $result = self::processFilter($config, $request); + $attributes = $result['Attributes']; + $this->assertEquals($attributes['test'], ['somethingelse', 'right']); + } + + /** * Test replacing attribute values. */ -- GitLab