| Name | Size | Mode | Actions |
|---|---|---|---|
| BasicAuthenticationTest.php | 2514 | 0644 | editdlrm |
| DigestAuthenticationTest.php | 6999 | 0644 | editdlrm |
| HttpResponseTest.php | 18411 | 0644 | editdlrm |
| HttpSocketTest.php | 60878 | 0644 | editdlrm |
/home/desid573/public_html/family/pdd/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php (18411B)
It's good to be html
" ), 'expectations' => array( 'httpVersion' => 'HTTP/1.x', 'code' => 200, 'reasonPhrase' => 'OK', 'headers' => array('Date' => 'Mon, 16 Apr 2007 04:14:16 GMT', 'Server' => 'CakeHttp Server'), 'body' => "It's good to be html
" ) ), 'no-header' => array( 'response' => array( 'status-line' => "HTTP/1.x 404 OK\r\n", 'header' => null ), 'expectations' => array( 'code' => 404, 'headers' => array() ) ) ); $testResponse = array(); $expectations = array(); foreach ($tests as $name => $test) { $testResponse = array_merge($testResponse, $test['response']); $testResponse['response'] = $testResponse['status-line'] . $testResponse['header'] . "\r\n" . $testResponse['body']; $this->HttpResponse->parseResponse($testResponse['response']); $expectations = array_merge($expectations, $test['expectations']); foreach ($expectations as $property => $expectedVal) { $this->assertEquals($expectedVal, $this->HttpResponse->{$property}, 'Test "' . $name . '": response.' . $property . ' - %s'); } foreach (array('status-line', 'header', 'body', 'response') as $field) { $this->assertEquals($this->HttpResponse['raw'][$field], $testResponse[$field], 'Test response.raw.' . $field . ': %s'); } } } /** * data provider function for testInvalidParseResponseData * * @return array */ public static function invalidParseResponseDataProvider() { return array( array(array('foo' => 'bar')), array(true), array("HTTP Foo\r\nBar: La"), array('HTTP/1.1 TEST ERROR') ); } /** * testInvalidParseResponseData * * @dataProvider invalidParseResponseDataProvider * @expectedException SocketException * @return void */ public function testInvalidParseResponseData($value) { $this->HttpResponse->parseResponse($value); } /** * testDecodeBody method * * @return void */ public function testDecodeBody() { $r = $this->HttpResponse->decodeBody(true); $this->assertEquals(false, $r); $r = $this->HttpResponse->decodeBody('Foobar', false); $this->assertEquals(array('body' => 'Foobar', 'header' => false), $r); $encoding = 'chunked'; $sample = array( 'encoded' => "19\r\nThis is a chunked message\r\n0\r\n", 'decoded' => array('body' => "This is a chunked message", 'header' => false) ); $r = $this->HttpResponse->decodeBody($sample['encoded'], $encoding); $this->assertEquals($r, $sample['decoded']); $encoding = 'chunked'; $sample = array( 'encoded' => "19\nThis is a chunked message\r\n0\n", 'decoded' => array('body' => "This is a chunked message", 'header' => false) ); $r = $this->HttpResponse->decodeBody($sample['encoded'], $encoding); $this->assertEquals($r, $sample['decoded'], 'Inconsistent line terminators should be tolerated.'); } /** * testDecodeFooCoded * * @return void */ public function testDecodeFooCoded() { $r = $this->HttpResponse->decodeBody(true); $this->assertEquals(false, $r); $r = $this->HttpResponse->decodeBody('Foobar', false); $this->assertEquals(array('body' => 'Foobar', 'header' => false), $r); $encoding = 'foo-bar'; $sample = array( 'encoded' => '!Foobar!', 'decoded' => array('body' => '!Foobar!', 'header' => false), ); $r = $this->HttpResponse->decodeBody($sample['encoded'], $encoding); $this->assertEquals($r, $sample['decoded']); } /** * testDecodeChunkedBody method * * @return void */ public function testDecodeChunkedBody() { $r = $this->HttpResponse->decodeChunkedBody(true); $this->assertEquals(false, $r); $encoded = "19\r\nThis is a chunked message\r\n0\r\n"; $decoded = "This is a chunked message"; $r = $this->HttpResponse->decodeChunkedBody($encoded); $this->assertEquals($r['body'], $decoded); $this->assertEquals(false, $r['header']); $encoded = "19 \r\nThis is a chunked message\r\n0\r\n"; $r = $this->HttpResponse->decodeChunkedBody($encoded); $this->assertEquals($r['body'], $decoded); $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n0\r\n"; $decoded = "This is a chunked message\nThat is cool\n"; $r = $this->HttpResponse->decodeChunkedBody($encoded); $this->assertEquals($r['body'], $decoded); $this->assertEquals(false, $r['header']); $encoded = "19\r\nThis is a chunked message\r\nE;foo-chunk=5\r\n\nThat is cool\n\r\n0\r\n"; $r = $this->HttpResponse->decodeChunkedBody($encoded); $this->assertEquals($r['body'], $decoded); $this->assertEquals(false, $r['header']); $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n0\r\nfoo-header: bar\r\ncake: PHP\r\n\r\n"; $r = $this->HttpResponse->decodeChunkedBody($encoded); $this->assertEquals($r['body'], $decoded); $this->assertEquals(array('foo-header' => 'bar', 'cake' => 'PHP'), $r['header']); } /** * testDecodeChunkedBodyError method * * @return void */ public function testDecodeChunkedBodyError() { $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n"; $result = $this->HttpResponse->decodeChunkedBody($encoded); $expected = "This is a chunked message\nThat is cool\n"; $this->assertEquals($expected, $result['body']); } /** * testParseCookies method * * @return void */ public function testParseCookies() { $header = array( 'Set-Cookie' => array( 'foo=bar', 'people=jim,jack,johnny";";Path=/accounts', 'google=not=nice' ), 'Transfer-Encoding' => 'chunked', 'Date' => 'Sun, 18 Nov 2007 18:57:42 GMT', ); $cookies = $this->HttpResponse->parseCookies($header); $expected = array( 'foo' => array( 'value' => 'bar' ), 'people' => array( 'value' => 'jim,jack,johnny";"', 'path' => '/accounts', ), 'google' => array( 'value' => 'not=nice', ) ); $this->assertEquals($expected, $cookies); $header['Set-Cookie'][] = 'cakephp=great; Secure'; $expected['cakephp'] = array('value' => 'great', 'secure' => true); $cookies = $this->HttpResponse->parseCookies($header); $this->assertEquals($expected, $cookies); $header['Set-Cookie'] = 'foo=bar'; unset($expected['people'], $expected['cakephp'], $expected['google']); $cookies = $this->HttpResponse->parseCookies($header); $this->assertEquals($expected, $cookies); } /** * Test that escaped token strings are properly unescaped by HttpSocket::unescapeToken * * @return void */ public function testUnescapeToken() { $this->assertEquals('Foo', $this->HttpResponse->unescapeToken('Foo')); $escape = $this->HttpResponse->tokenEscapeChars(false); foreach ($escape as $char) { $token = 'My-special-"' . $char . '"-Token'; $unescapedToken = $this->HttpResponse->unescapeToken($token); $expectedToken = 'My-special-' . $char . '-Token'; $this->assertEquals($expectedToken, $unescapedToken, 'Test token unescaping for ASCII ' . ord($char)); } $token = 'Extreme-":"Token-" "-""""@"-test'; $escapedToken = $this->HttpResponse->unescapeToken($token); $expectedToken = 'Extreme-:Token- -"@-test'; $this->assertEquals($expectedToken, $escapedToken); } /** * testArrayAccess * * @return void */ public function testArrayAccess() { $this->HttpResponse->httpVersion = 'HTTP/1.1'; $this->HttpResponse->code = 200; $this->HttpResponse->reasonPhrase = 'OK'; $this->HttpResponse->headers = array( 'Server' => 'CakePHP', 'ContEnt-Type' => 'text/plain' ); $this->HttpResponse->cookies = array( 'foo' => array('value' => 'bar'), 'bar' => array('value' => 'foo') ); $this->HttpResponse->body = 'This is a test!'; $this->HttpResponse->raw = "HTTP/1.1 200 OK\r\nServer: CakePHP\r\nContEnt-Type: text/plain\r\n\r\nThis is a test!"; $expectedOne = "HTTP/1.1 200 OK\r\n"; $this->assertEquals($expectedOne, $this->HttpResponse['raw']['status-line']); $expectedTwo = "Server: CakePHP\r\nContEnt-Type: text/plain\r\n"; $this->assertEquals($expectedTwo, $this->HttpResponse['raw']['header']); $expectedThree = 'This is a test!'; $this->assertEquals($expectedThree, $this->HttpResponse['raw']['body']); $expected = $expectedOne . $expectedTwo . "\r\n" . $expectedThree; $this->assertEquals($expected, $this->HttpResponse['raw']['response']); $expected = 'HTTP/1.1'; $this->assertEquals($expected, $this->HttpResponse['status']['http-version']); $expected = 200; $this->assertEquals($expected, $this->HttpResponse['status']['code']); $expected = 'OK'; $this->assertEquals($expected, $this->HttpResponse['status']['reason-phrase']); $expected = array( 'Server' => 'CakePHP', 'ContEnt-Type' => 'text/plain' ); $this->assertEquals($expected, $this->HttpResponse['header']); $expected = 'This is a test!'; $this->assertEquals($expected, $this->HttpResponse['body']); $expected = array( 'foo' => array('value' => 'bar'), 'bar' => array('value' => 'foo') ); $this->assertEquals($expected, $this->HttpResponse['cookies']); $this->HttpResponse->raw = "HTTP/1.1 200 OK\r\n\r\nThis is a test!"; $this->assertNull($this->HttpResponse['raw']['header']); } }