allow http auth to work in curl mode; add tests for basic and digest auth; refactor...
[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      * @todo reintroduce skipping of tests which failed when executed individually if test runs happen as separate processes
18      * @todo reintroduce skipping of tests within the loop
19      */
20     function _runtests()
21     {
22         $unsafeMethods = array('testHttps', 'testCatchExceptions', 'testUtf8Method', 'testServerComments', 'testExoticCharsetsRequests',
23             'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3',
24             // @todo the following are currently not compatible w Digest Auth (most likely because of client copy) and should be fixed
25             'testcatchWarnings', 'testWrappedMethodAsSource', 'testTransferOfObjectViaWrapping');
26         foreach(get_class_methods('LocalhostTest') as $method)
27         {
28             if(strpos($method, 'test') === 0 && !in_array($method, $unsafeMethods))
29             {
30                 if (!isset(self::$failed_tests[$method]))
31                     $this->$method();
32             }
33             /*if ($this->_failed)
34             {
35                 break;
36             }*/
37         }
38     }
39
40     function testDeflate()
41     {
42         if(!function_exists('gzdeflate'))
43         {
44             $this->markTestSkipped('Zlib missing: cannot test deflate functionality');
45             return;
46         }
47         $this->client->accepted_compression = array('deflate');
48         $this->client->request_compression = 'deflate';
49         $this->_runtests();
50     }
51
52     function testGzip()
53     {
54         if(!function_exists('gzdeflate'))
55         {
56             $this->markTestSkipped('Zlib missing: cannot test gzip functionality');
57             return;
58         }
59         $this->client->accepted_compression = array('gzip');
60         $this->client->request_compression = 'gzip';
61         $this->_runtests();
62     }
63
64     function testKeepAlives()
65     {
66         if(!function_exists('curl_init'))
67         {
68             $this->markTestSkipped('CURL missing: cannot test http 1.1');
69             return;
70         }
71         $this->method = 'http11';
72         $this->client->keepalive = true;
73         $this->_runtests();
74     }
75
76     function testProxy()
77     {
78         if ($this->args['PROXYSERVER'])
79         {
80             $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
81             $this->_runtests();
82         }
83         else
84             $this->markTestSkipped('PROXY definition missing: cannot test proxy');
85     }
86
87     function testHttp11()
88     {
89         if(!function_exists('curl_init'))
90         {
91             $this->markTestSkipped('CURL missing: cannot test http 1.1');
92             return;
93         }
94         $this->method = 'http11'; // not an error the double assignment!
95         $this->client->method = 'http11';
96         //$this->client->verifyhost = 0;
97         //$this->client->verifypeer = 0;
98         $this->client->keepalive = false;
99         $this->_runtests();
100     }
101
102     function testHttp11Gzip()
103     {
104         if(!function_exists('curl_init'))
105         {
106             $this->markTestSkipped('CURL missing: cannot test http 1.1');
107             return;
108         }
109         $this->method = 'http11'; // not an error the double assignment!
110         $this->client->method = 'http11';
111         $this->client->keepalive = false;
112         $this->client->accepted_compression = array('gzip');
113         $this->client->request_compression = 'gzip';
114         $this->_runtests();
115     }
116
117     function testHttp11Deflate()
118     {
119         if(!function_exists('curl_init'))
120         {
121             $this->markTestSkipped('CURL missing: cannot test http 1.1');
122             return;
123         }
124         $this->method = 'http11'; // not an error the double assignment!
125         $this->client->method = 'http11';
126         $this->client->keepalive = false;
127         $this->client->accepted_compression = array('deflate');
128         $this->client->request_compression = 'deflate';
129         $this->_runtests();
130     }
131
132     function testHttp11Proxy()
133     {
134         if(!function_exists('curl_init'))
135         {
136             $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy');
137             return;
138         }
139         else if ($this->args['PROXYSERVER'] == '')
140         {
141             $this->markTestSkipped('PROXY definition missing: cannot test proxy w. http 1.1');
142             return;
143         }
144         $this->method = 'http11'; // not an error the double assignment!
145         $this->client->method = 'http11';
146         $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
147         //$this->client->verifyhost = 0;
148         //$this->client->verifypeer = 0;
149         $this->client->keepalive = false;
150         $this->_runtests();
151     }
152
153     function testHttps()
154     {
155         if(!function_exists('curl_init'))
156         {
157             $this->markTestSkipped('CURL missing: cannot test https functionality');
158             return;
159         }
160         $this->client->server = $this->args['HTTPSSERVER'];
161         $this->method = 'https';
162         $this->client->method = 'https';
163         $this->client->path = $this->args['HTTPSURI'];
164         $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
165         $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
166         $this->client->setSSLVersion($this->args['SSLVERSION']);
167         $this->_runtests();
168     }
169
170     function testHttpsProxy()
171     {
172         if(!function_exists('curl_init'))
173         {
174             $this->markTestSkipped('CURL missing: cannot test https functionality');
175             return;
176         }
177         else if ($this->args['PROXYSERVER'] == '')
178         {
179             $this->markTestSkipped('PROXY definition missing: cannot test proxy w. http 1.1');
180             return;
181         }
182         $this->client->server = $this->args['HTTPSSERVER'];
183         $this->method = 'https';
184         $this->client->method = 'https';
185         $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
186         $this->client->path = $this->args['HTTPSURI'];
187         $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
188         $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
189         $this->client->setSSLVersion($this->args['SSLVERSION']);
190         $this->_runtests();
191     }
192
193     function testUTF8Responses()
194     {
195         //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8';
196         $this->client->path = $this->args['URI'].'?RESPONSE_ENCODING=UTF-8';
197         $this->_runtests();
198     }
199
200     function testUTF8Requests()
201     {
202         $this->client->request_charset_encoding = 'UTF-8';
203         $this->_runtests();
204     }
205
206     function testISOResponses()
207     {
208         //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8';
209         $this->client->path = $this->args['URI'].'?RESPONSE_ENCODING=ISO-8859-1';
210         $this->_runtests();
211     }
212
213     function testISORequests()
214     {
215         $this->client->request_charset_encoding = 'ISO-8859-1';
216         $this->_runtests();
217     }
218
219     function testBasicAuth()
220     {
221         $this->client->setCredentials('test', 'test');
222         $this->client->path = $this->args['URI'].'?FORCE_AUTH=Basic';
223         $this->_runtests();
224     }
225
226     function testDigestAuth()
227     {
228         if (!function_exists('curl_init'))
229         {
230             $this->markTestSkipped('CURL missing: cannot test digest auth functionality');
231             return;
232         }
233         $this->client->setCredentials('test', 'test', CURLAUTH_DIGEST);
234         $this->client->path = $this->args['URI'].'?FORCE_AUTH=Digest';
235         $this->method = 'http11';
236         $this->client->method = 'http11';
237         $this->_runtests();
238     }
239 }