X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=phpunit%2FParamsTest.php;h=a06d72e3a71c7917af9fff93c7ea9ccedebcf684;hb=40b8f999b7705c5474030aa67530a8b293f9ea8c;hp=0e139b8c581bcae29180d7d37dc9b100a11b9a22;hpb=2e9ac0202f2c5f1cb94e0afd4b66c1c35c316284;p=m6w6%2Fext-http diff --git a/phpunit/ParamsTest.php b/phpunit/ParamsTest.php index 0e139b8..a06d72e 100644 --- a/phpunit/ParamsTest.php +++ b/phpunit/ParamsTest.php @@ -17,6 +17,72 @@ class ParamsTest extends PHPUnit_Framework_TestCase { ); } + 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 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); @@ -37,34 +103,35 @@ class ParamsTest extends PHPUnit_Framework_TestCase { $this->assertEquals($s, (string) $p); - $this->assertEquals( + $comp = array ( + 'foo' => array ( - 'foo' => + 'value' => true, + 'arguments' => array ( - 'value' => true, - 'arguments' => - array ( - ), ), - 'bar' => + ), + 'bar' => + array ( + 'value' => true, + 'arguments' => array ( - 'value' => true, - 'arguments' => - array ( - 'arg' => '0', - 'bla' => true, - ), + 'arg' => '0', + 'bla' => true, ), - 'gotit' => + ), + 'gotit' => + array ( + 'value' => '0', + 'arguments' => array ( - 'value' => '0', - 'arguments' => - array ( - 'now' => true, - ), + 'now' => true, ), ), - $p->params ); + + $this->assertEquals($comp, $p->params); + $a = new http\Params($p->params); + $this->assertEquals($comp, $a->toArray()); } }