add tests for new internalencoding functionality
authorgggeek <giunta.gaetano@gmail.com>
Tue, 17 Jan 2023 10:42:18 +0000 (10:42 +0000)
committergggeek <giunta.gaetano@gmail.com>
Tue, 17 Jan 2023 10:42:18 +0000 (10:42 +0000)
tests/0CharsetTest.php
tests/1ValueTest.php
tests/2MessageTest.php
tests/3EncoderTest.php
tests/5ServerTest.php
tests/6HTTPTest.php
tests/7DemofilesTest.php
tests/8DebuggerTest.php
tests/9ExtraFilesTest.php

index fd971cf..82c9822 100644 (file)
@@ -8,7 +8,8 @@ include_once __DIR__ . '/PolyfillTestCase.php';
 use PhpXmlRpc\Helper\Charset;
 
 /**
- * Test conversion between encodings
+ * Test conversion between encodings via usage of the Charset class.
+ * Note that quite a few other tests testing different classes also test character set conversion.
  *
  * For Windows if you want to test the output use Consolas font
  * and run the following in cmd:
@@ -62,11 +63,6 @@ class CharsetTest extends PhpXmlRpc_PolyfillTestCase
 
     public function testUtf8ToLatin1All()
     {
-        /*$this->assertEquals(
-            'ISO-8859-1',
-            mb_detect_encoding($this->latinString, 'ISO-8859-1, UTF-8, WINDOWS-1251, ASCII', true),
-            'Setup latinString is not ISO-8859-1 encoded...'
-        );*/
         // the warning suppression is due to utf8_encode being deprecated in php 8.2
         $string = @utf8_encode($this->latinString);
         $encoded = $this->utf8ToLatin1($string);
index ad8adb6..9bada04 100644 (file)
@@ -10,7 +10,7 @@ include_once __DIR__ . '/PolyfillTestCase.php';
 use PHPUnit\Runner\BaseTestRunner;
 
 /**
- * Tests involving the Value class
+ * Tests involving the Value class.
  */
 class ValueTests extends PhpXmlRpc_PolyfillTestCase
 {
@@ -180,4 +180,24 @@ class ValueTests extends PhpXmlRpc_PolyfillTestCase
 
         $this->assertequals(0, $parser->_xh['isf']);
     }
+
+    public function testLatin15InternalEncoding()
+    {
+        if (!function_exists('mb_convert_encoding')) {
+            $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
+            return;
+        }
+
+        $string = chr(164);
+        $v = new \PhpXmlRpc\Value($string);
+
+        $originalEncoding = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding;
+        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-15';
+
+        $this->assertEquals("<value><string>&#8364;</string></value>", trim($v->serialize('US-ASCII')));
+        $this->assertEquals("<value><string>$string</string></value>", trim($v->serialize('ISO-8859-15')));
+        $this->assertEquals("<value><string>€</string></value>", trim($v->serialize('UTF-8')));
+
+        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = $originalEncoding;
+    }
 }
index 72e6562..fde14ca 100644 (file)
@@ -11,7 +11,8 @@ use PHPUnit\Runner\BaseTestRunner;
 
 /**
  * Tests involving the Request and Response classes.
- * @todo some tests are here only because we use a Response to trigger parsing of xml for a single Value, but they
+ *
+ * @todo many tests are here only because we use a Response to trigger parsing of xml for a single Value, but they
  *       logically belong elsewhere...
  */
 class MessageTests extends PhpXmlRpc_PolyfillTestCase
@@ -44,7 +45,6 @@ class MessageTests extends PhpXmlRpc_PolyfillTestCase
         return $msg;
     }
 
-
     public function testValidNumbers()
     {
         $m = $this->newMsg('dummy');
@@ -148,8 +148,7 @@ class MessageTests extends PhpXmlRpc_PolyfillTestCase
         // the warning suppression is due to utf8_decode being deprecated in php 8.2
         $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 -->
+<!-- covers what happens when lib receives UTF8 chars in response text and comments -->
 <!-- ' . chr(224) . chr(252) . chr(232) . '&#224;&#252;&#232; -->
 <methodResponse>
 <fault>
@@ -271,9 +270,7 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
     {
         $s = $this->newMsg('dummy');
         $f = '<?xml version="1.0"?>
-<!-- $Id -->
-<!-- found by 2z69xks7bpy001@sneakemail.com, amongst others
- covers what happens when there\'s character data after </string>
+<!-- found by 2z69xks7bpy001@sneakemail.com, amongst others covers what happens when there\'s character data after </string>
  and before </value> -->
 <methodResponse>
 <params>
@@ -398,7 +395,7 @@ and there they were.</value></member><member><name>postid</name><value>7414222</
 
     public function testUTF8Request()
     {
-        $sendstring = 'κόσμε'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
+        $sendstring = 'κόσμε'; // Greek word 'kosme'
         $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
         \PhpXmlRpc\PhpXmlRpc::importGlobals();
         $f = new xmlrpcval($sendstring, 'string');
index 2c41d75..d1d449f 100644 (file)
@@ -10,7 +10,8 @@ include_once __DIR__ . '/PolyfillTestCase.php';
 use PHPUnit\Runner\BaseTestRunner;
 
 /**
- * Tests involving automatic encoding/decoding of php values into xmlrpc values
+ * Tests involving automatic encoding/decoding of php values into xmlrpc values (the Encoder class).
+ *
  * @todo add tests for encoding options: 'encode_php_objs', 'auto_dates', 'null_extension' and 'extension_api'
  * @todo add tests for php_xmlrpc_decode options
  */
@@ -82,4 +83,29 @@ class EncoderTests extends PhpXmlRpc_PolyfillTestCase
         $m2->serialize(); // needed to set internal member payload
         $this->assertEquals($m1, $m2);
     }
+
+    public function testLatin15InternalEncoding()
+    {
+        if (!function_exists('mb_convert_encoding')) {
+            $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
+            return;
+        }
+
+        $string = chr(164);
+        $e = new \PhpXmlRpc\Encoder();
+
+        $originalEncoding = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding;
+        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-15';
+
+        $a = $e->decodeXml('<?xml version="1.0" encoding="US-ASCII" ?><value><string>&#8364;</string></value>');
+        $this->assertEquals($string, $a->scalarVal());
+
+        $i = $e->decodeXml('<?xml version="1.0" encoding="ISO-8859-15" ?><value><string>' . $string . '</string></value>');
+        $this->assertEquals($string, $i->scalarVal());
+
+        $u = $e->decodeXml('<?xml version="1.0" encoding="UTF-8" ?><value><string>€</string></value>');
+        $this->assertEquals($string, $u->scalarVal());
+
+        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = $originalEncoding;
+    }
 }
index 87e71d7..829f19c 100644 (file)
@@ -223,7 +223,7 @@ class ServerTest extends PhpXmlRpc_PolyfillTestCase
             $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
             return;
         }
-        $sendString = 'κόσμε'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
+        $sendString = 'κόσμε'; // Greek word 'kosme'
         $str = '<?xml version="1.0" encoding="_ENC_"?>
 <methodCall>
     <methodName>examples.stringecho</methodName>
@@ -255,7 +255,7 @@ class ServerTest extends PhpXmlRpc_PolyfillTestCase
             $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
             return;
         }
-        $sendString = '安室奈美恵'; // No idea what this means :-) NB: NOT a valid ISO8859 string!
+        $sendString = '安室奈美恵'; // Japanese name "Namie Amuro"
         $str = '<?xml version="1.0"?>
 <methodCall>
     <methodName>examples.stringecho</methodName>
index 6880a0c..4293e28 100644 (file)
@@ -9,7 +9,7 @@ include_once __DIR__ . '/5ServerTest.php';
 
 /**
  * Tests which stress http features of the library.
- * Each of these tests iterates over (almost) all the 'localhost' tests
+ * Each of these tests iterates over (almost) all the 'Server' tests
  */
 class HTTPTest extends ServerTest
 {
index 2496cf4..bb74546 100644 (file)
@@ -3,7 +3,7 @@
 include_once __DIR__ . '/WebTestCase.php';
 
 /**
- * Tests for php files in the 'demo' directory
+ * Tests for php files in the 'demo' directory.
  */
 class DemoFilesTest extends PhpXmlRpc_WebTestCase
 {
index f1c22da..d67129f 100644 (file)
@@ -2,6 +2,9 @@
 
 include_once __DIR__ . '/WebTestCase.php';
 
+/**
+ * Tests for the bundled debugger.
+ */
 class DebuggerTest extends PhpXmlRpc_WebTestCase
 {
     public function set_up()
index f3df560..456d7f2 100644 (file)
@@ -3,8 +3,7 @@
 include_once __DIR__ . '/WebTestCase.php';
 
 /**
- * Tests for php files in the 'extras' directory
- *
+ * Tests for php files in the 'extras' directory.
  */
 class ExtraFilesTest extends PhpXmlRpc_WebTestCase
 {