From b8187059016a98a55d74d261a79d8f242f10f09d Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 17 Jan 2023 10:42:18 +0000 Subject: [PATCH] add tests for new internalencoding functionality --- tests/0CharsetTest.php | 8 ++------ tests/1ValueTest.php | 22 +++++++++++++++++++++- tests/2MessageTest.php | 13 +++++-------- tests/3EncoderTest.php | 28 +++++++++++++++++++++++++++- tests/5ServerTest.php | 4 ++-- tests/6HTTPTest.php | 2 +- tests/7DemofilesTest.php | 2 +- tests/8DebuggerTest.php | 3 +++ tests/9ExtraFilesTest.php | 3 +-- 9 files changed, 63 insertions(+), 22 deletions(-) diff --git a/tests/0CharsetTest.php b/tests/0CharsetTest.php index fd971cf1..82c98220 100644 --- a/tests/0CharsetTest.php +++ b/tests/0CharsetTest.php @@ -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); diff --git a/tests/1ValueTest.php b/tests/1ValueTest.php index ad8adb6c..9bada042 100644 --- a/tests/1ValueTest.php +++ b/tests/1ValueTest.php @@ -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("", trim($v->serialize('US-ASCII'))); + $this->assertEquals("$string", trim($v->serialize('ISO-8859-15'))); + $this->assertEquals("€", trim($v->serialize('UTF-8'))); + + \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = $originalEncoding; + } } diff --git a/tests/2MessageTest.php b/tests/2MessageTest.php index 72e65628..fde14ca3 100644 --- a/tests/2MessageTest.php +++ b/tests/2MessageTest.php @@ -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( ' - - + @@ -271,9 +270,7 @@ and there they were.postid7414222newMsg('dummy'); $f = ' - - @@ -398,7 +395,7 @@ and there they were.postid7414222serialize(); // 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(''); + $this->assertEquals($string, $a->scalarVal()); + + $i = $e->decodeXml('' . $string . ''); + $this->assertEquals($string, $i->scalarVal()); + + $u = $e->decodeXml('€'); + $this->assertEquals($string, $u->scalarVal()); + + \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = $originalEncoding; + } } diff --git a/tests/5ServerTest.php b/tests/5ServerTest.php index 87e71d70..829f19ce 100644 --- a/tests/5ServerTest.php +++ b/tests/5ServerTest.php @@ -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 = ' examples.stringecho @@ -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 = ' examples.stringecho diff --git a/tests/6HTTPTest.php b/tests/6HTTPTest.php index 6880a0c3..4293e288 100644 --- a/tests/6HTTPTest.php +++ b/tests/6HTTPTest.php @@ -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 { diff --git a/tests/7DemofilesTest.php b/tests/7DemofilesTest.php index 2496cf44..bb745469 100644 --- a/tests/7DemofilesTest.php +++ b/tests/7DemofilesTest.php @@ -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 { diff --git a/tests/8DebuggerTest.php b/tests/8DebuggerTest.php index f1c22daa..d67129f7 100644 --- a/tests/8DebuggerTest.php +++ b/tests/8DebuggerTest.php @@ -2,6 +2,9 @@ include_once __DIR__ . '/WebTestCase.php'; +/** + * Tests for the bundled debugger. + */ class DebuggerTest extends PhpXmlRpc_WebTestCase { public function set_up() diff --git a/tests/9ExtraFilesTest.php b/tests/9ExtraFilesTest.php index f3df5607..456d7f24 100644 --- a/tests/9ExtraFilesTest.php +++ b/tests/9ExtraFilesTest.php @@ -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 { -- 2.47.0