two fixes for 'load method synopsis' action in the debugger; add tests for NIL values...
authorgggeek <giunta.gaetano@gmail.com>
Sat, 30 May 2015 09:04:18 +0000 (11:04 +0200)
committergggeek <giunta.gaetano@gmail.com>
Sat, 30 May 2015 09:04:18 +0000 (11:04 +0200)
NEWS
debugger/action.php
demo/server/server.php
tests/3LocalhostTest.php

diff --git a/NEWS b/NEWS
index 0a3a9a3..d941bcf 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -60,6 +60,11 @@ PLEASE READ CAREFULLY THE NOTES BELOW to insure a smooth upgrade.
 * fixed: the debugger would fail sending a request with ISO-8859-1 payload (it missed the character set declaration).
   It would have a hard time coping with ISO-8859-1 in other fields, such as e.g. the remote method name
 
+* fixed: the debugger would generate a bad payload via the 'load method synopsis' button for signatures containing NULLs
+
+* fixed: the debugger would generate a bad payload via the 'load method synopsis' button for methods with multiple
+  signatures
+
 * improved: the debugger is displayed using UTF-8, making it more useful to debug any kind of service
 
 * improved: echo all debug messages even when there are characters in them which php deems to be in a wrong encoding;
index 05cc99a..18d9295 100644 (file)
@@ -350,12 +350,13 @@ if ($action) {
                         $desc = "-";
                     }
                     echo "<tr><td class=\"evenrow\">Description</td><td colspan=\"3\" class=\"evenrow\">$desc</td></tr>\n";
-                    $payload = "";
-                    $alt_payload = "";
+
                     if ($r2->kindOf() != "array") {
                         echo "<tr><td class=\"oddrow\">Signature</td><td class=\"oddrow\">Unknown</td><td class=\"oddrow\">&nbsp;</td></tr>\n";
                     } else {
                         for ($i = 0; $i < $r2->arraysize(); $i++) {
+                            $payload = "";
+                            $alt_payload = "";
                             if ($i + 1 % 2) {
                                 $class = ' class="oddrow"';
                             } else {
@@ -371,9 +372,13 @@ if ($action) {
                                         $y = $x->arraymem($k);
                                         echo htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding);
                                         if ($wstype != 1) {
+                                            $type = $y->scalarval();
+                                            if ($type == 'null') {
+                                                $type = 'nil';
+                                            }
                                             $payload = $payload . '<param><value><' .
-                                                htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
-                                                '></' . htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
+                                                htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
+                                                '></' . htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
                                                 "></value></param>\n";
                                         }
                                         $alt_payload .= $y->scalarval();
index 1fdd49b..180a108 100644 (file)
@@ -186,6 +186,23 @@ $moreSignatures = $wrapper->wrapPhpClass($c, array('prefix' => 'tests.', 'method
 
 $returnObj_sig =  $wrapper->wrapPhpFunction(array($c, 'returnObject'), '', array('encode_php_objs' => true));
 
+// used to test signatures with NULL params
+$findstate12_sig = array(
+    array(Value::$xmlrpcString, Value::$xmlrpcInt, Value::$xmlrpcNull),
+    array(Value::$xmlrpcString, Value::$xmlrpcNull, Value::$xmlrpcInt),
+);
+
+function findStateWithNulls($req)
+{
+    $a = $req->getParam(0);
+    $b = $req->getParam(1);
+
+    if ($a->scalartyp() == Value::$xmlrpcNull)
+        return new PhpXmlRpc\Response(new Value(inner_findstate($b->scalarval())));
+    else
+        return new PhpXmlRpc\Response(new Value(inner_findstate($a->scalarval())));
+}
+
 $addtwo_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcInt, Value::$xmlrpcInt));
 $addtwo_doc = 'Add two integers together and return the result';
 function addTwo($req)
@@ -909,11 +926,20 @@ $signatures = array(
     'tests.getStateName.10' => $findstate10_sig,
     'tests.getStateName.11' => $findstate11_sig,
 
+    'tests.getStateName.12' => array(
+        "function" => "findStateWithNulls",
+        "signature" => $findstate12_sig,
+        "docstring" => $findstate_doc,
+    ),
+
     'tests.returnPhpObject' => $returnObj_sig,
 );
 
 $signatures = array_merge($signatures, $moreSignatures);
 
+// enable support for the NULL extension
+PhpXmlRpc\PhpXmlRpc::$xmlrpc_null_extension = true;
+
 $s = new PhpXmlRpc\Server($signatures, false);
 $s->setdebug(3);
 $s->compress_response = true;
index 4b721d6..a1f7dbf 100644 (file)
@@ -112,6 +112,12 @@ class LocalhostTest extends PHPUnit_Framework_TestCase
         }
     }
 
+    /**
+     * @param PhpXmlRpc\Request|array $msg
+     * @param int|array $errorCode
+     * @param bool $returnResponse
+     * @return mixed|\PhpXmlRpc\Response|\PhpXmlRpc\Response[]|\PhpXmlRpc\Value|string|void
+     */
     protected function send($msg, $errorCode = 0, $returnResponse = false)
     {
         if ($this->collectCodeCoverageInformation) {
@@ -546,6 +552,30 @@ And turned it into nylon';
         $v = $this->send($f);
     }
 
+    public function testNullParams()
+    {
+        $f = new xmlrpcmsg('tests.getStateName.12', array(
+            new xmlrpcval('whatever', 'null'),
+            new xmlrpcval(23, 'int'),
+        ));
+        $v = $this->send($f);
+        if ($v) {
+            $this->assertEquals('Michigan', $v->scalarval());
+        }
+        $f = new xmlrpcmsg('tests.getStateName.12', array(
+            new xmlrpcval(23, 'int'),
+            new xmlrpcval('whatever', 'null'),
+        ));
+        $v = $this->send($f);
+        if ($v) {
+            $this->assertEquals('Michigan', $v->scalarval());
+        }
+        $f = new xmlrpcmsg('tests.getStateName.12', array(
+            new xmlrpcval(23, 'int')
+        ));
+        $v = $this->send($f, array($GLOBALS['xmlrpcerr']['incorrect_params']));
+    }
+
     public function testCodeInjectionServerSide()
     {
         $f = new xmlrpcmsg('system.MethodHelp');