@@ -292,4 +292,98 @@ public function testCanUnsetClaimWhichIsSupportedByDefault(): void
292292 $ translate = ['nickname ' => []];
293293 $ this ->assertFalse (in_array ('nickname ' , $ this ->mock ([], $ translate )->getSupportedClaims (), true ));
294294 }
295+
296+ public function testCanReleaseMultiValueClaims (): void
297+ {
298+ $ claimSet = new ClaimSetEntity (
299+ 'multiValueClaimsScope ' ,
300+ ['multiValueClaim ' ],
301+ );
302+
303+ $ translate = [
304+ 'multiValueClaim ' => [
305+ 'multiValueAttribute ' ,
306+ ],
307+ ];
308+
309+ $ userAttributes = [
310+ 'multiValueAttribute ' => ['1 ' , '2 ' , '3 ' ],
311+ ];
312+
313+
314+ $ claimTranslator = $ this ->mock ([$ claimSet ], $ translate , ['multiValueClaim ' ]);
315+
316+ $ releasedClaims = $ claimTranslator ->extract (
317+ ['multiValueClaimsScope ' ],
318+ $ userAttributes ,
319+ );
320+
321+ $ expectedClaims = [
322+ 'multiValueClaim ' => ['1 ' , '2 ' , '3 ' ],
323+ ];
324+
325+ $ this ->assertSame ($ expectedClaims , $ releasedClaims );
326+ }
327+
328+ public function testWillReleaseSingleValueClaimsIfMultiValueNotAllowed (): void
329+ {
330+ $ claimSet = new ClaimSetEntity (
331+ 'multiValueClaimsScope ' ,
332+ ['multiValueClaim ' ],
333+ );
334+
335+
336+ $ translate = [
337+ 'multiValueClaim ' => [
338+ 'multiValueAttribute ' ,
339+ ],
340+ ];
341+
342+ $ userAttributes = [
343+ 'multiValueAttribute ' => ['1 ' , '2 ' , '3 ' ],
344+ ];
345+
346+ $ claimTranslator = $ this ->mock ([$ claimSet ], $ translate , []);
347+
348+ $ releasedClaims = $ claimTranslator ->extract (
349+ ['multiValueClaimsScope ' ],
350+ $ userAttributes ,
351+ );
352+
353+ $ expectedClaims = ['multiValueClaim ' => '1 ' ];
354+
355+ $ this ->assertSame ($ expectedClaims , $ releasedClaims );
356+ }
357+
358+ public function testWillReleaseSingleValueClaimsForMandatorySingleValueClaims (): void
359+ {
360+
361+ // TODO mivanci v7 Test for mandatory single value claims in other scopes, as per
362+ // \SimpleSAML\Module\oidc\Utils\ClaimTranslatorExtractor::MANDATORY_SINGLE_VALUE_CLAIMS
363+ $ claimSet = new ClaimSetEntity (
364+ 'customScopeWithSubClaim ' ,
365+ ['sub ' ],
366+ );
367+
368+ $ translate = [
369+ 'sub ' => [
370+ 'subAttribute ' ,
371+ ],
372+ ];
373+
374+ $ userAttributes = [
375+ 'subAttribute ' => ['1 ' , '2 ' , '3 ' ],
376+ ];
377+
378+ $ claimTranslator = $ this ->mock ([$ claimSet ], $ translate , ['sub ' ]);
379+
380+ $ releasedClaims = $ claimTranslator ->extract (
381+ ['openid ' ],
382+ $ userAttributes ,
383+ );
384+
385+ $ expectedClaims = ['sub ' => '1 ' ];
386+
387+ $ this ->assertSame ($ expectedClaims , $ releasedClaims );
388+ }
295389}
0 commit comments