more tests
authorgggeek <giunta.gaetano@gmail.com>
Mon, 23 Jan 2023 15:00:48 +0000 (15:00 +0000)
committergggeek <giunta.gaetano@gmail.com>
Mon, 23 Jan 2023 15:00:48 +0000 (15:00 +0000)
demo/server/methodProviders/wrapper.php
demo/vardemo.php
tests/08ServerTest.php
tests/09HTTPTest.php
tests/10DemofilesTest.php
tests/11DebuggerTest.php
tests/WebTestCase.php

index e128ff0..3a9081b 100644 (file)
@@ -65,7 +65,24 @@ class handlersContainer
      */
     public function exceptionGenerator($req)
     {
-        throw new Exception("it's just a test", 1);
+        $errNum = 1;
+        if ($req->getNumParams()) {
+            $p1 = $req->getParam(0);
+            if ($p1->kindOf() === 'scalar') {
+                $errNum = (int)$p1->scalarval();
+            }
+        }
+        throw new Exception("it's just a test", $errNum);
+    }
+
+    /**
+     * Method used to test catching of errors in the server.
+     * @param PhpXmlRpc\Request $req
+     * @throws Exception
+     */
+    public function errorGenerator($req)
+    {
+        throw new Error("it's just a test", 1);
     }
 
     /**
@@ -167,5 +184,8 @@ return array_merge(
         "tests.raiseException" => array(
             "function" => array($instance, "exceptionGenerator"),
         ),
+        "tests.raiseError" => array(
+            "function" => array($instance, "errorGenerator"),
+        ),
     )
 );
index d693d76..20a6b22 100644 (file)
@@ -22,7 +22,9 @@ $v = new PhpXmlRpc\Value(1234.5678, 'double');
 output("Double: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
 
 $v = new PhpXmlRpc\Value(time(), 'dateTime.iso8601');
-output("Datetime: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
+output("Datetime (from timestamp): <PRE>" . htmlentities($v->serialize()) . "</PRE>");
+$v = new PhpXmlRpc\Value(new DateTime(), 'dateTime.iso8601');
+output("Datetime (from php DateTime): <PRE>" . htmlentities($v->serialize()) . "</PRE>");
 
 $v = new PhpXmlRpc\Value('hello world', 'base64');
 output("Base64: <PRE>" . htmlentities($v->serialize()) . "</PRE>");
index ff4c320..44f6dee 100644 (file)
@@ -687,11 +687,31 @@ And turned it into nylon';
 
     public function testCatchExceptions()
     {
+        // this tests for the server to catch exceptions with erro  code 0
         $m = new xmlrpcmsg('tests.raiseException', array(
-            new xmlrpcval('whatever', 'string'),
+            new xmlrpcval(0, 'int'),
+        ));
+        $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
+
+        // these test for the different server exception catching modes
+        $m = new xmlrpcmsg('tests.raiseException', array(
+            new xmlrpcval(3, 'int'),
         ));
         $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
         $this->addQueryParams(array('EXCEPTION_HANDLING' => 1));
+        $v = $this->send($m, 3); // the error code of the expected exception
+        $this->addQueryParams(array('EXCEPTION_HANDLING' => 2));
+        // depending on whether display_errors is ON or OFF on the server, we will get back a different error here,
+        // as php will generate an http status code of either 200 or 500...
+        $v = $this->send($m, array($GLOBALS['xmlrpcerr']['invalid_return'], $GLOBALS['xmlrpcerr']['http_error']));
+    }
+
+    public function testCatchErrors()
+    {
+        // these test for the different server error catching modes
+        $m = new xmlrpcmsg('tests.raiseError');
+        $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
+        $this->addQueryParams(array('EXCEPTION_HANDLING' => 1));
         $v = $this->send($m, 1); // the error code of the expected exception
         $this->addQueryParams(array('EXCEPTION_HANDLING' => 2));
         // depending on whether display_errors is ON or OFF on the server, we will get back a different error here,
index 2af8dec..52f1b85 100644 (file)
@@ -24,7 +24,7 @@ class HTTPTest extends ServerTest
     public function getSingleHttpTestMethods()
     {
         $unsafeMethods = array(
-            'testCatchExceptions', 'testUtf8Method', 'testServerComments',
+            'testCatchExceptions', 'testCatchErrors', 'testUtf8Method', 'testServerComments',
             'testExoticCharsetsRequests', 'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3',
             'testWrapInexistentUrl',
         );
index 05868ba..1dfef48 100644 (file)
@@ -14,7 +14,7 @@ class DemoFilesTest extends PhpXmlRpc_WebTestCase
         $this->args = argParser::getArgs();
 
         // assumes HTTPURI to be in the form /tests/index.php?etc...
-        $this->baseUrl = $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
+        $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
         $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
     }
 
@@ -75,18 +75,39 @@ class DemoFilesTest extends PhpXmlRpc_WebTestCase
 
     public function testCodegenServer()
     {
-        /// @todo add a couple of proper xmlrpc calls, too
         $page = $this->request('?demo=server/codegen.php');
         $this->assertStringContainsString('<name>faultCode</name>', $page);
         $this->assertRegexp('#<int>10(5|3)</int>#', $page);
+
+        $c = $this->getClient('?demo=server/codegen.php');
+        $r = $c->send(new \PhpXmlRpc\Request('CommentManager.getComments', array(
+            new \PhpXmlRpc\Value('aCommentId')
+        )));
+        $this->assertEquals(0, $r->faultCode());
     }
 
     public function testDiscussServer()
     {
-        /// @todo add a couple of proper xmlrpc calls, too
         $page = $this->request('?demo=server/discuss.php');
         $this->assertStringContainsString('<name>faultCode</name>', $page);
         $this->assertRegexp('#<int>10(5|3)</int>#', $page);
+
+        $c = $this->getClient('?demo=server/discuss.php');
+
+        $r = $c->send(new \PhpXmlRpc\Request('discuss.addComment', array(
+            new \PhpXmlRpc\Value('aCommentId'),
+            new \PhpXmlRpc\Value('aCommentUser'),
+            new \PhpXmlRpc\Value('a Comment')
+        )));
+        $this->assertEquals(0, $r->faultCode());
+        $this->assertGreaterThanOrEqual(1, $r->value()->scalarval());
+
+        $r = $c->send(new \PhpXmlRpc\Request('discuss.getComments', array(
+            new \PhpXmlRpc\Value('aCommentId')
+        )));
+        $this->assertEquals(0, $r->faultCode());
+        $this->assertEquals(0, $r->faultCode());
+        $this->assertGreaterThanOrEqual(1, count($r->value()));
     }
 
     public function testProxyServer()
index d67129f..c5310a0 100644 (file)
@@ -12,7 +12,7 @@ class DebuggerTest extends PhpXmlRpc_WebTestCase
         $this->args = argParser::getArgs();
 
         // assumes HTTPURI to be in the form /tests/index.php?etc...
-        $this->baseUrl = $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
+        $this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
         $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
     }
 
index f4818b3..190b971 100644 (file)
@@ -93,4 +93,15 @@ abstract class PhpXmlRpc_WebTestCase extends PhpXmlRpc_PolyfillTestCase
 
         return $page;
     }
+
+    protected function getClient($path)
+    {
+        $client = new xmlrpc_client($this->baseUrl . $path);
+        if ($this->collectCodeCoverageInformation) {
+            $client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
+        }
+        $client->setAcceptedCompression(false);
+        $client->setDebug($this->args['DEBUG']);
+        return $client;
+    }
 }