ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilSamlMappedUserAttributeValueParserTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
22
24{
25 protected function getMappingRuleMock(string $externalAttributeReference): ilExternalAuthUserAttributeMappingRule
26 {
27 $rule = $this->getMockBuilder(ilExternalAuthUserAttributeMappingRule::class)
28 ->disableOriginalConstructor()
29 ->getMock();
30 $rule
31 ->method('getExternalAttribute')
32 ->willReturn($externalAttributeReference);
33 $rule
34 ->method('getAttribute')
35 ->willReturn($externalAttributeReference);
36
37 return $rule;
38 }
39
41 {
42 $expectedValue = 'ILIAS';
43
44 $attributeKey = 'firstname';
45 $attributeValue = $expectedValue;
46
47 $userData = [$attributeKey => $attributeValue];
48
49 $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
50 $this->assertSame($expectedValue, $parser->parse());
51 }
52
54 {
55 $expectedValue = 'ILIAS';
56
57 $attributeKey = 'firstname';
58 $attributeValue = [$expectedValue];
59
60 $userData = [$attributeKey => $attributeValue];
61
62 $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
63 $this->assertSame($expectedValue, $parser->parse());
64 }
65
67 {
68 $expectedValue = 'ILIAS';
69 $expectedValueIndex = 5;
70
71 $attributeKey = 'firstname';
72 $attributeValue = [$expectedValueIndex => $expectedValue];
73
74 $userData = [$attributeKey => $attributeValue];
75
77 $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
78 $userData
79 );
80 $this->assertSame($expectedValue, $parser->parse());
81 }
82
84 {
85 $this->expectException(ilSamlException::class);
86
87 $attributeKey = 'firstname';
88 $userData = [];
89
90 $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
91 $parser->parse();
92 }
93
95 {
96 $this->expectException(ilSamlException::class);
97
98 $expectedValue = 'ILIAS';
99 $expectedValueIndex = 5;
100
101 $attributeKey = 'firstname';
102 $attributeValue = [($expectedValueIndex + 1) => $expectedValue];
103
104 $userData = [$attributeKey => $attributeValue];
105
107 $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
108 $userData
109 );
110 $parser->parse();
111 }
112
114 {
115 $this->expectException(ilSamlException::class);
116
117 $expectedValue = ['ILIAS'];
118 $expectedValueIndex = 5;
119
120 $attributeKey = 'firstname';
121 $attributeValue = [$expectedValueIndex => $expectedValue];
122
123 $userData = [$attributeKey => $attributeValue];
124
126 $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
127 $userData
128 );
129 $parser->parse();
130 }
131}