tests
authorgggeek <giunta.gaetano@gmail.com>
Fri, 11 Dec 2020 11:45:46 +0000 (11:45 +0000)
committergggeek <giunta.gaetano@gmail.com>
Fri, 11 Dec 2020 11:45:46 +0000 (11:45 +0000)
17 files changed:
debugger/action.php
debugger/controller.php
debugger/index.php
demo/client/_bootstrap.php [new file with mode: 0644]
demo/client/agesort.php
demo/client/getstatename.php
demo/client/introspect.php
demo/client/mail.php
demo/client/proxy.php
demo/client/which.php
demo/client/wrap.php
demo/server/_bootstrap.php [new file with mode: 0644]
demo/server/discuss.php
demo/server/proxy.php
demo/server/server.php
tests/LocalFileTestCase.php
tests/parse_args.php

index 216c2c3..0474bfe 100644 (file)
@@ -14,7 +14,7 @@ header('Content-Type: text/html; charset=utf-8');
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
 <head>
     <title>XMLRPC Debugger</title>
     <meta name="robots" content="index,nofollow"/>
index 94c7410..46c1759 100644 (file)
@@ -26,7 +26,7 @@ $editorlibs = '../../phpjsrpc/lib/';
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
 <head>
     <title>XMLRPC Debugger</title>
     <meta name="robots" content="index,nofollow"/>
index eff10ea..a8c0b55 100644 (file)
@@ -9,7 +9,7 @@ if (isset($_GET['run'])) {
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
-<html>
+<html lang="en">
 <head>
     <title>XMLRPC Debugger</title>
 </head>
diff --git a/demo/client/_bootstrap.php b/demo/client/_bootstrap.php
new file mode 100644 (file)
index 0000000..d705d64
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Hackish code used to make the demos both viewable as source, runnable, and viewable as html
+ */
+
+// Make errors visible
+ini_set('display_errors', true);
+error_reporting(E_ALL);
+
+if (isset($_GET['showSource']) && $_GET['showSource']) {
+    $file = debug_backtrace()[0]['file'];
+    highlight_file($file);
+    die();
+}
+
+// Use the custom class autoloader. These two lines not needed when the phpxmlrpc library is installed using Composer
+include_once __DIR__ . '/../../src/Autoloader.php';
+PhpXmlRpc\Autoloader::register();
+
+// Let unit tests run against localhost, 'plain' demos against a known public server
+if (isset($_SERVER['LOCALSERVER'])) {
+    define('XMLRPCSERVER', 'http://'.$_SERVER['LOCALSERVER'].'/demo/server/server.php');
+} else {
+    define('XMLRPCSERVER', 'http://phpxmlrpc.sourceforge.net/server.php');
+}
index 60cc4b8..48011b3 100644 (file)
@@ -1,4 +1,4 @@
-<html>
+<?php require_once __DIR__ . "/_bootstrap.php"; ?><html lang="en">
 <head><title>xmlrpc - Agesort demo</title></head>
 <body>
 <h1>Agesort demo</h1>
@@ -7,12 +7,9 @@
 
 <h3>The source code demonstrates basic lib usage, including handling of xmlrpc arrays and structs</h3>
 
-<p></p>
+<p>You can see the source to this page here: <a href="agesort.php?showSource=1">agesort.php</a></p>
 <?php
 
-include_once __DIR__ . "/../../src/Autoloader.php";
-PhpXmlRpc\Autoloader::register();
-
 $inAr = array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);
 print "This is the input data:<br/><pre>";
 foreach ($inAr as $key => $val) {
@@ -20,7 +17,7 @@ foreach ($inAr as $key => $val) {
 }
 print "</pre>";
 
-// create parameters from the input array: an xmlrpc array of xmlrpc structs
+// Create parameters from the input array: an xmlrpc array of xmlrpc structs
 $p = array();
 foreach ($inAr as $key => $val) {
     $p[] = new PhpXmlRpc\Value(
@@ -36,7 +33,7 @@ print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v
 
 // create client and message objects
 $req = new PhpXmlRpc\Request('examples.sortByAge', array($v));
-$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
+$client = new PhpXmlRpc\Client(XMLRPCSERVER);
 
 // set maximum debug level, to have the complete communication printed to screen
 $client->setDebug(2);
index 69ce3e0..304bf25 100644 (file)
@@ -1,4 +1,4 @@
-<html>
+<?php require_once __DIR__ . "/_bootstrap.php"; ?><html lang="en">
 <head><title>xmlrpc - Getstatename demo</title></head>
 <body>
 <h1>Getstatename demo</h1>
@@ -6,10 +6,9 @@
 <h2>Send a U.S. state number to the server and get back the state name</h2>
 
 <h3>The code demonstrates usage of automatic encoding/decoding of php variables into xmlrpc values</h3>
-<?php
 
-include_once __DIR__ . "/../../src/Autoloader.php";
-PhpXmlRpc\Autoloader::register();
+<p>You can see the source to this page here: <a href="getstatename.php?showSource=1">getstatename.php</a></p>
+<?php
 
 if (isset($_POST["stateno"]) && $_POST["stateno"] != "") {
     $stateNo = (integer)$_POST["stateno"];
@@ -18,13 +17,13 @@ if (isset($_POST["stateno"]) && $_POST["stateno"] != "") {
         array($encoder->encode($stateNo))
     );
     print "Sending the following request:<pre>\n\n" . htmlentities($req->serialize()) . "\n\n</pre>Debug info of server data follows...\n\n";
-    $client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
+    $client = new PhpXmlRpc\Client(XMLRPCSERVER);
     $client->setDebug(1);
     $r = $client->send($req);
     if (!$r->faultCode()) {
         $v = $r->value();
         print "<br/>State number <b>" . $stateNo . "</b> is <b>"
-            . htmlspecialchars($encoder->decode($v)) . "</b><br/>";
+            . htmlspecialchars($encoder->decode($v)) . "</b><br/><br/>";
     } else {
         print "An error occurred: ";
         print "Code: " . htmlspecialchars($r->faultCode())
index 478d43b..57df918 100644 (file)
@@ -1,14 +1,12 @@
-<html>
+<?php require_once __DIR__ . "/_bootstrap.php"; ?><html lang="en">
 <head><title>xmlrpc - Introspect demo</title></head>
 <body>
 <h1>Introspect demo</h1>
 <h2>Query server for available methods and their description</h2>
 <h3>The code demonstrates usage of multicall and introspection methods</h3>
+<p>You can see the source to this page here: <a href="introspect.php?showSource=1">introspect.php</a></p>
 <?php
 
-include_once __DIR__ . "/../../src/Autoloader.php";
-PhpXmlRpc\Autoloader::register();
-
 function display_error($r)
 {
     print "An error occurred: ";
@@ -16,7 +14,7 @@ function display_error($r)
         . " Reason: '" . $r->faultString() . "'<br/>";
 }
 
-$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
+$client = new PhpXmlRpc\Client(XMLRPCSERVER);
 
 // First off, let's retrieve the list of methods available on the remote server
 print "<h3>methods available at http://" . $client->server . $client->path . "</h3>\n";
index 7ac6e78..32a4a1f 100644 (file)
@@ -1,11 +1,4 @@
-<?php
-// Allow users to see the source of this file even if PHP is not configured for it
-if (isset($_GET['showSource']) && $_GET['showSource']) {
-    highlight_file(__FILE__);
-    die();
-}
-?>
-<html>
+<?php require_once __DIR__ . "/_bootstrap.php"; ?><html lang="en">
 <head><title>xmlrpc - Mail demo</title></head>
 <body>
 <h1>Mail demo</h1>
@@ -14,17 +7,18 @@ if (isset($_GET['showSource']) && $_GET['showSource']) {
     When you press <kbd>Send</kbd> this page will reload, showing you the XML-RPC request sent to the host server, the
     XML-RPC response received and the internal evaluation done by the PHP implementation.</p>
 
-<p>You can find the source to this page here: <a href="mail.php?showSource=1">mail.php</a><br/>
+<p>You can see the source to this page here: <a href="mail.php?showSource=1">mail.php</a><br/>
     And the source to a functionally identical mail-by-XML-RPC server in the file <a
         href="../server/server.php?showSource=1">server.php</a> included with the library (look for the 'mail_send'
     method)</p>
 <?php
 
+// Use the custom class autoloader. These two lines not needed when the phpxmlrpc library is installed using Composer
 include_once __DIR__ . "/../../src/Autoloader.php";
 PhpXmlRpc\Autoloader::register();
 
 if (isset($_POST["mailto"]) && $_POST["mailto"]) {
-    $server = "http://phpxmlrpc.sourceforge.net/server.php";
+    $server = XMLRPCSERVER;
     $req = new PhpXmlRpc\Request('mail.send', array(
         new PhpXmlRpc\Value($_POST["mailto"]),
         new PhpXmlRpc\Value($_POST["mailsub"]),
index a8c696c..88be2f1 100644 (file)
@@ -1,14 +1,12 @@
-<html>
+<?php require_once __DIR__ . "/_bootstrap.php"; ?><html lang="en">
 <head><title>xmlrpc - Proxy demo</title></head>
 <body>
 <h1>proxy demo</h1>
 <h2>Query server using a 'proxy' object</h2>
 <h3>The code demonstrates usage for the terminally lazy. For a more complete proxy, look at at the Wrapper class</h3>
+<p>You can see the source to this page here: <a href="proxy.php?showSource=1">proxy.php</a></p>
 <?php
 
-include_once __DIR__ . "/../../src/Autoloader.php";
-PhpXmlRpc\Autoloader::register();
-
 class PhpXmlRpcProxy
 {
     protected $client;
@@ -50,11 +48,10 @@ class PhpXmlRpcProxy
             return $resp->value();
         }
     }
-
 }
 
 $stateNo = rand(1, 51);
-$proxy = new PhpXmlRpcProxy(new \PhpXmlRpc\Client('http://phpxmlrpc.sourceforge.net/server.php'));
+$proxy = new PhpXmlRpcProxy(new \PhpXmlRpc\Client(XMLRPCSERVER));
 $stateName = $proxy->getStateName($stateNo);
 
 echo "State $stateNo is ".htmlspecialchars($stateName);
index 5d33215..6664e2f 100644 (file)
@@ -1,20 +1,19 @@
-<html>
+<?php require_once __DIR__ . "/_bootstrap.php"; ?><html lang="en">
 <head><title>xmlrpc - Which toolkit demo</title></head>
 <body>
 <h1>Which toolkit demo</h1>
 <h2>Query server for toolkit information</h2>
 <h3>The code demonstrates usage of the PhpXmlRpc\Encoder class</h3>
+<p>You can see the source to this page here: <a href="which.php?showSource=1">which.php</a></p>
 <?php
 
-include_once __DIR__ . "/../../src/Autoloader.php";
-PhpXmlRpc\Autoloader::register();
-
 $req = new PhpXmlRpc\Request('interopEchoTests.whichToolkit', array());
-$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
+$client = new PhpXmlRpc\Client(XMLRPCSERVER);
 $resp = $client->send($req);
 if (!$resp->faultCode()) {
     $encoder = new PhpXmlRpc\Encoder();
     $value = $encoder->decode($resp->value());
+    print "Toolkit info:<br/>\n";
     print "<pre>";
     print "name: " . htmlspecialchars($value["toolkitName"]) . "\n";
     print "version: " . htmlspecialchars($value["toolkitVersion"]) . "\n";
index c13c55d..88d6a8d 100644 (file)
@@ -1,4 +1,4 @@
-<html>
+<?php require_once __DIR__ . "/_bootstrap.php"; ?><html lang="en">
 <head><title>xmlrpc - Webservice wrappper demo</title></head>
 <body>
 <h1>Webservice wrappper demo</h1>
     2) wrapping of remote methods into php functions<br/>
     See also proxy.php for an alternative take
 </h3>
+<p>You can see the source to this page here: <a href="wrap.php?showSource=1">wrap.php</a></p>
 <?php
 
-include_once __DIR__ . "/../../src/Autoloader.php";
-PhpXmlRpc\Autoloader::register();
-
-$client = new PhpXmlRpc\Client("http://phpxmlrpc.sourceforge.net/server.php");
+$client = new PhpXmlRpc\Client(XMLRPCSERVER);
 $client->return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
 $resp = $client->send(new PhpXmlRpc\Request('system.listMethods'));
 if ($resp->faultCode()) {
@@ -44,8 +42,9 @@ if ($resp->faultCode()) {
     if ($callable) {
         echo "Now testing function for remote method to convert U.S. state number into state name";
         $stateNum = rand(1, 51);
-        // the 2nd parameter gets added to the closure - it is teh debug level to be used for the client
+        // the 2nd parameter gets added to the closure - it is the debug level to be used for the client
         $stateName = $callable($stateNum, 2);
+        echo "State $stateNum is ".htmlspecialchars($stateName);
     }
 }
 ?>
diff --git a/demo/server/_bootstrap.php b/demo/server/_bootstrap.php
new file mode 100644 (file)
index 0000000..b16296e
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Hackish code used to make the demos both viewable as source, runnable, and viewable as html
+ */
+
+// Make errors visible
+ini_set('display_errors', true);
+error_reporting(E_ALL);
+
+if (isset($_GET['showSource']) && $_GET['showSource']) {
+    $file = debug_backtrace()[0]['file'];
+    highlight_file($file);
+    die();
+}
+
+// Use the custom class autoloader. These two lines not needed when the phpxmlrpc library is installed using Composer
+include_once __DIR__ . '/../../src/Autoloader.php';
+PhpXmlRpc\Autoloader::register();
index 5ecbe63..d187695 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-include_once __DIR__ . "/../../vendor/autoload.php";
+require_once __DIR__ . "/_bootstrap.php";
 
 use PhpXmlRpc\Value;
 
index a1b702e..812584f 100644 (file)
@@ -9,8 +9,7 @@
  * @license code licensed under the BSD License: see file license.txt
  */
 
-include_once __DIR__ . "/../../src/Autoloader.php";
-PhpXmlRpc\Autoloader::register();
+require_once __DIR__ . "/_bootstrap.php";
 
 /**
  * Forward an xmlrpc request to another server, and return to client the response received.
@@ -58,8 +57,8 @@ function forward_request($req)
 
     // build call for remote server
     /// @todo find a way to forward client info (such as IP) to server, either
-    /// - as xml comments in the payload, or
-    /// - using std http header conventions, such as X-forwarded-for...
+    ///       - as xml comments in the payload, or
+    ///       - using std http header conventions, such as X-forwarded-for...
     $reqMethod = $encoder->decode($req->getParam(1));
     $pars = $req->getParam(2);
     $req = new PhpXmlRpc\Request($reqMethod);
index d836674..6e9fdf9 100644 (file)
@@ -9,13 +9,7 @@
  * Please do not copy this file verbatim into your production server.
  **/
 
-// give user a chance to see the source for this server instead of running the services
-if ($_SERVER['REQUEST_METHOD'] != 'POST' && isset($_GET['showSource'])) {
-    highlight_file(__FILE__);
-    die();
-}
-
-include_once __DIR__ . "/../../vendor/autoload.php";
+require_once __DIR__ . "/_bootstrap.php";
 
 // out-of-band information: let the client manipulate the server operations.
 // we do this to help the testsuite script: do not reproduce in production!
index 6ec48b3..13160c7 100644 (file)
@@ -4,8 +4,6 @@ include_once __DIR__ . '/parse_args.php';
 
 include_once __DIR__ . '/PolyfillTestCase.php';
 
-use PHPUnit\Framework\TestResult;
-
 abstract class PhpXmlRpc_LocalFileTestCase extends PhpXmlRpc_PolyfillTestCase
 {
     public $args = array();
index 4ef568d..f9c4562 100644 (file)
@@ -7,12 +7,11 @@
  * @param string  LOCALSERVER
  * @param string  URI
  * @param string  HTTPSSERVER
- * @param string  HTTPSSURI
- * @param string  PROXY
- * @param string  NOPROXY
+ * @param string  HTTPSURI
  * @param bool    HTTPSIGNOREPEER
  * @param int     HTTPSVERIFYHOST
  * @param int     SSLVERSION
+ * @param string  PROXYSERVER
  *
  * @copyright (C) 2007-2020 G. Giunta
  * @license code licensed under the BSD License: see file license.txt
@@ -24,13 +23,12 @@ class argParser
         $args = array(
             'DEBUG' => 0,
             'LOCALSERVER' => 'localhost',
-            'HTTPSSERVER' => 'gggeek.ssl.altervista.org',
+            'HTTPSSERVER' => 'gggeek.altervista.org',
             'HTTPSURI' => '/sw/xmlrpc/demo/server/server.php',
             'HTTPSIGNOREPEER' => false,
             'HTTPSVERIFYHOST' => 2,
             'SSLVERSION' => 0,
             'PROXYSERVER' => null,
-            //'NOPROXY' => false,
             'LOCALPATH' => __DIR__,
         );
 
@@ -83,10 +81,6 @@ class argParser
                 $args['PROXYPORT'] = 8080;
             }
         }
-        // used to silence testsuite warnings about proxy code not being tested
-        //if (isset($NOPROXY)) {
-        //    $args['NOPROXY'] = true;
-        //}
         if (!isset($URI)) {
             // GUESTIMATE the url of local demo server
             // play nice to php 3 and 4-5 in retrieving URL of server.php