<?php require_once 'core/helpers/url.php'; class URLTest extends PHPUnit_Framework_TestCase {
function SetUp() { $_SERVER['REQUEST_URI'] = "/test/path/?f=1#foo"; $_SERVER['HTTP_HOST'] = "test.example.com"; } function testGet() { $this->assertEquals("/test/path/?f=1", URL::get()); } function testAdd(){ $this->assertEquals("/test/path/?f=1&x=1", URL::add('x',1)); $this->assertEquals("/test/path/?f=1&y=2", URL::add(Array('y'=>2))); $this->assertEquals("/test/path/?f=1&a=b&c=d", URL::add(Array('a'=>'b','c'=>'d'))); $url = URL::add(Array('y'=>2)); $this->assertEquals("/test/path/?f=1&y=2", URL::get($url)); $this->assertEquals("/test/path/?f=1&y=2&x=3", URL::add('x', 3, $url)); $this->assertEquals("/test/path/?f=1&y=2&b=5&v=4", URL::add(Array('b'=> 5, 'v'=>4),false, $url)); $this->assertEquals("/test/path/?f=1&y=2&d=5&z=4", $url = URL::add(Array('d'=> 5, 'z'=>4),false, $url)); $this->assertEquals("/test/path/?f=1&y=2&z=4", URL::remove('d', $url)); $this->assertEquals("/test/path/", URL::remove(false, $url)); } function testIgnore(){ $url = URL::add(Array('y'=>2,'x'=>3)); URL::ignore('x'); $this->assertEquals("/test/path/?f=1&y=2", URL::get($url)); } function testPath(){ $this->assertEquals("/test/mod/path/", URL::path('test/mod/path')); $this->assertEquals("/test/mod/path2/", URL::path('test','mod','path2')); $this->assertEquals("/test/mod/path3/", URL::path(Array('test','mod','path3'))); } function testFile(){ $this->assertEquals("/test/mod/file", URL::file('test/mod/file')); $this->assertEquals("/test/mod/file2", URL::file('test','mod','file2')); $this->assertEquals("/test/mod/file3", URL::file(Array('test','mod','file3'))); } function testCanonical(){ $this->assertEquals("http://test.example.com/test/path/", URL::canonical()); $this->assertEquals("http://test.example.com/test/path/?f=1", URL::canonical(false, true)); URL::protocol('https'); $this->assertEquals("https://test.example.com/test/path/", URL::canonical()); } function testHash(){ $this->assertEquals("/test/path/?f=1#testhash", URL::hash('testhash')); } function testArgs(){ $this->assertEquals(Array('f'=>1), URL::args()); $url = URL::add('t',3); $this->assertEquals(Array('f'=>1, 't'=>3), URL::args(false, false ,$url)); $url = new URL(); $url->add('t',2); $this->assertEquals(Array('f'=>1, 't'=>2), $url->args()); } /** * @test */ function instanceTest(){ $url = new URL(); ob_start(); echo $url; $str = ob_get_clean(); $this->assertEquals("/test/path/?f=1", $str); $this->assertEquals("/test/path/?f=1&c=4", $url->add('c',4)); $this->assertEquals("/test/path/?f=1&c=4&z=5", $url->add('z',5)); $this->assertEquals("/test/path/?f=1&z=5", $url->remove('c')); } /* * @test */ function testArray(){ $this->assertEquals("/test/path/?f=1&a[0]=1&a[1]=2", urldecode(URL::add('a',Array(1,2)))); $this->assertEquals("/test/path/?f=1&a[a]=1&a[b]=2", urldecode(URL::add('a',Array('a'=>1,'b'=>2)))); $url = new URL(); $this->assertEquals("/test/path/?f=1&x[a]=1&x[b]=2", urldecode($url->add('x',Array('a'=>1,'b'=>2)))); } } ?>
|