tests on php8
[plcapi.git] / tests / 1ParsingBugsTest.php
index ce463f7..4a9f23a 100644 (file)
@@ -7,21 +7,23 @@ include_once __DIR__ . '/../lib/xmlrpcs.inc';
 
 include_once __DIR__ . '/parse_args.php';
 
+include_once __DIR__ . '/PolyfillTestCase.php';
+
 /**
  * Tests involving parsing of xml and handling of xmlrpc values
  */
-class ParsingBugsTests extends PHPUnit_Framework_TestCase
+class ParsingBugsTests extends PhpXmlRpc_PolyfillTestCase
 {
     public $args = array();
 
-    protected function setUp()
+    protected function set_up()
     {
         $this->args = argParser::getArgs();
         if ($this->args['DEBUG'] == 1)
             ob_start();
     }
 
-    protected function tearDown()
+    protected function tear_down()
     {
         if ($this->args['DEBUG'] != 1)
             return;
@@ -76,8 +78,7 @@ class ParsingBugsTests extends PHPUnit_Framework_TestCase
         $response = utf8_encode(
             '<?xml version="1.0"?>
 <!-- $Id -->
-<!-- found by G. giunta, covers what happens when lib receives
-  UTF8 chars in response text and comments -->
+<!-- found by G. Giunta, covers what happens when lib receives UTF8 chars in response text and comments -->
 <!-- ' . chr(224) . chr(252) . chr(232) . '&#224;&#252;&#232; -->
 <methodResponse>
 <fault>
@@ -615,25 +616,46 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
         $v1 = new xmlrpcval(array(new xmlrpcval('one'), new xmlrpcval('two')), 'array');
         $this->assertequals(1, count($v1));
         $out = array('me' => array(), 'mytype' => 2, '_php_class' => null);
+
         foreach($v1 as $key => $val)
         {
-            $expected = each($out);
-            $this->assertequals($expected['key'], $key);
-            if (gettype($expected['value']) == 'array') {
+            $this->assertArrayHasKey($key, $out);
+            $expected = $out[$key];
+            if (gettype($expected) == 'array') {
                 $this->assertequals('array', gettype($val));
             } else {
-                $this->assertequals($expected['value'], $val);
+                $this->assertequals($expected, $val);
             }
         }
 
         $v2 = new \PhpXmlRpc\Value(array(new \PhpXmlRpc\Value('one'), new \PhpXmlRpc\Value('two')), 'array');
         $this->assertequals(2, count($v2));
-        $out = array(0 => 'object', 1 => 'object');
+        $out = array(array('key' => 0, 'value'  => 'object'), array('key' => 1, 'value'  => 'object'));
+        $i = 0;
         foreach($v2 as $key => $val)
         {
-            $expected = each($out);
+            $expected = $out[$i];
             $this->assertequals($expected['key'], $key);
             $this->assertequals($expected['value'], gettype($val));
+            $i++;
         }
     }
+
+    function testBigXML()
+    {
+        // nb: make sure that  the serialized xml corresponding to this is > 10MB in size
+        $data = array();
+        for ($i = 0; $i < 500000; $i++ ) {
+            $data[] = 'hello world';
+        }
+
+        $encoder = new \PhpXmlRpc\Encoder();
+        $val = $encoder->encode($data);
+        $req = new \PhpXmlRpc\Request('test', array($val));
+        $xml = $req->serialize();
+        $parser = new \PhpXmlRpc\Helper\XMLParser();
+        $parser->parse($xml);
+
+        $this->assertequals(0, $parser->_xh['isf']);
+    }
 }