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 vlaues
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 integer, array given in %s on line %s
92NULL
93-- Iteration 2 --
94
95Warning: get_html_translation_table() expects parameter 2 to be integer, array given in %s on line %s
96NULL
97-- Iteration 3 --
98
99Warning: get_html_translation_table() expects parameter 2 to be integer, array given in %s on line %s
100NULL
101-- Iteration 4 --
102
103Warning: get_html_translation_table() expects parameter 2 to be integer, array given in %s on line %s
104NULL
105-- Iteration 5 --
106
107Warning: get_html_translation_table() expects parameter 2 to be integer, array given in %s on line %s
108NULL
109-- Iteration 6 --
110array(4) {
111  ["&"]=>
112  string(5) "&amp;"
113  ["'"]=>
114  string(6) "&#039;"
115  ["<"]=>
116  string(4) "&lt;"
117  [">"]=>
118  string(4) "&gt;"
119}
120-- Iteration 7 --
121array(3) {
122  ["&"]=>
123  string(5) "&amp;"
124  ["<"]=>
125  string(4) "&lt;"
126  [">"]=>
127  string(4) "&gt;"
128}
129-- Iteration 8 --
130array(4) {
131  ["&"]=>
132  string(5) "&amp;"
133  ["'"]=>
134  string(6) "&#039;"
135  ["<"]=>
136  string(4) "&lt;"
137  [">"]=>
138  string(4) "&gt;"
139}
140-- Iteration 9 --
141array(3) {
142  ["&"]=>
143  string(5) "&amp;"
144  ["<"]=>
145  string(4) "&lt;"
146  [">"]=>
147  string(4) "&gt;"
148}
149-- Iteration 10 --
150
151Warning: get_html_translation_table() expects parameter 2 to be integer, string given in %s on line %s
152NULL
153-- Iteration 11 --
154
155Warning: get_html_translation_table() expects parameter 2 to be integer, string given in %s on line %s
156NULL
157-- Iteration 12 --
158
159Warning: get_html_translation_table() expects parameter 2 to be integer, object given in %s on line %s
160NULL
161-- Iteration 13 --
162
163Warning: get_html_translation_table() expects parameter 2 to be integer, string given in %s on line %s
164NULL
165-- Iteration 14 --
166
167Warning: get_html_translation_table() expects parameter 2 to be integer, string given in %s on line %s
168NULL
169-- Iteration 15 --
170array(3) {
171  ["&"]=>
172  string(5) "&amp;"
173  ["<"]=>
174  string(4) "&lt;"
175  [">"]=>
176  string(4) "&gt;"
177}
178-- Iteration 16 --
179array(3) {
180  ["&"]=>
181  string(5) "&amp;"
182  ["<"]=>
183  string(4) "&lt;"
184  [">"]=>
185  string(4) "&gt;"
186}
187-- Iteration 17 --
188
189Warning: get_html_translation_table() expects parameter 2 to be integer, resource given in %s on line %s
190NULL
191-- Iteration 18 --
192array(3) {
193  ["&"]=>
194  string(5) "&amp;"
195  ["<"]=>
196  string(4) "&lt;"
197  [">"]=>
198  string(4) "&gt;"
199}
200-- Iteration 19 --
201array(3) {
202  ["&"]=>
203  string(5) "&amp;"
204  ["<"]=>
205  string(4) "&lt;"
206  [">"]=>
207  string(4) "&gt;"
208}
209Done
210