summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortailor <cygnus@janrain.com>2006-08-18 19:54:30 +0000
committertailor <cygnus@janrain.com>2006-08-18 19:54:30 +0000
commit465e087c45db57585c15ccfb7e24786f9e2f4afb (patch)
treea6d15b086c7f51b6b84843b1ad0bacd126d76434
parent4d7517d2e8f8ff565628176ceacb00b904816eb3 (diff)
downloadphp-openid-465e087c45db57585c15ccfb7e24786f9e2f4afb.zip
php-openid-465e087c45db57585c15ccfb7e24786f9e2f4afb.tar.gz
php-openid-465e087c45db57585c15ccfb7e24786f9e2f4afb.tar.bz2
[project @ Added Services_Yadis_XRI function]
-rw-r--r--Services/Yadis/XRI.php21
-rw-r--r--Tests/Auth/OpenID/Discover.php3
-rw-r--r--Tests/Services/Yadis/XRDS.php4
-rw-r--r--Tests/Services/Yadis/XRI.php2
4 files changed, 21 insertions, 9 deletions
diff --git a/Services/Yadis/XRI.php b/Services/Yadis/XRI.php
index df943be..6783fc0 100644
--- a/Services/Yadis/XRI.php
+++ b/Services/Yadis/XRI.php
@@ -135,6 +135,7 @@ function Services_Yadis_rootAuthority($xri)
// Return the root authority for an XRI.
+ $root = null;
$authority = explode('/', $xri, 2);
$authority = $authority[0];
if ($authority[0] == '(') {
@@ -143,10 +144,10 @@ function Services_Yadis_rootAuthority($xri)
// there is another close-paren in there. Hopefully nobody
// does that before we have a real xriparse function.
// Hopefully nobody does that *ever*.
- return substr($authority, 0, strpos($authority, ')') + 1);
+ $root = substr($authority, 0, strpos($authority, ')') + 1);
} else if (in_array($authority[0], $XRI_AUTHORITIES)) {
// Other XRI reference.
- return $authority[0];
+ $root = $authority[0];
} else {
// IRI reference.
$_segments = explode("!", $authority);
@@ -154,8 +155,18 @@ function Services_Yadis_rootAuthority($xri)
foreach ($_segments as $s) {
$segments = array_merge($segments, explode("*", $s));
}
- return $segments[0];
+ $root = $segments[0];
}
+
+ return Services_Yadis_XRI($root);
+}
+
+function Services_Yadis_XRI($xri)
+{
+ if (!_startswith($xri, 'xri://')) {
+ $xri = 'xri://' . $xri;
+ }
+ return $xri;
}
function Services_Yadis_getCanonicalID($iname, $xrds)
@@ -174,7 +185,7 @@ function Services_Yadis_getCanonicalID($iname, $xrds)
}
$canonicalID = $canonicalID_nodes[count($canonicalID_nodes) - 1];
- $canonicalID = $parser->content($canonicalID);
+ $canonicalID = Services_Yadis_XRI($parser->content($canonicalID));
$childID = $canonicalID;
@@ -185,7 +196,7 @@ function Services_Yadis_getCanonicalID($iname, $xrds)
$parent_list = array();
foreach ($parser->evalXPath('xrd:CanonicalID', $xrd) as $c) {
- $parent_list[] = $parser->content($c);
+ $parent_list[] = Services_Yadis_XRI($parser->content($c));
}
if (!in_array($parent_sought, $parent_list)) {
diff --git a/Tests/Auth/OpenID/Discover.php b/Tests/Auth/OpenID/Discover.php
index 22cd434..4ed0063 100644
--- a/Tests/Auth/OpenID/Discover.php
+++ b/Tests/Auth/OpenID/Discover.php
@@ -6,6 +6,7 @@ require_once 'Auth/OpenID.php';
require_once 'Auth/OpenID/Discover.php';
require_once 'Services/Yadis/Manager.php';
require_once 'Services/Yadis/Misc.php';
+require_once 'Services/Yadis/XRI.php';
/**
* Tests for the core of the PHP Yadis library discovery logic.
@@ -614,7 +615,7 @@ class Tests_Auth_OpenID_Discover extends _DiscoveryBase {
"http://www.myopenid.com/server");
$this->assertEquals($services[1]->server_url,
"http://www.livejournal.com/openid/server.bml");
- $this->assertEquals($services[0]->canonicalID, "=!1000");
+ $this->assertEquals($services[0]->canonicalID, Services_Yadis_XRI("=!1000"));
}
}
diff --git a/Tests/Services/Yadis/XRDS.php b/Tests/Services/Yadis/XRDS.php
index 2c386da..44d34ab 100644
--- a/Tests/Services/Yadis/XRDS.php
+++ b/Tests/Services/Yadis/XRDS.php
@@ -107,13 +107,13 @@ class Tests_Services_Yadis_XRDS extends PHPUnit_TestCase {
function _getCanonicalID($iname, $xrds, $expectedID)
{
if ($expectedID === null) {
- $result =Services_Yadis_getCanonicalID($iname, $xrds);
+ $result = Services_Yadis_getCanonicalID($iname, $xrds);
if ($result !== false) {
$this->fail($iname.' (got '.$result.')');
}
} else {
$cid = Services_Yadis_getCanonicalID($iname, $xrds);
- $this->assertEquals($expectedID, $cid);
+ $this->assertEquals(Services_Yadis_XRI($expectedID), $cid);
}
}
diff --git a/Tests/Services/Yadis/XRI.php b/Tests/Services/Yadis/XRI.php
index c37128c..f00fef1 100644
--- a/Tests/Services/Yadis/XRI.php
+++ b/Tests/Services/Yadis/XRI.php
@@ -116,7 +116,7 @@ class Tests_Services_Yadis_TestGetRootAuthority extends PHPUnit_TestCase {
foreach ($xris as $tupl) {
list($thexri, $expected_root) = $tupl;
- $this->assertEquals($expected_root,
+ $this->assertEquals(Services_Yadis_XRI($expected_root),
Services_Yadis_rootAuthority($thexri),
'rootAuthority test ('.$thexri.')');
}