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 // this needs to be fixed.
111 function check_if_matches($method, $sent, $received) {
112 if (match($sent, $received)) {
116 fail($method, $sent, $received);
120 function foo($method_name, $args) {
121 xmlrpc_encode_request($method_name, $args);
124 function run_test($server, $debug, $output, $method, $args='', $expected='') {
125 global $HTTP_GET_VARS;
127 if (!is_array($args))
128 $params = $args ? array($args) : array();
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,
135 'host' => $server['host'],
136 'uri' => $server['uri'],
137 'port' => $server['port'],
139 'output' => $output));
140 check_if_matches($method, $expected, $result);
145 // should return non-zero integer
146 function run_no_param_test($server, $debug, $output, $method) {
147 global $HTTP_GET_VARS;
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'],
156 'output' => $output));
158 if ($result && gettype($result) === "integer") {
162 fail($method, false, $result);
169 // a method to run wiki tests against remote server. tests described at bottom.
170 function run_easy_tests($server, $debug=0, $output = null) {
174 run_test($server, $debug, $output, "wiki.getRPCVersionSupported", '', 1);
176 // getRecentChanges of the last day:
177 // Note: may crash with dba on index.php, not on RPC2.php
178 run_test($server, $debug, $output, "wiki.getRecentChanges", iso8601_encode(time()-86400));
180 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.");
181 run_test($server, $debug, $output, "wiki.getPageVersion", array("HomePage", 1));
182 run_test($server, $debug, $output, "wiki.getPageHTML", "HomePage");
183 run_test($server, $debug, $output, "wiki.getPageHTMLVersion", array("HomePage", 1));
184 run_test($server, $debug, $output, "wiki.getAllPages");
185 run_test($server, $debug, $output, "wiki.getPageInfo", "HomePage");
186 run_test($server, $debug, $output, "wiki.getPageInfoVersion", array("HomePage", 1));
187 run_test($server, $debug, $output, "wiki.listLinks", "HomePage");
189 run_test($server, $debug, $output, "wiki.putPage",
190 array("PutPage", "new PutPage content", "XxXx"),
191 array('code' => 200, 'version' => 1, 'message' => "Page PutPage version 1 created"));
192 run_test($server, $debug, $output, "wiki.putPage",
193 array("PutPage", "new PutPage content", "XxXx"),
194 array('code' => 400, 'version' => 1, 'message' => "Page PutPage unchanged"));
195 run_test($server, $debug, $output, "wiki.putPage",
196 array("PutPage", "new PutPage content", "disallowed"),
197 array('code' => 401, 'version' => 0, 'message' => "no permission for disallowed"));
199 run_test($server, $debug, $output, "wiki.rssPleaseNotify", "HomePage", 0);
200 run_test($server, $debug, $output, "wiki.mailPasswordToUser", ADMIN_USER);
202 run_test($server, $debug, $output, "wiki.titleSearch", "Hom");
205 function run_stress_tests($server, $debug=0, $output=null) {
209 run_no_param_test($server, $debug, $output, "wiki.getRPCVersionSupported");
211 run_test($server, $debug, $output, "wiki.getRecentChanges", iso8601_encode(time()-86400, 1));
215 // a method to display an html form for invoking the script
216 function print_html_form($servers_list) {
219 <h1>Choose an xmlrpc wiki server to run tests against</h1>
222 print_servers_form($servers_list);
225 // some code which determines if we are in form display or response mode.
226 $server_list = get_wiki_servers();
227 $server = get_server_from_user($server_list);
229 $debug = $GLOBALS['HTTP_GET_VARS']['debug'] || $GLOBALS['HTTP_GET_VARS']['start_debug'];
230 $output['version'] = $GLOBALS['HTTP_GET_VARS']['version'];
232 $title = $server['title'];
233 echo "<h2><center>Results for $title</center></h2>";
235 if($GLOBALS['HTTP_GET_VARS']['stress'] == 1) {
236 run_stress_tests($server, $debug, $output);
239 run_easy_tests($server, $debug, $output);
243 echo "<h3>invalid option</h3>";
247 print_html_form($server_list);