Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ae2f0dfd8b
Fetching contributors…

Cannot retrieve contributors at this time

184 lines (147 sloc) 5.103 kb
<?php
require_once 'Uri_Test_Helper.php';
class Uri_Test extends PHPUnit_Framework_TestCase {
function testDefault() {
$uri = new Uri('www.example.com');
self::assertEquals('http://www.example.com/', (string)$uri);
}
function testPath() {
$uri = new Uri('www.example.com', 'blog');
self::assertEquals('http://www.example.com/blog', (string)$uri);
}
function testMultiplePaths() {
$uri = new Uri('www.example.com', array('blog', 'first-post'));
self::assertEquals('http://www.example.com/blog/first-post', (string)$uri);
}
function testEncode() {
$uri = new Uri('www.example.com', 'blog', array('encode' => true));
self::assertEquals('http%3A%2F%2Fwww.example.com%2Fblog', (string)$uri);
}
function testParameters() {
$uri = new Uri(
'www.example.com',
'blog',
array(
'parameters' => array('foo' => 'bar', 'bar' => 'foo')
)
);
self::assertEquals('http://www.example.com/blog?foo=bar&bar=foo', (string)$uri);
}
function testParametersWithCustomSeparator() {
$uri = new Uri(
'www.example.com',
'blog',
array(
'parameters' => array('foo' => 'bar', 'bar' => 'foo'),
'separator' => '&amp;'
)
);
self::assertEquals('http://www.example.com/blog?foo=bar&amp;bar=foo', (string)$uri);
}
function testParametersEncode() {
$uri = new Uri(
'www.example.com',
'blog',
array(
'parameters' => array('foo' => 'Hello World!')
)
);
self::assertEquals('http://www.example.com/blog?foo=Hello+World%21', (string)$uri);
}
function testHash() {
$uri = new Uri(
'www.example.com',
'blog',
array(
'hash' => array('foo' => 'bar', 'bar' => 'foo')
)
);
self::assertEquals('http://www.example.com/blog#foo=bar&bar=foo', (string)$uri);
}
function testHashWithCustomSeparator() {
$uri = new Uri(
'www.example.com',
'blog',
array(
'hash' => array('foo' => 'bar', 'bar' => 'foo'),
'separator' => '&amp;'
)
);
self::assertEquals('http://www.example.com/blog#foo=bar&amp;bar=foo', (string)$uri);
}
function testHashEncode() {
$uri = new Uri(
'www.example.com',
'blog',
array(
'hash' => array('foo' => 'Hello World!')
)
);
self::assertEquals('http://www.example.com/blog#foo=Hello+World%21', (string)$uri);
}
function testUsername() {
$uri = new Uri('www.example.com', 'blog', array('username' => 'admin'));
self::assertEquals('http://admin@www.example.com/blog', (string)$uri);
}
function testUsernameAndPassword() {
$uri = new Uri(
'www.example.com',
'blog',
array('username' => 'admin', 'password' => 'secret')
);
self::assertEquals('http://admin:secret@www.example.com/blog', (string)$uri);
}
function testPort() {
$uri = new Uri(
'www.example.com',
'blog',
array('port' => 8080)
);
self::assertEquals('http://www.example.com:8080/blog', (string)$uri);
}
function testSslPort() {
$uri = new Uri(
'www.example.com',
'blog',
array('port' => 443)
);
self::assertEquals('http://www.example.com:443/blog', (string)$uri);
}
function testProtocol() {
$uri = new Uri(
'www.example.com',
'blog',
array('protocol' => 'ftp')
);
self::assertEquals('ftp://www.example.com/blog', (string)$uri);
}
function testProtocolWithSsl() {
$uri = new Uri(
'www.example.com',
'blog',
array('protocol' => 'ftp', 'ssl' => true)
);
self::assertEquals('ftps://www.example.com/blog', (string)$uri);
}
function testAllOptions() {
$uri = new Uri(
'www.example.com',
array('blog', 'second-post'),
array(
'encode' => true,
'hash' => array('foo' => 'bar', 'bar' => 'foo', 'foobar' => 1337),
'parameters' => array('bar' => 'foo', 'foo' => 'bar', 'foobar' => 1337),
'username' => 'admin',
'password' => 'secret',
'port' => 8080,
'protocol' => 'ftp',
'separator' => '&amp;',
'ssl' => true
)
);
self::assertEquals(
'ftps%3A%2F%2Fadmin%3Asecret%40www.example.com%3A8080%2Fblog%2Fsecond-post%3Fbar%3Dfoo%26amp%3Bfoo%3Dbar%26amp%3Bfoobar%3D1337%23foo%3Dbar%26amp%3Bbar%3Dfoo%26amp%3Bfoobar%3D1337',
(string)$uri
);
}
}
Jump to Line
Something went wrong with that request. Please try again.