1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AerialShip\SamlSPBundle\Tests\Bridge; |
4
|
|
|
|
5
|
|
|
use AerialShip\SamlSPBundle\Bridge\SamlSpInfo; |
6
|
|
|
|
7
|
|
|
class SamlSpInfoTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @test |
11
|
|
|
*/ |
12
|
|
|
public function shouldImplementSerializableInterface() |
13
|
|
|
{ |
14
|
|
|
$rc = new \ReflectionClass('AerialShip\SamlSPBundle\Bridge\SamlSpInfo'); |
15
|
|
|
$this->assertTrue($rc->implementsInterface('Serializable')); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @test |
20
|
|
|
*/ |
21
|
|
|
public function couldBeConstructedWithIdpID() |
22
|
|
|
{ |
23
|
|
|
new SamlSpInfo('idp'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @test |
28
|
|
|
*/ |
29
|
|
|
public function couldBeConstructedWithNameID() |
30
|
|
|
{ |
31
|
|
|
$helper = new SamlSpInfoHelper(); |
32
|
|
|
new SamlSpInfo('idp', $helper->getNameID()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @test |
37
|
|
|
*/ |
38
|
|
|
public function couldBeConstructedWithNameIDAndAttributes() |
39
|
|
|
{ |
40
|
|
|
$helper = new SamlSpInfoHelper(); |
41
|
|
|
new SamlSpInfo('idp', $helper->getNameID(), $helper->getAttributes()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @test |
46
|
|
|
*/ |
47
|
|
|
public function couldBeConstructedWithNameIDAndAttributesAndAuthnStatement() |
48
|
|
|
{ |
49
|
|
|
$helper = new SamlSpInfoHelper(); |
50
|
|
|
new SamlSpInfo('idp', $helper->getNameID(), $helper->getAttributes(), $helper->getAuthnStatement()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @test |
56
|
|
|
*/ |
57
|
|
|
public function shouldDeserialize() |
58
|
|
|
{ |
59
|
|
|
$helper = new SamlSpInfoHelper(); |
60
|
|
|
$expectedSamlSpInfo = $helper->getSamlSpInfo(); |
61
|
|
|
|
62
|
|
|
$unserializedSamlSpInfo = unserialize(serialize($expectedSamlSpInfo)); |
63
|
|
|
|
64
|
|
|
$this->assertEquals($expectedSamlSpInfo, $unserializedSamlSpInfo); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @test |
69
|
|
|
*/ |
70
|
|
|
public function shouldAllowGetIdpIdSetInConstructor() |
71
|
|
|
{ |
72
|
|
|
$expectedIDP = 'idp'; |
73
|
|
|
$samlSpInfo = new SamlSpInfo($expectedIDP); |
74
|
|
|
|
75
|
|
|
$this->assertEquals($expectedIDP, $samlSpInfo->getAuthenticationServiceID()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @test |
80
|
|
|
*/ |
81
|
|
|
public function shouldAllowGetNameIDSetInConstructor() |
82
|
|
|
{ |
83
|
|
|
$helper = new SamlSpInfoHelper(); |
84
|
|
|
$expectedNameID = $helper->getNameID(); |
85
|
|
|
|
86
|
|
|
$samlSpInfo = new SamlSpInfo('idp', $expectedNameID); |
87
|
|
|
|
88
|
|
|
$this->assertEquals($expectedNameID, $samlSpInfo->getNameID()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @test |
94
|
|
|
*/ |
95
|
|
|
public function shouldAllowGetAttributesSetInConstructor() |
96
|
|
|
{ |
97
|
|
|
$helper = new SamlSpInfoHelper(); |
98
|
|
|
$expectedAttributes = $helper->getAttributes(); |
99
|
|
|
|
100
|
|
|
$samlSpInfo = new SamlSpInfo('idp', null, $expectedAttributes); |
101
|
|
|
|
102
|
|
|
$this->assertEquals($expectedAttributes, $samlSpInfo->getAttributes()); |
103
|
|
|
$this->assertInternalType('array', $samlSpInfo->getAttributes()); |
104
|
|
|
$this->assertCount(2, $samlSpInfo->getAttributes()); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @test |
110
|
|
|
*/ |
111
|
|
|
public function shouldAllowGetAuthnStatementSetInConstructor() |
112
|
|
|
{ |
113
|
|
|
$helper = new SamlSpInfoHelper(); |
114
|
|
|
$expectedAuthnStatement = $helper->getAuthnStatement(); |
115
|
|
|
|
116
|
|
|
$samlSpInfo = new SamlSpInfo('idp', null, null, $expectedAuthnStatement); |
117
|
|
|
|
118
|
|
|
$this->assertEquals($expectedAuthnStatement, $samlSpInfo->getAuthnStatement()); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @test |
123
|
|
|
*/ |
124
|
|
|
public function shouldReturnEmptyArrayWhenNullAttributesSetInConstructor() |
125
|
|
|
{ |
126
|
|
|
$samlSpInfo = new SamlSpInfo('idp'); |
127
|
|
|
|
128
|
|
|
$this->assertEquals(array(), $samlSpInfo->getAttributes()); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|