diff --git a/src/Responses/XmlAuthenticationSuccessResponse.php b/src/Responses/XmlAuthenticationSuccessResponse.php
index 2147758..3a1e3c5 100644
--- a/src/Responses/XmlAuthenticationSuccessResponse.php
+++ b/src/Responses/XmlAuthenticationSuccessResponse.php
@@ -49,9 +49,12 @@ public function setAttributes($attributes)
$this->removeByXPath($authNode, 'cas:attributes');
$attributesNode = $authNode->addChild('cas:attributes');
foreach ($attributes as $key => $value) {
- $str = $this->stringify($value);
- if (is_string($str)) {
- $attributesNode->addChild('cas:'.$key, $str);
+ $value_arr = (array) $value;
+ foreach($value_arr as $v){
+ $str = $this->stringify($v);
+ if (is_string($str)) {
+ $attributesNode->addChild('cas:'.$key, $str);
+ }
}
}
diff --git a/tests/Responses/JsonAuthenticationSuccessResponseTest.php b/tests/Responses/JsonAuthenticationSuccessResponseTest.php
index 301efbe..c5ccb72 100644
--- a/tests/Responses/JsonAuthenticationSuccessResponseTest.php
+++ b/tests/Responses/JsonAuthenticationSuccessResponseTest.php
@@ -68,6 +68,15 @@ public function testSetAttributes()
$this->assertEquals(['serviceResponse' => ['authenticationSuccess' => ['attributes' => $attr2]]], $data);
}
+ public function testSetMultiValuedAttributes()
+ {
+ $resp = new JsonAuthenticationSuccessResponse();
+ $attr1 = ['key1' => ['value1', 'value2']];
+ $resp->setAttributes($attr1);
+ $data = $this->getData($resp);
+ $this->assertEquals(['serviceResponse' => ['authenticationSuccess' => ['attributes' => $attr1]]], $data);
+ }
+
protected function getData(JsonAuthenticationSuccessResponse $resp)
{
$property = self::getNonPublicProperty($resp, 'data');
diff --git a/tests/Responses/XmlAuthenticationSuccessResponseTest.php b/tests/Responses/XmlAuthenticationSuccessResponseTest.php
index 56612dc..0fb4b7e 100644
--- a/tests/Responses/XmlAuthenticationSuccessResponseTest.php
+++ b/tests/Responses/XmlAuthenticationSuccessResponseTest.php
@@ -54,12 +54,7 @@ public function testSetProxies()
public function testSetAttributes()
{
- $resp = Mockery::mock(XmlAuthenticationSuccessResponse::class, [])
- ->makePartial()
- ->shouldAllowMockingProtectedMethods()
- ->shouldReceive('stringify')
- ->andReturn('string')
- ->getMock();
+ $resp = new XmlAuthenticationSuccessResponse();
$content = $this->getXML($resp);
$this->assertNotContains('cas:attributes', $content);
@@ -76,6 +71,19 @@ public function testSetAttributes()
$this->assertContains('cas:key3', $content);
}
+ public function testSetMultiValuedAttributes()
+ {
+ $resp = new XmlAuthenticationSuccessResponse();
+ $content = $this->getXML($resp);
+ $this->assertNotContains('cas:attributes', $content);
+
+ $resp->setAttributes(['key1' => ['value1', 'value2']]);
+ $content = $this->getXML($resp);
+ $this->assertContains('cas:attributes', $content);
+ $this->assertContains('value1', $content);
+ $this->assertContains('value2', $content);
+ }
+
public function testSetProxyGrantingTicket()
{
$resp = new XmlAuthenticationSuccessResponse();