ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilSamlMappedUserAttributeValueParserTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 {
29  protected function getMappingRuleMock(string $externalAttributeReference): ilExternalAuthUserAttributeMappingRule
30  {
31  $rule = $this->getMockBuilder(ilExternalAuthUserAttributeMappingRule::class)
32  ->disableOriginalConstructor()
33  ->getMock();
34  $rule
35  ->method('getExternalAttribute')
36  ->willReturn($externalAttributeReference);
37  $rule
38  ->method('getAttribute')
39  ->willReturn($externalAttributeReference);
40 
41  return $rule;
42  }
43 
45  {
46  $expectedValue = 'ILIAS';
47 
48  $attributeKey = 'firstname';
49  $attributeValue = $expectedValue;
50 
51  $userData = [$attributeKey => $attributeValue];
52 
53  $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
54  $this->assertSame($expectedValue, $parser->parse());
55  }
56 
58  {
59  $expectedValue = 'ILIAS';
60 
61  $attributeKey = 'firstname';
62  $attributeValue = [$expectedValue];
63 
64  $userData = [$attributeKey => $attributeValue];
65 
66  $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
67  $this->assertSame($expectedValue, $parser->parse());
68  }
69 
71  {
72  $expectedValue = 'ILIAS';
73  $expectedValueIndex = 5;
74 
75  $attributeKey = 'firstname';
76  $attributeValue = [$expectedValueIndex => $expectedValue];
77 
78  $userData = [$attributeKey => $attributeValue];
79 
81  $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
82  $userData
83  );
84  $this->assertSame($expectedValue, $parser->parse());
85  }
86 
88  {
89  $this->expectException(ilSamlException::class);
90 
91  $attributeKey = 'firstname';
92  $userData = [];
93 
94  $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
95  $parser->parse();
96  }
97 
99  {
100  $this->expectException(ilSamlException::class);
101 
102  $expectedValue = 'ILIAS';
103  $expectedValueIndex = 5;
104 
105  $attributeKey = 'firstname';
106  $attributeValue = [($expectedValueIndex + 1) => $expectedValue];
107 
108  $userData = [$attributeKey => $attributeValue];
109 
111  $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
112  $userData
113  );
114  $parser->parse();
115  }
116 
118  {
119  $this->expectException(ilSamlException::class);
120 
121  $expectedValue = ['ILIAS'];
122  $expectedValueIndex = 5;
123 
124  $attributeKey = 'firstname';
125  $attributeValue = [$expectedValueIndex => $expectedValue];
126 
127  $userData = [$attributeKey => $attributeValue];
128 
130  $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
131  $userData
132  );
133  $parser->parse();
134  }
135 }
Class ilSamlMappedUserAttributeValueParserTest.