2007-06-21 21:14:21 +00:00
--TEST--
Test rename() function: usage variations
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
die('skip.. only for Windows');
}
?>
--FILE--
<?php
/* Prototype: bool rename ( string $oldname, string $newname [, resource $context] );
Description: Renames a file or directory
*/
require dirname(__FILE__).'/file.inc';
2008-04-30 13:53:50 +00:00
/* create directory */
2007-06-21 21:14:21 +00:00
$file_path = dirname(__FILE__);
2008-04-30 13:53:50 +00:00
mkdir("$file_path/rename_variation");
2007-06-21 21:14:21 +00:00
2008-04-30 13:53:50 +00:00
/* rename files across directories */
echo "*** Testing rename() : rename files across directories ***\n";
$src_filenames = array(
2007-06-21 21:14:21 +00:00
"$file_path/rename_variation/rename_variation.tmp",
2008-04-30 13:53:50 +00:00
/* Testing a file trailing slash */
"$file_path/rename_variation/rename_variation.tmp/",
2007-06-21 21:14:21 +00:00
/* Testing file with double slashes */
"$file_path/rename_variation//rename_variation.tmp",
2008-04-30 13:53:50 +00:00
"$file_path//rename_variation//rename_variation.tmp",
2007-06-21 21:14:21 +00:00
);
2008-04-30 13:53:50 +00:00
2007-06-21 21:14:21 +00:00
$counter = 1;
2008-04-30 13:53:50 +00:00
2007-06-21 21:14:21 +00:00
/* loop through each $file and rename it to rename_variation2.tmp */
2008-04-30 13:53:50 +00:00
foreach($src_filenames as $src_filename) {
echo "-- Iteration $counter --\n";
2007-06-21 21:14:21 +00:00
$fp = fopen("$file_path/rename_variation/rename_variation.tmp", "w");
fclose($fp);
2008-04-30 13:53:50 +00:00
$dest_filename = "$file_path/rename_variation2.tmp";
var_dump( rename($src_filename, $dest_filename) );
2007-06-21 21:14:21 +00:00
2008-04-30 13:53:50 +00:00
// ensure that file got renamed to new name
var_dump( file_exists($src_filename) ); // expecting false
var_dump( file_exists($dest_filename) ); // expecting true
2007-06-21 21:14:21 +00:00
$counter++;
2008-04-30 13:53:50 +00:00
// unlink the file
unlink($dest_filename);
2007-06-21 21:14:21 +00:00
}
2008-04-30 13:53:50 +00:00
rmdir("$file_path/rename_variation");
2007-06-21 21:14:21 +00:00
echo "Done\n";
?>
--CLEAN--
<?php
2008-04-30 13:53:50 +00:00
$file_path = dirname(__FILE__);
unlink($file_path."/rename_variation_link.tmp");
unlink($file_path."/rename_variation.tmp");
rmdir($file_path."/rename_variation_dir");
2007-06-21 21:14:21 +00:00
?>
--EXPECTF--
2008-04-30 13:53:50 +00:00
*** Testing rename() : rename files across directories ***
2007-06-21 21:14:21 +00:00
-- Iteration 1 --
bool(true)
bool(false)
bool(true)
-- Iteration 2 --
2010-01-27 10:08:43 +00:00
Warning: rename(%s/rename_variation/rename_variation.tmp/,%s/rename_variation2.tmp): The filename, directory name, or volume label syntax is incorrect. (code: 123) in %s on line %d
2007-06-21 21:14:21 +00:00
bool(false)
2008-11-26 17:48:41 +00:00
bool(false)
2007-06-21 21:14:21 +00:00
bool(false)
2008-04-30 13:53:50 +00:00
Warning: unlink(%s/rename_variation2.tmp): No such file or directory in %s on line %d
2007-06-21 21:14:21 +00:00
-- Iteration 3 --
bool(true)
bool(false)
bool(true)
-- Iteration 4 --
bool(true)
bool(false)
2008-04-30 13:53:50 +00:00
bool(true)
2007-06-21 21:14:21 +00:00
Done
2008-11-26 17:48:41 +00:00