ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilSamlMappedUserAttributeValueParserTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4use PHPUnit\Framework\TestCase;
5
10{
15 protected function getMappingRuleMock($externalAttributeReference)
16 {
17 $rule = $this->getMockBuilder(ilExternalAuthUserAttributeMappingRule::class)->disableOriginalConstructor()->getMock();
18 $rule->expects($this->any())->method('getExternalAttribute')->will($this->returnValue($externalAttributeReference));
19 $rule->expects($this->any())->method('getAttribute')->will($this->returnValue($externalAttributeReference));
20
21 return $rule;
22 }
23
25 {
26 $expectedValue = 'ILIAS';
27
28 $attributeKey = 'firstname';
29 $attributeValue = $expectedValue;
30
31 $userData = [$attributeKey => $attributeValue];
32
33 $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
34 $this->assertEquals($expectedValue, $parser->parse());
35 }
36
38 {
39 $expectedValue = 'ILIAS';
40
41 $attributeKey = 'firstname';
42 $attributeValue = [$expectedValue];
43
44 $userData = [$attributeKey => $attributeValue];
45
46 $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
47 $this->assertEquals($expectedValue, $parser->parse());
48 }
49
51 {
52 $expectedValue = 'ILIAS';
53 $expectedValueIndex = 5;
54
55 $attributeKey = 'firstname';
56 $attributeValue = [$expectedValueIndex => $expectedValue];
57
58 $userData = [$attributeKey => $attributeValue];
59
61 $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
62 $userData
63 );
64 $this->assertEquals($expectedValue, $parser->parse());
65 }
66
68 {
69 $this->expectException(ilSamlException::class);
70
71 $attributeKey = 'firstname';
72 $userData = [];
73
74 $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
75 $parser->parse();
76 }
77
79 {
80 $this->expectException(ilSamlException::class);
81
82 $expectedValue = 'ILIAS';
83 $expectedValueIndex = 5;
84
85 $attributeKey = 'firstname';
86 $attributeValue = [($expectedValueIndex + 1) => $expectedValue];
87
88 $userData = [$attributeKey => $attributeValue];
89
91 $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
92 $userData
93 );
94 $parser->parse();
95 }
96
98 {
99 $this->expectException(ilSamlException::class);
100
101 $expectedValue = array('ILIAS');
102 $expectedValueIndex = 5;
103
104 $attributeKey = 'firstname';
105 $attributeValue = [$expectedValueIndex => $expectedValue];
106
107 $userData = [$attributeKey => $attributeValue];
108
110 $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
111 $userData
112 );
113 $parser->parse();
114 }
115}
$parser
Definition: BPMN2Parser.php:23
An exception for terminatinating execution or to throw for unit testing.
Class ilSamlMappedUserAttributeValueParserTest.