public function testMarshalling()
 {
     $attributeQuery = new SAML2_AttributeQuery();
     $attributeQuery->setNameID(array('Value' => 'NameIDValue'));
     $attributeQuery->setAttributes(array('test1' => array('test1_attrv1', 'test1_attrv2'), 'test2' => array('test2_attrv1', 'test2_attrv2', 'test2_attrv3'), 'test3' => array()));
     $attributeQueryElement = $attributeQuery->toUnsignedXML();
     // Test Attribute Names
     $attributes = SAML2_Utils::xpQuery($attributeQueryElement, './saml_assertion:Attribute');
     $this->assertCount(3, $attributes);
     $this->assertEquals('test1', $attributes[0]->getAttribute('Name'));
     $this->assertEquals('test2', $attributes[1]->getAttribute('Name'));
     $this->assertEquals('test3', $attributes[2]->getAttribute('Name'));
     // Test Attribute Values for Attribute 1
     $av1 = SAML2_Utils::xpQuery($attributes[0], './saml_assertion:AttributeValue');
     $this->assertCount(2, $av1);
     $this->assertEquals('test1_attrv1', $av1[0]->textContent);
     $this->assertEquals('test1_attrv2', $av1[1]->textContent);
     // Test Attribute Values for Attribute 2
     $av2 = SAML2_Utils::xpQuery($attributes[1], './saml_assertion:AttributeValue');
     $this->assertCount(3, $av2);
     $this->assertEquals('test2_attrv1', $av2[0]->textContent);
     $this->assertEquals('test2_attrv2', $av2[1]->textContent);
     $this->assertEquals('test2_attrv3', $av2[2]->textContent);
     // Test Attribute Values for Attribute 3
     $av3 = SAML2_Utils::xpQuery($attributes[2], './saml_assertion:AttributeValue');
     $this->assertCount(0, $av3);
 }
/**
 * build and send AttributeQuery
 */
function sendQuery($dataId, $url, $nameId, $attributes, $attributeNameFormat, $src, $dst)
{
    assert('is_string($dataId)');
    assert('is_string($url)');
    assert('is_array($nameId)');
    assert('is_array($attributes)');
    SimpleSAML_Logger::debug('[attributeaggregator] - sending request');
    $query = new SAML2_AttributeQuery();
    $query->setRelayState($dataId);
    $query->setDestination($url);
    $query->setIssuer($src->getValue('entityid'));
    $query->setNameId($nameId);
    $query->setAttributeNameFormat($attributeNameFormat);
    if (!empty($attributes)) {
        $query->setAttributes($attributes);
    }
    sspmod_saml_Message::addSign($src, $dst, $query);
    if (!$query->getSignatureKey()) {
        throw new SimpleSAML_Error_Exception('[attributeaggregator] - Unable to find private key for signing attribute request.');
    }
    SimpleSAML_Logger::debug('[attributeaggregator] - sending attribute query: ' . var_export($query, 1));
    $binding = new SAML2_SOAPClient();
    $result = $binding->send($query, $src);
    return $result;
}