Improve testsuite to make it easily executable by Travis
[plcapi.git] / test / parse_args.php
1 <?php
2 /**
3  * Common parameter parsing for benchmarks and tests scripts
4  *
5  * @param integer DEBUG
6  * @param string  LOCALSERVER
7  * @param string  URI
8  * @param string  HTTPSSERVER
9  * @param string  HTTPSSURI
10  * @param string  PROXY
11  *
12  * @copyright (C) 2007-20013 G. Giunta
13  * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
14  **/
15
16         require_once('xmlrpc.inc');
17         require_once('xmlrpcs.inc');
18
19         // play nice to older PHP versions that miss superglobals
20         if(!isset($_SERVER))
21         {
22                 $_SERVER = $HTTP_SERVER_VARS;
23                 $_GET = isset($HTTP_GET_VARS) ? $HTTP_GET_VARS : array();
24                 $_POST = isset($HTTP_POST_VARS) ? $HTTP_POST_VARS : array();
25         }
26
27         // check for command line vs web page input params
28         if(!isset($_SERVER['REQUEST_METHOD']))
29         {
30                 if(isset($argv))
31                 {
32                         foreach($argv as $param)
33                         {
34                                 $param = explode('=', $param);
35                                 if(count($param) > 1)
36                                 {
37                                         $$param[0]=$param[1];
38                                 }
39                         }
40                 }
41         }
42         elseif(!ini_get('register_globals'))
43         {
44                 // play nice to 'safe' PHP installations with register globals OFF
45                 // NB: we might as well consider using $_GET stuff later on...
46                 extract($_GET);
47                 extract($_POST);
48         }
49
50         if(!isset($DEBUG))
51         {
52                 $DEBUG = 0;
53         }
54         else
55         {
56                 $DEBUG = intval($DEBUG);
57         }
58
59         if(!isset($LOCALSERVER))
60         {
61                 if(isset($HTTP_HOST))
62                 {
63                         $LOCALSERVER = $HTTP_HOST;
64                 }
65                 elseif(isset($_SERVER['HTTP_HOST']))
66                 {
67                         $LOCALSERVER = $_SERVER['HTTP_HOST'];
68                 }
69                 else
70                 {
71                         $LOCALSERVER = 'localhost';
72                 }
73         }
74         if(!isset($HTTPSSERVER))
75         {
76                 $HTTPSSERVER = 'xmlrpc.usefulinc.com';
77         }
78         if(!isset($HTTPSURI))
79         {
80                 $HTTPSURI = '/server.php';
81         }
82         if(!isset($HTTPSIGNOREPEER))
83         {
84                 $HTTPSIGNOREPEER = false;
85         }
86         if(!isset($PROXY))
87         {
88                 $PROXYSERVER = null;
89         }
90         else
91         {
92                 $arr = explode(':',$PROXY);
93                 $PROXYSERVER = $arr[0];
94                 if(count($arr) > 1)
95                 {
96                         $PROXYPORT = $arr[1];
97                 }
98                 else
99                 {
100                         $PROXYPORT = 8080;
101                 }
102         }
103     // used to silence testsuite warnings about proxy code not being tested
104     if(!isset($NOPROXY))
105     {
106         $NOPROXY = false;
107     }
108         if(!isset($URI))
109         {
110                 // GUESTIMATE the url of local demo server
111                 // play nice to php 3 and 4-5 in retrieving URL of server.php
112                 /// @todo filter out query string from REQUEST_URI
113                 if(isset($REQUEST_URI))
114                 {
115                         $URI = str_replace('/test/testsuite.php', '/demo/server/server.php', $REQUEST_URI);
116                         $URI = str_replace('/testsuite.php', '/server.php', $URI);
117                         $URI = str_replace('/test/benchmark.php', '/demo/server/server.php', $URI);
118                         $URI = str_replace('/benchmark.php', '/server.php', $URI);
119                 }
120                 elseif(isset($_SERVER['PHP_SELF']) && isset($_SERVER['REQUEST_METHOD']))
121                 {
122                         $URI = str_replace('/test/testsuite.php', '/demo/server/server.php', $_SERVER['PHP_SELF']);
123                         $URI = str_replace('/testsuite.php', '/server.php', $URI);
124                         $URI = str_replace('/test/benchmark.php', '/demo/server/server.php', $URI);
125                         $URI = str_replace('/benchmark.php', '/server.php', $URI);
126                 }
127                 else
128                 {
129                         $URI = '/demo/server/server.php';
130                 }
131         }
132         if($URI[0] != '/')
133         {
134                 $URI = '/'.$URI;
135         }
136         if(!isset($LOCALPATH))
137         {
138                 $LOCALPATH = dirname(__FILE__);
139         }
140 ?>