示例#1
0
 public function test_add_query_arg()
 {
     // Regular tests
     $this->assertEquals('/app/admin/users?user=5', util::add_query_arg('user', 5, '/app/admin/users'));
     $this->assertEquals('/app/admin/users?user=5', util::add_query_arg(array('user' => 5), '/app/admin/users'));
     $this->assertEquals('/app/admin/users?user=5', util::add_query_arg(array('user' => 5), null, '/app/admin/users'));
     $this->assertEquals('/app/admin/users?action=edit&user=5', util::add_query_arg('user', 5, '/app/admin/users?action=edit'));
     $this->assertEquals('/app/admin/users?action=edit&user=5', util::add_query_arg(array('user' => 5), '/app/admin/users?action=edit'));
     $this->assertEquals('/app/admin/users?action=edit&tab=personal&user=5', util::add_query_arg('user', 5, '/app/admin/users?action=edit&tab=personal'));
     $this->assertEquals('/app/admin/users?action=edit&tab=personal&user=5', util::add_query_arg(array('user' => 5), '/app/admin/users?action=edit&tab=personal'));
     // Ensure strips false.
     $this->assertEquals('/index.php', util::add_query_arg('debug', false, '/index.php'));
     // With valueless parameters.
     $this->assertEquals('/index.php?debug', util::add_query_arg('debug', null, '/index.php'));
     $this->assertEquals('/index.php?debug#hash', util::add_query_arg('debug', null, '/index.php#hash'));
     // With a URL fragment
     $this->assertEquals('/app/admin/users?user=5#test', util::add_query_arg('user', 5, '/app/admin/users#test'));
     // Full URL
     $this->assertEquals('http://example.com/?a=b', util::add_query_arg('a', 'b', 'http://example.com'));
     // Only the query string
     $this->assertEquals('?a=b&c=d', util::add_query_arg('c', 'd', '?a=b'));
     $this->assertEquals('a=b&c=d', util::add_query_arg('c', 'd', 'a=b'));
     // Url encoding test
     $this->assertEquals('/app/admin/users?param=containsa%26sym', util::add_query_arg('param', 'containsa&sym', '/app/admin/users'));
     // If not provided, grab the URI from the server.
     $_SERVER['REQUEST_URI'] = '/app/admin/users';
     $this->assertEquals('/app/admin/users?user=6', util::add_query_arg(array('user' => 6)));
     $this->assertEquals('/app/admin/users?user=7', util::add_query_arg('user', 7));
 }