xmlrpc_test.module

You are here

  1. 7 modules/simpletest/tests/xmlrpc_test.module
  2. 8 core/modules/xmlrpc/tests/modules/xmlrpc_test/xmlrpc_test.module

Functions

File

modules/simpletest/tests/xmlrpc_test.module
View source
  1. <?php
  2. function xmlrpc_test_arrayOfStructsTest($array) {
  3. $sum = 0;
  4. foreach ($array as $struct) {
  5. if (isset($struct['curly'])) {
  6. $sum += $struct['curly'];
  7. }
  8. }
  9. return $sum;
  10. }
  11. function xmlrpc_test_countTheEntities($string) {
  12. return array(
  13. 'ctLeftAngleBrackets' => substr_count($string, '<'),
  14. 'ctRightAngleBrackets' => substr_count($string, '>'),
  15. 'ctAmpersands' => substr_count($string, '&'),
  16. 'ctApostrophes' => substr_count($string, "'"),
  17. 'ctQuotes' => substr_count($string, '"'),
  18. );
  19. }
  20. function xmlrpc_test_easyStructTest($array) {
  21. return $array["curly"] + $array["moe"] + $array["larry"];
  22. }
  23. function xmlrpc_test_echoStructTest($array) {
  24. return $array;
  25. }
  26. function xmlrpc_test_manyTypesTest($number, $boolean, $string, $double, $dateTime, $base64) {
  27. $timestamp = gmmktime($dateTime->hour, $dateTime->minute, $dateTime->second, $dateTime->month, $dateTime->day, $dateTime->year);
  28. return array($number, $boolean, $string, $double, xmlrpc_date($timestamp), xmlrpc_Base64($base64));
  29. }
  30. function xmlrpc_test_moderateSizeArrayCheck($array) {
  31. return array_shift($array) . array_pop($array);
  32. }
  33. function xmlrpc_test_nestedStructTest($array) {
  34. return $array["2000"]["04"]["01"]["larry"] + $array["2000"]["04"]["01"]["moe"] + $array["2000"]["04"]["01"]["curly"];
  35. }
  36. function xmlrpc_test_simpleStructReturnTest($number) {
  37. return array("times10" => ($number*10), "times100" => ($number*100), "times1000" => ($number*1000));
  38. }
  39. /**
  40. * Implements hook_xmlrpc().
  41. */
  42. function xmlrpc_test_xmlrpc() {
  43. return array(
  44. 'validator1.arrayOfStructsTest' => 'xmlrpc_test_arrayOfStructsTest',
  45. 'validator1.countTheEntities' => 'xmlrpc_test_countTheEntities',
  46. 'validator1.easyStructTest' => 'xmlrpc_test_easyStructTest',
  47. 'validator1.echoStructTest' => 'xmlrpc_test_echoStructTest',
  48. 'validator1.manyTypesTest' => 'xmlrpc_test_manyTypesTest',
  49. 'validator1.moderateSizeArrayCheck' => 'xmlrpc_test_moderateSizeArrayCheck',
  50. 'validator1.nestedStructTest' => 'xmlrpc_test_nestedStructTest',
  51. 'validator1.simpleStructReturnTest' => 'xmlrpc_test_simpleStructReturnTest',
  52. 'messages.messageSizedInKB' => 'xmlrpc_test_message_sized_in_kb',
  53. );
  54. }
  55. /**
  56. * Implements hook_xmlrpc_alter().
  57. *
  58. * Hide (or not) the system.methodSignature() service depending on a variable.
  59. */
  60. function xmlrpc_test_xmlrpc_alter(&$services) {
  61. if (variable_get('xmlrpc_test_xmlrpc_alter', FALSE)) {
  62. $remove = NULL;
  63. foreach ($services as $key => $value) {
  64. if (!is_array($value)) {
  65. continue;
  66. }
  67. if ($value[0] == 'system.methodSignature') {
  68. $remove = $key;
  69. break;
  70. }
  71. }
  72. if (isset($remove)) {
  73. unset($services[$remove]);
  74. }
  75. }
  76. }
  77. /**
  78. * Created a message of the desired size in KB.
  79. *
  80. * @param $size
  81. * Message size in KB.
  82. * @return array
  83. * Generated message structure.
  84. */
  85. function xmlrpc_test_message_sized_in_kb($size) {
  86. $message = array();
  87. $word = 'abcdefg';
  88. // Create a ~1KB sized struct.
  89. for ($i = 0 ; $i < 128; $i++) {
  90. $line['word_' . $i] = $word;
  91. }
  92. for ($i = 0; $i < $size; $i++) {
  93. $message['line_' . $i] = $line;
  94. }
  95. return $message;
  96. }