root / drupal7 / sites / all / libraries / simplepie-1.3.1 / tests / HTTPParserTest.php @ edccd837
1 |
<?php
|
---|---|
2 |
/**
|
3 |
* HTTP parsing tests
|
4 |
*
|
5 |
* SimplePie
|
6 |
*
|
7 |
* A PHP-Based RSS and Atom Feed Framework.
|
8 |
* Takes the hard work out of managing a complete RSS/Atom solution.
|
9 |
*
|
10 |
* Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
11 |
* All rights reserved.
|
12 |
*
|
13 |
* Redistribution and use in source and binary forms, with or without modification, are
|
14 |
* permitted provided that the following conditions are met:
|
15 |
*
|
16 |
* * Redistributions of source code must retain the above copyright notice, this list of
|
17 |
* conditions and the following disclaimer.
|
18 |
*
|
19 |
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
20 |
* of conditions and the following disclaimer in the documentation and/or other materials
|
21 |
* provided with the distribution.
|
22 |
*
|
23 |
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
24 |
* to endorse or promote products derived from this software without specific prior
|
25 |
* written permission.
|
26 |
*
|
27 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
28 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
29 |
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
30 |
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
31 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
32 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
33 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
34 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
35 |
* POSSIBILITY OF SUCH DAMAGE.
|
36 |
*
|
37 |
* @package SimplePie
|
38 |
* @version 1.3.1
|
39 |
* @copyright 2004-2011 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
40 |
* @author Ryan Parman
|
41 |
* @author Geoffrey Sneddon
|
42 |
* @author Ryan McCue
|
43 |
* @link http://simplepie.org/ SimplePie
|
44 |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
45 |
*/
|
46 |
|
47 |
require_once dirname(__FILE__) . '/bootstrap.php'; |
48 |
|
49 |
class HTTPParserTest extends PHPUnit_Framework_TestCase |
50 |
{ |
51 |
public static function chunkedProvider() |
52 |
{ |
53 |
return array( |
54 |
array(
|
55 |
"25\r\nThis is the data in the first chunk\r\n\r\n1A\r\nand this is the second one\r\n0\r\n",
|
56 |
"This is the data in the first chunk\r\nand this is the second one"
|
57 |
), |
58 |
array(
|
59 |
"02\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0\r\nnothing\n",
|
60 |
"abra\ncadabra"
|
61 |
), |
62 |
array(
|
63 |
"02\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n",
|
64 |
"abra\ncadabra\nall we got\n"
|
65 |
), |
66 |
); |
67 |
} |
68 |
|
69 |
/**
|
70 |
* @dataProvider chunkedProvider
|
71 |
*/
|
72 |
public function testChunkedNormal($data, $expected) |
73 |
{ |
74 |
$data = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n" . $data; |
75 |
$parser = new SimplePie_HTTP_Parser($data); |
76 |
$this->assertTrue($parser->parse()); |
77 |
$this->assertEquals(1.1, $parser->http_version); |
78 |
$this->assertEquals(200, $parser->status_code); |
79 |
$this->assertEquals('OK', $parser->reason); |
80 |
$this->assertEquals(array('content-type' => 'text/plain'), $parser->headers); |
81 |
$this->assertEquals($expected, $parser->body); |
82 |
|
83 |
} |
84 |
} |