Skip to content

Commit 582b32c

Browse files
author
andy wharmby
committed
Fixed base64_decode variation tests and new base64_encode test. Tested on Windows, Linux and Linux64 bit
1 parent f7abb84 commit 582b32c

File tree

3 files changed

+252
-181
lines changed

3 files changed

+252
-181
lines changed

ext/standard/tests/url/base64_decode_variation_001.phpt

Lines changed: 101 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -18,150 +18,164 @@ echo "*** Testing base64_decode() : usage variations ***\n";
1818
// Initialise function arguments not being substituted (if any)
1919
$strict = true;
2020

21+
//getting the resource
22+
$file_handle = fopen(__FILE__, "r");
23+
2124
//get an unset variable
2225
$unset_var = 10;
2326
unset ($unset_var);
2427

2528
//array of values to iterate over
26-
$values = array(
27-
28-
// int data
29-
0,
30-
1,
31-
12345,
32-
-2345,
33-
34-
// float data
35-
10.5,
36-
-10.5,
37-
10.1234567e10,
38-
10.7654321E-10,
39-
.5,
40-
41-
// array data
42-
array(),
43-
array(0),
44-
array(1),
45-
array(1, 2),
46-
array('color' => 'red', 'item' => 'pen'),
47-
48-
// null data
49-
NULL,
50-
null,
51-
52-
// boolean data
53-
true,
54-
false,
55-
TRUE,
56-
FALSE,
57-
58-
// empty data
59-
"",
60-
'',
61-
62-
// object data
63-
new stdclass(),
64-
65-
// undefined data
66-
$undefined_var,
67-
68-
// unset data
69-
$unset_var,
29+
$values = array (
30+
// int data
31+
"0" => 0,
32+
"1" => 1,
33+
"12345" => 12345,
34+
"-2345" => -2345,
35+
36+
// float data
37+
"10.5" => 10.5,
38+
"-10.5" => -10.5,
39+
"10.1234567e10" => 10.1234567e10,
40+
"10.7654321E-10" => 10.7654321E-10,
41+
".5" => .5,
42+
43+
// array data
44+
"array()" => array(),
45+
"array(0)" => array(0),
46+
"array(1)" => array(1),
47+
"array(1, 2)" => array(1, 2),
48+
"array('color' => 'red', 'item' => 'pen'" => array('color' => 'red', 'item' => 'pen'),
49+
50+
// null data
51+
"NULL" => NULL,
52+
"null" => null,
53+
54+
// boolean data
55+
"true" => true,
56+
"false" => false,
57+
"TRUE" => TRUE,
58+
"FALSE" => FALSE,
59+
60+
// empty data
61+
"\"\"" => "",
62+
"''" => '',
63+
64+
// object data
65+
"stdClass object" => new stdclass(),
66+
67+
// undefined data
68+
"undefined variable" => $undefined_var,
69+
70+
// unset data
71+
"unset variable" => $unset_var,
72+
73+
// resource data
74+
"resource" => $file_handle
7075
);
7176

72-
// loop through each element of the array for str
73-
74-
foreach($values as $value) {
75-
echo "\nArg value $value \n";
76-
var_dump( base64_decode($value, $strict) );
77+
// loop through each element of the array for str argument
78+
79+
foreach($values as $key=>$value) {
80+
echo "\n-- Arg value $key --\n";
81+
$output = base64_decode($value, $strict);
82+
83+
if (is_string($output)) {
84+
var_dump(bin2hex($output));
85+
} else {
86+
var_dump($output);
87+
}
7788
};
7889

79-
echo "Done";
8090
?>
91+
===Done===
8192
--EXPECTF--
8293
*** Testing base64_decode() : usage variations ***
83-
Error: 8 - Undefined variable: undefined_var, %s(63)
84-
Error: 8 - Undefined variable: unset_var, %s(66)
94+
Error: 8 - Undefined variable: undefined_var, %s(%d)
95+
Error: 8 - Undefined variable: unset_var, %s(%d)
8596

86-
Arg value 0
97+
-- Arg value 0 --
8798
string(0) ""
8899

89-
Arg value 1
100+
-- Arg value 1 --
90101
string(0) ""
91102

92-
Arg value 12345
93-
string(3) "×mø"
103+
-- Arg value 12345 --
104+
string(6) "d76df8"
94105

95-
Arg value -2345
106+
-- Arg value -2345 --
96107
bool(false)
97108

98-
Arg value 10.5
109+
-- Arg value 10.5 --
99110
bool(false)
100111

101-
Arg value -10.5
112+
-- Arg value -10.5 --
102113
bool(false)
103114

104-
Arg value 101234567000
105-
string(9) "×MvߎzïM4"
115+
-- Arg value 10.1234567e10 --
116+
string(18) "d74d76df8e7aef4d34"
106117

107-
Arg value 1.07654321E-9
118+
-- Arg value 10.7654321E-10 --
108119
bool(false)
109120

110-
Arg value 0.5
121+
-- Arg value .5 --
111122
bool(false)
112123

113-
Arg value Array
114-
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(73)
124+
-- Arg value array() --
125+
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
115126
NULL
116127

117-
Arg value Array
118-
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(73)
128+
-- Arg value array(0) --
129+
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
119130
NULL
120131

121-
Arg value Array
122-
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(73)
132+
-- Arg value array(1) --
133+
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
123134
NULL
124135

125-
Arg value Array
126-
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(73)
136+
-- Arg value array(1, 2) --
137+
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
127138
NULL
128139

129-
Arg value Array
130-
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(73)
140+
-- Arg value array('color' => 'red', 'item' => 'pen' --
141+
Error: 2 - base64_decode() expects parameter 1 to be string, array given, %s(%d)
131142
NULL
132143

133-
Arg value
144+
-- Arg value NULL --
134145
string(0) ""
135146

136-
Arg value
147+
-- Arg value null --
137148
string(0) ""
138149

139-
Arg value 1
150+
-- Arg value true --
140151
string(0) ""
141152

142-
Arg value
153+
-- Arg value false --
143154
string(0) ""
144155

145-
Arg value 1
156+
-- Arg value TRUE --
146157
string(0) ""
147158

148-
Arg value
159+
-- Arg value FALSE --
149160
string(0) ""
150161

151-
Arg value
162+
-- Arg value "" --
152163
string(0) ""
153164

154-
Arg value
165+
-- Arg value '' --
155166
string(0) ""
156-
Error: 4096 - Object of class stdClass could not be converted to string, %s(72)
157167

158-
Arg value
159-
Error: 2 - base64_decode() expects parameter 1 to be string, object given, %s(73)
168+
-- Arg value stdClass object --
169+
Error: 2 - base64_decode() expects parameter 1 to be string, object given, %s(%d)
160170
NULL
161171

162-
Arg value
172+
-- Arg value undefined variable --
163173
string(0) ""
164174

165-
Arg value
175+
-- Arg value unset variable --
166176
string(0) ""
167-
Done
177+
178+
-- Arg value resource --
179+
Error: 2 - base64_decode() expects parameter 1 to be string, resource given, %s(%d)
180+
NULL
181+
===Done===

0 commit comments

Comments
 (0)