3 include_once __DIR__ . '/../lib/xmlrpc.inc';
4 include_once __DIR__ . '/../lib/xmlrpcs.inc';
6 include_once __DIR__ . '/parse_args.php';
8 include_once __DIR__ . '/PolyfillTestCase.php';
10 use PHPUnit\Runner\BaseTestRunner;
13 * Tests involving the Value class
15 class ValueTests extends PhpXmlRpc_PolyfillTestCase
17 public $args = array();
19 protected function set_up()
21 $this->args = argParser::getArgs();
22 if ($this->args['DEBUG'] == 1)
26 protected function tear_down()
28 if ($this->args['DEBUG'] != 1)
30 $out = ob_get_clean();
31 $status = $this->getStatus();
32 if ($status == BaseTestRunner::STATUS_ERROR
33 || $status == BaseTestRunner::STATUS_FAILURE) {
38 public function testMinusOneString()
40 $v = new xmlrpcval('-1');
41 $u = new xmlrpcval('-1', 'string');
42 $t = new xmlrpcval(-1, 'string');
43 $this->assertEquals($v->scalarval(), $u->scalarval());
44 $this->assertEquals($v->scalarval(), $t->scalarval());
48 * This looks funny, and we might call it a bug. But we strive for 100 backwards compat...
50 public function testMinusOneInt()
53 $v = new xmlrpcval(-1);
54 $this->assertEquals($u->scalarval(), $v->scalarval());
57 public function testAddScalarToStruct()
59 $v = new xmlrpcval(array('a' => 'b'), 'struct');
60 // use @ operator in case error_log gets on screen
61 $r = @$v->addscalar('c');
62 $this->assertEquals(0, $r);
65 public function testAddStructToStruct()
67 $v = new xmlrpcval(array('a' => new xmlrpcval('b')), 'struct');
68 $r = $v->addstruct(array('b' => new xmlrpcval('c')));
69 $this->assertEquals(2, $v->structsize());
70 $this->assertEquals(1, $r);
71 $r = $v->addstruct(array('b' => new xmlrpcval('b')));
72 $this->assertEquals(2, $v->structsize());
75 public function testAddArrayToArray()
77 $v = new xmlrpcval(array(new xmlrpcval('a'), new xmlrpcval('b')), 'array');
78 $r = $v->addarray(array(new xmlrpcval('b'), new xmlrpcval('c')));
79 $this->assertEquals(4, $v->arraysize());
80 $this->assertEquals(1, $r);
83 public function testUTF8IntString()
85 $v = new xmlrpcval(100, 'int');
86 $s = $v->serialize('UTF-8');
87 $this->assertequals("<value><int>100</int></value>\n", $s);
90 public function testStringInt()
92 $v = new xmlrpcval('hello world', 'int');
94 $this->assertequals("<value><int>0</int></value>\n", $s);
97 public function testStructMemExists()
99 $v = new xmlrpcval(array('hello' => new xmlrpcval('world')), 'struct');
100 $b = $v->structmemexists('hello');
101 $this->assertequals(true, $b);
102 $b = $v->structmemexists('world');
103 $this->assertequals(false, $b);
106 public function testLocale()
108 $locale = setlocale(LC_NUMERIC, 0);
109 /// @todo on php 5.3/win setting locale to german does not seem to set decimal separator to comma...
110 if (setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false) {
111 $v = new xmlrpcval(1.1, 'double');
112 if (strpos($v->scalarval(), ',') == 1) {
113 $r = $v->serialize();
114 $this->assertequals(false, strpos($r, ','));
115 setlocale(LC_NUMERIC, $locale);
117 setlocale(LC_NUMERIC, $locale);
118 $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
121 $this->markTestSkipped('did not find a locale which sets decimal separator to comma');
125 public function testArrayAccess()
127 $v1 = new xmlrpcval(array(new xmlrpcval('one'), new xmlrpcval('two')), 'array');
128 $this->assertequals(1, count($v1));
129 $out = array('me' => array(), 'mytype' => 2, '_php_class' => null);
131 foreach($v1 as $key => $val)
133 $this->assertArrayHasKey($key, $out);
134 $expected = $out[$key];
135 if (gettype($expected) == 'array') {
136 $this->assertequals('array', gettype($val));
138 $this->assertequals($expected, $val);
142 $v2 = new \PhpXmlRpc\Value(array(new \PhpXmlRpc\Value('one'), new \PhpXmlRpc\Value('two')), 'array');
143 $this->assertequals(2, count($v2));
144 $out = array(array('key' => 0, 'value' => 'object'), array('key' => 1, 'value' => 'object'));
146 foreach($v2 as $key => $val)
148 $expected = $out[$i];
149 $this->assertequals($expected['key'], $key);
150 $this->assertequals($expected['value'], gettype($val));
155 /// @todo do not use \PhpXmlRpc\Encoder for this test
156 function testBigXML()
158 // nb: make sure that the serialized xml corresponding to this is > 10MB in size
160 for ($i = 0; $i < 500000; $i++ ) {
161 $data[] = 'hello world';
164 $encoder = new \PhpXmlRpc\Encoder();
165 $val = $encoder->encode($data);
166 $req = new \PhpXmlRpc\Request('test', array($val));
167 $xml = $req->serialize();
168 $parser = new \PhpXmlRpc\Helper\XMLParser();
169 $parser->parse($xml);
171 $this->assertequals(0, $parser->_xh['isf']);