ParsingBugsTests

The Contact Form 7 - Infusionsoft Add-on ParsingBugsTests class.

Defined (1)

The class is defined in the following location(s).

/src/xmlrpc-3.0/test/testsuite.php  
  1. class ParsingBugsTests extends PHPUnit_TestCase 
  2. function testMinusOneString() 
  3. $v=new xmlrpcval('-1'); 
  4. $u=new xmlrpcval('-1', 'string'); 
  5. $this->assertEquals($u->scalarval(), $v->scalarval()); 
  6.  
  7. function testUnicodeInMemberName() { 
  8. $v = array('Gnter, Elne' => new xmlrpcval(1)); 
  9. $r = new xmlrpcresp(new xmlrpcval($v, 'struct')); 
  10. $r = $r->serialize(); 
  11. $m = new xmlrpcmsg('dummy'); 
  12. $r = $m->parseResponse($r); 
  13. $v = $r->value(); 
  14. $this->assertEquals($v->structmemexists('Gnter, Elne'), true); 
  15.  
  16. function testUnicodeInErrorString() 
  17. $response = utf8_encode( 
  18. '<?xml version="1.0"?> 
  19. <!-- $Id --> 
  20. <!-- found by G. giunta, covers what happens when lib receives 
  21. UTF8 chars in reponse text and comments --> 
  22. <!-- àüè --> 
  23. <methodResponse> 
  24. <fault> 
  25. <value> 
  26. <struct> 
  27. <member> 
  28. <name>faultCode</name> 
  29. <value><int>888</int></value> 
  30. </member> 
  31. <member> 
  32. <name>faultString</name> 
  33. <value><string>àüè</string></value> 
  34. </member> 
  35. </struct> 
  36. </value> 
  37. </fault> 
  38. </methodResponse>'); 
  39. $m=new xmlrpcmsg('dummy'); 
  40. $r=$m->parseResponse($response); 
  41. $v=$r->faultString(); 
  42. $this->assertEquals('', $v); 
  43.  
  44. function testValidNumbers() 
  45. $m=new xmlrpcmsg('dummy'); 
  46. $fp= 
  47. '<?xml version="1.0"?> 
  48. <methodResponse> 
  49. <params> 
  50. <param> 
  51. <value> 
  52. <struct> 
  53. <member> 
  54. <name>integer1</name> 
  55. <value><int>01</int></value> 
  56. </member> 
  57. <member> 
  58. <name>float1</name> 
  59. <value><double>01.10</double></value> 
  60. </member> 
  61. <member> 
  62. <name>integer2</name> 
  63. <value><int>+1</int></value> 
  64. </member> 
  65. <member> 
  66. <name>float2</name> 
  67. <value><double>+1.10</double></value> 
  68. </member> 
  69. <member> 
  70. <name>float3</name> 
  71. <value><double>-1.10e2</double></value> 
  72. </member> 
  73. </struct> 
  74. </value> 
  75. </param> 
  76. </params> 
  77. </methodResponse>'; 
  78. $r=$m->parseResponse($fp); 
  79. $v=$r->value(); 
  80. $s=$v->structmem('integer1'); 
  81. $t=$v->structmem('float1'); 
  82. $u=$v->structmem('integer2'); 
  83. $w=$v->structmem('float2'); 
  84. $x=$v->structmem('float3'); 
  85. $this->assertEquals(1, $s->scalarval()); 
  86. $this->assertEquals(1.1, $t->scalarval()); 
  87. $this->assertEquals(1, $u->scalarval()); 
  88. $this->assertEquals(1.1, $w->scalarval()); 
  89. $this->assertEquals(-110.0, $x->scalarval()); 
  90.  
  91. function testAddScalarToStruct() 
  92. $v=new xmlrpcval(array('a' => 'b'), 'struct'); 
  93. // use @ operator in case error_log gets on screen 
  94. $r= @$v->addscalar('c'); 
  95. $this->assertEquals(0, $r); 
  96.  
  97. function testAddStructToStruct() 
  98. $v=new xmlrpcval(array('a' => new xmlrpcval('b')), 'struct'); 
  99. $r=$v->addstruct(array('b' => new xmlrpcval('c'))); 
  100. $this->assertEquals(2, $v->structsize()); 
  101. $this->assertEquals(1, $r); 
  102. $r=$v->addstruct(array('b' => new xmlrpcval('b'))); 
  103. $this->assertEquals(2, $v->structsize()); 
  104.  
  105. function testAddArrayToArray() 
  106. $v=new xmlrpcval(array(new xmlrpcval('a'), new xmlrpcval('b')), 'array'); 
  107. $r=$v->addarray(array(new xmlrpcval('b'), new xmlrpcval('c'))); 
  108. $this->assertEquals(4, $v->arraysize()); 
  109. $this->assertEquals(1, $r); 
  110.  
  111. function testEncodeArray() 
  112. $r=range(1, 100); 
  113. $v = php_xmlrpc_encode($r); 
  114. $this->assertEquals('array', $v->kindof()); 
  115.  
  116. function testEncodeRecursive() 
  117. $v = php_xmlrpc_encode(php_xmlrpc_encode('a simple string')); 
  118. $this->assertEquals('scalar', $v->kindof()); 
  119.  
  120. function testBrokenRequests() 
  121. $s = new xmlrpc_server(); 
  122. // omitting the 'params' tag: not tolerated by the lib anymore 
  123. $f = '<?xml version="1.0"?> 
  124. <methodCall> 
  125. <methodName>system.methodHelp</methodName> 
  126. <param> 
  127. <value><string>system.methodHelp</string></value> 
  128. </param> 
  129. </methodCall>'; 
  130. $r = $s->parserequest($f); 
  131. $this->assertEquals(15, $r->faultCode()); 
  132. // omitting a 'param' tag 
  133. $f = '<?xml version="1.0"?> 
  134. <methodCall> 
  135. <methodName>system.methodHelp</methodName> 
  136. <params> 
  137. <value><string>system.methodHelp</string></value> 
  138. </params> 
  139. </methodCall>'; 
  140. $r = $s->parserequest($f); 
  141. $this->assertEquals(15, $r->faultCode()); 
  142. // omitting a 'value' tag 
  143. $f = '<?xml version="1.0"?> 
  144. <methodCall> 
  145. <methodName>system.methodHelp</methodName> 
  146. <params> 
  147. <param><string>system.methodHelp</string></param> 
  148. </params> 
  149. </methodCall>'; 
  150. $r = $s->parserequest($f); 
  151. $this->assertEquals(15, $r->faultCode()); 
  152.  
  153. function testBrokenResponses() 
  154. $m=new xmlrpcmsg('dummy'); 
  155. //$m->debug = 1; 
  156. // omitting the 'params' tag: no more tolerated by the lib... 
  157. $f = '<?xml version="1.0"?> 
  158. <methodResponse> 
  159. <param> 
  160. <value><string>system.methodHelp</string></value> 
  161. </param> 
  162. </methodResponse>'; 
  163. $r = $m->parseResponse($f); 
  164. $this->assertEquals(2, $r->faultCode()); 
  165. // omitting the 'param' tag: no more tolerated by the lib... 
  166. $f = '<?xml version="1.0"?> 
  167. <methodResponse> 
  168. <params> 
  169. <value><string>system.methodHelp</string></value> 
  170. </params> 
  171. </methodResponse>'; 
  172. $r = $m->parseResponse($f); 
  173. $this->assertEquals(2, $r->faultCode()); 
  174. // omitting a 'value' tag: KO 
  175. $f = '<?xml version="1.0"?> 
  176. <methodResponse> 
  177. <params> 
  178. <param><string>system.methodHelp</string></param> 
  179. </params> 
  180. </methodResponse>'; 
  181. $r = $m->parseResponse($f); 
  182. $this->assertEquals(2, $r->faultCode()); 
  183.  
  184. function testBuggyHttp() 
  185. $s = new xmlrpcmsg('dummy'); 
  186. $f = 'HTTP/1.1 100 Welcome to the jungle 
  187.  
  188. HTTP/1.0 200 OK 
  189. X-Content-Marx-Brothers: Harpo 
  190. Chico and Groucho 
  191. Content-Length: who knows? 
  192.  
  193.  
  194.  
  195. <?xml version="1.0"?> 
  196. <!-- First of all, let\'s check out if the lib properly handles a commented </methodResponse> tag... --> 
  197. <methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> 
  198. <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow 
  199.  
  200.  
  201. and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> 
  202. <script type="text\javascript">document.write(\'Hello, my name is added nag, I\\\'m happy to serve your content for free\');</script> 
  203. '; 
  204. $r = $s->parseResponse($f); 
  205. $v = $r->value(); 
  206. $s = $v->structmem('content'); 
  207. $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval()); 
  208.  
  209. function testStringBug() 
  210. $s = new xmlrpcmsg('dummy'); 
  211. $f = '<?xml version="1.0"?> 
  212. <!-- $Id --> 
  213. <!-- found by 2z69xks7bpy001@sneakemail.com, amongst others 
  214. covers what happens when there\'s character data after </string> 
  215. and before </value> --> 
  216. <methodResponse> 
  217. <params> 
  218. <param> 
  219. <value> 
  220. <struct> 
  221. <member> 
  222. <name>success</name> 
  223. <value> 
  224. <boolean>1</boolean> 
  225. </value> 
  226. </member> 
  227. <member> 
  228. <name>sessionID</name> 
  229. <value> 
  230. <string>S300510007I</string> 
  231. </value> 
  232. </member> 
  233. </struct> 
  234. </value> 
  235. </param> 
  236. </params> 
  237. </methodResponse> '; 
  238. $r = $s->parseResponse($f); 
  239. $v = $r->value(); 
  240. $s = $v->structmem('sessionID'); 
  241. $this->assertEquals('S300510007I', $s->scalarval()); 
  242.  
  243. function testWhiteSpace() 
  244. $s = new xmlrpcmsg('dummy'); 
  245. $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> 
  246. <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow 
  247.  
  248.  
  249. and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> 
  250. '; 
  251. $r = $s->parseResponse($f); 
  252. $v = $r->value(); 
  253. $s = $v->structmem('content'); 
  254. $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s->scalarval()); 
  255.  
  256. function testDoubleDataInArrayTag() 
  257. $s = new xmlrpcmsg('dummy'); 
  258. $f = '<?xml version="1.0"?><methodResponse><params><param><value><array> 
  259. <data></data> 
  260. <data></data> 
  261. </array></value></param></params></methodResponse> 
  262. '; 
  263. $r = $s->parseResponse($f); 
  264. $v = $r->faultCode(); 
  265. $this->assertEquals(2, $v); 
  266. $f = '<?xml version="1.0"?><methodResponse><params><param><value><array> 
  267. <data><value>Hello world</value></data> 
  268. <data></data> 
  269. </array></value></param></params></methodResponse> 
  270. '; 
  271. $r = $s->parseResponse($f); 
  272. $v = $r->faultCode(); 
  273. $this->assertEquals(2, $v); 
  274.  
  275. function testDoubleStuffInValueTag() 
  276. $s = new xmlrpcmsg('dummy'); 
  277. $f = '<?xml version="1.0"?><methodResponse><params><param><value> 
  278. <string>hello world</string> 
  279. <array><data></data></array> 
  280. </value></param></params></methodResponse> 
  281. '; 
  282. $r = $s->parseResponse($f); 
  283. $v = $r->faultCode(); 
  284. $this->assertEquals(2, $v); 
  285. $f = '<?xml version="1.0"?><methodResponse><params><param><value> 
  286. <string>hello</string> 
  287. <string>world</string> 
  288. </value></param></params></methodResponse> 
  289. '; 
  290. $r = $s->parseResponse($f); 
  291. $v = $r->faultCode(); 
  292. $this->assertEquals(2, $v); 
  293. $f = '<?xml version="1.0"?><methodResponse><params><param><value> 
  294. <string>hello</string> 
  295. <struct><member><name>hello><value>world</value></member></struct> 
  296. </value></param></params></methodResponse> 
  297. '; 
  298. $r = $s->parseResponse($f); 
  299. $v = $r->faultCode(); 
  300. $this->assertEquals(2, $v); 
  301.  
  302. function testAutodecodeResponse() 
  303. $s = new xmlrpcmsg('dummy'); 
  304. $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> 
  305. <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow 
  306.  
  307.  
  308. and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> 
  309. '; 
  310. $r = $s->parseResponse($f, true, 'phpvals'); 
  311. $v = $r->value(); 
  312. $s = $v['content']; 
  313. $this->assertEquals("hello world. 2 newlines follow\n\n\nand there they were.", $s); 
  314.  
  315. function testNoDecodeResponse() 
  316. $s = new xmlrpcmsg('dummy'); 
  317. $f = '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> 
  318. <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>hello world. 2 newlines follow 
  319.  
  320.  
  321. and there they were.</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>'; 
  322. $r = $s->parseResponse($f, true, 'xml'); 
  323. $v = $r->value(); 
  324. $this->assertEquals($f, $v); 
  325.  
  326. function testAutoCoDec() 
  327. $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00'); 
  328. $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1); 
  329. $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2); 
  330. //$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'); 
  331. $v1 = php_xmlrpc_encode($data, array('auto_dates')); 
  332. $v2 = php_xmlrpc_decode_xml($v1->serialize()); 
  333. $this->assertEquals($v1, $v2); 
  334. $r1 = new xmlrpcresp($v1); 
  335. $r2 = php_xmlrpc_decode_xml($r1->serialize()); 
  336. $r2->serialize(); // needed to set internal member payload 
  337. $this->assertEquals($r1, $r2); 
  338. $m1 = new xmlrpcmsg('hello dolly', array($v1)); 
  339. $m2 = php_xmlrpc_decode_xml($m1->serialize()); 
  340. $m2->serialize(); // needed to set internal member payload 
  341. $this->assertEquals($m1, $m2); 
  342.  
  343. function testUTF8Request() 
  344. $sendstring='*****'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string! 
  345. $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8'; 
  346. $f = new xmlrpcval($sendstring, 'string'); 
  347. $v=$f->serialize(); 
  348. $this->assertEquals("<value><string>κόσμε</string></value>\n", $v); 
  349. $GLOBALS['xmlrpc_internalencoding'] = 'ISO-8859-1'; 
  350.  
  351. function testUTF8Response() 
  352. $s = new xmlrpcmsg('dummy'); 
  353. $f = "HTTP/1.1 200 OK\r\nContent-type: text/xml; charset=UTF-8\r\n\r\n".'<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> 
  354. <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>'.utf8_encode('').'</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> 
  355. '; 
  356. $r = $s->parseResponse($f, false, 'phpvals'); 
  357. $v = $r->value(); 
  358. $v = $v['content']; 
  359. $this->assertEquals("", $v); 
  360. $f = '<?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member> 
  361. <member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>'.utf8_encode('').'</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse> 
  362. '; 
  363. $r = $s->parseResponse($f, false, 'phpvals'); 
  364. $v = $r->value(); 
  365. $v = $v['content']; 
  366. $this->assertEquals("", $v); 
  367.  
  368. function testUTF8IntString() 
  369. $v=new xmlrpcval(100, 'int'); 
  370. $s=$v->serialize('UTF-8'); 
  371. $this->assertequals("<value><int>100</int></value>\n", $s); 
  372.  
  373. function testStringInt() 
  374. $v=new xmlrpcval('hello world', 'int'); 
  375. $s=$v->serialize(); 
  376. $this->assertequals("<value><int>0</int></value>\n", $s); 
  377.  
  378. function testStructMemExists() 
  379. $v=php_xmlrpc_encode(array('hello' => 'world')); 
  380. $b=$v->structmemexists('hello'); 
  381. $this->assertequals(true, $b); 
  382. $b=$v->structmemexists('world'); 
  383. $this->assertequals(false, $b); 
  384.  
  385. function testNilvalue() 
  386. // default case: we do not accept nil values received 
  387. $v = new xmlrpcval('hello', 'null'); 
  388. $r = new xmlrpcresp($v); 
  389. $s = $r->serialize(); 
  390. $m = new xmlrpcmsg('dummy'); 
  391. $r = $m->parseresponse($s); 
  392. $this->assertequals(2, $r->faultCode()); 
  393. // enable reception of nil values 
  394. $GLOBALS['xmlrpc_null_extension'] = true; 
  395. $r = $m->parseresponse($s); 
  396. $v = $r->value(); 
  397. $this->assertequals('null', $v->scalartyp()); 
  398. // test with the apache version: EX:NIL 
  399. $GLOBALS['xmlrpc_null_apache_encoding'] = true; 
  400. // serialization 
  401. $v = new xmlrpcval('hello', 'null'); 
  402. $s = $v->serialize(); 
  403. $this->assertequals(1, preg_match( '#<value><ex:nil/></value>#', $s )); 
  404. // deserialization 
  405. $r = new xmlrpcresp($v); 
  406. $s = $r->serialize(); 
  407. $r = $m->parseresponse($s); 
  408. $v = $r->value(); 
  409. $this->assertequals('null', $v->scalartyp()); 
  410. $GLOBALS['xmlrpc_null_extension'] = false; 
  411. $r = $m->parseresponse($s); 
  412. $this->assertequals(2, $r->faultCode()); 
  413.  
  414. function TestLocale() 
  415. $locale = setlocale(LC_NUMERIC, 0); 
  416. if ( setlocale(LC_NUMERIC, 'deu', 'de_DE@euro', 'de_DE', 'de', 'ge') !== false ) 
  417. $v = new xmlrpcval(1.1, 'double'); 
  418. $r = $v->serialize(); 
  419. $this->assertequals(false, strpos($r, ', ')); 
  420. $this->assertequals(1, strpos($v->scalarval(), ', ')); 
  421. setlocale(LC_NUMERIC, $locale);