![]() ![]() | ![]() |
1.1 misho 1: --TEST--
2: Test token_get_all() function : usage variations - invalid token values
1.1.1.2 misho 3: --SKIPIF--
4: <?php if (!extension_loaded("tokenizer")) print "skip"; ?>
1.1 misho 5: --FILE--
6: <?php
7: /* Prototype : array token_get_all(string $source)
8: * Description: splits the given source into an array of PHP languange tokens
9: * Source code: ext/tokenizer/tokenizer.c
10: */
11:
12: /*
13: * Testing token_get_all() with 'source' string containing invalid/unknown token value
14: * unknown tokens - T_UNKNOWN(307)
15: */
16:
17: echo "*** Testing token_get_all() : with invalid/unknown tokens ***\n";
18:
19: // with valid php tags and invalid tokens
20: echo "-- with valid PHP tags & invlid tokens --\n";
21: $source = '<?php
22: struct myStruct {
23: variable $a;
24: method() { display $a; }
25: }
26: ?>';
27: var_dump( token_get_all($source));
28:
1.1.1.3 ! misho 29: // with invalid open tag for testing entire source to be unknown token
1.1 misho 30: echo "-- with invlalid PHP open tag & valid tokens --\n";
31: $source = '<pli
32: echo "hello world"; ?>';
33: var_dump( token_get_all($source));
34:
35: // with invalid PHP tags and invalid tokens
36: echo "-- with invalid PHP tags and tokens --\n";
37: $source = '<PDP display $a; <';
38: var_dump( token_get_all($source));
39:
40: echo "Done"
41: ?>
42: --EXPECTF--
43: *** Testing token_get_all() : with invalid/unknown tokens ***
44: -- with valid PHP tags & invlid tokens --
45: array(29) {
46: [0]=>
47: array(3) {
48: [0]=>
1.1.1.2 misho 49: int(%d)
1.1 misho 50: [1]=>
51: string(6) "<?php "
52: [2]=>
53: int(1)
54: }
55: [1]=>
56: array(3) {
57: [0]=>
1.1.1.2 misho 58: int(%d)
1.1 misho 59: [1]=>
60: string(1) "
61: "
62: [2]=>
63: int(1)
64: }
65: [2]=>
66: array(3) {
67: [0]=>
1.1.1.2 misho 68: int(%d)
1.1 misho 69: [1]=>
70: string(6) "struct"
71: [2]=>
72: int(2)
73: }
74: [3]=>
75: array(3) {
76: [0]=>
1.1.1.2 misho 77: int(%d)
1.1 misho 78: [1]=>
79: string(1) " "
80: [2]=>
81: int(2)
82: }
83: [4]=>
84: array(3) {
85: [0]=>
1.1.1.2 misho 86: int(%d)
1.1 misho 87: [1]=>
88: string(8) "myStruct"
89: [2]=>
90: int(2)
91: }
92: [5]=>
93: array(3) {
94: [0]=>
1.1.1.2 misho 95: int(%d)
1.1 misho 96: [1]=>
97: string(1) " "
98: [2]=>
99: int(2)
100: }
101: [6]=>
102: string(1) "{"
103: [7]=>
104: array(3) {
105: [0]=>
1.1.1.2 misho 106: int(%d)
1.1 misho 107: [1]=>
108: string(3) "
109: "
110: [2]=>
111: int(2)
112: }
113: [8]=>
114: array(3) {
115: [0]=>
1.1.1.2 misho 116: int(%d)
1.1 misho 117: [1]=>
118: string(8) "variable"
119: [2]=>
1.1.1.2 misho 120: int(%d)
1.1 misho 121: }
122: [9]=>
123: array(3) {
124: [0]=>
1.1.1.2 misho 125: int(%d)
1.1 misho 126: [1]=>
127: string(1) " "
128: [2]=>
1.1.1.2 misho 129: int(%d)
1.1 misho 130: }
131: [10]=>
132: array(3) {
133: [0]=>
1.1.1.2 misho 134: int(%d)
1.1 misho 135: [1]=>
136: string(2) "$a"
137: [2]=>
1.1.1.2 misho 138: int(%d)
1.1 misho 139: }
140: [11]=>
141: string(1) ";"
142: [12]=>
143: array(3) {
144: [0]=>
1.1.1.2 misho 145: int(%d)
1.1 misho 146: [1]=>
147: string(3) "
148: "
149: [2]=>
1.1.1.2 misho 150: int(%d)
1.1 misho 151: }
152: [13]=>
153: array(3) {
154: [0]=>
1.1.1.2 misho 155: int(%d)
1.1 misho 156: [1]=>
157: string(6) "method"
158: [2]=>
159: int(4)
160: }
161: [14]=>
162: string(1) "("
163: [15]=>
164: string(1) ")"
165: [16]=>
166: array(3) {
167: [0]=>
1.1.1.2 misho 168: int(%d)
1.1 misho 169: [1]=>
170: string(1) " "
171: [2]=>
172: int(4)
173: }
174: [17]=>
175: string(1) "{"
176: [18]=>
177: array(3) {
178: [0]=>
1.1.1.2 misho 179: int(%d)
1.1 misho 180: [1]=>
181: string(1) " "
182: [2]=>
183: int(4)
184: }
185: [19]=>
186: array(3) {
187: [0]=>
1.1.1.2 misho 188: int(%d)
1.1 misho 189: [1]=>
190: string(7) "display"
191: [2]=>
192: int(4)
193: }
194: [20]=>
195: array(3) {
196: [0]=>
1.1.1.2 misho 197: int(%d)
1.1 misho 198: [1]=>
199: string(1) " "
200: [2]=>
201: int(4)
202: }
203: [21]=>
204: array(3) {
205: [0]=>
1.1.1.2 misho 206: int(%d)
1.1 misho 207: [1]=>
208: string(2) "$a"
209: [2]=>
210: int(4)
211: }
212: [22]=>
213: string(1) ";"
214: [23]=>
215: array(3) {
216: [0]=>
1.1.1.2 misho 217: int(%d)
1.1 misho 218: [1]=>
219: string(1) " "
220: [2]=>
221: int(4)
222: }
223: [24]=>
224: string(1) "}"
225: [25]=>
226: array(3) {
227: [0]=>
1.1.1.2 misho 228: int(%d)
1.1 misho 229: [1]=>
230: string(1) "
231: "
232: [2]=>
233: int(4)
234: }
235: [26]=>
236: string(1) "}"
237: [27]=>
238: array(3) {
239: [0]=>
1.1.1.2 misho 240: int(%d)
1.1 misho 241: [1]=>
242: string(1) "
243: "
244: [2]=>
245: int(5)
246: }
247: [28]=>
248: array(3) {
249: [0]=>
1.1.1.2 misho 250: int(%d)
1.1 misho 251: [1]=>
252: string(2) "?>"
253: [2]=>
254: int(6)
255: }
256: }
257: -- with invlalid PHP open tag & valid tokens --
258: array(1) {
259: [0]=>
260: array(3) {
261: [0]=>
1.1.1.2 misho 262: int(%d)
1.1 misho 263: [1]=>
264: string(28) "<pli
265: echo "hello world"; ?>"
266: [2]=>
267: int(1)
268: }
269: }
270: -- with invalid PHP tags and tokens --
271: array(1) {
272: [0]=>
273: array(3) {
274: [0]=>
1.1.1.2 misho 275: int(%d)
1.1 misho 276: [1]=>
277: string(19) "<PDP display $a; <"
278: [2]=>
279: int(1)
280: }
281: }
282: Done