| 1 |
lars |
1 |
--TEST--
|
|
|
2 |
XMLRPCext Backend XML-RPC server Validator1 test (countTheEntities)
|
|
|
3 |
--SKIPIF--
|
|
|
4 |
<?php
|
|
|
5 |
if (!function_exists('xmlrpc_server_create')) {
|
|
|
6 |
print "Skip XMLRPC extension unavailable";
|
|
|
7 |
}
|
|
|
8 |
?>
|
|
|
9 |
--FILE--
|
|
|
10 |
<?php
|
|
|
11 |
class TestServer {
|
|
|
12 |
/**
|
|
|
13 |
* test function
|
|
|
14 |
*
|
|
|
15 |
* see http://www.xmlrpc.com/validator1Docs
|
|
|
16 |
*
|
|
|
17 |
* @param string a string
|
|
|
18 |
* @return array result
|
|
|
19 |
*/
|
|
|
20 |
public static function countTheEntities($string) {
|
|
|
21 |
$ctLeftAngleBrackets = substr_count($string, '<');
|
|
|
22 |
$ctRightAngleBrackets = substr_count($string, '>');
|
|
|
23 |
$ctAmpersands = substr_count($string, '&');
|
|
|
24 |
$ctApostrophes = substr_count($string, "'");
|
|
|
25 |
$ctQuotes = substr_count($string, '"');
|
|
|
26 |
return array(
|
|
|
27 |
'ctLeftAngleBrackets' => $ctLeftAngleBrackets,
|
|
|
28 |
'ctRightAngleBrackets' => $ctRightAngleBrackets,
|
|
|
29 |
'ctAmpersands' => $ctAmpersands,
|
|
|
30 |
'ctApostrophes' => $ctApostrophes,
|
|
|
31 |
'ctQuotes' => $ctQuotes
|
|
|
32 |
);
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
set_include_path(realpath(dirname(__FILE__) . '/../../../../') . PATH_SEPARATOR . get_include_path());
|
|
|
37 |
require_once 'XML/RPC2/Server.php';
|
|
|
38 |
$options = array(
|
|
|
39 |
'prefix' => 'validator1.',
|
|
|
40 |
'backend' => 'Xmlrpcext'
|
|
|
41 |
);
|
|
|
42 |
|
|
|
43 |
$server = XML_RPC2_Server::create('TestServer', $options);
|
|
|
44 |
$GLOBALS['HTTP_RAW_POST_DATA'] = <<<EOS
|
|
|
45 |
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
|
46 |
<methodCall>
|
|
|
47 |
<methodName>validator1.countTheEntities</methodName>
|
|
|
48 |
<params>
|
|
|
49 |
<param>
|
|
|
50 |
<value>
|
|
|
51 |
<string>foo <<< bar '> && '' #fo>o " bar</string>
|
|
|
52 |
</value>
|
|
|
53 |
</param>
|
|
|
54 |
</params>
|
|
|
55 |
</methodCall>
|
|
|
56 |
EOS
|
|
|
57 |
;
|
|
|
58 |
$response = $server->getResponse();
|
|
|
59 |
$result = (XML_RPC2_Backend_Php_Response::decode(simplexml_load_string($response)));
|
|
|
60 |
var_dump($result['ctLeftAngleBrackets']);
|
|
|
61 |
var_dump($result['ctRightAngleBrackets']);
|
|
|
62 |
var_dump($result['ctAmpersands']);
|
|
|
63 |
var_dump($result['ctApostrophes']);
|
|
|
64 |
var_dump($result['ctQuotes']);
|
|
|
65 |
|
|
|
66 |
?>
|
|
|
67 |
--EXPECT--
|
|
|
68 |
int(3)
|
|
|
69 |
int(2)
|
|
|
70 |
int(2)
|
|
|
71 |
int(3)
|
|
|
72 |
int(1)
|