xref: /PHP-5.6/ext/standard/tests/file/001.phpt (revision 9f8501b3)
1--TEST--
2File type functions
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip no symlinks on Windows');
7}
8if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
9?>
10--FILE--
11<?php
12chdir(dirname(__FILE__));
13@unlink('test.file');
14@unlink('test.link');
15if (file_exists('test.file')) {
16    echo "test.file exists\n";
17} else {
18    echo "test.file does not exist\n";
19}
20fclose (fopen('test.file', 'w'));
21chmod ('test.file', 0744);
22if (file_exists('test.file')) {
23    echo "test.file exists\n";
24} else {
25    echo "test.file does not exist\n";
26}
27sleep (2);
28symlink('test.file','test.link');
29if (file_exists('test.link')) {
30    echo "test.link exists\n";
31} else {
32    echo "test.link does not exist\n";
33}
34if (is_link('test.file')) {
35    echo "test.file is a symlink\n";
36} else {
37    echo "test.file is not a symlink\n";
38}
39if (is_link('test.link')) {
40    echo "test.link is a symlink\n";
41} else {
42    echo "test.link is not a symlink\n";
43}
44if (file_exists('test.file')) {
45    echo "test.file exists\n";
46} else {
47    echo "test.file does not exist\n";
48}
49$s = stat ('test.file');
50$ls = lstat ('test.file');
51for ($i = 0; $i <= 12; $i++) {
52    if ($ls[$i] != $s[$i]) {
53	echo "test.file lstat and stat differ at element $i\n";
54    }
55}
56$s = stat ('test.link');
57$ls = lstat ('test.link');
58for ($i = 0; $i <= 11; $i++) {
59    if ($ls[$i] != $s[$i]) {
60	if ($i != 6 && $i != 10 && $i != 11) echo "test.link lstat and stat differ at element $i\n";
61    }
62}
63echo "test.file is " . filetype('test.file') . "\n";
64echo "test.link is " . filetype('test.link') . "\n";
65printf ("test.file permissions are 0%o\n", 0777 & fileperms('test.file'));
66echo "test.file size is " . filesize('test.file') . "\n";
67if (is_writeable('test.file')) {
68    echo "test.file is writeable\n";
69} else {
70    echo "test.file is not writeable\n";
71}
72if (is_readable('test.file')) {
73    echo "test.file is readable\n";
74} else {
75    echo "test.file is not readable\n";
76}
77if (is_executable('test.file')) {
78    echo "test.file is executable\n";
79} else {
80    echo "test.file is not executable\n";
81}
82if (is_file('test.file')) {
83    echo "test.file is a regular file\n";
84} else {
85    echo "test.file is not a regular file\n";
86}
87if (is_file('test.link')) {
88    echo "test.link is a regular file\n";
89} else {
90    echo "test.link is not a regular file\n";
91}
92if (is_dir('test.link')) {
93    echo "test.link is a directory\n";
94} else {
95    echo "test.link is not a directory\n";
96}
97if (is_dir('../file')) {
98    echo "../file is a directory\n";
99} else {
100    echo "../file is not a directory\n";
101}
102if (is_dir('test.file')) {
103    echo "test.file is a directory\n";
104} else {
105    echo "test.file is not a directory\n";
106}
107unlink('test.file');
108unlink('test.link');
109if (file_exists('test.file')) {
110    echo "test.file exists (cached)\n";
111} else {
112    echo "test.file does not exist\n";
113}
114clearstatcache();
115if (file_exists('test.file')) {
116    echo "test.file exists\n";
117} else {
118    echo "test.file does not exist\n";
119}
120?>
121--EXPECT--
122test.file does not exist
123test.file exists
124test.link exists
125test.file is not a symlink
126test.link is a symlink
127test.file exists
128test.link lstat and stat differ at element 1
129test.link lstat and stat differ at element 2
130test.link lstat and stat differ at element 7
131test.link lstat and stat differ at element 8
132test.link lstat and stat differ at element 9
133test.file is file
134test.link is link
135test.file permissions are 0744
136test.file size is 0
137test.file is writeable
138test.file is readable
139test.file is executable
140test.file is a regular file
141test.link is a regular file
142test.link is not a directory
143../file is a directory
144test.file is not a directory
145test.file does not exist
146test.file does not exist
147