61e94947ed134d6d08d0b419d46972276f1a575e
[plcapi.git] / tests / 4LocalhostMultiTest.php
1 <?php
2
3 include_once __DIR__ . '/../lib/xmlrpc.inc';
4 include_once __DIR__ . '/../lib/xmlrpc_wrappers.inc';
5
6 include_once __DIR__ . '/parse_args.php';
7
8 include_once __DIR__ . '/3LocalhostTest.php';
9
10 /**
11  * Tests which stress http features of the library.
12  * Each of these tests iterates over (almost) all of the 'localhost' tests
13  */
14 class LocalhostMultiTest extends LocalhostTest
15 {
16     /**
17      * Returns all test methods from the base class, except the ones which failed already
18      *
19      * @todo reintroduce skipping of tests which failed when executed individually if test runs happen as separate processes
20      * @todo reintroduce skipping of tests within the loop
21      */
22     public function getSingleHttpTestMethods()
23     {
24         $unsafeMethods = array('testHttps', 'testCatchExceptions', 'testUtf8Method', 'testServerComments', 'testExoticCharsetsRequests',
25             'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3',
26             // @todo the following are currently not compatible w Digest Auth (most likely because of client copy) and should be fixed
27             'testcatchWarnings', 'testWrappedMethodAsSource', 'testTransferOfObjectViaWrapping');
28
29         $methods = array();
30         foreach(get_class_methods('LocalhostTest') as $method)
31         {
32             if(strpos($method, 'test') === 0 && !in_array($method, $unsafeMethods))
33             {
34                 if (!isset(self::$failed_tests[$method])) {
35                     $methods[$method] = array($method);
36                 }
37             }
38         }
39
40         return $methods;
41     }
42
43     /**
44      * @dataProvider getSingleHttpTestMethods
45      * @param string $method
46      */
47     public function testDeflate($method)
48     {
49         if(!function_exists('gzdeflate'))
50         {
51             $this->markTestSkipped('Zlib missing: cannot test deflate functionality');
52             return;
53         }
54
55         $this->client->accepted_compression = array('deflate');
56         $this->client->request_compression = 'deflate';
57
58         $this->$method();
59     }
60
61     /**
62      * @dataProvider getSingleHttpTestMethods
63      * @param string $method
64      */
65     public function testGzip($method)
66     {
67         if(!function_exists('gzdeflate'))
68         {
69             $this->markTestSkipped('Zlib missing: cannot test gzip functionality');
70             return;
71         }
72
73         $this->client->accepted_compression = array('gzip');
74         $this->client->request_compression = 'gzip';
75
76         $this->$method();
77     }
78
79     public function testKeepAlives()
80     {
81         if(!function_exists('curl_init'))
82         {
83             $this->markTestSkipped('CURL missing: cannot test http 1.1');
84             return;
85         }
86
87         $this->method = 'http11';
88         $this->client->method = 'http11';
89         $this->client->keepalive = true;
90
91         // to successfully test keepalive, we have to reuse the same client for all tests, we can not recreate one on setup/teardown...
92         foreach ($this->getSingleHttpTestMethods() as $methods) {
93             $method = $methods[0];
94             $this->$method();
95         }
96     }
97
98     /**
99      * @dataProvider getSingleHttpTestMethods
100      * @param string $method
101      */
102     public function testProxy($method)
103     {
104         if (!$this->args['PROXYSERVER'])
105         {
106             $this->markTestSkipped('PROXY definition missing: cannot test proxy');
107             return;
108         }
109
110         $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
111
112         $this->$method();
113     }
114
115     /**
116      * @dataProvider getSingleHttpTestMethods
117      * @param string $method
118      */
119     public function testHttp11($method)
120     {
121         if(!function_exists('curl_init'))
122         {
123             $this->markTestSkipped('CURL missing: cannot test http 1.1');
124             return;
125         }
126
127         $this->method = 'http11'; // not an error the double assignment!
128         $this->client->method = 'http11';
129         $this->client->keepalive = false;
130
131         $this->$method();
132     }
133
134     /**
135      * @dataProvider getSingleHttpTestMethods
136      * @param string $method
137      */
138     public function testHttp11Gzip($method)
139     {
140         if(!function_exists('curl_init'))
141         {
142             $this->markTestSkipped('CURL missing: cannot test http 1.1');
143             return;
144         }
145         $this->method = 'http11'; // not an error the double assignment!
146         $this->client->method = 'http11';
147         $this->client->keepalive = false;
148         $this->client->accepted_compression = array('gzip');
149         $this->client->request_compression = 'gzip';
150
151         $this->$method();
152     }
153
154     /**
155      * @dataProvider getSingleHttpTestMethods
156      * @param string $method
157      */
158     public function testHttp11Deflate($method)
159     {
160         if(!function_exists('curl_init'))
161         {
162             $this->markTestSkipped('CURL missing: cannot test http 1.1');
163             return;
164         }
165         $this->method = 'http11'; // not an error the double assignment!
166         $this->client->method = 'http11';
167         $this->client->keepalive = false;
168         $this->client->accepted_compression = array('deflate');
169         $this->client->request_compression = 'deflate';
170
171         $this->$method();
172     }
173
174     /**
175      * @dataProvider getSingleHttpTestMethods
176      * @param string $method
177      */
178     public function testHttp11Proxy($method)
179     {
180         if(!function_exists('curl_init'))
181         {
182             $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy');
183             return;
184         }
185         else if ($this->args['PROXYSERVER'] == '')
186         {
187             $this->markTestSkipped('PROXY definition missing: cannot test proxy w. http 1.1');
188             return;
189         }
190
191         $this->method = 'http11'; // not an error the double assignment!
192         $this->client->method = 'http11';
193         $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
194         $this->client->keepalive = false;
195
196         $this->$method();
197     }
198
199     /**
200      * @dataProvider getSingleHttpTestMethods
201      * @param string $method
202      */
203     public function testHttps($method)
204     {
205         if(!function_exists('curl_init'))
206         {
207             $this->markTestSkipped('CURL missing: cannot test https functionality');
208             return;
209         }
210
211         $this->client->server = $this->args['HTTPSSERVER'];
212         $this->method = 'https';
213         $this->client->method = 'https';
214         $this->client->path = $this->args['HTTPSURI'];
215         $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
216         $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
217         $this->client->setSSLVersion($this->args['SSLVERSION']);
218
219         $this->$method();
220     }
221
222     /**
223      * @dataProvider getSingleHttpTestMethods
224      * @param string $method
225      */
226     public function testHttpsProxy($method)
227     {
228         if(!function_exists('curl_init'))
229         {
230             $this->markTestSkipped('CURL missing: cannot test https functionality');
231             return;
232         }
233         else if ($this->args['PROXYSERVER'] == '')
234         {
235             $this->markTestSkipped('PROXY definition missing: cannot test proxy w. http 1.1');
236             return;
237         }
238         $this->client->server = $this->args['HTTPSSERVER'];
239         $this->method = 'https';
240         $this->client->method = 'https';
241         $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
242         $this->client->path = $this->args['HTTPSURI'];
243         $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
244         $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
245         $this->client->setSSLVersion($this->args['SSLVERSION']);
246
247         $this->$method();
248     }
249
250     /**
251      * @dataProvider getSingleHttpTestMethods
252      * @param string $method
253      */
254     public function testUTF8Responses($method)
255     {
256         $this->addQueryParams(array('RESPONSE_ENCODING' => 'UTF-8'));
257
258         $this->$method();
259     }
260
261     /**
262      * @dataProvider getSingleHttpTestMethods
263      * @param string $method
264      */
265     public function testUTF8Requests($method)
266     {
267         $this->client->request_charset_encoding = 'UTF-8';
268
269         $this->$method();
270     }
271
272     /**
273      * @dataProvider getSingleHttpTestMethods
274      * @param string $method
275      */
276     public function testISOResponses($method)
277     {
278         $this->addQueryParams(array('RESPONSE_ENCODING' => 'ISO-8859-1'));
279
280         $this->$method();
281     }
282
283     /**
284      * @dataProvider getSingleHttpTestMethods
285      * @param string $method
286      */
287     public function testISORequests($method)
288     {
289         $this->client->request_charset_encoding = 'ISO-8859-1';
290
291         $this->$method();
292     }
293
294     /**
295      * @dataProvider getSingleHttpTestMethods
296      * @param string $method
297      */
298     public function testBasicAuth($method)
299     {
300         $this->client->setCredentials('test', 'test');
301         $this->addQueryParams(array('FORCE_AUTH' => 'Basic'));
302
303         $this->$method();
304     }
305
306     /**
307      * @dataProvider getSingleHttpTestMethods
308      * @param string $method
309      */
310     public function testDigestAuth($method)
311     {
312         if (!function_exists('curl_init'))
313         {
314             $this->markTestSkipped('CURL missing: cannot test digest auth functionality');
315             return;
316         }
317
318         $this->client->setCredentials('test', 'test', CURLAUTH_DIGEST);
319         $this->addQueryParams(array('FORCE_AUTH' => 'Digest'));
320         $this->method = 'http11';
321         $this->client->method = 'http11';
322
323         $this->$method();
324     }
325 }