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:
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);
use PHPUnit\Runner\BaseTestRunner;
/**
- * Tests involving the Value class
+ * Tests involving the Value class.
*/
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>€</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;
+ }
}
/**
* 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
return $msg;
}
-
public function testValidNumbers()
{
$m = $this->newMsg('dummy');
// 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) . 'àüè -->
<methodResponse>
<fault>
{
$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>
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');
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
*/
$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>€</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;
+ }
}
$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>
$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>
/**
* 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
{
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
{
include_once __DIR__ . '/WebTestCase.php';
+/**
+ * Tests for the bundled debugger.
+ */
class DebuggerTest extends PhpXmlRpc_WebTestCase
{
public function set_up()
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
{