1 <?php // #!/usr/local/bin/php -Cq
3 * Test the wiki XMLRPC interface methods.
4 * This is a client app used to query most methods from our server.
6 * The interface specification is that discussed at
7 * http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=WikiRPCInterface
13 This file is part of, or distributed with, libXMLRPC - a C library for
14 xml-encoded function calls.
16 Author: Dan Libby (dan@libby.com)
17 Epinions.com may be contacted at feedback@epinions-inc.com
21 Copyright 2001 Epinions, Inc.
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.
28 1) The above copyright notice and this permission notice shall be included
29 without modification in all copies or substantial portions of the
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.
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
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);
54 if ($HTTP_SERVER_VARS["SERVER_NAME"] == 'phpwiki.sourceforge.net') {
55 ini_set('include_path', ini_get('include_path') . ":/usr/share/pear");
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";
62 require_once $rootdir.'index.php';
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
71 include("./xmlrpc-servers.php");
73 function match($a, $b) {
75 if (gettype($a) === "array") {
76 foreach ($a as $key => $c) {
84 if ($a !== $b || xmlrpc_get_type($a) !== xmlrpc_get_type($b)) {
91 function pass($method) {
92 echo "<font color='green'><b>pass</b></font> $method()<br>";
95 function fail($method, $sent, $received) {
96 echo "<font color='red'><b>fail</b></font> $method()<br>";
98 echo "<h3>sent</h3><xmp>";
104 echo "<h3>received</h3><xmp>";
110 function check_if_matches($method, $sent, $received) {
111 if (match($sent, $received)) {
115 fail($method, $sent, $received);
119 function foo($method_name, $args) {
120 xmlrpc_encode_request($method_name, $args);
123 function run_test($server, $debug, $output, $method, $args) {
124 global $HTTP_GET_VARS;
126 $params = array($args);
127 if (!empty($HTTP_GET_VARS['start_debug'])) // zend ide support
128 $server['uri'] .= "?start_debug=1";
129 $result = xu_rpc_http_concise(array('method' => $method,
131 'host' => $server['host'],
132 'uri' => $server['uri'],
133 'port' => $server['port'],
135 'output' => $output));
136 check_if_matches($method, $args, $result);
141 function run_no_param_test($server, $debug, $output, $method) {
142 global $HTTP_GET_VARS;
144 if (!empty($HTTP_GET_VARS['start_debug'])) // zend ide support
145 $server['uri'] .= "?start_debug=1";
146 $result = xu_rpc_http_concise(array('method' => $method,
147 'host' => $server['host'],
148 'uri' => $server['uri'],
149 'port' => $server['port'],
151 'output' => $output));
153 if ($result && gettype($result) === "integer") {
157 fail($method, false, $result);
164 // a method to run wiki tests against remote server. tests described at bottom.
165 function run_easy_tests($server, $debug=0, $output = null) {
169 run_no_param_test($server, $debug, $output, "wiki.getRPCVersionSupported");
171 run_test($server, $debug, $output, "wiki.getRecentChanges", iso8601_encode(time()-86400, 1));
175 function run_stress_tests($server, $debug=0, $output=null) {
179 run_no_param_test($server, $debug, $output, "wiki.getRPCVersionSupported");
181 run_test($server, $debug, $output, "wiki.getRecentChanges", iso8601_encode(time()-86400, 1));
185 // a method to display an html form for invoking the script
186 function print_html_form($servers_list) {
189 <h1>Choose an xmlrpc wiki server to run tests against</h1>
192 print_servers_form($servers_list);
195 // some code which determines if we are in form display or response mode.
196 $server_list = get_wiki_servers();
197 $server = get_server_from_user($server_list);
199 $debug = $GLOBALS['HTTP_GET_VARS']['debug'] || $GLOBALS['HTTP_GET_VARS']['start_debug'];
200 $output['version'] = $GLOBALS['HTTP_GET_VARS']['version'];
202 $title = $server['title'];
203 echo "<h2><CENTER>Results for $title</CENTER></H2>";
205 if($GLOBALS['HTTP_GET_VARS']['stress'] == 1) {
206 run_stress_tests($server, $debug, $output);
209 run_easy_tests($server, $debug, $output);
213 echo "<h3>invalid option</h3>";
217 print_html_form($server_list);