Skip to content

Commit da17740

Browse files
phy25leo108
authored andcommitted
Add support for multi-valued attributes for XML, and add appropriate tests for XML and JSON
1 parent d4520e3 commit da17740

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/Responses/XmlAuthenticationSuccessResponse.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ public function setAttributes($attributes)
4949
$this->removeByXPath($authNode, 'cas:attributes');
5050
$attributesNode = $authNode->addChild('cas:attributes');
5151
foreach ($attributes as $key => $value) {
52-
$str = $this->stringify($value);
53-
if (is_string($str)) {
54-
$attributesNode->addChild('cas:'.$key, $str);
52+
$value_arr = (array) $value;
53+
foreach($value_arr as $v){
54+
$str = $this->stringify($v);
55+
if (is_string($str)) {
56+
$attributesNode->addChild('cas:'.$key, $str);
57+
}
5558
}
5659
}
5760

tests/Responses/JsonAuthenticationSuccessResponseTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ public function testSetAttributes()
6868
$this->assertEquals(['serviceResponse' => ['authenticationSuccess' => ['attributes' => $attr2]]], $data);
6969
}
7070

71+
public function testSetMultiValuedAttributes()
72+
{
73+
$resp = new JsonAuthenticationSuccessResponse();
74+
$attr1 = ['key1' => ['value1', 'value2']];
75+
$resp->setAttributes($attr1);
76+
$data = $this->getData($resp);
77+
$this->assertEquals(['serviceResponse' => ['authenticationSuccess' => ['attributes' => $attr1]]], $data);
78+
}
79+
7180
protected function getData(JsonAuthenticationSuccessResponse $resp)
7281
{
7382
$property = self::getNonPublicProperty($resp, 'data');

tests/Responses/XmlAuthenticationSuccessResponseTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@ public function testSetProxies()
5454

5555
public function testSetAttributes()
5656
{
57-
$resp = Mockery::mock(XmlAuthenticationSuccessResponse::class, [])
58-
->makePartial()
59-
->shouldAllowMockingProtectedMethods()
60-
->shouldReceive('stringify')
61-
->andReturn('string')
62-
->getMock();
57+
$resp = new XmlAuthenticationSuccessResponse();
6358
$content = $this->getXML($resp);
6459
$this->assertNotContains('cas:attributes', $content);
6560

@@ -76,6 +71,19 @@ public function testSetAttributes()
7671
$this->assertContains('cas:key3', $content);
7772
}
7873

74+
public function testSetMultiValuedAttributes()
75+
{
76+
$resp = new XmlAuthenticationSuccessResponse();
77+
$content = $this->getXML($resp);
78+
$this->assertNotContains('cas:attributes', $content);
79+
80+
$resp->setAttributes(['key1' => ['value1', 'value2']]);
81+
$content = $this->getXML($resp);
82+
$this->assertContains('cas:attributes', $content);
83+
$this->assertContains('<cas:key1>value1</cas:key1>', $content);
84+
$this->assertContains('<cas:key1>value2</cas:key1>', $content);
85+
}
86+
7987
public function testSetProxyGrantingTicket()
8088
{
8189
$resp = new XmlAuthenticationSuccessResponse();

0 commit comments

Comments
 (0)