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
14 This file is part of, or distributed with, libXMLRPC - a C library for
15 xml-encoded function calls.
17 Author: Dan Libby (dan@libby.com)
18 Epinions.com may be contacted at feedback@epinions-inc.com
22 Copyright 2001 Epinions, Inc.
24 Subject to the following 3 conditions, Epinions, Inc. permits you, free
25 of charge, to (a) use, copy, distribute, modify, perform and display this
26 software and associated documentation files (the "Software"), and (b)
27 permit others to whom the Software is furnished to do so as well.
29 1) The above copyright notice and this permission notice shall be included
30 without modification in all copies or substantial portions of the
33 2) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF
34 ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY
35 IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 PURPOSE OR NONINFRINGEMENT.
38 3) IN NO EVENT SHALL EPINIONS, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
39 SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
40 OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER ARISING, INCLUDING
41 NEGLIGENCE), EVEN IF EPINIONS, INC. IS AWARE OF THE POSSIBILITY OF SUCH
47 # Add root dir to the path
48 if (substr(PHP_OS,0,3) == 'WIN')
49 $cur_dir = str_replace("\\","/", $cur_dir);
50 $rootdir = $cur_dir . '/../../';
51 $ini_sep = substr(PHP_OS,0,3) == 'WIN' ? ';' : ':';
52 $include_path = ini_get('include_path') . $ini_sep . $rootdir . $ini_sep . $rootdir . "lib/pear";
53 ini_set('include_path', $include_path);
55 if ($HTTP_SERVER_VARS["SERVER_NAME"] == 'phpwiki.sourceforge.net') {
56 ini_set('include_path', ini_get('include_path') . ":/usr/share/pear");
58 define('PHPWIKI_NOMAIN', true);
59 # Quiet warnings in IniConfig.php
60 $HTTP_SERVER_VARS['REMOTE_ADDR'] = '127.0.0.1';
61 $HTTP_SERVER_VARS['HTTP_USER_AGENT'] = "PHPUnit";
63 require_once $rootdir.'index.php';
65 // fake a POST request to be able to load our interfaces
66 $save = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_METHOD'];
67 $GLOBALS['HTTP_SERVER_VARS']['REQUEST_METHOD'] = "POST";
68 include($rootdir."lib/XmlRpcServer.php");
69 $GLOBALS['HTTP_SERVER_VARS']['REQUEST_METHOD'] = $save;
70 // now we have $wiki_dmap
72 include("./xmlrpc-servers.php");
74 function match($a, $b) {
76 if (gettype($a) === "array") {
77 foreach ($a as $key => $c) {
85 if ($a !== $b || xmlrpc_get_type($a) !== xmlrpc_get_type($b)) {
92 function pass($method) {
93 echo "<font color=\"green\"><b>pass</b></font> $method()<br>";
96 function fail($method, $sent, $received) {
97 echo "<font color=\"red\"><b>fail</b></font> $method()<br>";
99 echo "<h3>sent</h3><xmp>";
105 echo "<h3>received</h3><xmp>";
111 // this needs to be fixed.
112 function check_if_matches($method, $sent, $received) {
113 if (match($sent, $received)) {
117 fail($method, $sent, $received);
121 function foo($method_name, $args) {
122 xmlrpc_encode_request($method_name, $args);
125 function run_test($server, $debug, $output, $method, $args='', $expected='') {
126 global $HTTP_GET_VARS;
128 if (!is_array($args))
129 $params = $args ? array($args) : array();
132 if (!empty($HTTP_GET_VARS['start_debug'])) // zend ide support
133 $server['uri'] .= "?start_debug=1";
134 $result = xu_rpc_http_concise(array('method' => $method,
136 'host' => $server['host'],
137 'uri' => $server['uri'],
138 'port' => $server['port'],
140 'output' => $output));
141 check_if_matches($method, $expected, $result);
146 // should return non-zero integer
147 function run_no_param_test($server, $debug, $output, $method) {
148 global $HTTP_GET_VARS;
150 if (!empty($HTTP_GET_VARS['start_debug'])) // zend ide support
151 $server['uri'] .= "?start_debug=1";
152 $result = xu_rpc_http_concise(array('method' => $method,
153 'host' => $server['host'],
154 'uri' => $server['uri'],
155 'port' => $server['port'],
157 'output' => $output));
159 if ($result && gettype($result) === "integer") {
163 fail($method, false, $result);
170 // a method to run wiki tests against remote server. tests described at bottom.
171 function run_easy_tests($server, $debug=0, $output = null) {
175 run_test($server, $debug, $output, "wiki.getRPCVersionSupported", '', 1);
177 // getRecentChanges of the last day:
178 // Note: may crash with dba on index.php, not on RPC2.php
179 run_test($server, $debug, $output, "wiki.getRecentChanges", iso8601_encode(time()-86400));
181 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.");
182 run_test($server, $debug, $output, "wiki.getPageVersion", array("HomePage", 1));
183 run_test($server, $debug, $output, "wiki.getPageHTML", "HomePage");
184 run_test($server, $debug, $output, "wiki.getPageHTMLVersion", array("HomePage", 1));
185 run_test($server, $debug, $output, "wiki.getAllPages");
186 run_test($server, $debug, $output, "wiki.getPageInfo", "HomePage");
187 run_test($server, $debug, $output, "wiki.getPageInfoVersion", array("HomePage", 1));
188 run_test($server, $debug, $output, "wiki.listLinks", "HomePage");
190 run_test($server, $debug, $output, "wiki.putPage",
191 array("PutPage", "new PutPage content", "XxXx"),
192 array('code' => 200, 'version' => 1, 'message' => "Page PutPage version 1 created"));
193 run_test($server, $debug, $output, "wiki.putPage",
194 array("PutPage", "new PutPage content", "XxXx"),
195 array('code' => 400, 'version' => 1, 'message' => "Page PutPage unchanged"));
196 run_test($server, $debug, $output, "wiki.putPage",
197 array("PutPage", "new PutPage content", "disallowed"),
198 array('code' => 401, 'version' => 0, 'message' => "no permission for disallowed"));
200 run_test($server, $debug, $output, "wiki.rssPleaseNotify", "HomePage", 0);
201 run_test($server, $debug, $output, "wiki.mailPasswordToUser", ADMIN_USER);
203 run_test($server, $debug, $output, "wiki.titleSearch", "Hom");
206 function run_stress_tests($server, $debug=0, $output=null) {
210 run_no_param_test($server, $debug, $output, "wiki.getRPCVersionSupported");
212 run_test($server, $debug, $output, "wiki.getRecentChanges", iso8601_encode(time()-86400, 1));
216 // a method to display an html form for invoking the script
217 function print_html_form($servers_list) {
220 <h1>Choose an xmlrpc wiki server to run tests against</h1>
223 print_servers_form($servers_list);
226 // some code which determines if we are in form display or response mode.
227 $server_list = get_wiki_servers();
228 $server = get_server_from_user($server_list);
230 $debug = $GLOBALS['HTTP_GET_VARS']['debug'] || $GLOBALS['HTTP_GET_VARS']['start_debug'];
231 $output['version'] = $GLOBALS['HTTP_GET_VARS']['version'];
233 $title = $server['title'];
234 echo "<h2><center>Results for $title</center></h2>";
236 if($GLOBALS['HTTP_GET_VARS']['stress'] == 1) {
237 run_stress_tests($server, $debug, $output);
240 run_easy_tests($server, $debug, $output);
244 echo "<h3>invalid option</h3>";
248 print_html_form($server_list);