--- /dev/null
+--TEST--
+Test stat() functions: usage variations - effects of rename()
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die('skip.. only for Windows');
+}
+?>
+--FILE--
+<?php
+
+/*
+ * Prototype: array stat ( string $filename );
+ * Description: Gives information about a file
+ */
+
+/* test the effects of rename() on stats of dir/file */
+
+$file_path = dirname(__FILE__);
+require "$file_path/file.inc";
+
+
+/* create temp file and directory */
+mkdir("$file_path/stat_variation1/"); // temp dir
+
+$file_handle = fopen("$file_path/stat_variation1.tmp", "w"); // temp file
+fclose($file_handle);
+
+
+echo "*** Testing stat(): on file and directory ater renaming them ***\n";
+
+// renaming a file
+echo "-- Testing stat() for files after being renamed --\n";
+$old_filename = "$file_path/stat_variation1.tmp";
+$new_filename = "$file_path/stat_variation1a.tmp";
+$old_stat = stat($old_filename);
+clearstatcache();
+sleep(2);
+var_dump( rename($old_filename, $new_filename) );
+$new_stat = stat($new_filename);
+
+// compare the self stat
+var_dump( compare_self_stat($old_stat) );
+var_dump( compare_self_stat($new_stat) );
+
+// compare the two stats
+var_dump( compare_stats($old_stat, $old_stat, $all_stat_keys) );
+// clear the cache
+clearstatcache();
+
+// renaming a directory
+echo "-- Testing stat() for directory after being renamed --\n";
+$old_dirname = "$file_path/stat_variation1";
+$new_dirname = "$file_path/stat_variation1a";
+$old_stat = stat($old_dirname);
+clearstatcache();
+sleep(2);
+var_dump( rename($old_dirname, $new_dirname) );
+$new_stat = stat($new_dirname);
+
+// compare self stats
+var_dump( compare_self_stat($old_stat) );
+var_dump( compare_self_stat($new_stat) );
+
+// compare the two stats
+var_dump( compare_stats($old_stat, $new_stat, $all_stat_keys) );
+// clear the cache
+clearstatcache();
+
+
+echo "\n*** Done ***";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink("$file_path/stat_variation1a.tmp");
+rmdir("$file_path/stat_variation1a");
+?>
+--EXPECTF--
+*** Testing stat(): on file and directory ater renaming them ***
+-- Testing stat() for files after being renamed --
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+-- Testing stat() for directory after being renamed --
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+
+*** Done ***
--- /dev/null
+--TEST--
+Test stat() functions: usage variations - effects of writing to file
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die('skip.. only for Windows');
+}
+?>
+--FILE--
+<?php
+
+/*
+ * Prototype: array stat ( string $filename );
+ * Description: Gives information about a file
+ */
+
+/* test the effects of writing to a file on the stats of the file */
+
+
+$file_path = dirname(__FILE__);
+require "$file_path/file.inc";
+
+
+$filename = "$file_path/stat_variation2.tmp";
+$file_handle = fopen($filename, "w"); // temp file
+fclose($file_handle);
+
+
+echo "*** Testing stat(): writing to a file ***\n";
+
+// writing to an empty file
+echo "-- Testing stat() on file after data is written in it --\n";
+$old_stat = stat($filename);
+clearstatcache();
+sleep(2);
+$file_handle = fopen($filename, "w"); // temp file
+fwrite($file_handle, "Hello World");
+fclose($file_handle);
+$new_stat = stat($filename);
+
+// compare self stats
+var_dump( compare_self_stat($old_stat) );
+var_dump( compare_self_stat($new_stat) );
+// compare the stats
+$comp_arr = array(7, 'size');
+var_dump(compare_stats($old_stat, $new_stat, $comp_arr, "<"));
+clearstatcache();
+
+echo "\n*** Done ***";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink("$file_path/stat_variation2.tmp");
+?>
+--EXPECTF--
+*** Testing stat(): writing to a file ***
+-- Testing stat() on file after data is written in it --
+bool(true)
+bool(true)
+bool(true)
+
+*** Done ***
--- /dev/null
+--TEST--
+Test stat() functions: usage variations - effects of creating/deleting the dir/file
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die('skip.. only for Windows');
+}
+?>
+--FILE--
+<?php
+
+/*
+ * Prototype: array stat ( string $filename );
+ * Description: Gives information about a file
+ */
+
+/* test the effects of creating & deleting of subdir/file on the stats of dir/file */
+
+$file_path = dirname(__FILE__);
+require "$file_path/file.inc";
+
+
+/* create temp file and directory */
+mkdir("$file_path/stat_variation3/"); // temp dir
+
+echo "*** Testing stat(): with creating & deleting subdir/file ***\n";
+
+// creating and deleting subdir and files in the dir
+echo "-- Testing stat() on dir after subdir and file is created in it --\n";
+$dirname = "$file_path/stat_variation3";
+$old_stat = stat($dirname);
+clearstatcache();
+sleep(2);
+mkdir("$dirname/stat_variation3_subdir");
+$file_handle = fopen("$dirname/stat_variation3a.tmp", "w");
+fclose($file_handle);
+$new_stat = stat($dirname);
+
+// compare self stats
+var_dump( compare_self_stat($old_stat) );
+var_dump( compare_self_stat($new_stat) );
+// compare the stats
+$affected_members = array( 9, 'mtime');
+clearstatcache();
+sleep(2);
+var_dump(compare_stats($old_stat, $new_stat, $affected_members, "<"));
+unlink("$dirname/stat_variation3a.tmp");
+rmdir("$dirname/stat_variation3_subdir");
+clearstatcache();
+
+// comparing stats after the deletion of subdir and file
+echo "-- Testing stat() for comparing stats after the deletion of subdir and file --\n";
+$new_stat1 = stat($dirname);
+// compare self stats
+var_dump( compare_self_stat($new_stat1) );
+// compare the stats
+var_dump(compare_stats($new_stat, $new_stat1, $all_stat_keys, "="));
+clearstatcache();
+
+echo "Done\n";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+rmdir("$file_path/stat_variation3");
+?>
+--EXPECTF--
+
+*** Testing stat(): with creating & deleting subdir/file ***
+-- Testing stat() on dir after subdir and file is created in it --
+bool(true)
+bool(true)
+bool(true)
+-- Testing stat() for comparing stats after the deletion of subdir and file --
+bool(true)
+bool(true)
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test stat() functions: usage variations - effects of is_dir() & is_file()
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die('skip.. only for Windows');
+}
+?>
+--FILE--
+<?php
+
+/*
+ * Prototype: array stat ( string $filename );
+ * Description: Gives information about a file
+ */
+
+/* test the effects on the stats of dir/file for using is_dir() & is_file() on dir/file */
+
+$file_path = dirname(__FILE__);
+require "$file_path/file.inc";
+
+
+/* create temp file and directory */
+mkdir("$file_path/stat_variation4/"); // temp dir
+
+$file_handle = fopen("$file_path/stat_variation4.tmp", "w"); // temp file
+fclose($file_handle);
+
+
+echo "\n*** Testing stat(): on file and directory after accessing it
+ with is_dir() and is_file() functions ***\n";
+
+// is_dir() on a directory
+echo "-- Testing on Directory --\n";
+$old_dirname = "$file_path/stat_variation4";
+$old_stat = stat($old_dirname);
+// clear the cache
+clearstatcache();
+sleep(2);
+var_dump( is_dir($old_dirname) );
+$new_stat = stat($old_dirname);
+
+// compare self stats
+var_dump( compare_self_stat($old_stat) );
+var_dump( compare_self_stat($new_stat) );
+// compare the stat
+var_dump( compare_stats($old_stat, $new_stat, $all_stat_keys, "=") );
+// clear the stat
+clearstatcache();
+
+
+// is_file() on a file
+echo "-- Testing on file --\n";
+$old_filename = "$file_path/stat_variation4.tmp";
+$old_stat = stat($old_filename);
+// clear the stat
+clearstatcache();
+sleep(2);
+var_dump( is_file($old_filename) );
+$new_stat = stat($old_filename);
+// compare self stats
+var_dump( compare_self_stat($old_stat) );
+var_dump( compare_self_stat($new_stat) );
+// compare the stat
+var_dump( compare_stats($old_stat, $new_stat, $all_stat_keys, "=") );
+// clear the stat
+clearstatcache();
+
+echo "Done\n";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink("$file_path/stat_variation4.tmp");
+rmdir("$file_path/stat_variation4");
+?>
+--EXPECTF--
+*** Testing stat(): on file and directory after accessing it
+ with is_dir() and is_file() functions ***
+-- Testing on Directory --
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+-- Testing on file --
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+Test stat() functions: usage variations - file opened in read/write mode
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die('skip.. only for Windows');
+}
+?>
+--FILE--
+<?php
+
+/*
+ * Prototype: array stat ( string $filename );
+ * Description: Gives information about a file
+ */
+
+/* test the stats of file opened in write mode and then same in read mode */
+
+$file_path = dirname(__FILE__);
+require "$file_path/file.inc";
+
+
+$file_handle = fopen("$file_path/stat_variation5.tmp", "w"); // temp file
+fclose($file_handle);
+
+
+echo "\n*** Testing stat(): on a file with read/write permission ***\n";
+
+$filename = "$file_path/stat_variation5.tmp";
+$file_handle = fopen($filename, "w"); // create file
+fclose($file_handle);
+$old_stat = stat($filename);
+// clear the stat
+clearstatcache();
+sleep(2);
+// opening file again in read mode
+$file_handle = fopen($filename, "r"); // read file
+fclose($file_handle);
+$new_stat = stat($filename);
+// compare self stats
+var_dump( compare_self_stat($old_stat) );
+var_dump( compare_self_stat($new_stat) );
+// compare the stat
+$affected_members = array(10, 'ctime');
+var_dump( compare_stats($old_stat, $new_stat, $affected_members, "=") );
+// clear the stat
+clearstatcache();
+
+
+echo "Done\n";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink("$file_path/stat_variation5.tmp");
+?>
+--EXPECTF--
+
+*** Testing stat(): on a file with read/write permission ***
+bool(true)
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+Test stat() functions: usage variations - changing permissions of dir/file
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die('skip.. only for Windows');
+}
+?>
+--FILE--
+<?php
+
+/*
+ * Prototype: array stat ( string $filename );
+ * Description: Gives information about a file
+ */
+
+/* test the effects on the stats of dir/file for changing permissions of dir/file */
+
+
+$file_path = dirname(__FILE__);
+require "$file_path/file.inc";
+
+
+/* create temp file and directory */
+$dirname = "$file_path/stat_variation6";
+mkdir($dirname); // temp dir
+
+$filename = "$file_path/stat_variation6.tmp";
+$file_handle = fopen($filename, "w"); // temp file
+fclose($file_handle);
+
+
+// checking stat() on file
+echo "\n*** Testing stat() on file with miscelleneous file permission and content ***\n";
+$old_stat = stat($filename);
+var_dump( chmod($filename, 0777) );
+// clear the stat
+clearstatcache();
+sleep(2);
+$new_stat = stat($filename);
+// compare self stats
+var_dump( compare_self_stat($old_stat) );
+var_dump( compare_self_stat($new_stat) );
+// compare the stat
+$affected_members = array( 10, 'ctime');
+var_dump( compare_stats($old_stat, $new_stat, $affected_members, "=") );
+// clear the stat
+clearstatcache(); // clear statement cache
+
+// checking stat() on directory
+echo "\n*** Testing stat() on directory with miscelleneous file permission ***\n";
+$old_stat = stat($dirname);
+var_dump( chmod($dirname, 0777) );
+// clear the stat
+clearstatcache();
+sleep(2);
+$new_stat = stat($dirname);
+// compare self stats
+var_dump( compare_self_stat($old_stat) );
+var_dump( compare_self_stat($new_stat) );
+// compare the stat
+$affected_members = array( 10, 'ctime');
+var_dump( compare_stats($old_stat, $new_stat, $affected_members, "=") );
+// clear the stat
+clearstatcache(); // clear statement cache
+
+
+echo "Done\n";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink("$file_path/stat_variation6.tmp");
+rmdir("$file_path/stat_variation6");
+?>
+--EXPECTF--
+
+*** Testing stat() on file with miscelleneous file permission and content ***
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+
+*** Testing stat() on directory with miscelleneous file permission ***
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done
--- /dev/null
+--TEST--
+Test stat() functions: usage variations - names of dir/file stored in objects
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die('skip.. only for Windows');
+}
+?>
+--FILE--
+<?php
+
+/*
+ * Prototype: array stat ( string $filename );
+ * Description: Gives information about a file
+ */
+
+/* test the stats of dir/file when their names are stored in objects */
+
+$file_path = dirname(__FILE__);
+require "$file_path/file.inc";
+
+
+/* create temp file and directory */
+mkdir("$file_path/stat_variation7/"); // temp dir
+
+$file_handle = fopen("$file_path/stat_variation7.tmp", "w"); // temp file
+fclose($file_handle);
+
+
+echo "\n*** Testing stat(): with filename
+ and directory name stored inside a object ***\n";
+
+// creating object with members as numeric and non-numeric filename and directory name
+class object_temp {
+public $var_name;
+public function object_temp($name) {
+$this->var_name = $name;
+ }
+}
+
+// directory as member
+$obj1 = new object_temp("$file_path/stat_variation7/");
+$obj2 = new object_temp("$file_path/stat_variation7a/");
+
+// file as member
+$obj3 = new object_temp("$file_path/stat_variation7.tmp");
+$obj4 = new object_temp("$file_path/stat_variation7a.tmp");
+
+echo "\n-- Testing stat() on filename stored inside an object --\n";
+var_dump( stat($obj3->var_name) );
+
+$file_handle = fopen("$file_path/stat_variation7a.tmp", "w");
+fclose($file_handle);
+var_dump( stat($obj4->var_name) );
+
+echo "\n-- Testing stat() on directory name stored inside an object --\n";
+var_dump( stat($obj1->var_name) );
+
+mkdir("$file_path/stat_variation7a/");
+var_dump( stat($obj2->var_name) );
+
+echo "\n*** Done ***";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink("$file_path/stat_variation7.tmp");
+unlink("$file_path/stat_variation7a.tmp");
+rmdir("$file_path/stat_variation7");
+rmdir("$file_path/stat_variation7a");
+?>
+--EXPECTF--
+*** Testing stat(): with filename
+ and directory name stored inside a object ***
+
+-- Testing stat() on filename stored inside an object --
+array(26) {
+ [0]=>
+ int(%d)
+ [1]=>
+ int(%d)
+ [2]=>
+ int(%d)
+ [3]=>
+ int(%d)
+ [4]=>
+ int(%d)
+ [5]=>
+ int(%d)
+ [6]=>
+ int(%d)
+ [7]=>
+ int(%d)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(-%d)
+ [12]=>
+ int(-%d)
+ ["dev"]=>
+ int(%d)
+ ["ino"]=>
+ int(%d)
+ ["mode"]=>
+ int(%d)
+ ["nlink"]=>
+ int(%d)
+ ["uid"]=>
+ int(%d)
+ ["gid"]=>
+ int(%d)
+ ["rdev"]=>
+ int(%d)
+ ["size"]=>
+ int(%d)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(-%d)
+ ["blocks"]=>
+ int(-%d)
+}
+array(26) {
+ [0]=>
+ int(%d)
+ [1]=>
+ int(%d)
+ [2]=>
+ int(%d)
+ [3]=>
+ int(%d)
+ [4]=>
+ int(%d)
+ [5]=>
+ int(%d)
+ [6]=>
+ int(%d)
+ [7]=>
+ int(%d)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(-%d)
+ [12]=>
+ int(-%d)
+ ["dev"]=>
+ int(%d)
+ ["ino"]=>
+ int(%d)
+ ["mode"]=>
+ int(%d)
+ ["nlink"]=>
+ int(%d)
+ ["uid"]=>
+ int(%d)
+ ["gid"]=>
+ int(%d)
+ ["rdev"]=>
+ int(%d)
+ ["size"]=>
+ int(%d)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(-%d)
+ ["blocks"]=>
+ int(-%d)
+}
+
+-- Testing stat() on directory name stored inside an object --
+array(26) {
+ [0]=>
+ int(%d)
+ [1]=>
+ int(%d)
+ [2]=>
+ int(%d)
+ [3]=>
+ int(%d)
+ [4]=>
+ int(%d)
+ [5]=>
+ int(%d)
+ [6]=>
+ int(%d)
+ [7]=>
+ int(%d)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(-%d)
+ [12]=>
+ int(-%d)
+ ["dev"]=>
+ int(%d)
+ ["ino"]=>
+ int(%d)
+ ["mode"]=>
+ int(%d)
+ ["nlink"]=>
+ int(%d)
+ ["uid"]=>
+ int(%d)
+ ["gid"]=>
+ int(%d)
+ ["rdev"]=>
+ int(%d)
+ ["size"]=>
+ int(%d)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(-%d)
+ ["blocks"]=>
+ int(-%d)
+}
+array(26) {
+ [0]=>
+ int(%d)
+ [1]=>
+ int(%d)
+ [2]=>
+ int(%d)
+ [3]=>
+ int(%d)
+ [4]=>
+ int(%d)
+ [5]=>
+ int(%d)
+ [6]=>
+ int(%d)
+ [7]=>
+ int(%d)
+ [8]=>
+ int(%d)
+ [9]=>
+ int(%d)
+ [10]=>
+ int(%d)
+ [11]=>
+ int(-%d)
+ [12]=>
+ int(-%d)
+ ["dev"]=>
+ int(%d)
+ ["ino"]=>
+ int(%d)
+ ["mode"]=>
+ int(%d)
+ ["nlink"]=>
+ int(%d)
+ ["uid"]=>
+ int(%d)
+ ["gid"]=>
+ int(%d)
+ ["rdev"]=>
+ int(%d)
+ ["size"]=>
+ int(%d)
+ ["atime"]=>
+ int(%d)
+ ["mtime"]=>
+ int(%d)
+ ["ctime"]=>
+ int(%d)
+ ["blksize"]=>
+ int(-%d)
+ ["blocks"]=>
+ int(-%d)
+}
+
+*** Done ***
--- /dev/null
+--TEST--
+Test stat() functions: usage variations - effects of truncate()
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) != 'WIN') {
+ die('skip.. only for Windows');
+}
+?>
+--FILE--
+<?php
+
+/*
+ * Prototype: array stat ( string $filename );
+ * Description: Gives information about a file
+ */
+
+/* test the effects of truncate() on stats of file */
+
+
+$file_path = dirname(__FILE__);
+require "$file_path/file.inc";
+
+
+/* create temp file and directory */
+
+$filename = "$file_path/stat_variation8.tmp";
+$file_handle = fopen($filename, "w"); // temp file
+fclose($file_handle);
+
+
+echo "\n*** Testing stat(): on file by truncating it to given size ***\n";
+
+// create temp file
+$file_handle = fopen($filename, "w");
+fclose($file_handle);
+
+clearstatcache();
+$old_stat = stat($filename);
+// clear the cache
+sleep(2);
+
+// opening file in r/w mode
+$file_handle = fopen($filename, "r+");
+var_dump( ftruncate($file_handle, 512) ); // truncate it
+fclose($file_handle);
+
+clearstatcache();
+$new_stat = stat($filename);
+
+// compare self stats
+var_dump( compare_self_stat($old_stat) );
+var_dump( compare_self_stat($new_stat) );
+
+// compare the stat
+$affected_members = array(7, 8, 9, 'size', 'atime', 'mtime');
+var_dump( compare_stats($old_stat, $new_stat, $affected_members, '!=') );
+
+// clear the stat
+clearstatcache(); // clear previous size value in cache
+
+echo "Done\n";
+?>
+
+--CLEAN--
+<?php
+$file_path = dirname(__FILE__);
+unlink("$file_path/stat_variation8.tmp");
+?>
+--EXPECTF--
+*** Testing stat(): on file by truncating it to given size ***
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done