1st pass at cleanup of unit tests; a couple of nitpicks from SLInsights
[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 $method) {
93             $this->$method;
94         }
95     }
96
97     /**
98      * @dataProvider getSingleHttpTestMethods
99      * @param string $method
100      */
101     public function testProxy($method)
102     {
103         if (!$this->args['PROXYSERVER'])
104         {
105             $this->markTestSkipped('PROXY definition missing: cannot test proxy');
106             return;
107         }
108
109         $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
110
111         $this->$method();
112     }
113
114     /**
115      * @dataProvider getSingleHttpTestMethods
116      * @param string $method
117      */
118     public function testHttp11($method)
119     {
120         if(!function_exists('curl_init'))
121         {
122             $this->markTestSkipped('CURL missing: cannot test http 1.1');
123             return;
124         }
125
126         $this->method = 'http11'; // not an error the double assignment!
127         $this->client->method = 'http11';
128         $this->client->keepalive = false;
129
130         $this->$method();
131     }
132
133     /**
134      * @dataProvider getSingleHttpTestMethods
135      * @param string $method
136      */
137     public function testHttp11Gzip($method)
138     {
139         if(!function_exists('curl_init'))
140         {
141             $this->markTestSkipped('CURL missing: cannot test http 1.1');
142             return;
143         }
144         $this->method = 'http11'; // not an error the double assignment!
145         $this->client->method = 'http11';
146         $this->client->keepalive = false;
147         $this->client->accepted_compression = array('gzip');
148         $this->client->request_compression = 'gzip';
149
150         $this->$method();
151     }
152
153     /**
154      * @dataProvider getSingleHttpTestMethods
155      * @param string $method
156      */
157     public function testHttp11Deflate($method)
158     {
159         if(!function_exists('curl_init'))
160         {
161             $this->markTestSkipped('CURL missing: cannot test http 1.1');
162             return;
163         }
164         $this->method = 'http11'; // not an error the double assignment!
165         $this->client->method = 'http11';
166         $this->client->keepalive = false;
167         $this->client->accepted_compression = array('deflate');
168         $this->client->request_compression = 'deflate';
169
170         $this->$method();
171     }
172
173     /**
174      * @dataProvider getSingleHttpTestMethods
175      * @param string $method
176      */
177     public function testHttp11Proxy($method)
178     {
179         if(!function_exists('curl_init'))
180         {
181             $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy');
182             return;
183         }
184         else if ($this->args['PROXYSERVER'] == '')
185         {
186             $this->markTestSkipped('PROXY definition missing: cannot test proxy w. http 1.1');
187             return;
188         }
189
190         $this->method = 'http11'; // not an error the double assignment!
191         $this->client->method = 'http11';
192         $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
193         $this->client->keepalive = false;
194
195         $this->$method();
196     }
197
198     /**
199      * @dataProvider getSingleHttpTestMethods
200      * @param string $method
201      */
202     public function testHttps($method)
203     {
204         if(!function_exists('curl_init'))
205         {
206             $this->markTestSkipped('CURL missing: cannot test https functionality');
207             return;
208         }
209
210         $this->client->server = $this->args['HTTPSSERVER'];
211         $this->method = 'https';
212         $this->client->method = 'https';
213         $this->client->path = $this->args['HTTPSURI'];
214         $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
215         $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
216         $this->client->setSSLVersion($this->args['SSLVERSION']);
217
218         $this->$method();
219     }
220
221     /**
222      * @dataProvider getSingleHttpTestMethods
223      * @param string $method
224      */
225     public function testHttpsProxy($method)
226     {
227         if(!function_exists('curl_init'))
228         {
229             $this->markTestSkipped('CURL missing: cannot test https functionality');
230             return;
231         }
232         else if ($this->args['PROXYSERVER'] == '')
233         {
234             $this->markTestSkipped('PROXY definition missing: cannot test proxy w. http 1.1');
235             return;
236         }
237         $this->client->server = $this->args['HTTPSSERVER'];
238         $this->method = 'https';
239         $this->client->method = 'https';
240         $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
241         $this->client->path = $this->args['HTTPSURI'];
242         $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
243         $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
244         $this->client->setSSLVersion($this->args['SSLVERSION']);
245
246         $this->$method();
247     }
248
249     /**
250      * @dataProvider getSingleHttpTestMethods
251      * @param string $method
252      */
253     public function testUTF8Responses($method)
254     {
255         $this->addQueryParams(array('RESPONSE_ENCODING' => 'UTF-8'));
256
257         $this->$method();
258     }
259
260     /**
261      * @dataProvider getSingleHttpTestMethods
262      * @param string $method
263      */
264     public function testUTF8Requests($method)
265     {
266         $this->client->request_charset_encoding = 'UTF-8';
267
268         $this->$method();
269     }
270
271     /**
272      * @dataProvider getSingleHttpTestMethods
273      * @param string $method
274      */
275     public function testISOResponses($method)
276     {
277         $this->addQueryParams(array('RESPONSE_ENCODING' => 'ISO-8859-1'));
278
279         $this->$method();
280     }
281
282     /**
283      * @dataProvider getSingleHttpTestMethods
284      * @param string $method
285      */
286     public function testISORequests($method)
287     {
288         $this->client->request_charset_encoding = 'ISO-8859-1';
289
290         $this->$method();
291     }
292
293     /**
294      * @dataProvider getSingleHttpTestMethods
295      * @param string $method
296      */
297     public function testBasicAuth($method)
298     {
299         $this->client->setCredentials('test', 'test');
300         $this->addQueryParams(array('FORCE_AUTH' => 'Basic'));
301
302         $this->$method();
303     }
304
305     /**
306      * @dataProvider getSingleHttpTestMethods
307      * @param string $method
308      */
309     public function testDigestAuth($method)
310     {
311         if (!function_exists('curl_init'))
312         {
313             $this->markTestSkipped('CURL missing: cannot test digest auth functionality');
314             return;
315         }
316
317         $this->client->setCredentials('test', 'test', CURLAUTH_DIGEST);
318         $this->addQueryParams(array('FORCE_AUTH' => 'Digest'));
319         $this->method = 'http11';
320         $this->client->method = 'http11';
321
322         $this->$method();
323     }
324 }