Merge branch 'R_2_0'
authorMichael Wallner <mike@php.net>
Wed, 9 Jul 2014 15:52:13 +0000 (17:52 +0200)
committerMichael Wallner <mike@php.net>
Wed, 9 Jul 2014 15:52:13 +0000 (17:52 +0200)
Conflicts:
tests/params001.phpt
tests/params003.phpt
tests/params004.phpt
tests/params005.phpt

34 files changed:
phpunit/EncodingTest.php [deleted file]
phpunit/ParamsTest.php [deleted file]
phpunit/QueryStringTest.php [deleted file]
phpunit/UrlTest.php [deleted file]
tests/encstream001.phpt [new file with mode: 0644]
tests/encstream002.phpt [new file with mode: 0644]
tests/encstream003.phpt [new file with mode: 0644]
tests/encstream004.phpt [new file with mode: 0644]
tests/encstream005.phpt [new file with mode: 0644]
tests/encstream006.phpt [new file with mode: 0644]
tests/encstream007.phpt [new file with mode: 0644]
tests/encstream008.phpt [new file with mode: 0644]
tests/encstream009.phpt [new file with mode: 0644]
tests/params001.phpt
tests/params003.phpt
tests/params004.phpt
tests/params005.phpt
tests/params006.phpt [new file with mode: 0644]
tests/params007.phpt [new file with mode: 0644]
tests/params008.phpt [new file with mode: 0644]
tests/params009.phpt [new file with mode: 0644]
tests/params010.phpt [new file with mode: 0644]
tests/params011.phpt [new file with mode: 0644]
tests/params012.phpt [new file with mode: 0644]
tests/params013.phpt [new file with mode: 0644]
tests/params014.phpt [new file with mode: 0644]
tests/params015.phpt [new file with mode: 0644]
tests/querystring001.phpt [new file with mode: 0644]
tests/querystring002.phpt [new file with mode: 0644]
tests/querystring_001.phpt [deleted file]
tests/url002.phpt [new file with mode: 0644]
tests/url003.phpt [new file with mode: 0644]
tests/url004.phpt [new file with mode: 0644]
tests/url005.phpt [new file with mode: 0644]

diff --git a/phpunit/EncodingTest.php b/phpunit/EncodingTest.php
deleted file mode 100644 (file)
index 4642613..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-<?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");
-    }
-}
diff --git a/phpunit/ParamsTest.php b/phpunit/ParamsTest.php
deleted file mode 100644 (file)
index 71bfcf4..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-<?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());
-       }
-}
diff --git a/phpunit/QueryStringTest.php b/phpunit/QueryStringTest.php
deleted file mode 100644 (file)
index fb2eb47..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-<?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)));
-    }
-}
diff --git a/phpunit/UrlTest.php b/phpunit/UrlTest.php
deleted file mode 100644 (file)
index dcf3b4f..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?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());
-    }
-}
diff --git a/tests/encstream001.phpt b/tests/encstream001.phpt
new file mode 100644 (file)
index 0000000..5dc13d3
--- /dev/null
@@ -0,0 +1,27 @@
+--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
+
diff --git a/tests/encstream002.phpt b/tests/encstream002.phpt
new file mode 100644 (file)
index 0000000..3be0aca
--- /dev/null
@@ -0,0 +1,21 @@
+--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
diff --git a/tests/encstream003.phpt b/tests/encstream003.phpt
new file mode 100644 (file)
index 0000000..ad8c737
--- /dev/null
@@ -0,0 +1,38 @@
+--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
diff --git a/tests/encstream004.phpt b/tests/encstream004.phpt
new file mode 100644 (file)
index 0000000..eb9da0f
--- /dev/null
@@ -0,0 +1,38 @@
+--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
diff --git a/tests/encstream005.phpt b/tests/encstream005.phpt
new file mode 100644 (file)
index 0000000..6455ed4
--- /dev/null
@@ -0,0 +1,41 @@
+--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
diff --git a/tests/encstream006.phpt b/tests/encstream006.phpt
new file mode 100644 (file)
index 0000000..5430bfa
--- /dev/null
@@ -0,0 +1,30 @@
+--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
diff --git a/tests/encstream007.phpt b/tests/encstream007.phpt
new file mode 100644 (file)
index 0000000..5fdeffe
--- /dev/null
@@ -0,0 +1,34 @@
+--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
diff --git a/tests/encstream008.phpt b/tests/encstream008.phpt
new file mode 100644 (file)
index 0000000..a46f9f0
--- /dev/null
@@ -0,0 +1,42 @@
+--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
diff --git a/tests/encstream009.phpt b/tests/encstream009.phpt
new file mode 100644 (file)
index 0000000..fa51a8a
--- /dev/null
@@ -0,0 +1,20 @@
+--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
index f69624918ab561122395887d70f31f7659f3771f..5b28deed83a041d1c355fd3e5bc658bceb72f643 100644 (file)
@@ -28,7 +28,8 @@ var_dump(
 
 var_dump((string) $ct,$ct);
 
-echo "Done\n";
+?>
+DONE
 --EXPECTF--
 Test
 bool(true)
@@ -61,4 +62,4 @@ object(http\Params)#%d (5) {
   ["flags"]=>
   int(0)
 }
-Done
+DONE
index c9cec725264677599826913cf9f1dbfd18889146..11e27595adddca8371482d8d74734f7061b48f74 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-header params rfc5987
+default params
 --SKIPIF--
 <?php
 include "skipif.inc";
@@ -8,72 +8,90 @@ 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
index b61953ddd93acb86d3c2e1d3e733f1bbc1aaa6ec..69075ea2d49a2f3603aa70408ac88063f9add1d3 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-header params rfc5987
+custom params
 --SKIPIF--
 <?php
 include "skipif.inc";
@@ -7,64 +7,91 @@ 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
index ad3948cb0581cda7dd60ec86a4c4a36768f30eb0..7c64a31b4d472cc0f211ad8376d5253c3db7908a 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-header params rfc5987 regression
+quoted params
 --SKIPIF--
 <?php
 include "skipif.inc";
@@ -7,19 +7,22 @@ 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
diff --git a/tests/params006.phpt b/tests/params006.phpt
new file mode 100644 (file)
index 0000000..5c6455c
--- /dev/null
@@ -0,0 +1,29 @@
+--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
diff --git a/tests/params007.phpt b/tests/params007.phpt
new file mode 100644 (file)
index 0000000..c56e2fa
--- /dev/null
@@ -0,0 +1,35 @@
+--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
diff --git a/tests/params008.phpt b/tests/params008.phpt
new file mode 100644 (file)
index 0000000..463a96c
--- /dev/null
@@ -0,0 +1,37 @@
+--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
diff --git a/tests/params009.phpt b/tests/params009.phpt
new file mode 100644 (file)
index 0000000..07c58c7
--- /dev/null
@@ -0,0 +1,17 @@
+--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
diff --git a/tests/params010.phpt b/tests/params010.phpt
new file mode 100644 (file)
index 0000000..ced5e92
--- /dev/null
@@ -0,0 +1,21 @@
+--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
diff --git a/tests/params011.phpt b/tests/params011.phpt
new file mode 100644 (file)
index 0000000..1f9ecf7
--- /dev/null
@@ -0,0 +1,23 @@
+--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
diff --git a/tests/params012.phpt b/tests/params012.phpt
new file mode 100644 (file)
index 0000000..f5a33ca
--- /dev/null
@@ -0,0 +1,22 @@
+--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
diff --git a/tests/params013.phpt b/tests/params013.phpt
new file mode 100644 (file)
index 0000000..d69782a
--- /dev/null
@@ -0,0 +1,79 @@
+--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===
diff --git a/tests/params014.phpt b/tests/params014.phpt
new file mode 100644 (file)
index 0000000..b61953d
--- /dev/null
@@ -0,0 +1,70 @@
+--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===
diff --git a/tests/params015.phpt b/tests/params015.phpt
new file mode 100644 (file)
index 0000000..ad3948c
--- /dev/null
@@ -0,0 +1,25 @@
+--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===
diff --git a/tests/querystring001.phpt b/tests/querystring001.phpt
new file mode 100644 (file)
index 0000000..203be33
--- /dev/null
@@ -0,0 +1,179 @@
+--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
diff --git a/tests/querystring002.phpt b/tests/querystring002.phpt
new file mode 100644 (file)
index 0000000..ab82672
--- /dev/null
@@ -0,0 +1,95 @@
+--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
diff --git a/tests/querystring_001.phpt b/tests/querystring_001.phpt
deleted file mode 100644 (file)
index 203be33..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
---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
diff --git a/tests/url002.phpt b/tests/url002.phpt
new file mode 100644 (file)
index 0000000..2b31ee9
--- /dev/null
@@ -0,0 +1,45 @@
+--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
diff --git a/tests/url003.phpt b/tests/url003.phpt
new file mode 100644 (file)
index 0000000..b2def7f
--- /dev/null
@@ -0,0 +1,27 @@
+--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
diff --git a/tests/url004.phpt b/tests/url004.phpt
new file mode 100644 (file)
index 0000000..c3055da
--- /dev/null
@@ -0,0 +1,22 @@
+--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
diff --git a/tests/url005.phpt b/tests/url005.phpt
new file mode 100644 (file)
index 0000000..f9b6965
--- /dev/null
@@ -0,0 +1,22 @@
+--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