1--TEST-- 2Test get_html_translation_table() function : usage variations - unexpected quote_style values 3--FILE-- 4<?php 5/* Prototype : array get_html_translation_table ( [int $table [, int $quote_style [, string charset_hint]]] ) 6 * Description: Returns the internal translation table used by htmlspecialchars and htmlentities 7 * Source code: ext/standard/html.c 8*/ 9 10/* 11 * test get_html_translation_table() with unexpteced value for argument $quote_style 12*/ 13 14//set locale to en_US.UTF-8 15setlocale(LC_ALL, "en_US.UTF-8"); 16 17echo "*** Testing get_html_translation_table() : usage variations ***\n"; 18// initialize all required variables 19$table = HTML_SPECIALCHARS; 20 21// get an unset variable 22$unset_var = 10; 23unset($unset_var); 24 25// a resource var 26$fp = fopen(__FILE__, "r"); 27 28// array with different values 29$values = array ( 30 31 // array values 32 array(), 33 array(0), 34 array(1), 35 array(1, 2), 36 array('color' => 'red', 'item' => 'pen'), 37 38 // boolean values 39 true, 40 false, 41 TRUE, 42 FALSE, 43 44 // string values 45 "string", 46 'string', 47 48 // objects 49 new stdclass(), 50 51 // empty string 52 "", 53 '', 54 55 // null values 56 NULL, 57 null, 58 59 // resource var 60 $fp, 61 62 // undefined variable 63 @$undefined_var, 64 65 // unset variable 66 @$unset_var 67); 68 69 70// loop through each element of the array and check the working of get_html_translation_table() 71// when $quote_style argument is supplied with different values 72echo "\n--- Testing get_html_translation_table() by supplying different values for 'quote_style' argument ---\n"; 73$counter = 1; 74for($index = 0; $index < count($values); $index ++) { 75 echo "-- Iteration $counter --\n"; 76 $quote_style = $values [$index]; 77 78 var_dump( get_html_translation_table($table, $quote_style) ); 79 80 $counter ++; 81} 82 83echo "Done\n"; 84?> 85--EXPECTF-- 86*** Testing get_html_translation_table() : usage variations *** 87 88--- Testing get_html_translation_table() by supplying different values for 'quote_style' argument --- 89-- Iteration 1 -- 90 91Warning: get_html_translation_table() expects parameter 2 to be int, array given in %s on line %d 92NULL 93-- Iteration 2 -- 94 95Warning: get_html_translation_table() expects parameter 2 to be int, array given in %s on line %d 96NULL 97-- Iteration 3 -- 98 99Warning: get_html_translation_table() expects parameter 2 to be int, array given in %s on line %d 100NULL 101-- Iteration 4 -- 102 103Warning: get_html_translation_table() expects parameter 2 to be int, array given in %s on line %d 104NULL 105-- Iteration 5 -- 106 107Warning: get_html_translation_table() expects parameter 2 to be int, array given in %s on line %d 108NULL 109-- Iteration 6 -- 110array(4) { 111 ["&"]=> 112 string(5) "&" 113 ["'"]=> 114 string(6) "'" 115 ["<"]=> 116 string(4) "<" 117 [">"]=> 118 string(4) ">" 119} 120-- Iteration 7 -- 121array(3) { 122 ["&"]=> 123 string(5) "&" 124 ["<"]=> 125 string(4) "<" 126 [">"]=> 127 string(4) ">" 128} 129-- Iteration 8 -- 130array(4) { 131 ["&"]=> 132 string(5) "&" 133 ["'"]=> 134 string(6) "'" 135 ["<"]=> 136 string(4) "<" 137 [">"]=> 138 string(4) ">" 139} 140-- Iteration 9 -- 141array(3) { 142 ["&"]=> 143 string(5) "&" 144 ["<"]=> 145 string(4) "<" 146 [">"]=> 147 string(4) ">" 148} 149-- Iteration 10 -- 150 151Warning: get_html_translation_table() expects parameter 2 to be int, string given in %s on line %d 152NULL 153-- Iteration 11 -- 154 155Warning: get_html_translation_table() expects parameter 2 to be int, string given in %s on line %d 156NULL 157-- Iteration 12 -- 158 159Warning: get_html_translation_table() expects parameter 2 to be int, object given in %s on line %d 160NULL 161-- Iteration 13 -- 162 163Warning: get_html_translation_table() expects parameter 2 to be int, string given in %s on line %d 164NULL 165-- Iteration 14 -- 166 167Warning: get_html_translation_table() expects parameter 2 to be int, string given in %s on line %d 168NULL 169-- Iteration 15 -- 170array(3) { 171 ["&"]=> 172 string(5) "&" 173 ["<"]=> 174 string(4) "<" 175 [">"]=> 176 string(4) ">" 177} 178-- Iteration 16 -- 179array(3) { 180 ["&"]=> 181 string(5) "&" 182 ["<"]=> 183 string(4) "<" 184 [">"]=> 185 string(4) ">" 186} 187-- Iteration 17 -- 188 189Warning: get_html_translation_table() expects parameter 2 to be int, resource given in %s on line %d 190NULL 191-- Iteration 18 -- 192array(3) { 193 ["&"]=> 194 string(5) "&" 195 ["<"]=> 196 string(4) "<" 197 [">"]=> 198 string(4) ">" 199} 200-- Iteration 19 -- 201array(3) { 202 ["&"]=> 203 string(5) "&" 204 ["<"]=> 205 string(4) "<" 206 [">"]=> 207 string(4) ">" 208} 209Done 210