Projet

Général

Profil

Paste
Télécharger (3,1 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / simpletest / tests / xmlrpc_test.module @ db2d93dd

1
<?php
2

    
3
function xmlrpc_test_arrayOfStructsTest($array) {
4
  $sum = 0;
5
  foreach ($array as $struct) {
6
    if (isset($struct['curly'])) {
7
      $sum += $struct['curly'];
8
    }
9
  }
10
  return $sum;
11
}
12

    
13
function xmlrpc_test_countTheEntities($string) {
14
  return array(
15
    'ctLeftAngleBrackets' => substr_count($string, '<'),
16
    'ctRightAngleBrackets' => substr_count($string, '>'),
17
    'ctAmpersands' => substr_count($string, '&'),
18
    'ctApostrophes' => substr_count($string, "'"),
19
    'ctQuotes' => substr_count($string, '"'),
20
  );
21
}
22

    
23
function xmlrpc_test_easyStructTest($array) {
24
  return $array["curly"] + $array["moe"] + $array["larry"];
25
}
26

    
27
function xmlrpc_test_echoStructTest($array) {
28
  return $array;
29
}
30

    
31
function xmlrpc_test_manyTypesTest($number, $boolean, $string, $double, $dateTime, $base64) {
32
  $timestamp = gmmktime($dateTime->hour, $dateTime->minute, $dateTime->second, $dateTime->month, $dateTime->day, $dateTime->year);
33
  return array($number, $boolean, $string, $double, xmlrpc_date($timestamp), xmlrpc_Base64($base64));
34
}
35

    
36
function xmlrpc_test_moderateSizeArrayCheck($array) {
37
  return array_shift($array) . array_pop($array);
38
}
39

    
40
function xmlrpc_test_nestedStructTest($array) {
41
  return $array["2000"]["04"]["01"]["larry"] + $array["2000"]["04"]["01"]["moe"] + $array["2000"]["04"]["01"]["curly"];
42
}
43

    
44
function xmlrpc_test_simpleStructReturnTest($number) {
45
  return array("times10" => ($number*10), "times100" => ($number*100), "times1000" => ($number*1000));
46
}
47

    
48
/**
49
 * Implements hook_xmlrpc().
50
 */
51
function xmlrpc_test_xmlrpc() {
52
  return array(
53
    'validator1.arrayOfStructsTest' => 'xmlrpc_test_arrayOfStructsTest',
54
    'validator1.countTheEntities' => 'xmlrpc_test_countTheEntities',
55
    'validator1.easyStructTest' => 'xmlrpc_test_easyStructTest',
56
    'validator1.echoStructTest' => 'xmlrpc_test_echoStructTest',
57
    'validator1.manyTypesTest' => 'xmlrpc_test_manyTypesTest',
58
    'validator1.moderateSizeArrayCheck' => 'xmlrpc_test_moderateSizeArrayCheck',
59
    'validator1.nestedStructTest' => 'xmlrpc_test_nestedStructTest',
60
    'validator1.simpleStructReturnTest' => 'xmlrpc_test_simpleStructReturnTest',
61
    'messages.messageSizedInKB' => 'xmlrpc_test_message_sized_in_kb',
62
  );
63
}
64

    
65
/**
66
 * Implements hook_xmlrpc_alter().
67
 *
68
 * Hide (or not) the system.methodSignature() service depending on a variable.
69
 */
70
function xmlrpc_test_xmlrpc_alter(&$services) {
71
  if (variable_get('xmlrpc_test_xmlrpc_alter', FALSE)) {
72
    $remove = NULL;
73
    foreach ($services as $key => $value) {
74
      if (!is_array($value)) {
75
        continue;
76
      }
77
      if ($value[0] == 'system.methodSignature') {
78
        $remove = $key;
79
        break;
80
      }
81
    }
82
    if (isset($remove)) {
83
      unset($services[$remove]);
84
    }
85
  }
86
}
87

    
88
/**
89
 * Created a message of the desired size in KB.
90
 *
91
 * @param $size
92
 *   Message size in KB.
93
 * @return array
94
 *   Generated message structure.
95
 */
96
function xmlrpc_test_message_sized_in_kb($size) {
97
  $message = array();
98

    
99
  $word = 'abcdefg';
100

    
101
  // Create a ~1KB sized struct.
102
  for ($i = 0 ; $i < 128; $i++) {
103
    $line['word_' . $i] = $word;
104
  }
105

    
106
  for ($i = 0; $i < $size; $i++) {
107
    $message['line_' . $i] = $line;
108
  }
109

    
110
  return $message;
111
}