ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
8{
12 protected function assertException($exception_class)
13 {
14 if (version_compare(PHPUnit_Runner_Version::id(), '5.0', '>=')) {
15 $this->setExpectedException($exception_class);
16 }
17 }
18
23 protected function getMappingRuleMock($externalAttributeReference)
24 {
25 $rule = $this->getMockBuilder(ilExternalAuthUserAttributeMappingRule::class)->disableOriginalConstructor()->getMock();
26 $rule->expects($this->any())->method('getExternalAttribute')->will($this->returnValue($externalAttributeReference));
27 $rule->expects($this->any())->method('getAttribute')->will($this->returnValue($externalAttributeReference));
28
29 return $rule;
30 }
31
33 {
34 $expectedValue = 'ILIAS';
35
36 $attributeKey = 'firstname';
37 $attributeValue = $expectedValue;
38
39 $userData = [$attributeKey => $attributeValue];
40
41 $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
42 $this->assertEquals($expectedValue, $parser->parse());
43 }
44
46 {
47 $expectedValue = 'ILIAS';
48
49 $attributeKey = 'firstname';
50 $attributeValue = [$expectedValue];
51
52 $userData = [$attributeKey => $attributeValue];
53
54 $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
55 $this->assertEquals($expectedValue, $parser->parse());
56 }
57
59 {
60 $expectedValue = 'ILIAS';
61 $expectedValueIndex = 5;
62
63 $attributeKey = 'firstname';
64 $attributeValue = [$expectedValueIndex => $expectedValue];
65
66 $userData = [$attributeKey => $attributeValue];
67
69 $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
70 $userData
71 );
72 $this->assertEquals($expectedValue, $parser->parse());
73 }
74
76 {
77 $this->assertException(ilSamlException::class);
78
79 $attributeKey = 'firstname';
80 $userData = [];
81
82 $parser = new ilSamlMappedUserAttributeValueParser($this->getMappingRuleMock($attributeKey), $userData);
83 $parser->parse();
84 }
85
87 {
88 $this->assertException(ilSamlException::class);
89
90 $expectedValue = 'ILIAS';
91 $expectedValueIndex = 5;
92
93 $attributeKey = 'firstname';
94 $attributeValue = [($expectedValueIndex + 1) => $expectedValue];
95
96 $userData = [$attributeKey => $attributeValue];
97
99 $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
100 $userData
101 );
102 $parser->parse();
103 }
104
106 {
107 $this->assertException(ilSamlException::class);
108
109 $expectedValue = array('ILIAS');
110 $expectedValueIndex = 5;
111
112 $attributeKey = 'firstname';
113 $attributeValue = [$expectedValueIndex => $expectedValue];
114
115 $userData = [$attributeKey => $attributeValue];
116
118 $this->getMappingRuleMock($attributeKey . '|' . $expectedValueIndex),
119 $userData
120 );
121 $parser->parse();
122 }
123}
$parser
Definition: BPMN2Parser.php:23
An exception for terminatinating execution or to throw for unit testing.
Class ilSamlMappedUserAttributeValueParserTest.
$rule
Definition: showstats.php:43