summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortailor <cygnus@janrain.com>2006-01-02 20:19:16 +0000
committertailor <cygnus@janrain.com>2006-01-02 20:19:16 +0000
commit1d021b8e1d7bd5b52a73640cbc3556a901dbc4eb (patch)
tree431ee19ff546b4196e145bfbf5d2a2e098854128
parent383618d25d42207072bdb1b7e0765f98ee59cdc8 (diff)
downloadphp-openid-1d021b8e1d7bd5b52a73640cbc3556a901dbc4eb.zip
php-openid-1d021b8e1d7bd5b52a73640cbc3556a901dbc4eb.tar.gz
php-openid-1d021b8e1d7bd5b52a73640cbc3556a901dbc4eb.tar.bz2
[project @ Added tests for oidutils: normalizeUrl and appendArgs]
-rw-r--r--Tests/Net/OpenID/OIDUtil.php140
1 files changed, 140 insertions, 0 deletions
diff --git a/Tests/Net/OpenID/OIDUtil.php b/Tests/Net/OpenID/OIDUtil.php
index 1c26206..9e2f9d3 100644
--- a/Tests/Net/OpenID/OIDUtil.php
+++ b/Tests/Net/OpenID/OIDUtil.php
@@ -55,6 +55,146 @@ class Tests_Net_OpenID_OIDUtil extends PHPUnit_TestCase {
$this->assertEquals($s_prime, $s);
}
}
+
+ function test_normalizeUrl() {
+ $this->assertEquals("http://foo.com/", Net_OpenID_normalizeUrl("foo.com"));
+
+ $this->assertEquals("http://foo.com/", Net_OpenID_normalizeUrl("http://foo.com"));
+ $this->assertEquals("https://foo.com/", Net_OpenID_normalizeUrl("https://foo.com"));
+ $this->assertEquals("http://foo.com/bar", Net_OpenID_normalizeUrl("foo.com/bar"));
+ $this->assertEquals("http://foo.com/bar", Net_OpenID_normalizeUrl("http://foo.com/bar"));
+
+ $this->assertEquals("http://foo.com/", Net_OpenID_normalizeUrl("http://foo.com/"));
+ $this->assertEquals("https://foo.com/", Net_OpenID_normalizeUrl("https://foo.com/"));
+ $this->assertEquals("https://foo.com/bar" , Net_OpenID_normalizeUrl("https://foo.com/bar"));
+
+ if (0) {
+ $this->assertEquals("http://foo.com/%E8%8D%89", Net_OpenID_normalizeUrl("foo.com/\u8349"));
+ $this->assertEquals("http://foo.com/%E8%8D%89", Net_OpenID_normalizeUrl("http://foo.com/\u8349"));
+ }
+
+ $non_ascii_domain_cases = array(
+ array("http://xn--vl1a.com/", "\u8349.com"),
+ array("http://xn--vl1a.com/", "http://\u8349.com"),
+ array("http://xn--vl1a.com/", "\u8349.com/"),
+ array("http://xn--vl1a.com/", "http://\u8349.com/"),
+ array("http://xn--vl1a.com/%E8%8D%89", "\u8349.com/\u8349"),
+ array("http://xn--vl1a.com/%E8%8D%89", "http://\u8349.com/\u8349"),
+ );
+
+ // XXX
+ /*
+ codecs.getencoder('idna')
+ except LookupError:
+ # If there is no idna codec, these cases with
+ # non-ascii-representable domain names should fail.
+ should_raise = True
+ else:
+ should_raise = False
+
+ for expected, case in non_ascii_domain_cases:
+try:
+actual = Net_OpenID_normalizeUrl(case)
+ except UnicodeError:
+ assert should_raise
+ else:
+assert not should_raise and actual == expected, case
+ */
+
+ $this->assertNull(Net_OpenID_normalizeUrl(null));
+ $this->assertNull(Net_OpenID_normalizeUrl(''));
+ $this->assertNull(Net_OpenID_normalizeUrl('http://'));
+ }
+
+ function test_appendArgs() {
+
+ $simple = 'http://www.example.com/';
+
+ $cases = array(
+ array('empty list',
+ array($simple, array()),
+ $simple),
+
+ array('empty dict',
+ array($simple, array()),
+ $simple),
+
+ array('one list',
+ array($simple, array(array('a', 'b'))),
+ $simple . '?a=b'),
+
+ array('one dict',
+ array($simple, array('a' => 'b')),
+ $simple . '?a=b'),
+
+ array('two list (same)',
+ array($simple, array(array('a', 'b'), array('a', 'c'))),
+ $simple . '?a=b&a=c'),
+
+ array('two list',
+ array($simple, array(array('a', 'b'), array('b', 'c'))),
+ $simple . '?a=b&b=c'),
+
+ array('two list (order)',
+ array($simple, array(array('b', 'c'), array('a', 'b'))),
+ $simple . '?b=c&a=b'),
+
+ array('two dict (order)',
+ array($simple, array('b' => 'c', 'a' => 'b')),
+ $simple . '?a=b&b=c'),
+
+ array('escape',
+ array($simple, array(array('=', '='))),
+ $simple . '?%3D=%3D'),
+
+ array('escape (URL)',
+ array($simple, array(array('this_url', $simple))),
+ $simple . '?this_url=http%3A%2F%2Fwww.example.com%2F'),
+
+ array('use dots',
+ array($simple, array(array('openid.stuff', 'bother'))),
+ $simple . '?openid.stuff=bother'),
+
+ array('args exist (empty)',
+ array($simple . '?stuff=bother', array()),
+ $simple . '?stuff=bother'),
+
+ array('args exist',
+ array($simple . '?stuff=bother', array(array('ack', 'ack'))),
+ $simple . '?stuff=bother&ack=ack'),
+
+ array('args exist',
+ array($simple . '?stuff=bother', array(array('ack', 'ack'))),
+ $simple . '?stuff=bother&ack=ack'),
+
+ array('args exist (dict)',
+ array($simple . '?stuff=bother', array('ack' => 'ack')),
+ $simple . '?stuff=bother&ack=ack'),
+
+ array('args exist (dict 2)',
+ array($simple . '?stuff=bother', array('ack' => 'ack', 'zebra' => 'lion')),
+ $simple . '?stuff=bother&ack=ack&zebra=lion'),
+
+ array('three args (dict)',
+ array($simple, array('stuff' => 'bother', 'ack' => 'ack',
+ 'zebra' => 'lion')),
+ $simple . '?ack=ack&stuff=bother&zebra=lion'),
+
+ array('three args (list)',
+ array($simple, array(
+ array('stuff', 'bother'),
+ array('ack', 'ack'),
+ array('zebra', 'lion'))),
+ $simple . '?stuff=bother&ack=ack&zebra=lion'),
+ );
+
+ // Tests.
+ foreach ($cases as $case) {
+ list($desc, $data, $expected) = $case;
+ list($url, $query) = $data;
+ $this->assertEquals($expected, Net_OpenID_appendArgs($url, $query));
+ }
+ }
}
?> \ No newline at end of file