1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: leo108 |
5
|
|
|
* Date: 2016/10/24 |
6
|
|
|
* Time: 11:40 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Leo108\CAS\Responses; |
10
|
|
|
|
11
|
|
|
use Mockery; |
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
13
|
|
|
use TestCase; |
14
|
|
|
|
15
|
|
|
class XmlAuthenticationSuccessResponseTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public function testSetUser() |
18
|
|
|
{ |
19
|
|
|
$resp = new XmlAuthenticationSuccessResponse(); |
20
|
|
|
$content = $this->getXML($resp); |
21
|
|
|
$this->assertNotContains('cas:user', $content); |
22
|
|
|
$resp->setUser('test'); |
23
|
|
|
$content = $this->getXML($resp); |
24
|
|
|
$this->assertContains('cas:user', $content); |
25
|
|
|
$this->assertContains('test', $content); |
26
|
|
|
|
27
|
|
|
$resp->setUser('username_2'); |
28
|
|
|
$content = $this->getXML($resp); |
29
|
|
|
$this->assertContains('cas:user', $content); |
30
|
|
|
$this->assertNotContains('test', $content); |
31
|
|
|
$this->assertContains('username_2', $content); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testSetProxies() |
35
|
|
|
{ |
36
|
|
|
$resp = new XmlAuthenticationSuccessResponse(); |
37
|
|
|
$content = $this->getXML($resp); |
38
|
|
|
$this->assertNotContains('cas:proxies', $content); |
39
|
|
|
$this->assertNotContains('cas:proxy', $content); |
40
|
|
|
|
41
|
|
|
$resp->setProxies(['http://proxy1.com']); |
42
|
|
|
$content = $this->getXML($resp); |
43
|
|
|
$this->assertContains('cas:proxies', $content); |
44
|
|
|
$this->assertContains('cas:proxy', $content); |
45
|
|
|
$this->assertContains('http://proxy1.com', $content); |
46
|
|
|
|
47
|
|
|
$resp->setProxies(['http://proxy2.com', 'http://proxy3.com']); |
48
|
|
|
$content = $this->getXML($resp); |
49
|
|
|
$this->assertContains('cas:proxies', $content); |
50
|
|
|
$this->assertContains('cas:proxy', $content); |
51
|
|
|
$this->assertNotContains('http://proxy1.com', $content); |
52
|
|
|
$this->assertContains('http://proxy2.com', $content); |
53
|
|
|
$this->assertContains('http://proxy3.com', $content); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testSetAttributes() |
57
|
|
|
{ |
58
|
|
|
$resp = Mockery::mock(XmlAuthenticationSuccessResponse::class, []) |
59
|
|
|
->makePartial() |
60
|
|
|
->shouldAllowMockingProtectedMethods() |
61
|
|
|
->shouldReceive('stringify') |
62
|
|
|
->andReturn('string') |
63
|
|
|
->getMock(); |
64
|
|
|
$content = $this->getXML($resp); |
65
|
|
|
$this->assertNotContains('cas:attributes', $content); |
66
|
|
|
|
67
|
|
|
$resp->setAttributes(['key1' => 'value1']); |
68
|
|
|
$content = $this->getXML($resp); |
69
|
|
|
$this->assertContains('cas:attributes', $content); |
70
|
|
|
$this->assertContains('cas:key1', $content); |
71
|
|
|
|
72
|
|
|
$resp->setAttributes(['key2' => 'value2', 'key3' => 'value3']); |
73
|
|
|
$content = $this->getXML($resp); |
74
|
|
|
$this->assertContains('cas:attributes', $content); |
75
|
|
|
$this->assertNotContains('cas:key1', $content); |
76
|
|
|
$this->assertContains('cas:key2', $content); |
77
|
|
|
$this->assertContains('cas:key3', $content); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testSetProxyGrantingTicket() |
81
|
|
|
{ |
82
|
|
|
$resp = new XmlAuthenticationSuccessResponse(); |
83
|
|
|
$content = $this->getXML($resp); |
84
|
|
|
$this->assertNotContains('cas:proxyGrantingTicket', $content); |
85
|
|
|
|
86
|
|
|
$ticket1 = 'ticket1'; |
87
|
|
|
$ticket2 = 'ticket2'; |
88
|
|
|
$resp->setProxyGrantingTicket($ticket1); |
|
|
|
|
89
|
|
|
$content = $this->getXML($resp); |
90
|
|
|
$this->assertContains('cas:proxyGrantingTicket', $content); |
91
|
|
|
$this->assertContains($ticket1, $content); |
92
|
|
|
|
93
|
|
|
$resp->setProxyGrantingTicket($ticket2); |
|
|
|
|
94
|
|
|
$content = $this->getXML($resp); |
95
|
|
|
$this->assertContains('cas:proxyGrantingTicket', $content); |
96
|
|
|
$this->assertNotContains($ticket1, $content); |
97
|
|
|
$this->assertContains($ticket2, $content); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
protected function getXML(XmlAuthenticationSuccessResponse $resp) |
101
|
|
|
{ |
102
|
|
|
$property = self::getNonPublicProperty($resp, 'node'); |
103
|
|
|
$node = $property->getValue($resp); |
104
|
|
|
|
105
|
|
|
return $node->asXML(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: