* xmlrpcs.inc, xmlrpcs.inc: remove code that was left for compatibility with php...
[plcapi.git] / test / testsuite.php
index 5784be4..d2e56d4 100644 (file)
@@ -222,6 +222,20 @@ And turned it into nylon';
                        }
                }
 
+        function testDateTime()
+        {
+            $time = time();
+            $t1 = new xmlrpcval($time, 'dateTime.iso8601');
+            $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601');
+            $this->assertEquals($t1->serialize(), $t2->serialize());
+            if (class_exists('DateTime'))
+            {
+                $datetime = new DateTime();
+                $t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601');
+                $this->assertEquals($t1->serialize(), $t3->serialize());
+            }
+        }
+
                function testCountEntities()
                {
                        $sendstring = "h'fd>onc>>l>>rw&bpu>q>e<v&gxs<ytjzkami<";
@@ -446,6 +460,19 @@ And turned it into nylon';
                        }
                }
 
+           function testCatchExceptions()
+           {
+               global $URI;
+               $f = new xmlrpcmsg('examples.raiseException', array(
+                       new xmlrpcval('whatever', 'string')
+               ));
+               $v = $this->send($f, $GLOBALS['xmlrpcerr']['server_error']);
+               $this->client->path = $URI.'?EXCEPTION_HANDLING=1';
+               $v = $this->send($f, 1);
+               $this->client->path = $URI.'?EXCEPTION_HANDLING=2';
+               $v = $this->send($f, $GLOBALS['xmlrpcerr']['invalid_return']);
+           }
+
                function testZeroParams()
                {
                        $f = new xmlrpcmsg('system.listMethods');
@@ -528,7 +555,7 @@ And turned it into nylon';
                                'c4' => array('value' => 'c4', 'expires' => time()+60*60*24*30, 'path' => '/'),
                                'c5' => array('value' => 'c5', 'expires' => time()+60*60*24*30, 'path' => '/', 'domain' => 'localhost'),
                        );
-                       $cookiesval =& php_xmlrpc_encode($cookies);
+                       $cookiesval = php_xmlrpc_encode($cookies);
                        $f=new xmlrpcmsg('examples.setcookies',array($cookiesval));
                        $r=$this->send($f, 0, true);
                        if($r)
@@ -603,7 +630,7 @@ And turned it into nylon';
                        global $failed_tests;
                        foreach(get_class_methods('LocalhostTests') as $meth)
                        {
-                               if(strpos($meth, 'test') === 0 && $meth != 'testHttps')
+                               if(strpos($meth, 'test') === 0 && $meth != 'testHttps' && $meth != 'testCatchExceptions')
                                {
                                        if (!isset($failed_tests[$meth]))
                                                $this->$meth();
@@ -1241,6 +1268,21 @@ $f = '<?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><valu
                        $r = $m->parseresponse($s);
                        $v = $r->value();
                        $this->assertequals('null', $v->scalartyp());
+                   // test with the apache version: EX:NIL
+                   $GLOBALS['xmlrpc_null_apache_encoding'] = true;
+                   // serialization
+                   $v = new xmlrpcval('hello', 'null');
+                   $s = $v->serialize();
+                   $this->assertequals(1, preg_match( '#<value><ex:nil/></value>#', $s ));
+                   // deserialization
+            $r = new xmlrpcresp($v);
+            $s = $r->serialize();
+            $r = $m->parseresponse($s);
+            $v = $r->value();
+            $this->assertequals('null', $v->scalartyp());
+                   $GLOBALS['xmlrpc_null_extension'] = false;
+                   $r = $m->parseresponse($s);
+                   $this->assertequals(2, $r->faultCode());
                }
 
                function TestLocale()
@@ -1317,8 +1359,8 @@ $f = '<?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><valu
                        $this->client->path = $URI;
 
                        $r = $this->client->send($f, 5, 'http11');
-                       $r = $r->value();
-                       $this->assertEquals('hello', $r->scalarVal());
+                       $ro = $r->value();
+                       $this->assertEquals('hello', $ro->scalarVal());
                }
        }
 
@@ -1330,11 +1372,13 @@ $f = '<?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><valu
        $suite->addTest(new LocalhostTests('testBoolean'));
        $suite->addTest(new LocalhostTests('testCountEntities'));
        $suite->addTest(new LocalhostTests('testBase64'));
+       $suite->addTest(new LocalhostTests('testDateTime'));
        $suite->addTest(new LocalhostTests('testServerMulticall'));
        $suite->addTest(new LocalhostTests('testClientMulticall1'));
        $suite->addTest(new LocalhostTests('testClientMulticall2'));
        $suite->addTest(new LocalhostTests('testClientMulticall3'));
        $suite->addTest(new LocalhostTests('testCatchWarnings'));
+       $suite->addTest(new LocalhostTests('testCatchExceptions'));
        $suite->addTest(new LocalhostTests('testZeroParams'));
        $suite->addTest(new LocalhostTests('testCodeInjectionServerSide'));
        $suite->addTest(new LocalhostTests('testAutoRegisteredFunction'));
@@ -1410,7 +1454,7 @@ $f = '<?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><valu
                echo "<h3>Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."</h3>\n";
                echo '<h3>Running '.$suite->testCount().' tests (some of which are multiple) against servers: http://'.htmlspecialchars($LOCALSERVER.$URI).' and https://'.htmlspecialchars($HTTPSSERVER.$HTTPSURI)."\n ...</h3>\n";
                flush();
-           ob_flush();
+           @ob_flush();
        }
        else
        {