Line # | Frequency | Source Line |
1 | | <?php
|
2 | | // $Id: xmlrpc.inc.test,v 1.4 2008/03/23 22:06:33 boombatower Exp $
|
3 | |
|
4 | | class XMLRPCValidator1Test extends DrupalTestCase {
|
5 | | function getInfo() {
|
6 | 1 | return array('name' => 'XML-RPC validator1',
|
7 | | 'description' => t('See !validator-link. note: simpletest_xmlrpc.module must be enabled', array('!validator-link' => l('the xmlrpc validator1 specification', 'http://www.xmlrpc.com/validator1Docs'))),
|
8 | | 'group' => 'XML-RPC Tests');
|
9 | | }
|
10 | |
|
11 | | function test_run_all_tests() {
|
12 | | if (!$this->drupalModuleEnable('simpletest_xmlrpc')) {
|
13 | | return FALSE;
|
14 | | }
|
15 | | $xml_url = url(NULL, array('absolute' => TRUE)) . 'xmlrpc.php';
|
16 | | srand();
|
17 | | mt_srand();
|
18 | |
|
19 | |
|
20 | | $array_1 = array(array('curly' => mt_rand(-100,100)),
|
21 | | array('curly' => mt_rand(-100,100)),
|
22 | | array('larry' => mt_rand(-100,100)),
|
23 | | array('larry' => mt_rand(-100,100)),
|
24 | | array('moe' => mt_rand(-100,100)),
|
25 | | array('moe' => mt_rand(-100,100)),
|
26 | | array('larry' => mt_rand(-100,100)));
|
27 | | shuffle($array_1);
|
28 | | $l_res_1 = simpletest_xmlrpc_arrayOfStructsTest($array_1);
|
29 | | $r_res_1 = xmlrpc($xml_url, 'validator1.arrayOfStructsTest', $array_1);
|
30 | | $this->assertIdentical($l_res_1, $r_res_1, 'array of structs test: %s');
|
31 | |
|
32 | |
|
33 | | $string_2 = 't\'&>>zf"md>yr>xlcev<h<"k&j<og"w&&>">>uai"np&s>>q\'&b<>"&&&';
|
34 | | $l_res_2 = simpletest_xmlrpc_countTheEntities($string_2);
|
35 | | $r_res_2 = xmlrpc($xml_url, 'validator1.countTheEntities', $string_2);
|
36 | | $this->assertIdentical($l_res_2, $r_res_2, 'count the entities test: %s');
|
37 | |
|
38 | |
|
39 | | $struct_3 = array('moe' => mt_rand(-100,100), 'larry' => mt_rand(-100,100), 'curly' => mt_rand(-100,100), 'homer' => mt_rand(-100,100));
|
40 | | $l_res_3 = simpletest_xmlrpc_easyStructTest($struct_3);
|
41 | | $r_res_3 = xmlrpc($xml_url, 'validator1.easyStructTest', $struct_3);
|
42 | | $this->assertIdentical($l_res_3, $r_res_3, 'easy struct test: %s');
|
43 | |
|
44 | |
|
45 | | $struct_4 = array('sub1' => array('bar' => 13),
|
46 | | 'sub2' => 14,
|
47 | | 'sub3' => array('foo' => 1, 'baz' => 2),
|
48 | | 'sub4' => array('ss' => array('sss' => array('ssss' => 'sssss'))));
|
49 | | $l_res_4 = simpletest_xmlrpc_echoStructTest($struct_4);
|
50 | | $r_res_4 = xmlrpc($xml_url, 'validator1.echoStructTest', $struct_4);
|
51 | | $this->assertIdentical($l_res_4, $r_res_4, 'echo struct test: %s');
|
52 | |
|
53 | | $int_5 = mt_rand(-100,100);
|
54 | | $bool_5 = (($int_5 % 2) == 0);
|
55 | | $string_5 = $this->randomName();
|
56 | | $double_5 = (double)(mt_rand(-1000,1000) / 100);
|
57 | | $time_5 = time();
|
58 | | $base64_5 = $this->randomName(100);
|
59 | | $l_res_5 = simpletest_xmlrpc_manyTypesTest($int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), $base64_5);
|
60 | | $l_res_5[5] = $l_res_5[5]->data; /* override warpping */
|
61 | | $r_res_5 = xmlrpc($xml_url, 'validator1.manyTypesTest', $int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), xmlrpc_base64($base64_5));
|
62 | | /* Contains objects, objects are not equal */
|
63 | | // See http://drupal.org/node/37766 why this currnetly fails
|
64 | | $this->assertEqual($l_res_5, $r_res_5, 'many types test: %s');
|
65 | |
|
66 | |
|
67 | | $size = mt_rand(100,200);
|
68 | | $array_6 = array();
|
69 | | for ($i = 0; $i < $size; $i++) {
|
70 | | $array_6[] = $this->randomName(mt_rand(8,12));
|
71 | | }
|
72 | |
|
73 | | $l_res_6 = simpletest_xmlrpc_moderateSizeArrayCheck($array_6);
|
74 | | $r_res_6 = xmlrpc($xml_url, 'validator1.moderateSizeArrayCheck', $array_6);
|
75 | | $this->assertIdentical($l_res_6, $r_res_6, 'moderate size array check: %s');
|
76 | |
|
77 | |
|
78 | | $struct_7 = array();
|
79 | | for ($y = 2000; $y < 2002; $y++) {
|
80 | | for ($m = 3; $m < 5; $m++) {
|
81 | | for ($d = 1; $d < 6; $d++) {
|
82 | | $ys = (string)$y;
|
83 | | $ms = sprintf('%02d', $m);
|
84 | | $ds = sprintf('%02d', $d);
|
85 | | $struct_7[$ys][$ms][$ds]['moe'] = mt_rand(-100,100);
|
86 | | $struct_7[$ys][$ms][$ds]['larry'] = mt_rand(-100,100);
|
87 | | $struct_7[$ys][$ms][$ds]['curly'] = mt_rand(-100,100);
|
88 | | }
|
89 | | }
|
90 | | }
|
91 | | $l_res_7 = simpletest_xmlrpc_nestedStructTest($struct_7);
|
92 | | $r_res_7 = xmlrpc($xml_url, 'validator1.nestedStructTest', $struct_7);
|
93 | | $this->assertIdentical($l_res_7, $r_res_7, 'nested struct test: %s');
|
94 | |
|
95 | |
|
96 | | $int_8 = mt_rand(-100,100);
|
97 | | $l_res_8 = simpletest_xmlrpc_simpleStructReturnTest($int_8);
|
98 | | $r_res_8 = xmlrpc($xml_url, 'validator1.simpleStructReturnTest', $int_8);
|
99 | | $this->assertIdentical($l_res_8, $r_res_8, 'nested struct test: %s');
|
100 | |
|
101 | | /* Now test multicall */
|
102 | | $x = array();
|
103 | | $x[] = array('validator1.arrayOfStructsTest', $array_1);
|
104 | | $x[] = array('validator1.countTheEntities', $string_2);
|
105 | | $x[] = array('validator1.easyStructTest', $struct_3);
|
106 | | $x[] = array('validator1.echoStructTest', $struct_4);
|
107 | | $x[] = array('validator1.manyTypesTest', $int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), xmlrpc_base64($base64_5));
|
108 | | $x[] = array('validator1.moderateSizeArrayCheck', $array_6);
|
109 | | $x[] = array('validator1.nestedStructTest', $struct_7);
|
110 | | $x[] = array('validator1.simpleStructReturnTest', $int_8);
|
111 | |
|
112 | | $a_l_res = array($l_res_1, $l_res_2, $l_res_3, $l_res_4, $l_res_5, $l_res_6, $l_res_7, $l_res_8);
|
113 | | $a_r_res = xmlrpc($xml_url, $x);
|
114 | | $this->assertEqual($a_l_res, $a_r_res, 'multicall equals result');
|
115 | | }
|
116 | | }
|
117 | | ? |