From b166f84da53c6cbfc0f8de76006a51cb3027f1b7 Mon Sep 17 00:00:00 2001 From: gggeek Date: Mon, 23 Jan 2023 15:00:48 +0000 Subject: [PATCH] more tests --- demo/server/methodProviders/wrapper.php | 22 +++++++++++++++++++- demo/vardemo.php | 4 +++- tests/08ServerTest.php | 22 +++++++++++++++++++- tests/09HTTPTest.php | 2 +- tests/10DemofilesTest.php | 27 ++++++++++++++++++++++--- tests/11DebuggerTest.php | 2 +- tests/WebTestCase.php | 11 ++++++++++ 7 files changed, 82 insertions(+), 8 deletions(-) diff --git a/demo/server/methodProviders/wrapper.php b/demo/server/methodProviders/wrapper.php index e128ff0c..3a9081bc 100644 --- a/demo/server/methodProviders/wrapper.php +++ b/demo/server/methodProviders/wrapper.php @@ -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"), + ), ) ); diff --git a/demo/vardemo.php b/demo/vardemo.php index d693d760..20a6b228 100644 --- a/demo/vardemo.php +++ b/demo/vardemo.php @@ -22,7 +22,9 @@ $v = new PhpXmlRpc\Value(1234.5678, 'double'); output("Double:
" . htmlentities($v->serialize()) . "
"); $v = new PhpXmlRpc\Value(time(), 'dateTime.iso8601'); -output("Datetime:
" . htmlentities($v->serialize()) . "
"); +output("Datetime (from timestamp):
" . htmlentities($v->serialize()) . "
"); +$v = new PhpXmlRpc\Value(new DateTime(), 'dateTime.iso8601'); +output("Datetime (from php DateTime):
" . htmlentities($v->serialize()) . "
"); $v = new PhpXmlRpc\Value('hello world', 'base64'); output("Base64:
" . htmlentities($v->serialize()) . "
"); diff --git a/tests/08ServerTest.php b/tests/08ServerTest.php index ff4c320a..44f6deee 100644 --- a/tests/08ServerTest.php +++ b/tests/08ServerTest.php @@ -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, diff --git a/tests/09HTTPTest.php b/tests/09HTTPTest.php index 2af8decb..52f1b855 100644 --- a/tests/09HTTPTest.php +++ b/tests/09HTTPTest.php @@ -24,7 +24,7 @@ class HTTPTest extends ServerTest public function getSingleHttpTestMethods() { $unsafeMethods = array( - 'testCatchExceptions', 'testUtf8Method', 'testServerComments', + 'testCatchExceptions', 'testCatchErrors', 'testUtf8Method', 'testServerComments', 'testExoticCharsetsRequests', 'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3', 'testWrapInexistentUrl', ); diff --git a/tests/10DemofilesTest.php b/tests/10DemofilesTest.php index 05868ba9..1dfef489 100644 --- a/tests/10DemofilesTest.php +++ b/tests/10DemofilesTest.php @@ -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('faultCode', $page); $this->assertRegexp('#10(5|3)#', $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('faultCode', $page); $this->assertRegexp('#10(5|3)#', $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() diff --git a/tests/11DebuggerTest.php b/tests/11DebuggerTest.php index d67129f7..c5310a09 100644 --- a/tests/11DebuggerTest.php +++ b/tests/11DebuggerTest.php @@ -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']); } diff --git a/tests/WebTestCase.php b/tests/WebTestCase.php index f4818b30..190b971b 100644 --- a/tests/WebTestCase.php +++ b/tests/WebTestCase.php @@ -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; + } } -- 2.47.0