PluginProbe
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 1.0.0
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v1.0.0
4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 All 189 releases
embedpress / library / ostraining / embera / Tests / TestHttpRequest.php
TestHttpRequest.php
170 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * TestHttpRequest.php
4 *
5 * @package Tests
6 * @author Michael Pratt <pratt@hablarmierda.net>
7 * @link http://www.michael-pratt.com/
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12
13 class TestHttpRequest extends PHPUnit_Framework_TestCase
14 {
15 /**
16 * This needs more execution time ..
17 * @large
18 */
19 public function testInvalidUrl()
20 {
21 $this->setExpectedException('Exception');
22
23 $http = new \Embera\HttpRequest();
24 $http->fetch('this is an invalid url');
25 }
26
27 /**
28 * This needs more execution time ..
29 * @large
30 */
31 public function testInvalidUrl2()
32 {
33 $this->setExpectedException('Exception');
34
35 if (!ini_get('allow_url_fopen'))
36 {
37 $this->markTestIncomplete('Could not test file_get_contents wrapper, allow_url_fopen is closed');
38 return ;
39 }
40
41 $http = new \Embera\HttpRequest(array('prefer_curl' => false));
42 $http->fetch('this is an invalid url');
43 }
44
45 /**
46 * This needs more execution time ..
47 * @large
48 */
49 public function testFetchCurl()
50 {
51 $http = new \Embera\HttpRequest();
52 $response = $http->fetch('http://httpbin.org/user-agent');
53 $response = json_decode($response, true);
54
55 $this->assertEquals('Mozilla/5.0 PHP/Embera', $response['user-agent']);
56
57 $config = array(
58 'curl' => array(
59 CURLOPT_USERAGENT => 'PHP/Morcilla',
60 )
61 );
62
63 $http = new \Embera\HttpRequest($config);
64 $response = $http->fetch('http://httpbin.org/user-agent');
65 $response = json_decode($response, true);
66
67 $this->assertEquals('PHP/Morcilla', $response['user-agent']);
68
69 $config = array(
70 'curl' => array(
71 CURLOPT_FOLLOWLOCATION => 0,
72 CURLOPT_USERAGENT => 'PHP/Morcilla 2',
73 ),
74 'force_redirects' => true
75 );
76
77 $http = new \Embera\HttpRequest($config);
78 $response = $http->fetch('http://httpbin.org/relative-redirect/2');
79 $response = json_decode($response, true);
80
81 $this->assertEquals('http://httpbin.org/get', $response['url']);
82
83 $response = $http->fetch('http://httpbin.org/redirect-to?url=' . urlencode('http://httpbin.org/user-agent'));
84 $response = json_decode($response, true);
85
86 $this->assertEquals('PHP/Morcilla 2', $response['user-agent']);
87
88 $config = array(
89 'curl' => array(
90 CURLOPT_FOLLOWLOCATION => 1,
91 CURLOPT_USERAGENT => 'PHP/Morcilla 3',
92 ),
93 );
94
95 $http = new \Embera\HttpRequest($config);
96 $response = $http->fetch('http://httpbin.org/relative-redirect/2');
97 $response = json_decode($response, true);
98
99 $this->assertEquals('http://httpbin.org/get', $response['url']);
100
101 $response = $http->fetch('http://httpbin.org/redirect-to?url=' . urlencode('http://httpbin.org/user-agent'));
102 $response = json_decode($response, true);
103
104 $this->assertEquals('PHP/Morcilla 3', $response['user-agent']);
105 }
106
107 /**
108 * This needs more execution time ..
109 * @large
110 */
111 public function testFetchFileGetcontents()
112 {
113 if (!ini_get('allow_url_fopen'))
114 {
115 $this->markTestIncomplete('Could not test file_get_contents wrapper, allow_url_fopen is closed');
116 return ;
117 }
118
119 $config = array(
120 'prefer_curl' => false,
121 'fopen' => array(
122 'user_agent' => 'PHP/FGC Morcilla'
123 )
124 );
125
126 $http = new \Embera\HttpRequest($config);
127 $response = $http->fetch('http://httpbin.org/user-agent');
128 $response = json_decode($response, true);
129
130 $this->assertEquals('PHP/FGC Morcilla', $response['user-agent']);
131
132 $http = new \Embera\HttpRequest($config);
133 $response = $http->fetch('http://httpbin.org/relative-redirect/2');
134 $response = json_decode($response, true);
135
136 $this->assertEquals('http://httpbin.org/get', $response['url']);
137
138 $response = $http->fetch('http://httpbin.org/redirect-to?url=' . urlencode('http://httpbin.org/user-agent'));
139 $response = json_decode($response, true);
140
141 $this->assertEquals('PHP/FGC Morcilla', $response['user-agent']);
142 }
143
144 /**
145 * This needs more execution time ..
146 * @large
147 */
148 public function testOptionsPrecedence()
149 {
150 $config = array(
151 'curl' => array(
152 CURLOPT_USERAGENT => 'PHP/Morcilla 1',
153 )
154 );
155
156 $http = new \Embera\HttpRequest($config);
157 $response = $http->fetch('http://httpbin.org/user-agent', array(
158 'curl' => array(
159 CURLOPT_USERAGENT => 'PHP/Morcilla 2',
160 )
161 ));
162
163 $response = json_decode($response, true);
164
165 $this->assertEquals('PHP/Morcilla 2', $response['user-agent']);
166 }
167 }
168
169 ?>
170