]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/xmlrpc/xmlrpc-client.php
Use forge_get_config('groupdir_prefix')
[SourceForge/phpwiki.git] / tests / xmlrpc / xmlrpc-client.php
1 <?php // #!/usr/local/bin/php -Cq
2 /*
3  * Test the wiki XMLRPC interface methods.
4  * This is a client app used to query most methods from our server.
5
6  * The interface specification is that discussed at
7  * http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=WikiRPCInterface
8
9  * Author: Reini Urban
10  */
11
12 /*
13   This file is part of, or distributed with, libXMLRPC - a C library for
14   xml-encoded function calls.
15
16   Author: Dan Libby (dan@libby.com)
17   Epinions.com may be contacted at feedback@epinions-inc.com
18 */
19
20 /*
21   Copyright 2001 Epinions, Inc.
22
23   Subject to the following 3 conditions, Epinions, Inc.  permits you, free
24   of charge, to (a) use, copy, distribute, modify, perform and display this
25   software and associated documentation files (the "Software"), and (b)
26   permit others to whom the Software is furnished to do so as well.
27
28   1) The above copyright notice and this permission notice shall be included
29   without modification in all copies or substantial portions of the
30   Software.
31
32   2) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF
33   ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY
34   IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR
35   PURPOSE OR NONINFRINGEMENT.
36
37   3) IN NO EVENT SHALL EPINIONS, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
38   SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
39   OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER ARISING, INCLUDING
40   NEGLIGENCE), EVEN IF EPINIONS, INC.  IS AWARE OF THE POSSIBILITY OF SUCH
41   DAMAGES.
42
43 */
44
45 $cur_dir = getcwd();
46 # Add root dir to the path
47 if (substr(PHP_OS,0,3) == 'WIN')
48     $cur_dir = str_replace("\\","/", $cur_dir);
49 $rootdir = $cur_dir . '/../../';
50 $ini_sep = substr(PHP_OS,0,3) == 'WIN' ? ';' : ':';
51 $include_path = ini_get('include_path') . $ini_sep . $rootdir . $ini_sep . $rootdir . "lib/pear";
52 ini_set('include_path', $include_path);
53
54 if ($HTTP_SERVER_VARS["SERVER_NAME"] == 'phpwiki.sourceforge.net') {
55     ini_set('include_path', ini_get('include_path') . ":/usr/share/pear");
56 }
57 define('PHPWIKI_NOMAIN', true);
58 # Quiet warnings in IniConfig.php
59 $HTTP_SERVER_VARS['REMOTE_ADDR'] = '127.0.0.1';
60 $HTTP_SERVER_VARS['HTTP_USER_AGENT'] = "PHPUnit";
61 # Other needed files
62 require_once $rootdir.'index.php';
63
64 // fake a POST request to be able to load our interfaces
65 $save = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_METHOD'];
66 $GLOBALS['HTTP_SERVER_VARS']['REQUEST_METHOD'] = "POST";
67 include($rootdir."lib/XmlRpcServer.php");
68 $GLOBALS['HTTP_SERVER_VARS']['REQUEST_METHOD'] = $save;
69 // now we have $wiki_dmap
70
71 include './xmlrpc-servers.php';
72
73 function match($a, $b) {
74    $matches = true;
75    if (gettype($a) === "array") {
76       foreach ($a as $key => $c) {
77          $d = $b[$key];
78          if (!match($c, $d)) {
79             $matches = false;
80             break;
81          }
82       }
83    } else {
84       if ($a !== $b || xmlrpc_get_type($a) !== xmlrpc_get_type($b)) {
85          $matches = false;
86       }
87    }
88    return $matches;
89 }
90
91 function pass($method) {
92    echo "<font color=\"green\"><b>pass</b></font> $method()<br>";
93 }
94
95 function fail($method, $sent, $received) {
96    echo "<font color=\"red\"><b>fail</b></font> $method()<br>";
97    if ($sent) {
98      echo "<h3>sent</h3><xmp>";
99      var_dump($sent);
100      echo "</xmp>";
101    }
102
103    if ($received) {
104        echo "<h3>received</h3><xmp>";
105        var_dump($received);
106        echo "</xmp>";
107    }
108 }
109
110 // this needs to be fixed.
111 function check_if_matches($method, $sent, $received) {
112    if (match($sent, $received)) {
113        pass($method);
114    }
115    else {
116        fail($method, $sent, $received);
117    }
118 }
119
120 function foo($method_name, $args) {
121     xmlrpc_encode_request($method_name, $args);
122 }
123
124 function run_test($server, $debug, $output, $method, $args='', $expected='') {
125     global $HTTP_GET_VARS;
126     echo "<hr>";
127     if (!is_array($args))
128         $params = $args ? array($args) : array();
129     else
130         $params = $args;
131     if (!empty($HTTP_GET_VARS['start_debug'])) // zend ide support
132         $server['uri'] .= "?start_debug=1";
133     $result =  xu_rpc_http_concise(array('method' => $method,
134                                          'args'   => $params,
135                                          'host'   => $server['host'],
136                                          'uri'    => $server['uri'],
137                                          'port'   => $server['port'],
138                                          'debug'  => $debug,
139                                          'output' => $output));
140     check_if_matches($method, $expected, $result);
141     echo "</hr>";
142     flush();
143 }
144
145 // should return non-zero integer
146 function run_no_param_test($server, $debug, $output, $method) {
147     global $HTTP_GET_VARS;
148     echo "<hr>";
149     if (!empty($HTTP_GET_VARS['start_debug'])) // zend ide support
150         $server['uri'] .= "?start_debug=1";
151     $result =  xu_rpc_http_concise(array('method' => $method,
152                                          'host'   => $server['host'],
153                                          'uri'    => $server['uri'],
154                                          'port'   => $server['port'],
155                                          'debug'  => $debug,
156                                          'output' => $output));
157
158     if ($result && gettype($result) === "integer") {
159         pass($method);
160     }
161     else {
162         fail($method, false, $result);
163     }
164
165     flush();
166 }
167
168 // a method to run wiki tests against remote server. tests described at bottom.
169 function run_easy_tests($server, $debug=0, $output = null) {
170
171     //global $wiki_dmap;
172
173     run_test($server, $debug, $output, "wiki.getRPCVersionSupported", '', 1);
174
175     // getRecentChanges of the last day:
176     // Note: may crash with dba on index.php, not on RPC2.php
177     run_test($server, $debug, $output, "wiki.getRecentChanges", iso8601_encode(time()-86400));
178
179     run_test($server, $debug, $output, "wiki.getPage", "HomePage", "* What is a WikiWikiWeb? A description of this application. * Learn HowToUseWiki and learn about AddingPages. * Use the SandBox page to experiment with Wiki pages. * Please sign your name in RecentVisitors. * See RecentChanges for the latest page additions and changes. * Find out which pages are MostPopular. * Read the ReleaseNotes and RecentReleases. * Administer this wiki via PhpWikiAdministration. * See more PhpWikiDocumentation.");
180     run_test($server, $debug, $output, "wiki.getPageVersion", array("HomePage", 1));
181     run_test($server, $debug, $output, "wiki.getPageHTML", "HomePage");
182     run_test($server, $debug, $output, "wiki.getPageHTMLVersion", array("HomePage", 1));
183     run_test($server, $debug, $output, "wiki.getAllPages");
184     run_test($server, $debug, $output, "wiki.getPageInfo", "HomePage");
185     run_test($server, $debug, $output, "wiki.getPageInfoVersion", array("HomePage", 1));
186     run_test($server, $debug, $output, "wiki.listLinks", "HomePage");
187
188     run_test($server, $debug, $output, "wiki.putPage",
189              array("PutPage", "new PutPage content", "XxXx"),
190              array('code' => 200, 'version' => 1, 'message' => "Page PutPage version 1 created"));
191     run_test($server, $debug, $output, "wiki.putPage",
192              array("PutPage", "new PutPage content", "XxXx"),
193              array('code' => 400, 'version' => 1, 'message' => "Page PutPage unchanged"));
194     run_test($server, $debug, $output, "wiki.putPage",
195              array("PutPage", "new PutPage content", "disallowed"),
196              array('code' => 401, 'version' => 0, 'message' => "no permission for disallowed"));
197
198     run_test($server, $debug, $output, "wiki.rssPleaseNotify", "HomePage", 0);
199     run_test($server, $debug, $output, "wiki.mailPasswordToUser", ADMIN_USER);
200
201     run_test($server, $debug, $output, "wiki.titleSearch", "Hom");
202 }
203
204 function run_stress_tests($server, $debug=0, $output=null) {
205
206     global $wiki_dmap;
207
208     run_no_param_test($server, $debug, $output, "wiki.getRPCVersionSupported");
209     // of the last day:
210     run_test($server, $debug, $output, "wiki.getRecentChanges", iso8601_encode(time()-86400, 1));
211     /* ... */
212 }
213
214 // a method to display an html form for invoking the script
215 function print_html_form($servers_list) {
216
217    echo <<< END
218 <h1>Choose an xmlrpc wiki server to run tests against</h1>
219 END;
220
221    print_servers_form($servers_list);
222 }
223
224 // some code which determines if we are in form display or response mode.
225 $server_list = get_wiki_servers();
226 $server = get_server_from_user($server_list);
227 if ($server) {
228    $debug = $GLOBALS['HTTP_GET_VARS']['debug'] || $GLOBALS['HTTP_GET_VARS']['start_debug'];
229    $output['version'] = $GLOBALS['HTTP_GET_VARS']['version'];
230    if ($server) {
231       $title = $server['title'];
232       echo "<h2><center>Results for $title</center></h2>";
233
234       if($GLOBALS['HTTP_GET_VARS']['stress'] == 1) {
235          run_stress_tests($server, $debug, $output);
236       }
237       else {
238          run_easy_tests($server, $debug, $output);
239       }
240    }
241    else {
242       echo "<h3>invalid option</h3>";
243    }
244 }
245 else {
246    print_html_form($server_list);
247 }