1--TEST--
2Bug #75063 Many filesystem-related functions do not work with multibyte file names, UTF-8
3--SKIPIF--
4<?php
5include __DIR__ . DIRECTORY_SEPARATOR . "util.inc";
6
7skip_if_not_win();
8if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
9skip_if_no_required_exts();
10
11?>
12--FILE--
13<?php
14
15/* This file is in UTF-8. */
16
17include __DIR__ . DIRECTORY_SEPARATOR . "util.inc";
18
19$dir_basename = "тест";
20$prefix = __DIR__ . DIRECTORY_SEPARATOR . "bug75063-utf8";
21$d0 = $prefix . DIRECTORY_SEPARATOR . $dir_basename;
22
23mkdir($prefix);
24create_verify_dir($prefix, $dir_basename);
25
26var_dump(get_basename_with_cp($d0, 65001, false));
27
28$old_cwd = getcwd();
29var_dump(chdir($d0));
30
31$code = <<<CODE
32<?php
33
34foreach(["test", "таст"] as \$fn) {
35    file_put_contents("\$fn.txt", "");
36}
37
38var_dump(getcwd());
39if (\$dh = opendir(getcwd())) {
40    while ((\$file = readdir(\$dh)) !== false) {
41        if ("." == \$file || ".." == \$file) continue;
42        var_dump(\$file);
43    }
44    closedir(\$dh);
45}
46CODE;
47$code_fn = "code.php";
48file_put_contents($code_fn, $code);
49
50print(shell_exec(getenv('TEST_PHP_EXECUTABLE_ESCAPED') . " -nf code.php"));
51
52chdir($old_cwd);
53
54?>
55--CLEAN--
56<?php
57$dir_basename = "тест";
58$prefix = __DIR__ . DIRECTORY_SEPARATOR . "bug75063-utf8";
59$d0 = $prefix . DIRECTORY_SEPARATOR . $dir_basename;
60
61$obj = scandir($d0);
62foreach ($obj as $file) {
63    if ("." == $file || ".." == $file) continue;
64    unlink($d0 . DIRECTORY_SEPARATOR . $file);
65}
66
67rmdir($d0);
68rmdir($prefix);
69
70?>
71--EXPECTF--
72string(8) "тест"
73bool(true)
74string(%d) "%sbug75063-utf8%eтест"
75string(8) "code.php"
76string(8) "test.txt"
77string(12) "таст.txt"
78