New testcases for filesystem handling function : unlink()

This commit is contained in:
Raghubansh Kumar 2007-07-18 04:59:46 +00:00
parent 20aa854940
commit 9d7e023e37
10 changed files with 2693 additions and 0 deletions

View File

@ -0,0 +1,43 @@
--TEST--
Testing unlink() function : basic functionality
--FILE--
<?php
/* Prototype : bool unlink ( string $filename [, resource $context] );
Description : Deletes filename
*/
$file_path = dirname(__FILE__);
echo "*** Testing unlink() on a file ***\n";
$filename = "$file_path/unlink_basic.tmp"; // temp file name used here
$fp = fopen($filename, "w"); // create file
fwrite($fp, "Hello World");
fclose($fp);
// delete file
var_dump( unlink($filename) );
var_dump( file_exists($filename) ); // confirm file doesnt exist
echo "\n*** Testing unlink() : checking second argument ***\n";
// creating a context
$context = stream_context_create();
// temp file name used here
$filename = "$file_path/unlink_basic.tmp";
$fp = fopen($filename, "w"); // create file
fclose($fp);
// delete file
var_dump( unlink($filename, $context) ); // using $context in second argument
var_dump( file_exists($filename) ); // confirm file doesnt exist
echo "Done\n";
?>
--EXPECTF--
*** Testing unlink() on a file ***
bool(true)
bool(false)
*** Testing unlink() : checking second argument ***
bool(true)
bool(false)
Done

View File

@ -0,0 +1,111 @@
--TEST--
Testing unlink() function : error conditions
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
die('skip.. only on Windows');
}
?>
--FILE--
<?php
/* Prototype : bool unlink ( string $filename [, resource $context] );
Description : Deletes filename
*/
$file_path = dirname(__FILE__);
$filename = "$file_path/unlink_error.tmp"; // temp file name used here
$fp = fopen($filename, "w"); // create file
fclose($fp);
// creating a context
$context = stream_context_create();
echo "*** Testing unlink() : error conditions ***\n";
echo "-- Testing unlink() on unexpected no. of arguments --\n";
// arg < expected
var_dump( unlink() );
// args > expected
var_dump( unlink($filename, $context, true) );
var_dump( file_exists($filename) );
echo "\n-- Testing unlink() on invalid arguments --\n";
// invalid arguments
var_dump( unlink('') ); // $filename as empty string
var_dump( file_exists('') ); // confirm file doesnt exist
var_dump( unlink(NULL) ); // $filename as NULL
var_dump( file_exists(NULL) ); // confirm file doesnt exist
var_dump( unlink(false) ); // $filename as boolean false
var_dump( file_exists(false) ); // confirm file doesnt exist
var_dump( unlink($filename, '') ); // $context as empty string
var_dump( unlink($filename, false) ); // $context as boolean false
var_dump( unlink($filename, NULL) ); // $context as NULL
echo "\n-- Testing unlink() on non-existent file --\n";
var_dump( unlink(dirname(__FILE__)."/non_existent_file.tmp") );
echo "\n-- Testing unlink() on directory --\n";
// temp directory used here
$dirname = "$file_path/unlink_error";
// create temp dir
mkdir($dirname);
// unlinking directory
var_dump( unlink($dirname) ); // expected: false as unlink() does not work on dir
echo "Done\n";
?>
--CLEAN--
<?php
unlink(dirname(__FILE__)."/unlink_error.tmp");
rmdir(dirname(__FILE__)."/unlink_error");
?>
--EXPECTF--
*** Testing unlink() : error conditions ***
-- Testing unlink() on unexpected no. of arguments --
Warning: unlink() expects at least 1 parameter, 0 given in %s on line %d
bool(false)
Warning: unlink() expects at most 2 parameters, 3 given in %s on line %d
bool(false)
bool(true)
-- Testing unlink() on invalid arguments --
Warning: unlink(): No such file or directory in %s on line %d
bool(false)
bool(false)
Warning: unlink(): No such file or directory in %s on line %d
bool(false)
bool(false)
Warning: unlink(): No such file or directory in %s on line %d
bool(false)
bool(false)
Warning: unlink() expects parameter 2 to be resource, string given in %s on line %d
bool(false)
Warning: unlink() expects parameter 2 to be resource, boolean given in %s on line %d
bool(false)
Warning: unlink() expects parameter 2 to be resource, null given in %s on line %d
bool(false)
-- Testing unlink() on non-existent file --
Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d
bool(false)
-- Testing unlink() on directory --
Warning: unlink(%s/unlink_error): Permission denied in %s on line %d
bool(false)
Done

View File

@ -0,0 +1,108 @@
--TEST--
Testing unlink() function : error conditions
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip.. only on Linux');
}
?>
--FILE--
<?php
/* Prototype : bool unlink ( string $filename [, resource $context] );
Description : Deletes filename
*/
$file_path = dirname(__FILE__);
$filename = "$file_path/unlink_error.tmp"; // temp file name used here
$fp = fopen($filename, "w"); // create file
fclose($fp);
// creating a context
$context = stream_context_create();
echo "*** Testing unlink() : error conditions ***\n";
echo "-- Testing unlink() on unexpected no. of arguments --\n";
// arg < expected
var_dump( unlink() );
// args > expected
var_dump( unlink($filename, $context, true) );
var_dump( file_exists($filename) );
echo "\n-- Testing unlink() on invalid arguments --\n";
// invalid arguments
var_dump( unlink('') ); // $filename as empty string
var_dump( file_exists('') ); // confirm file doesnt exist
var_dump( unlink(NULL) ); // $filename as NULL
var_dump( file_exists(NULL) ); // confirm file doesnt exist
var_dump( unlink(false) ); // $filename as boolean false
var_dump( file_exists(false) ); // confirm file doesnt exist
var_dump( unlink($filename, '') ); // $context as empty string
var_dump( unlink($filename, false) ); // $context as boolean false
var_dump( unlink($filename, NULL) ); // $context as NULL
echo "\n-- Testing unlink() on non-existent file --\n";
var_dump( unlink(dirname(__FILE__)."/non_existent_file.tmp") );
echo "\n-- Testing unlink() on directory --\n";
// temp directory used here
$dirname = "$file_path/unlink_error";
// create temp dir
mkdir($dirname);
// unlinking directory
var_dump( unlink($dirname) ); // expected: false as unlink() does not work on dir
rmdir($dirname);
// delete temp file
unlink($filename);
echo "Done\n";
?>
--EXPECTF--
*** Testing unlink() : error conditions ***
-- Testing unlink() on unexpected no. of arguments --
Warning: unlink() expects at least 1 parameter, 0 given in %s on line %d
bool(false)
Warning: unlink() expects at most 2 parameters, 3 given in %s on line %d
bool(false)
bool(true)
-- Testing unlink() on invalid arguments --
Warning: unlink(): %s in %s on line %d
bool(false)
bool(false)
Warning: unlink(): %s in %s on line %d
bool(false)
bool(false)
Warning: unlink(): %s in %s on line %d
bool(false)
bool(false)
Warning: unlink() expects parameter 2 to be resource, string given in %s on line %d
bool(false)
Warning: unlink() expects parameter 2 to be resource, boolean given in %s on line %d
bool(false)
Warning: unlink() expects parameter 2 to be resource, null given in %s on line %d
bool(false)
-- Testing unlink() on non-existent file --
Warning: unlink(%s/non_existent_file.tmp): %s in %s on line %d
bool(false)
-- Testing unlink() on directory --
Warning: unlink(%s/unlink_error): %s in %s on line %d
bool(false)
Done

View File

@ -0,0 +1,85 @@
--TEST--
Test unlink() function : usage variations - unlinking file in a directory
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
die('skip only on Windows');
}
?>
--FILE--
<?php
/* Prototype : bool unlink ( string $filename [, resource $context] );
Description : Deletes filename
*/
/* Delete file having default permission but its dir having readonly permission
Delete file having readonly permission but dir having default permission
*/
$file_path = dirname(__FILE__);
// temp dir name used here
$dirname = "$file_path/unlink_variation1";
// temp filename used here
$filename = "$dirname/unlink_variation1-win32.tmp";
echo "*** Testing unlink() on file inside a directory ***\n";
// create temp dir
mkdir($dirname);
// create temp file inside $dirname
$fp = fopen($filename, "w");
fclose($fp);
echo "-- Unlink file having default permission and its dir having read only permission --\n";
// remove write permission of $dirname
// on windows dir permission is not respected
var_dump( chmod($dirname, 0444) );
// now try deleting $filename
var_dump( unlink($filename) ); // expected: true
var_dump( file_exists($filename) ); // confirm file is deleted
// remove the dir
var_dump( chmod($dirname, 0777) );
rmdir($dirname);
echo "\n-- Unlinking file without write permission, its dir having default permission --\n";
// create the temp dir
mkdir($dirname);
// create the temp file
$fp = fopen($filename, "w");
fclose($fp);
// remove write permission from file
var_dump( chmod($filename, 0444) );
// now try deleting temp file inside $dirname
var_dump( unlink($filename) ); // expected: false
// reassign write permission to temp file
chmod($filename, 0777);
// delete temp file
var_dump( unlink($filename) );
var_dump( file_exists($filename) ); // confirm file is deleted
// remove temp dir
rmdir($dirname);
echo "Done\n";
?>
--EXPECTF--
*** Testing unlink() on file inside a directory ***
-- Unlink file having default permission and its dir having read only permission --
bool(true)
bool(true)
bool(false)
bool(true)
-- Unlinking file without write permission, its dir having default permission --
bool(true)
Warning: unlink(%s/unlink_variation1/unlink_variation1-win32.tmp): Permission denied in %s on line %d
bool(false)
bool(true)
bool(false)
Done

View File

@ -0,0 +1,82 @@
--TEST--
Test unlink() function : usage variations - unlinking file in a directory
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip only on Linux');
}
?>
--FILE--
<?php
/* Prototype : bool unlink ( string $filename [, resource $context] );
Description : Deletes filename
*/
/* Delete file having default permission but its dir having readonly permission
Delete file having readonly permission but dir having default permission
*/
$file_path = dirname(__FILE__);
// temp dir name used here
$dirname = "$file_path/unlink_variation1";
// temp filename used here
$filename = "$dirname/unlink_variation1.tmp";
echo "*** Testing unlink() on file inside a directory ***\n";
// create temp dir
mkdir($dirname);
// create temp file inside $dirname
$fp = fopen($filename, "w");
fclose($fp);
echo "-- Unlink file having default permission and its dir having read only permission --\n";
// remove write permission of $dirname
var_dump( chmod($dirname, 0444) );
// now try deleting $filename
var_dump( unlink($filename) ); // expected false
var_dump( file_exists($filename) ); // confirm file is deleted
// remove the dir
var_dump( chmod($dirname, 0777) );
var_dump( unlink($filename) ); // expected true
var_dump( rmdir($dirname) );
echo "\n-- Unlinking file without write permission, its dir having default permission --\n";
// create the temp dir
var_dump( mkdir($dirname) );
// create the temp file
$fp = fopen($filename, "w");
fclose($fp);
// remove write permission from file
var_dump( chmod($filename, 0444) );
// now try deleting temp file inside $dirname
var_dump( unlink($filename) ); // expected: true
var_dump( file_exists($filename) ); // expected: false
// remove temp dir
var_dump( rmdir($dirname) );
echo "Done\n";
?>
--EXPECTF--
*** Testing unlink() on file inside a directory ***
-- Unlink file having default permission and its dir having read only permission --
bool(true)
Warning: unlink(%s): %s in %s on line %d
bool(false)
bool(false)
bool(true)
bool(true)
bool(true)
-- Unlinking file without write permission, its dir having default permission --
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)
Done

View File

@ -0,0 +1,43 @@
--TEST--
Test unlink() function : usage variations - unlink file in use
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
die('skip only on Windows');
}
?>
--FILE--
<?php
/* Prototype : bool unlink ( string $filename [, resource $context] );
Description : Deletes filename
*/
/* Try to unlink file when file handle is still in use */
$file_path = dirname(__FILE__);
echo "*** Testing unlink() on a file when file handle is open ***\n";
// temp file name used here
$filename = "$file_path/unlink_variation2.tmp";
// create file
$fp = fopen($filename, "w");
// try unlink() on $filename
var_dump( unlink($filename) ); // expected: false as file handle is still open
// now close file handle
fclose($fp);
// now unlink file
var_dump( unlink($filename) ); // expected: true
var_dump( file_exists($filename) ); // confirm file is deleted
echo "Done\n";
?>
--EXPECTF--
*** Testing unlink() on a file when file handle is open ***
Warning: unlink(%s): %s in %s on line %d
bool(false)
bool(true)
bool(false)
Done

View File

@ -0,0 +1,37 @@
--TEST--
Test unlink() function : usage variations - unlink file in use
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip only on Linux');
}
?>
--FILE--
<?php
/* Prototype : bool unlink ( string $filename [, resource $context] );
Description : Deletes filename
*/
/* Try to unlink file when file handle is still in use */
$file_path = dirname(__FILE__);
echo "*** Testing unlink() on a file which is in use ***\n";
// temp file name used here
$filename = "$file_path/unlink_variation2.tmp";
// create file
$fp = fopen($filename, "w");
// try unlink() on $filename
var_dump( unlink($filename) ); // expected: true on linux
var_dump( file_exists($filename) ); // confirm file is deleted
// now close file handle
fclose($fp);
echo "Done\n";
?>
--EXPECTF--
*** Testing unlink() on a file which is in use ***
bool(true)
bool(false)
Done

View File

@ -0,0 +1,60 @@
--TEST--
Test unlink() function : usage variations - unlink links
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip only on Linux');
}
?>
--FILE--
<?php
/* Prototype : bool unlink ( string $filename [, resource $context] );
Description : Deletes filename
*/
/* Delete link files - soft and hard links */
$file_path = dirname(__FILE__);
// temp file used
$filename = "$file_path/unlink_variation3.tmp";
echo "*** Testing unlink() on soft and hard links ***\n";
// create temp file
$fp = fopen($filename, "w");
fclose($fp);
// link name used here
$linkname = "$file_path/unlink_variation3_link.tmp";
echo "-- Testing unlink() on soft link --\n";
// create soft link
var_dump( symlink($filename, $linkname) ); // expected: true
// unlink soft link
var_dump( unlink($linkname) ); // expected: true
var_dump( file_exists($linkname) ); // confirm link is deleted
echo "-- Testing unlink() on hard link --\n";
// create hard link
var_dump( link($filename, $linkname) ); // expected: true
// delete hard link
var_dump( unlink($linkname) ); // expected: true
var_dump( file_exists($linkname) ); // confirm link is deleted
// delete temp file
var_dump( unlink($filename) );
var_dump( file_exists($filename) ); // confirm file is deleted
echo "Done\n";
?>
--EXPECTF--
*** Testing unlink() on soft and hard links ***
-- Testing unlink() on soft link --
bool(true)
bool(true)
bool(false)
-- Testing unlink() on hard link --
bool(true)
bool(true)
bool(false)
bool(true)
bool(false)
Done

View File

@ -0,0 +1,37 @@
--TEST--
Test unlink() function : usage variations - unlink deleted file
--FILE--
<?php
/* Prototype : bool unlink ( string $filename [, resource $context] );
Description : Deletes filename
*/
$file_path = dirname(__FILE__);
// temp file used
$filename = "$file_path/unlink_variation4.tmp";
/* Try deleting a file which is already deleted */
echo "*** Testing unlink() on deleted file ***\n";
// create temp file
$fp = fopen($filename, "w");
fclose($fp);
// delete temp file
var_dump( unlink($filename) ); // expected: true
var_dump( file_exists($filename) ); // confirm file deleted
// delete deleted file
var_dump( unlink($filename) ); // expected: false
echo "Done\n";
?>
--EXPECTF--
*** Testing unlink() on deleted file ***
bool(true)
bool(false)
Warning: unlink(%s/unlink_variation4.tmp): %s in %s on line %d
bool(false)
Done

File diff suppressed because it is too large Load Diff