+++ /dev/null
-<?php
-
-class EncodingStreamTest extends PHPUnit_Framework_TestCase {
- function testChunkStatic() {
- $file = file(__FILE__);
- $cenc = array_reduce(
- $file,
- function($data, $line) {
- return $data . sprintf("%lx\r\n%s\r\n", strlen($line), $line);
- }
- ) . "0\r\n";
-
- $this->assertEquals(implode("", $file), http\Encoding\Stream\Dechunk::decode($cenc));
- }
-
- function testChunkNoteEncoded() {
- $s = "this is apparently not encodded\n";
- $this->assertEquals($s, @http\Encoding\Stream\Dechunk::decode($s));
- }
-
- function testChunkNotEncodedNotice() {
- error_reporting(E_ALL);
- $this->setExpectedException("PHPUnit_Framework_Error_Notice",
- "Data does not seem to be chunked encoded");
- $s = "this is apparently not encodded\n";
- $this->assertEquals($s, http\Encoding\Stream\Dechunk::decode($s));
- }
-
- function testChunkNotEncodedFail() {
- $s = "3\nis \nbetter than\n1\n";
- $this->assertNotEquals($s, @http\Encoding\Stream\Dechunk::decode($s));
- }
-
- function testChunkNotEncodedWarning1() {
- $this->setExpectedException("PHPUnit_Framework_Error_Warning",
- "Expected LF at pos 8 of 20 but got 0x74");
- $s = "3\nis \nbetter than\n1\n";
- http\Encoding\Stream\Dechunk::decode($s);
- }
-
- function testChunkNotEncodedWarning2() {
- $this->setExpectedException("PHPUnit_Framework_Error_Warning",
- "Expected CRLF at pos 10 of 24 but got 0x74 0x74");
- $s = "3\r\nis \r\nbetter than\r\n1\r\n";
- http\Encoding\Stream\Dechunk::decode($s);
- }
-
- function testChunkNotEncodedWarning3() {
- $this->setExpectedException("PHPUnit_Framework_Error_Warning",
- "Expected chunk size at pos 6 of 27 but got trash");
- $s = "3\nis \nreally better than\n1\n";
- http\Encoding\Stream\Dechunk::decode($s);
- }
-
- function testChunkFlush() {
- $dech = new http\Encoding\Stream\Dechunk(http\Encoding\Stream::FLUSH_FULL);
- $file = file(__FILE__);
- $data = "";
- foreach ($file as $i => $line) {
- $dech = clone $dech;
- if ($i % 2) {
- $data .= $dech->update(sprintf("%lx\r\n%s\r\n", strlen($line), $line));
- } else {
- $data .= $dech->update(sprintf("%lx\r\n", strlen($line)));
- $data .= $dech->flush();
- $data .= $dech->update($line);
- $data .= $dech->flush();
- $data .= $dech->update("\r\n");
- }
- $dech->flush();
- $this->assertFalse($dech->done());
- }
- $data .= $dech->update("0\r\n");
- $this->assertTrue($dech->done());
- $data .= $dech->finish();
- $this->assertEquals(implode("", $file), $data);
- }
-
- function testZlibStatic() {
- $file = file_get_contents(__FILE__);
- $this->assertEquals($file,
- http\Encoding\Stream\Inflate::decode(
- http\Encoding\Stream\Deflate::encode(
- $file, http\Encoding\Stream\Deflate::TYPE_GZIP
- )
- )
- );
- $this->assertEquals($file,
- http\Encoding\Stream\Inflate::decode(
- http\Encoding\Stream\Deflate::encode(
- $file, http\Encoding\Stream\Deflate::TYPE_ZLIB
- )
- )
- );
- $this->assertEquals($file,
- http\Encoding\Stream\Inflate::decode(
- http\Encoding\Stream\Deflate::encode(
- $file, http\Encoding\Stream\Deflate::TYPE_RAW
- )
- )
- );
- }
-
- function testZlibAutoFlush() {
- $defl = new http\Encoding\Stream\Deflate(http\Encoding\Stream::FLUSH_FULL);
- $infl = new http\Encoding\Stream\Inflate;
-
- for ($f = fopen(__FILE__, "rb"); !feof($f); $data = fread($f, 0x100)) {
- $infl = clone $infl;
- $defl = clone $defl;
- if (isset($data)) {
- $this->assertEquals($data, $infl->update($defl->update($data)));
- }
- }
-
- echo $infl->update($defl->finish());
- echo $infl->finish();
- }
-
- function testZlibWithoutFlush() {
- $defl = new http\Encoding\Stream\Deflate;
- $infl = new http\Encoding\Stream\Inflate;
- $file = file(__FILE__);
- $data = "";
- foreach ($file as $line) {
- $infl = clone $infl;
- $defl = clone $defl;
- if (strlen($temp = $defl->update($line))) {
- foreach(str_split($temp) as $byte) {
- $data .= $infl->update($byte);
- }
- }
- }
- if (strlen($temp = $defl->finish())) {
- $data .= $infl->update($temp);
- }
- $data .= $infl->finish();
- $this->assertEquals(implode("", $file), $data);
- }
-
- function testZlibWithExplicitFlush() {
- $defl = new http\Encoding\Stream\Deflate;
- $infl = new http\Encoding\Stream\Inflate;
- $file = file(__FILE__);
- $data = "";
- foreach ($file as $line) {
- $data .= $infl->flush();
- if (strlen($temp = $defl->update($line))) {
- $data .= $infl->update($temp);
- $data .= $infl->flush();
- }
- if (strlen($temp = $defl->flush())) {
- $data .= $infl->update($temp);
- $data .= $infl->flush();
- }
- $this->assertTrue($defl->done());
- }
- if (strlen($temp = $defl->finish())) {
- $data .= $infl->update($temp);
- }
- $this->assertTrue($defl->done());
- $data .= $infl->finish();
- $this->assertTrue($infl->done());
- $this->assertEquals(implode("", $file), $data);
- }
-
- function testInflateError() {
- $this->setExpectedException("PHPUnit_Framework_Error_Warning",
- "Could not inflate data: data error");
- http\Encoding\Stream\Inflate::decode("if this goes through, something's pretty wrong");
- }
-}
+++ /dev/null
-<?php
-
-class ParamsTest extends PHPUnit_Framework_TestCase {
- function testDefault() {
- $s = "foo, bar;arg=0;bla, gotit=0;now";
- $this->runAssertions(
- new http\Params($s),
- str_replace(" ", "", $s)
- );
- }
-
- function testCustom() {
- $s = "foo bar.arg:0.bla gotit:0.now";
- $this->runAssertions(
- new http\Params($s, " ", ".", ":"),
- $s
- );
- }
-
- function testQuoted() {
- $p = new http\Params("multipart/form-data; boundary=\"--123\"");
- $this->assertEquals(
- array(
- "multipart/form-data" => array(
- "value" => true,
- "arguments" => array(
- "boundary" => "--123"
- )
- )
- ),
- $p->params
- );
- $this->assertEquals("multipart/form-data;boundary=--123", (string) $p);
- }
-
- function testEscaped() {
- $p = new http\Params("form-data; name=\"upload\"; filename=\"trick\\\"\0\\\"ed\"");
- $this->assertEquals(
- array(
- "form-data" => array(
- "value" => true,
- "arguments" => array(
- "name" => "upload",
- "filename" => "trick\"\0\"ed"
- )
- )
- ),
- $p->params
- );
- $this->assertEquals("form-data;name=upload;filename=\"trick\\\"\\0\\\"ed\"", (string) $p);
- }
-
- function testUrlencoded() {
- $s = "foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1";
- $p = new http\Params($s, "&", "", "=", http\Params::PARSE_URLENCODED);
- $this->assertEquals(
- array(
- "foo" => array(
- "value" => "b\"r",
- "arguments" => array(),
- ),
- "bar" => array(
- "value" => "b\"z",
- "arguments" => array(),
- ),
- "a[][]" => array(
- "value" => "1",
- "arguments" => array(),
- ),
- ),
- $p->params
- );
- $this->assertEquals("foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1", (string) $p);
- }
-
- function testQuery() {
- $s = "foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1";
- $p = new http\Params($s, "&", "", "=", http\Params::PARSE_QUERY);
- $this->assertEquals(
- array(
- "foo" => array(
- "value" => "b\"r",
- "arguments" => array(),
- ),
- "bar" => array(
- "value" => "b\"z",
- "arguments" => array(),
- ),
- "a" => array(
- "value" => array(
- array("1")
- ),
- "arguments" => array(),
- ),
- ),
- $p->params
- );
- $this->assertEquals("foo=b%22r&bar=b%22z&a%5B0%5D%5B0%5D=1", (string) $p);
- }
-
-
- function testEmpty() {
- $p = new http\Params(NULL);
- $this->assertEquals(array(), $p->params);
- }
-
- function testErrorOfToArrayWithArgs() {
- $this->setExpectedException("PHPUnit_Framework_Error_Warning");
- $p = new http\Params();
- $p->toArray("dummy");
- }
-
- function testIntegerKeys() {
- $p = new http\Params("0=nothing;1=yes");
- $this->assertEquals(array("0" => array("value" => "nothing", "arguments" => array(1=>"yes"))), $p->params);
- $this->assertEquals("0=nothing;1=yes", $p->toString());
- }
-
- function testBoolParamArguments() {
- $p = new http\Params;
- $container = array("value" => false, "arguments" => array("wrong" => false, "correct" => true));
- $p["container"] = $container;
- $this->assertEquals("container=0;wrong=0;correct", $p->toString());
- $this->assertEquals(array("container" => $container), $p->toArray());
- }
-
- function testNoArgsForParam() {
- $p = new http\Params;
- $p["param"] = true;
- $this->assertEquals("param", $p->toString());
- $p["param"] = false;
- $this->assertEquals("param=0", $p->toString());
- }
-
- protected function runAssertions($p, $s) {
- $this->assertCount(3, $p->params);
- $this->assertArrayHasKey("foo", $p->params);
- $this->assertArrayHasKey("bar", $p->params);
- $this->assertArrayHasKEy("gotit", $p->params);
-
- $this->assertTrue($p["foo"]["value"]);
- $this->assertTrue($p["bar"]["value"]);
- $this->assertEmpty($p["gotit"]["value"]);
-
- $this->assertEmpty($p["foo"]["arguments"]);
- $this->assertCount(2, $p["bar"]["arguments"]);
- $this->assertCount(1, $p["gotit"]["arguments"]);
-
- $this->assertEmpty($p["bar"]["arguments"]["arg"]);
- $this->assertTrue($p["bar"]["arguments"]["bla"]);
- $this->assertTrue($p["gotit"]["arguments"]["now"]);
-
- $this->assertEquals($s, (string) $p);
-
- $comp = array (
- 'foo' =>
- array (
- 'value' => true,
- 'arguments' =>
- array (
- ),
- ),
- 'bar' =>
- array (
- 'value' => true,
- 'arguments' =>
- array (
- 'arg' => '0',
- 'bla' => true,
- ),
- ),
- 'gotit' =>
- array (
- 'value' => '0',
- 'arguments' =>
- array (
- 'now' => true,
- ),
- ),
- );
-
- $this->assertEquals($comp, $p->params);
- $a = new http\Params($p->params);
- $this->assertEquals($comp, $a->toArray());
- }
-}
+++ /dev/null
-<?php
-
-class QueryStringTest extends PHPUnit_Framework_TestCase {
- protected $q;
- protected $s = "a=b&r[]=0&r[]=1&r[]=2&rr[][]=00&rr[][]=01&1=2";
- protected $e = "a=b&r%5B0%5D=0&r%5B1%5D=1&r%5B2%5D=2&rr%5B0%5D%5B0%5D=00&rr%5B0%5D%5B1%5D=01&1=2";
-
- function setUp() {
- $this->q = new http\QueryString($this->s);
- }
-
- function testSimple() {
- $this->assertEquals($this->e, (string) $this->q);
- $this->assertEquals($this->e, $this->q->get());
- }
-
- function testGetDefval() {
- $this->assertEquals("nonexistant", $this->q->get("unknown", "s", "nonexistant"));
- $this->assertEquals(null, $this->q->get("unknown"));
- }
-
- function testGetA() {
- $this->assertEquals("b", $this->q->get("a"));
- $this->assertEquals(0, $this->q->get("a", "i"));
- $this->assertEquals(array("b"), $this->q->get("a", "a"));
- $this->assertEquals((object)array("scalar" => "b"), $this->q->get("a", "o"));
- }
-
- function testGetR() {
- $this->assertEquals(array(0,1,2), $this->q->get("r"));
- }
-
- function testGetRR() {
- $this->assertEquals(array(array("00","01")), $this->q->get("rr"));
- }
-
- function testGet1() {
- $this->assertEquals(2, $this->q->get(1));
- $this->assertEquals("2", $this->q->get(1, "s"));
- $this->assertEquals(2.0, $this->q->get(1, "f"));
- $this->assertTrue($this->q->get(1, "b"));
- }
-
- function testDelA() {
- $this->assertEquals("b", $this->q->get("a", http\QueryString::TYPE_STRING, null, true));
- $this->assertEquals(null, $this->q->get("a"));
- }
-
- function testDelAll() {
- $this->q->set(array("a" => null, "r" => null, "rr" => null, 1 => null));
- $this->assertEquals("", $this->q->toString());
- }
-
- function testQSO() {
- $this->assertEquals($this->e, (string) new http\QueryString($this->q));
- $this->assertEquals(http_build_query(array("e"=>$this->q->toArray())), (string) new http\QueryString(array("e" => $this->q)));
- }
-
- function testIterator() {
- $this->assertEquals($this->q->toArray(), iterator_to_array($this->q));
- }
-
- function testSerialize() {
- $this->assertEquals($this->e, (string) unserialize(serialize($this->q)));
- }
-}
+++ /dev/null
-<?php
-
-class UrlTest extends PHPUnit_Framework_TestCase {
- protected $url;
- function setUp() {
- $this->url = "http://user:pass@www.example.com:8080/path/file.ext".
- "?foo=bar&more[]=1&more[]=2#hash";
- }
-
- function testStandard() {
- $this->assertEquals($this->url, (string) new http\Url($this->url));
-
- $url = new http\Url($this->url,
- array("path" => "changed", "query" => "foo=&added=this"),
- http\Url::JOIN_PATH |
- http\Url::JOIN_QUERY |
- http\Url::STRIP_AUTH |
- http\Url::STRIP_FRAGMENT
- );
-
- $this->assertEquals("http", $url->scheme);
- $this->assertEmpty($url->user);
- $this->assertEmpty($url->pass);
- $this->assertEquals("www.example.com", $url->host);
- $this->assertEquals(8080, $url->port);
- $this->assertEquals("/path/changed", $url->path);
- $this->assertEquals("more%5B0%5D=1&more%5B1%5D=2&added=this", $url->query);
- $this->assertEmpty($url->fragment);
- }
-
- function testMod() {
- $tmp = new http\Url($this->url);
- $mod = $tmp->mod(array("query" => "set=1"), http\Url::REPLACE);
- $this->assertNotEquals($tmp->toArray(), $mod->toArray());
- $this->assertEquals("set=1", $mod->query);
- $this->assertEquals("new_fragment", $tmp->mod("#new_fragment")->fragment);
- }
-
- function testStrings() {
- $url = new http\Url($this->url);
- $this->assertEquals((string) $url, (string) new http\Url((string) $url));
- }
-
- function testArrays() {
- $url = new http\Url($this->url);
- $url2 = new http\Url($url->toArray());
- $this->assertEquals($url->toArray(), $url2->toArray());
- }
-}
--- /dev/null
+--TEST--
+encoding stream chunked static
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$file = file(__FILE__);
+$cenc = array_reduce(
+ $file,
+ function($data, $line) {
+ return $data . sprintf("%lx\r\n%s\r\n", strlen($line), $line);
+ }
+) . "0\r\n";
+
+var_dump(implode("", $file) === http\Encoding\Stream\Dechunk::decode($cenc));
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+DONE
+
--- /dev/null
+--TEST--
+encoding stream chunked not encoded
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$s = "this is apparently not encodded\n";
+var_dump($s === http\Encoding\Stream\Dechunk::decode($s));
+
+?>
+DONE
+--EXPECTF--
+Test
+
+Notice: http\Encoding\Stream\Dechunk::decode(): Data does not seem to be chunked encoded in %s on line %d
+bool(true)
+DONE
--- /dev/null
+--TEST--
+encoding stream chunked error
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$s = "3\nis \nbetter than\n1\n";
+var_dump(http\Encoding\Stream\Dechunk::decode($s));
+$s = "3\r\nis \r\nbetter than\r\n1\r\n";
+var_dump(http\Encoding\Stream\Dechunk::decode($s));
+$s = "3\nis \nreally better than\n1\n";
+var_dump(http\Encoding\Stream\Dechunk::decode($s));
+?>
+DONE
+--EXPECTF--
+Test
+
+Warning: http\Encoding\Stream\Dechunk::decode(): Expected LF at pos 8 of 20 but got 0x74 in %s on line %d
+
+Warning: http\Encoding\Stream\Dechunk::decode(): Truncated message: chunk size 190 exceeds remaining data size 11 at pos 9 of 20 in %s on line %d
+string(14) "is ter than
+1
+"
+
+Warning: http\Encoding\Stream\Dechunk::decode(): Expected CRLF at pos 10 of 24 but got 0x74 0x74 in %s on line %d
+
+Warning: http\Encoding\Stream\Dechunk::decode(): Truncated message: chunk size 190 exceeds remaining data size 12 at pos 12 of 24 in %s on line %d
+string(15) "is er than
+1
+"
+
+Warning: http\Encoding\Stream\Dechunk::decode(): Expected chunk size at pos 6 of 27 but got trash in %s on line %d
+bool(false)
+DONE
--- /dev/null
+--TEST--
+encoding stream chunked flush
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$dech = new http\Encoding\Stream\Dechunk(http\Encoding\Stream::FLUSH_FULL);
+$file = file(__FILE__);
+$data = "";
+foreach ($file as $i => $line) {
+ $dech = clone $dech;
+ if ($i % 2) {
+ $data .= $dech->update(sprintf("%lx\r\n%s\r\n", strlen($line), $line));
+ } else {
+ $data .= $dech->update(sprintf("%lx\r\n", strlen($line)));
+ $data .= $dech->flush();
+ $data .= $dech->update($line);
+ $data .= $dech->flush();
+ $data .= $dech->update("\r\n");
+ }
+ $dech->flush();
+ $dech->done() and printf("uh-oh done() reported true!\n");
+}
+$data .= $dech->update("0\r\n");
+var_dump($dech->done());
+$data .= $dech->finish();
+var_dump(implode("", $file) === $data);
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+DONE
--- /dev/null
+--TEST--
+encoding stream zlib static
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$file = file_get_contents(__FILE__);
+var_dump($file ===
+ http\Encoding\Stream\Inflate::decode(
+ http\Encoding\Stream\Deflate::encode(
+ $file, http\Encoding\Stream\Deflate::TYPE_GZIP
+ )
+ )
+);
+var_dump($file ===
+ http\Encoding\Stream\Inflate::decode(
+ http\Encoding\Stream\Deflate::encode(
+ $file, http\Encoding\Stream\Deflate::TYPE_ZLIB
+ )
+ )
+);
+var_dump($file ===
+ http\Encoding\Stream\Inflate::decode(
+ http\Encoding\Stream\Deflate::encode(
+ $file, http\Encoding\Stream\Deflate::TYPE_RAW
+ )
+ )
+);
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+DONE
--- /dev/null
+--TEST--
+encoding stream zlib auto flush
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$defl = new http\Encoding\Stream\Deflate(http\Encoding\Stream::FLUSH_FULL);
+$infl = new http\Encoding\Stream\Inflate;
+
+for ($f = fopen(__FILE__, "rb"); !feof($f); $data = fread($f, 0x100)) {
+ $infl = clone $infl;
+ $defl = clone $defl;
+ if (isset($data)) {
+ if ($data !== $d=$infl->update($defl->update($data))) {
+ printf("uh-oh »%s« != »%s«\n", $data, $d);
+ }
+ }
+}
+
+echo $infl->update($defl->finish());
+echo $infl->finish();
+?>
+DONE
+--EXPECT--
+Test
+DONE
--- /dev/null
+--TEST--
+encoding stream zlib without flush
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$defl = new http\Encoding\Stream\Deflate;
+$infl = new http\Encoding\Stream\Inflate;
+$file = file(__FILE__);
+$data = "";
+foreach ($file as $line) {
+ $infl = clone $infl;
+ $defl = clone $defl;
+ if (strlen($temp = $defl->update($line))) {
+ foreach(str_split($temp) as $byte) {
+ $data .= $infl->update($byte);
+ }
+ }
+}
+if (strlen($temp = $defl->finish())) {
+ $data .= $infl->update($temp);
+}
+$data .= $infl->finish();
+var_dump(implode("", $file) === $data);
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+DONE
--- /dev/null
+--TEST--
+encoding stream zlib with explicit flush
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$defl = new http\Encoding\Stream\Deflate;
+$infl = new http\Encoding\Stream\Inflate;
+$file = file(__FILE__);
+$data = "";
+foreach ($file as $line) {
+ $data .= $infl->flush();
+ if (strlen($temp = $defl->update($line))) {
+ $data .= $infl->update($temp);
+ $data .= $infl->flush();
+ }
+ if (strlen($temp = $defl->flush())) {
+ $data .= $infl->update($temp);
+ $data .= $infl->flush();
+ }
+ $defl->done() or printf("uh-oh stream's not done yet!\n");
+}
+if (strlen($temp = $defl->finish())) {
+ $data .= $infl->update($temp);
+}
+var_dump($defl->done());
+$data .= $infl->finish();
+var_dump($infl->done());
+var_dump(implode("", $file) === $data);
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+DONE
--- /dev/null
+--TEST--
+encoding stream zlib error
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+var_dump(http\Encoding\Stream\Inflate::decode("if this goes through, something's pretty wrong"));
+
+?>
+DONE
+--EXPECTF--
+Test
+
+Warning: http\Encoding\Stream\Inflate::decode(): Could not inflate data: data error in %s on line %d
+bool(false)
+DONE
var_dump((string) $ct,$ct);
-echo "Done\n";
+?>
+DONE
--EXPECTF--
Test
bool(true)
["flags"]=>
int(0)
}
-Done
+DONE
--TEST--
-header params rfc5987
+default params
--SKIPIF--
<?php
include "skipif.inc";
<?php
echo "Test\n";
-$p = new http\Params("attachment; filename*=IsO-8859-1''d%f6ner.pdf");
-var_dump($p->params, (string) $p);
-$p = new http\Params("bar; title*=iso-8859-1'en'%A3%20rates");
-var_dump($p->params, (string) $p);
-$p = new http\Params("bar; title*=UTF-8''%c2%a3%20and%20%e2%82%ac%20rates");
-var_dump($p->params, (string) $p);
+$s = "foo, bar;arg=0;bla, gotit=0;now";
+$p = new http\Params($s);
+$c = str_replace(" ", "", $s);
+$k = array("foo", "bar", "gotit");
+$a = array("foo"=>"arg", "bar"=>"bla", "gotit"=>"now");
+$r = array (
+ 'foo' =>
+ array (
+ 'value' => true,
+ 'arguments' =>
+ array (
+ ),
+ ),
+ 'bar' =>
+ array (
+ 'value' => true,
+ 'arguments' =>
+ array (
+ 'arg' => '0',
+ 'bla' => true,
+ ),
+ ),
+ 'gotit' =>
+ array (
+ 'value' => '0',
+ 'arguments' =>
+ array (
+ 'now' => true,
+ ),
+ ),
+);
-?>
-===DONE===
---EXPECT--
-Test
-array(1) {
- ["attachment"]=>
- array(2) {
- ["value"]=>
- bool(true)
- ["arguments"]=>
- array(1) {
- ["*rfc5987*"]=>
- array(1) {
- ["filename"]=>
- array(1) {
- [""]=>
- string(10) "döner.pdf"
- }
- }
- }
- }
+# ---
+
+var_dump(count($p->params));
+
+echo "key exists\n";
+foreach ($k as $key) {
+ var_dump(array_key_exists($key, $p->params));
}
-string(42) "attachment;filename*=utf-8''d%C3%B6ner.pdf"
-array(1) {
- ["bar"]=>
- array(2) {
- ["value"]=>
- bool(true)
- ["arguments"]=>
- array(1) {
- ["*rfc5987*"]=>
- array(1) {
- ["title"]=>
- array(1) {
- ["en"]=>
- string(8) "£ rates"
- }
- }
- }
- }
+
+echo "values\n";
+foreach ($k as $key) {
+ var_dump($p[$key]["value"]);
}
-string(34) "bar;title*=utf-8'en'%C2%A3%20rates"
-array(1) {
- ["bar"]=>
- array(2) {
- ["value"]=>
- bool(true)
- ["arguments"]=>
- array(1) {
- ["*rfc5987*"]=>
- array(1) {
- ["title"]=>
- array(1) {
- [""]=>
- string(16) "£ and € rates"
- }
- }
- }
- }
+
+echo "args\n";
+foreach ($k as $key) {
+ var_dump(count($p[$key]["arguments"]));
}
-string(50) "bar;title*=utf-8''%C2%A3%20and%20%E2%82%AC%20rates"
-===DONE===
\ No newline at end of file
+
+echo "arg values\n";
+foreach ($k as $key) {
+ var_dump(@$p[$key]["arguments"][$a[$key]]);
+}
+
+echo "equals\n";
+var_dump($c === (string) $p);
+var_dump($r === $p->params);
+$x = new http\Params($p->params);
+var_dump($r === $x->toArray());
+?>
+DONE
+--EXPECT--
+Test
+int(3)
+key exists
+bool(true)
+bool(true)
+bool(true)
+values
+bool(true)
+bool(true)
+string(1) "0"
+args
+int(0)
+int(2)
+int(1)
+arg values
+NULL
+bool(true)
+bool(true)
+equals
+bool(true)
+bool(true)
+bool(true)
+DONE
--TEST--
-header params rfc5987
+custom params
--SKIPIF--
<?php
include "skipif.inc";
--FILE--
<?php
echo "Test\n";
-$u = urlencode("ü");
-$s = urlencode("ß");
-$t = "p1*=utf-8''s$u$s,p2*=utf-8''hei$s;a1*=utf-8''a$s;a2*=utf-8''e$s;a3=no,p3=not";
-$p = new http\Params($t);
-var_dump($p->params);
-var_dump((string)$p === $t, (string)$p, $t);
+
+$s = "foo bar.arg:0.bla gotit:0.now";
+$p = new http\Params($s, " ", ".", ":");
+$c = $s;
+$k = array("foo", "bar", "gotit");
+$a = array("foo"=>"arg", "bar"=>"bla", "gotit"=>"now");
+$r = array (
+ 'foo' =>
+ array (
+ 'value' => true,
+ 'arguments' =>
+ array (
+ ),
+ ),
+ 'bar' =>
+ array (
+ 'value' => true,
+ 'arguments' =>
+ array (
+ 'arg' => '0',
+ 'bla' => true,
+ ),
+ ),
+ 'gotit' =>
+ array (
+ 'value' => '0',
+ 'arguments' =>
+ array (
+ 'now' => true,
+ ),
+ ),
+);
+
+# ---
+
+var_dump(count($p->params));
+
+echo "key exists\n";
+foreach ($k as $key) {
+ var_dump(array_key_exists($key, $p->params));
+}
+
+echo "values\n";
+foreach ($k as $key) {
+ var_dump($p[$key]["value"]);
+}
+
+echo "args\n";
+foreach ($k as $key) {
+ var_dump(count($p[$key]["arguments"]));
+}
+
+echo "arg values\n";
+foreach ($k as $key) {
+ var_dump(@$p[$key]["arguments"][$a[$key]]);
+}
+
+echo "equals\n";
+var_dump($c === (string) $p);
+var_dump($r === $p->params);
+$x = new http\Params($p->params);
+var_dump($r === $x->toArray());
?>
-===DONE===
+DONE
--EXPECT--
Test
-array(3) {
- ["p1"]=>
- array(2) {
- ["*rfc5987*"]=>
- array(1) {
- [""]=>
- string(5) "süß"
- }
- ["arguments"]=>
- array(0) {
- }
- }
- ["p2"]=>
- array(2) {
- ["*rfc5987*"]=>
- array(1) {
- [""]=>
- string(5) "heiß"
- }
- ["arguments"]=>
- array(2) {
- ["*rfc5987*"]=>
- array(2) {
- ["a1"]=>
- array(1) {
- [""]=>
- string(3) "aß"
- }
- ["a2"]=>
- array(1) {
- [""]=>
- string(3) "eß"
- }
- }
- ["a3"]=>
- string(2) "no"
- }
- }
- ["p3"]=>
- array(2) {
- ["value"]=>
- string(3) "not"
- ["arguments"]=>
- array(0) {
- }
- }
-}
+int(3)
+key exists
+bool(true)
+bool(true)
+bool(true)
+values
+bool(true)
+bool(true)
+string(1) "0"
+args
+int(0)
+int(2)
+int(1)
+arg values
+NULL
+bool(true)
+bool(true)
+equals
+bool(true)
+bool(true)
bool(true)
-string(96) "p1*=utf-8''s%C3%BC%C3%9F,p2*=utf-8''hei%C3%9F;a1*=utf-8''a%C3%9F;a2*=utf-8''e%C3%9F;a3=no,p3=not"
-string(96) "p1*=utf-8''s%C3%BC%C3%9F,p2*=utf-8''hei%C3%9F;a1*=utf-8''a%C3%9F;a2*=utf-8''e%C3%9F;a3=no,p3=not"
-===DONE===
+DONE
--TEST--
-header params rfc5987 regression
+quoted params
--SKIPIF--
<?php
include "skipif.inc";
--FILE--
<?php
echo "Test\n";
-$p = new http\Params(["attachment"=>["filename"=>"foo.bar"]]);
-var_dump($p->params);
-var_dump((string)$p);
+
+$p = new http\Params("multipart/form-data; boundary=\"--123\"");
+$c = array(
+ "multipart/form-data" => array(
+ "value" => true,
+ "arguments" => array(
+ "boundary" => "--123"
+ )
+ )
+);
+var_dump($c === $p->params);
+var_dump("multipart/form-data;boundary=--123" === (string) $p);
?>
-===DONE===
+DONE
--EXPECT--
Test
-array(1) {
- ["attachment"]=>
- array(1) {
- ["filename"]=>
- string(7) "foo.bar"
- }
-}
-string(27) "attachment;filename=foo.bar"
-===DONE===
+bool(true)
+bool(true)
+DONE
--- /dev/null
+--TEST--
+escaped params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$p = new http\Params("form-data; name=\"upload\"; filename=\"trick\\\"\0\\\"ed\"");
+$c = array(
+ "form-data" => array(
+ "value" => true,
+ "arguments" => array(
+ "name" => "upload",
+ "filename" => "trick\"\0\"ed"
+ )
+ )
+);
+var_dump($c === $p->params);
+var_dump("form-data;name=upload;filename=\"trick\\\"\\0\\\"ed\"" === (string) $p);
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+DONE
--- /dev/null
+--TEST--
+urlencoded params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$s = "foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1";
+$p = new http\Params($s, "&", "", "=", http\Params::PARSE_URLENCODED);
+$c = array(
+ "foo" => array(
+ "value" => "b\"r",
+ "arguments" => array(),
+ ),
+ "bar" => array(
+ "value" => "b\"z",
+ "arguments" => array(),
+ ),
+ "a[][]" => array(
+ "value" => "1",
+ "arguments" => array(),
+ ),
+);
+var_dump($c === $p->params);
+var_dump("foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1" === (string) $p);
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+DONE
--- /dev/null
+--TEST--
+querystring params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$s = "foo=b%22r&bar=b%22z&a%5B%5D%5B%5D=1";
+$p = new http\Params($s, "&", "", "=", http\Params::PARSE_QUERY);
+$c = array(
+ "foo" => array(
+ "value" => "b\"r",
+ "arguments" => array(),
+ ),
+ "bar" => array(
+ "value" => "b\"z",
+ "arguments" => array(),
+ ),
+ "a" => array(
+ "value" => array(
+ array("1")
+ ),
+ "arguments" => array(),
+ ),
+);
+var_dump($c === $p->params);
+var_dump("foo=b%22r&bar=b%22z&a%5B0%5D%5B0%5D=1" === (string) $p);
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+DONE
--- /dev/null
+--TEST--
+empty params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+$p = new http\Params(NULL);
+var_dump(array() === $p->params);
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+DONE
--- /dev/null
+--TEST--
+int key params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$p = new http\Params("0=nothing;1=yes");
+var_dump(array("0" => array("value" => "nothing", "arguments" => array(1=>"yes"))) === $p->params);
+var_dump("0=nothing;1=yes" === $p->toString());
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+DONE
--- /dev/null
+--TEST--
+bool args params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$p = new http\Params;
+$container = array("value" => false, "arguments" => array("wrong" => false, "correct" => true));
+$p["container"] = $container;
+var_dump("container=0;wrong=0;correct" === $p->toString());
+var_dump(array("container" => $container) === $p->toArray());
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+DONE
--- /dev/null
+--TEST--
+no args params
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$p = new http\Params;
+$p["param"] = true;
+var_dump("param" === $p->toString());
+$p["param"] = false;
+var_dump("param=0" === $p->toString());
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+DONE
--- /dev/null
+--TEST--
+header params rfc5987
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$p = new http\Params("attachment; filename*=IsO-8859-1''d%f6ner.pdf");
+var_dump($p->params, (string) $p);
+$p = new http\Params("bar; title*=iso-8859-1'en'%A3%20rates");
+var_dump($p->params, (string) $p);
+$p = new http\Params("bar; title*=UTF-8''%c2%a3%20and%20%e2%82%ac%20rates");
+var_dump($p->params, (string) $p);
+
+?>
+===DONE===
+--EXPECT--
+Test
+array(1) {
+ ["attachment"]=>
+ array(2) {
+ ["value"]=>
+ bool(true)
+ ["arguments"]=>
+ array(1) {
+ ["*rfc5987*"]=>
+ array(1) {
+ ["filename"]=>
+ array(1) {
+ [""]=>
+ string(10) "döner.pdf"
+ }
+ }
+ }
+ }
+}
+string(42) "attachment;filename*=utf-8''d%C3%B6ner.pdf"
+array(1) {
+ ["bar"]=>
+ array(2) {
+ ["value"]=>
+ bool(true)
+ ["arguments"]=>
+ array(1) {
+ ["*rfc5987*"]=>
+ array(1) {
+ ["title"]=>
+ array(1) {
+ ["en"]=>
+ string(8) "£ rates"
+ }
+ }
+ }
+ }
+}
+string(34) "bar;title*=utf-8'en'%C2%A3%20rates"
+array(1) {
+ ["bar"]=>
+ array(2) {
+ ["value"]=>
+ bool(true)
+ ["arguments"]=>
+ array(1) {
+ ["*rfc5987*"]=>
+ array(1) {
+ ["title"]=>
+ array(1) {
+ [""]=>
+ string(16) "£ and € rates"
+ }
+ }
+ }
+ }
+}
+string(50) "bar;title*=utf-8''%C2%A3%20and%20%E2%82%AC%20rates"
+===DONE===
--- /dev/null
+--TEST--
+header params rfc5987
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+$u = urlencode("ü");
+$s = urlencode("ß");
+$t = "p1*=utf-8''s$u$s,p2*=utf-8''hei$s;a1*=utf-8''a$s;a2*=utf-8''e$s;a3=no,p3=not";
+$p = new http\Params($t);
+var_dump($p->params);
+var_dump((string)$p === $t, (string)$p, $t);
+?>
+===DONE===
+--EXPECT--
+Test
+array(3) {
+ ["p1"]=>
+ array(2) {
+ ["*rfc5987*"]=>
+ array(1) {
+ [""]=>
+ string(5) "süß"
+ }
+ ["arguments"]=>
+ array(0) {
+ }
+ }
+ ["p2"]=>
+ array(2) {
+ ["*rfc5987*"]=>
+ array(1) {
+ [""]=>
+ string(5) "heiß"
+ }
+ ["arguments"]=>
+ array(2) {
+ ["*rfc5987*"]=>
+ array(2) {
+ ["a1"]=>
+ array(1) {
+ [""]=>
+ string(3) "aß"
+ }
+ ["a2"]=>
+ array(1) {
+ [""]=>
+ string(3) "eß"
+ }
+ }
+ ["a3"]=>
+ string(2) "no"
+ }
+ }
+ ["p3"]=>
+ array(2) {
+ ["value"]=>
+ string(3) "not"
+ ["arguments"]=>
+ array(0) {
+ }
+ }
+}
+bool(true)
+string(96) "p1*=utf-8''s%C3%BC%C3%9F,p2*=utf-8''hei%C3%9F;a1*=utf-8''a%C3%9F;a2*=utf-8''e%C3%9F;a3=no,p3=not"
+string(96) "p1*=utf-8''s%C3%BC%C3%9F,p2*=utf-8''hei%C3%9F;a1*=utf-8''a%C3%9F;a2*=utf-8''e%C3%9F;a3=no,p3=not"
+===DONE===
--- /dev/null
+--TEST--
+header params rfc5987 regression
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+$p = new http\Params(["attachment"=>["filename"=>"foo.bar"]]);
+var_dump($p->params);
+var_dump((string)$p);
+?>
+===DONE===
+--EXPECT--
+Test
+array(1) {
+ ["attachment"]=>
+ array(1) {
+ ["filename"]=>
+ string(7) "foo.bar"
+ }
+}
+string(27) "attachment;filename=foo.bar"
+===DONE===
--- /dev/null
+--TEST--
+query string
+--SKIPIF--
+<?php
+include("skipif.inc");
+?>
+--GET--
+str=abc&num=-123&dec=123.123&bool=1&arr[]=1&arr[]=2&ma[l1][l2]=2&ma[l2][l3][l4]=3
+--FILE--
+<?php
+echo "Test\n";
+
+printf("\nGlobal instance:\n");
+$q = http\QueryString::getGlobalInstance();
+printf("%s\n", $q);
+
+printf("\nStandard getters:\n");
+var_dump($q->getString("str"));
+var_dump($q->getInt("num"));
+var_dump($q->getFloat("dec"));
+var_dump($q->getInt("dec"));
+var_dump($q->getFloat("dec"));
+var_dump($q->getBool("bool"));
+var_dump($q->getInt("bool"));
+var_dump($q->getBool("num"));
+var_dump($q->getInt("num"));
+var_dump($q->getArray("arr"));
+var_dump($q->getArray("ma"));
+var_dump($q->getObject("arr"));
+var_dump($q->getObject("ma"));
+
+$s = $q->toString();
+
+printf("\nClone modifications do not alter global instance:\n");
+$q->mod(array("arr" => array(3 => 3)));
+printf("%s\n", $q);
+
+printf("\nClone modifications do not alter standard instance:\n");
+$q2 = new http\QueryString($s);
+$q3 = $q2->mod(array("arr" => array(3 => 3)));
+printf("%s\n%s\n", $q2, $q3);
+#var_dump($q2, $q3);
+
+printf("\nIterator:\n");
+$it = new RecursiveIteratorIterator($q2, RecursiveIteratorIterator::SELF_FIRST);
+foreach ($it as $k => $v) {
+ $i = $it->getDepth()*8;
+ @printf("%{$i}s: %s\n", $k, $v);
+}
+
+printf("\nReplace a multi dimensional key:\n");
+printf("%s\n", $q2->mod(array("ma" => null))->set(array("ma" => array("l1" => false))));
+
+printf("\nXlate:\n");
+$qu = new http\QueryString("ü=ö");
+printf("utf8: %s\n", $qu);
+printf("latin1: %s\n", method_exists($qu, "xlate") ? $qu->xlate("utf-8", "latin1") : "%FC=%F6");
+
+printf("\nOffsets:\n");
+var_dump($q2["ma"]);
+$q2["ma"] = array("bye");
+var_dump($q2["ma"]);
+var_dump(isset($q2["ma"]));
+unset($q2["ma"]);
+var_dump(isset($q2["ma"]));
+
+echo "Done\n";
+?>
+--EXPECTF--
+Test
+
+Global instance:
+str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
+
+Standard getters:
+string(3) "abc"
+int(-123)
+float(123.123)
+int(123)
+float(123.123)
+bool(true)
+int(1)
+bool(true)
+int(-123)
+array(2) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+}
+array(2) {
+ ["l1"]=>
+ array(1) {
+ ["l2"]=>
+ string(1) "2"
+ }
+ ["l2"]=>
+ array(1) {
+ ["l3"]=>
+ array(1) {
+ ["l4"]=>
+ string(1) "3"
+ }
+ }
+}
+object(stdClass)#%d (2) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(1) "2"
+}
+object(stdClass)#%d (2) {
+ ["l1"]=>
+ array(1) {
+ ["l2"]=>
+ string(1) "2"
+ }
+ ["l2"]=>
+ array(1) {
+ ["l3"]=>
+ array(1) {
+ ["l4"]=>
+ string(1) "3"
+ }
+ }
+}
+
+Clone modifications do not alter global instance:
+str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
+
+Clone modifications do not alter standard instance:
+str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
+str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&arr%5B3%5D=3&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
+
+Iterator:
+str: abc
+num: -123
+dec: 123.123
+bool: 1
+arr: Array
+ 0: 1
+ 1: 2
+ma: Array
+ l1: Array
+ l2: 2
+ l2: Array
+ l3: Array
+ l4: 3
+
+Replace a multi dimensional key:
+str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D=
+
+Xlate:
+utf8: %C3%BC=%C3%B6
+latin1: %FC=%F6
+
+Offsets:
+array(2) {
+ ["l1"]=>
+ array(1) {
+ ["l2"]=>
+ string(1) "2"
+ }
+ ["l2"]=>
+ array(1) {
+ ["l3"]=>
+ array(1) {
+ ["l4"]=>
+ string(1) "3"
+ }
+ }
+}
+array(1) {
+ [0]=>
+ string(3) "bye"
+}
+bool(true)
+bool(false)
+Done
--- /dev/null
+--TEST--
+query string
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$s = "a=b&r[]=0&r[]=1&r[]=2&rr[][]=00&rr[][]=01&1=2";
+$e = "a=b&r%5B0%5D=0&r%5B1%5D=1&r%5B2%5D=2&rr%5B0%5D%5B0%5D=00&rr%5B0%5D%5B1%5D=01&1=2";
+$q = new http\QueryString($s);
+
+var_dump($e === (string) $q);
+var_dump($e === $q->get());
+
+printf("Get defval\n");
+var_dump("nonexistant" === $q->get("unknown", "s", "nonexistant"));
+var_dump(null === $q->get("unknown"));
+
+printf("Get 'a'\n");
+var_dump("b" === $q->get("a"));
+var_dump(0 === $q->get("a", "i"));
+var_dump(array("b") === $q->get("a", "a"));
+var_dump((object)array("scalar" => "b") == $q->get("a", "o"));
+
+printf("Get 'r'\n");
+var_dump(array("0","1","2") === $q->get("r"));
+
+printf("Get 'rr'\n");
+var_dump(array(array("00","01")) === $q->get("rr"));
+
+printf("Get 1\n");
+var_dump(2 == $q->get(1));
+var_dump("2" === $q->get(1, "s"));
+var_dump(2.0 === $q->get(1, "f"));
+var_dump($q->get(1, "b"));
+
+printf("Del 'a'\n");
+var_dump("b" === $q->get("a", http\QueryString::TYPE_STRING, null, true));
+var_dump(null === $q->get("a"));
+
+printf("Del all\n");
+$q->set(array("a" => null, "r" => null, "rr" => null, 1 => null));
+var_dump("" === $q->toString());
+
+$q = new http\QueryString($s);
+
+printf("QSO\n");
+var_dump($e === (string) new http\QueryString($q));
+var_dump(http_build_query(array("e"=>$q->toArray())) === (string) new http\QueryString(array("e" => $q)));
+
+printf("Iterator\n");
+var_dump($q->toArray() === iterator_to_array($q));
+
+printf("Serialize\n");
+var_dump($e === (string) unserialize(serialize($q)));
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+Get defval
+bool(true)
+bool(true)
+Get 'a'
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Get 'r'
+bool(true)
+Get 'rr'
+bool(true)
+Get 1
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Del 'a'
+bool(true)
+bool(true)
+Del all
+bool(true)
+QSO
+bool(true)
+bool(true)
+Iterator
+bool(true)
+Serialize
+bool(true)
+DONE
+++ /dev/null
---TEST--
-query string
---SKIPIF--
-<?php
-include("skipif.inc");
-?>
---GET--
-str=abc&num=-123&dec=123.123&bool=1&arr[]=1&arr[]=2&ma[l1][l2]=2&ma[l2][l3][l4]=3
---FILE--
-<?php
-echo "Test\n";
-
-printf("\nGlobal instance:\n");
-$q = http\QueryString::getGlobalInstance();
-printf("%s\n", $q);
-
-printf("\nStandard getters:\n");
-var_dump($q->getString("str"));
-var_dump($q->getInt("num"));
-var_dump($q->getFloat("dec"));
-var_dump($q->getInt("dec"));
-var_dump($q->getFloat("dec"));
-var_dump($q->getBool("bool"));
-var_dump($q->getInt("bool"));
-var_dump($q->getBool("num"));
-var_dump($q->getInt("num"));
-var_dump($q->getArray("arr"));
-var_dump($q->getArray("ma"));
-var_dump($q->getObject("arr"));
-var_dump($q->getObject("ma"));
-
-$s = $q->toString();
-
-printf("\nClone modifications do not alter global instance:\n");
-$q->mod(array("arr" => array(3 => 3)));
-printf("%s\n", $q);
-
-printf("\nClone modifications do not alter standard instance:\n");
-$q2 = new http\QueryString($s);
-$q3 = $q2->mod(array("arr" => array(3 => 3)));
-printf("%s\n%s\n", $q2, $q3);
-#var_dump($q2, $q3);
-
-printf("\nIterator:\n");
-$it = new RecursiveIteratorIterator($q2, RecursiveIteratorIterator::SELF_FIRST);
-foreach ($it as $k => $v) {
- $i = $it->getDepth()*8;
- @printf("%{$i}s: %s\n", $k, $v);
-}
-
-printf("\nReplace a multi dimensional key:\n");
-printf("%s\n", $q2->mod(array("ma" => null))->set(array("ma" => array("l1" => false))));
-
-printf("\nXlate:\n");
-$qu = new http\QueryString("ü=ö");
-printf("utf8: %s\n", $qu);
-printf("latin1: %s\n", method_exists($qu, "xlate") ? $qu->xlate("utf-8", "latin1") : "%FC=%F6");
-
-printf("\nOffsets:\n");
-var_dump($q2["ma"]);
-$q2["ma"] = array("bye");
-var_dump($q2["ma"]);
-var_dump(isset($q2["ma"]));
-unset($q2["ma"]);
-var_dump(isset($q2["ma"]));
-
-echo "Done\n";
-?>
---EXPECTF--
-Test
-
-Global instance:
-str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
-
-Standard getters:
-string(3) "abc"
-int(-123)
-float(123.123)
-int(123)
-float(123.123)
-bool(true)
-int(1)
-bool(true)
-int(-123)
-array(2) {
- [0]=>
- string(1) "1"
- [1]=>
- string(1) "2"
-}
-array(2) {
- ["l1"]=>
- array(1) {
- ["l2"]=>
- string(1) "2"
- }
- ["l2"]=>
- array(1) {
- ["l3"]=>
- array(1) {
- ["l4"]=>
- string(1) "3"
- }
- }
-}
-object(stdClass)#%d (2) {
- [0]=>
- string(1) "1"
- [1]=>
- string(1) "2"
-}
-object(stdClass)#%d (2) {
- ["l1"]=>
- array(1) {
- ["l2"]=>
- string(1) "2"
- }
- ["l2"]=>
- array(1) {
- ["l3"]=>
- array(1) {
- ["l4"]=>
- string(1) "3"
- }
- }
-}
-
-Clone modifications do not alter global instance:
-str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
-
-Clone modifications do not alter standard instance:
-str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
-str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&arr%5B3%5D=3&ma%5Bl1%5D%5Bl2%5D=2&ma%5Bl2%5D%5Bl3%5D%5Bl4%5D=3
-
-Iterator:
-str: abc
-num: -123
-dec: 123.123
-bool: 1
-arr: Array
- 0: 1
- 1: 2
-ma: Array
- l1: Array
- l2: 2
- l2: Array
- l3: Array
- l4: 3
-
-Replace a multi dimensional key:
-str=abc&num=-123&dec=123.123&bool=1&arr%5B0%5D=1&arr%5B1%5D=2&ma%5Bl1%5D=
-
-Xlate:
-utf8: %C3%BC=%C3%B6
-latin1: %FC=%F6
-
-Offsets:
-array(2) {
- ["l1"]=>
- array(1) {
- ["l2"]=>
- string(1) "2"
- }
- ["l2"]=>
- array(1) {
- ["l3"]=>
- array(1) {
- ["l4"]=>
- string(1) "3"
- }
- }
-}
-array(1) {
- [0]=>
- string(3) "bye"
-}
-bool(true)
-bool(false)
-Done
--- /dev/null
+--TEST--
+url properties
+--SKIPIF--
+<?php
+include "skipif";
+?>
+--FILE--
+<?php
+echo "Test\n";
+$u = "http://user:pass@www.example.com:8080/path/file.ext".
+ "?foo=bar&more[]=1&more[]=2#hash";
+
+var_dump($u === (string) new http\Url($u));
+
+$url = new http\Url($u,
+ array("path" => "changed", "query" => "foo=&added=this"),
+ http\Url::JOIN_PATH |
+ http\Url::JOIN_QUERY |
+ http\Url::STRIP_AUTH |
+ http\Url::STRIP_FRAGMENT
+);
+
+var_dump($url->scheme);
+var_dump($url->user);
+var_dump($url->pass);
+var_dump($url->host);
+var_dump($url->port);
+var_dump($url->path);
+var_dump($url->query);
+var_dump($url->fragment);
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+string(4) "http"
+NULL
+NULL
+string(15) "www.example.com"
+int(8080)
+string(13) "/path/changed"
+string(38) "more%5B0%5D=1&more%5B1%5D=2&added=this"
+NULL
+DONE
--- /dev/null
+--TEST--
+url modification
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$u = "http://user:pass@www.example.com:8080/path/file.ext".
+ "?foo=bar&more[]=1&more[]=2#hash";
+
+$tmp = new http\Url($u);
+$mod = $tmp->mod(array("query" => "set=1"), http\Url::REPLACE);
+var_dump($tmp->toArray() != $mod->toArray());
+var_dump("set=1" === $mod->query);
+var_dump("new_fragment" === $tmp->mod("#new_fragment")->fragment);
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+bool(true)
+bool(true)
+DONE
--- /dev/null
+--TEST--
+url as string
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$u = "http://user:pass@www.example.com:8080/path/file.ext".
+ "?foo=bar&more[]=1&more[]=2#hash";
+
+$url = new http\Url($u);
+var_dump((string) $url == (string) new http\Url((string) $url));
+
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+DONE
--- /dev/null
+--TEST--
+url as array
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$u = "http://user:pass@www.example.com:8080/path/file.ext".
+ "?foo=bar&more[]=1&more[]=2#hash";
+
+$url = new http\Url($u);
+$url2 = new http\Url($url->toArray());
+var_dump($url->toArray() === $url2->toArray());
+?>
+DONE
+--EXPECT--
+Test
+bool(true)
+DONE