Set default internal charset to UTF8 and change tests accordingly; add function has_e...
[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 class LocalhostMultiTest extends LocalhostTest
11 {
12     /**
13      * @todo reintroduce skipping of tests which failed when executed individually if test runs happen as separate processes
14      * @todo reintroduce skipping of tests within the loop
15      */
16     function _runtests()
17     {
18         $unsafeMethods = array('testHttps', 'testCatchExceptions', 'testUtf8Method');
19         foreach(get_class_methods('LocalhostTest') as $method)
20         {
21             if(strpos($method, 'test') === 0 && !in_array($method, $unsafeMethods))
22             {
23                 if (!isset(self::$failed_tests[$method]))
24                     $this->$method();
25             }
26             /*if ($this->_failed)
27             {
28                 break;
29             }*/
30         }
31     }
32
33     function testDeflate()
34     {
35         if(!function_exists('gzdeflate'))
36         {
37             $this->fail('Zlib missing: cannot test deflate functionality');
38             return;
39         }
40         $this->client->accepted_compression = array('deflate');
41         $this->client->request_compression = 'deflate';
42         $this->_runtests();
43     }
44
45     function testGzip()
46     {
47         if(!function_exists('gzdeflate'))
48         {
49             $this->fail('Zlib missing: cannot test gzip functionality');
50             return;
51         }
52         $this->client->accepted_compression = array('gzip');
53         $this->client->request_compression = 'gzip';
54         $this->_runtests();
55     }
56
57     function testKeepAlives()
58     {
59         if(!function_exists('curl_init'))
60         {
61             $this->fail('CURL missing: cannot test http 1.1');
62             return;
63         }
64         $this->method = 'http11';
65         $this->client->keepalive = true;
66         $this->_runtests();
67     }
68
69     function testProxy()
70     {
71         if ($this->args['PROXYSERVER'])
72         {
73             $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
74             $this->_runtests();
75         }
76         else
77             $this->fail('PROXY definition missing: cannot test proxy');
78     }
79
80     function testHttp11()
81     {
82         if(!function_exists('curl_init'))
83         {
84             $this->fail('CURL missing: cannot test http 1.1');
85             return;
86         }
87         $this->method = 'http11'; // not an error the double assignment!
88         $this->client->method = 'http11';
89         //$this->client->verifyhost = 0;
90         //$this->client->verifypeer = 0;
91         $this->client->keepalive = false;
92         $this->_runtests();
93     }
94
95     function testHttp11Gzip()
96     {
97         if(!function_exists('curl_init'))
98         {
99             $this->fail('CURL missing: cannot test http 1.1');
100             return;
101         }
102         $this->method = 'http11'; // not an error the double assignment!
103         $this->client->method = 'http11';
104         $this->client->keepalive = false;
105         $this->client->accepted_compression = array('gzip');
106         $this->client->request_compression = 'gzip';
107         $this->_runtests();
108     }
109
110     function testHttp11Deflate()
111     {
112         if(!function_exists('curl_init'))
113         {
114             $this->fail('CURL missing: cannot test http 1.1');
115             return;
116         }
117         $this->method = 'http11'; // not an error the double assignment!
118         $this->client->method = 'http11';
119         $this->client->keepalive = false;
120         $this->client->accepted_compression = array('deflate');
121         $this->client->request_compression = 'deflate';
122         $this->_runtests();
123     }
124
125     function testHttp11Proxy()
126     {
127         if(!function_exists('curl_init'))
128         {
129             $this->fail('CURL missing: cannot test http 1.1 w. proxy');
130             return;
131         }
132         else if ($this->args['PROXYSERVER'] == '')
133         {
134             $this->fail('PROXY definition missing: cannot test proxy w. http 1.1');
135             return;
136         }
137         $this->method = 'http11'; // not an error the double assignment!
138         $this->client->method = 'http11';
139         $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
140         //$this->client->verifyhost = 0;
141         //$this->client->verifypeer = 0;
142         $this->client->keepalive = false;
143         $this->_runtests();
144     }
145
146     function testHttps()
147     {
148         if(!function_exists('curl_init'))
149         {
150             $this->fail('CURL missing: cannot test https functionality');
151             return;
152         }
153         $this->client->server = $this->args['HTTPSSERVER'];
154         $this->method = 'https';
155         $this->client->method = 'https';
156         $this->client->path = $this->args['HTTPSURI'];
157         $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
158         $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
159         $this->client->setSSLVersion($this->args['SSLVERSION']);
160         $this->_runtests();
161     }
162
163     function testHttpsProxy()
164     {
165         if(!function_exists('curl_init'))
166         {
167             $this->fail('CURL missing: cannot test https functionality');
168             return;
169         }
170         else if ($this->args['PROXYSERVER'] == '')
171         {
172             $this->fail('PROXY definition missing: cannot test proxy w. http 1.1');
173             return;
174         }
175         $this->client->server = $this->args['HTTPSSERVER'];
176         $this->method = 'https';
177         $this->client->method = 'https';
178         $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
179         $this->client->path = $this->args['HTTPSURI'];
180         $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
181         $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
182         $this->client->setSSLVersion($this->args['SSLVERSION']);
183         $this->_runtests();
184     }
185
186     function testUTF8Responses()
187     {
188         //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8';
189         $this->client->path = $this->args['URI'].'?RESPONSE_ENCODING=UTF-8';
190         $this->_runtests();
191     }
192
193     function testUTF8Requests()
194     {
195         $this->client->request_charset_encoding = 'UTF-8';
196         $this->_runtests();
197     }
198
199     function testISOResponses()
200     {
201         //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8';
202         $this->client->path = $this->args['URI'].'?RESPONSE_ENCODING=ISO-8859-1';
203         $this->_runtests();
204     }
205
206     function testISORequests()
207     {
208         $this->client->request_charset_encoding = 'ISO-8859-1';
209         $this->_runtests();
210     }
211 }