1--TEST--
2Test base64_encode() function : basic functionality - check algorithm round trips
3--FILE--
4<?php
5/*
6 * Test base64_encode with single byte values.
7 */
8
9echo "*** Testing base64_encode() : basic functionality ***\n";
10
11$values = array(
12    "Hello World",
13    "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!%^&*(){}[]",
14    "\n\t Line with control characters\r\n",
15    "\xC1\xC2\xC3\xC4\xC5\xC6",
16    "\75\76\77\78\79\80",
17    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%!",
18    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%!\75\76\77\78\79\80",
19    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%!ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%!",
20    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%!ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%!\75\76\77\78\79\80"
21);
22
23echo "\n--- Testing base64_encode() with binary string input ---\n";
24
25$counter = 1;
26foreach($values as $str) {
27    echo "-- Iteration $counter --\n";
28
29    $enc = base64_encode($str);
30    $dec = base64_decode($enc);
31
32    if ($dec != $str) {
33        echo "TEST FAILED\n";
34    } else {
35        echo "TEST PASSED\n";
36    }
37
38    $counter ++;
39}
40
41?>
42--EXPECT--
43*** Testing base64_encode() : basic functionality ***
44
45--- Testing base64_encode() with binary string input ---
46-- Iteration 1 --
47TEST PASSED
48-- Iteration 2 --
49TEST PASSED
50-- Iteration 3 --
51TEST PASSED
52-- Iteration 4 --
53TEST PASSED
54-- Iteration 5 --
55TEST PASSED
56-- Iteration 6 --
57TEST PASSED
58-- Iteration 7 --
59TEST PASSED
60-- Iteration 8 --
61TEST PASSED
62-- Iteration 9 --
63TEST PASSED
64