| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Unit tests for HTTP_Request2 package
|
|
|
4 |
*
|
|
|
5 |
* PHP version 5
|
|
|
6 |
*
|
|
|
7 |
* LICENSE:
|
|
|
8 |
*
|
|
|
9 |
* Copyright (c) 2008-2011, Alexey Borzov <avb@php.net>
|
|
|
10 |
* All rights reserved.
|
|
|
11 |
*
|
|
|
12 |
* Redistribution and use in source and binary forms, with or without
|
|
|
13 |
* modification, are permitted provided that the following conditions
|
|
|
14 |
* are met:
|
|
|
15 |
*
|
|
|
16 |
* * Redistributions of source code must retain the above copyright
|
|
|
17 |
* notice, this list of conditions and the following disclaimer.
|
|
|
18 |
* * Redistributions in binary form must reproduce the above copyright
|
|
|
19 |
* notice, this list of conditions and the following disclaimer in the
|
|
|
20 |
* documentation and/or other materials provided with the distribution.
|
|
|
21 |
* * The names of the authors may not be used to endorse or promote products
|
|
|
22 |
* derived from this software without specific prior written permission.
|
|
|
23 |
*
|
|
|
24 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
|
25 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
26 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
27 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
28 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
29 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
30 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
31 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
|
32 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
33 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
34 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
35 |
*
|
|
|
36 |
* @category HTTP
|
|
|
37 |
* @package HTTP_Request2
|
|
|
38 |
* @author Alexey Borzov <avb@php.net>
|
|
|
39 |
* @license http://opensource.org/licenses/bsd-license.php New BSD License
|
|
|
40 |
* @version SVN: $Id: CurlTest.php 308629 2011-02-24 17:34:24Z avb $
|
|
|
41 |
* @link http://pear.php.net/package/HTTP_Request2
|
|
|
42 |
*/
|
|
|
43 |
|
|
|
44 |
/** Tests for HTTP_Request2 package that require a working webserver */
|
|
|
45 |
require_once dirname(__FILE__) . '/CommonNetworkTest.php';
|
|
|
46 |
|
|
|
47 |
/** Adapter for HTTP_Request2 wrapping around cURL extension */
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Unit test for Curl Adapter of HTTP_Request2
|
|
|
51 |
*/
|
|
|
52 |
class HTTP_Request2_Adapter_CurlTest extends HTTP_Request2_Adapter_CommonNetworkTest
|
|
|
53 |
{
|
|
|
54 |
/**
|
|
|
55 |
* Configuration for HTTP Request object
|
|
|
56 |
* @var array
|
|
|
57 |
*/
|
|
|
58 |
protected $config = array(
|
|
|
59 |
'adapter' => 'HTTP_Request2_Adapter_Curl'
|
|
|
60 |
);
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Checks whether redirect support in cURL is disabled by safe_mode or open_basedir
|
|
|
64 |
* @return bool
|
|
|
65 |
*/
|
|
|
66 |
protected function isRedirectSupportDisabled()
|
|
|
67 |
{
|
|
|
68 |
return ini_get('safe_mode') || ini_get('open_basedir');
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public function testRedirectsDefault()
|
|
|
72 |
{
|
|
|
73 |
if ($this->isRedirectSupportDisabled()) {
|
|
|
74 |
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
|
|
75 |
} else {
|
|
|
76 |
parent::testRedirectsDefault();
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
public function testRedirectsStrict()
|
|
|
81 |
{
|
|
|
82 |
if ($this->isRedirectSupportDisabled()) {
|
|
|
83 |
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
|
|
84 |
} else {
|
|
|
85 |
parent::testRedirectsStrict();
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
public function testRedirectsLimit()
|
|
|
90 |
{
|
|
|
91 |
if ($this->isRedirectSupportDisabled()) {
|
|
|
92 |
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
|
|
93 |
} else {
|
|
|
94 |
parent::testRedirectsLimit();
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
public function testRedirectsRelative()
|
|
|
99 |
{
|
|
|
100 |
if ($this->isRedirectSupportDisabled()) {
|
|
|
101 |
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
|
|
102 |
} else {
|
|
|
103 |
parent::testRedirectsRelative();
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
public function testRedirectsNonHTTP()
|
|
|
108 |
{
|
|
|
109 |
if ($this->isRedirectSupportDisabled()) {
|
|
|
110 |
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
|
|
111 |
} else {
|
|
|
112 |
parent::testRedirectsNonHTTP();
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
public function testCookieJarAndRedirect()
|
|
|
117 |
{
|
|
|
118 |
if ($this->isRedirectSupportDisabled()) {
|
|
|
119 |
$this->markTestSkipped('Redirect support in cURL is disabled by safe_mode or open_basedir setting');
|
|
|
120 |
} else {
|
|
|
121 |
parent::testCookieJarAndRedirect();
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
public function testBug17450()
|
|
|
126 |
{
|
|
|
127 |
if (!$this->isRedirectSupportDisabled()) {
|
|
|
128 |
$this->markTestSkipped('Neither safe_mode nor open_basedir is enabled');
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
$this->request->setUrl($this->baseUrl . 'redirects.php')
|
|
|
132 |
->setConfig(array('follow_redirects' => true));
|
|
|
133 |
|
|
|
134 |
try {
|
|
|
135 |
$this->request->send();
|
|
|
136 |
$this->fail('Expected HTTP_Request2_Exception was not thrown');
|
|
|
137 |
|
|
|
138 |
} catch (HTTP_Request2_LogicException $e) {
|
|
|
139 |
$this->assertEquals(HTTP_Request2_Exception::MISCONFIGURATION, $e->getCode());
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
?>
|