diff options
author | Andreas Gohr <andi@splitbrain.org> | 2013-08-01 22:08:23 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2013-08-01 22:09:09 +0200 |
commit | 4d4b1f8c22cf406b35a88c7299f8ee2bc033bf4d (patch) | |
tree | 0157fc6f9315c9d8b3d9e2f92eed52397d12f1ac /_test/tests | |
parent | 991a5ddd298562a9b0e37df25cb7e682519ccf7a (diff) | |
download | rpg-4d4b1f8c22cf406b35a88c7299f8ee2bc033bf4d.tar.gz rpg-4d4b1f8c22cf406b35a88c7299f8ee2bc033bf4d.tar.bz2 |
use http_build_query() in HTTPClient
this ensures nested POST data is correctly encoded
Diffstat (limited to '_test/tests')
-rw-r--r-- | _test/tests/inc/httpclient_http.test.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index 387eb53aa..522f0790c 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -215,5 +215,55 @@ class httpclient_http_test extends DokuWikiTest { $data = $http->get('http://www.wikimatrix.org/cfeed/dokuwiki/-/-'); $this->assertTrue($data !== false, $http->error); } + + function test_postencode(){ + $http = new HTTPClient(); + + + // check simple data + $data = array( + 'öä?' => 'öä?', + 'foo' => 'bang' + ); + $this->assertEquals( + '%C3%B6%C3%A4%3F=%C3%B6%C3%A4%3F&foo=bang', + $http->_postEncode($data), + 'simple' + ); + + // check first level numeric array + $data = array( + 'foo' => 'bang', + 'ärr' => array('ö', 'b', 'c') + ); + $this->assertEquals( + 'foo=bang&%C3%A4rr%5B0%5D=%C3%B6&%C3%A4rr%5B1%5D=b&%C3%A4rr%5B2%5D=c', + $http->_postEncode($data), + 'onelevelnum' + ); + + // check first level associative array + $data = array( + 'foo' => 'bang', + 'ärr' => array('ö'=>'ä', 'b' => 'c') + ); + $this->assertEquals( + 'foo=bang&%C3%A4rr%5B%C3%B6%5D=%C3%A4&%C3%A4rr%5Bb%5D=c', + $http->_postEncode($data), + 'onelevelassoc' + ); + + + // check first level associative array + $data = array( + 'foo' => 'bang', + 'ärr' => array('ö'=>'ä', 'ä' => array('ö'=>'ä')) + ); + $this->assertEquals( + 'foo=bang&%C3%A4rr%5B%C3%B6%5D=%C3%A4&%C3%A4rr%5B%C3%A4%5D%5B%C3%B6%5D=%C3%A4', + $http->_postEncode($data), + 'twolevelassoc' + ); + } } //Setup VIM: ex: et ts=4 : |