Test fopen() function : variation: use include path create and read a file (relative)
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
---XFAIL--
-Bug #46680
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
require_once('fopen_include_path.inc');
-echo "*** Testing fopen() : variation ***\n";
-$thisTestDir = "fopenVariation17.dir";
+$thisTestDir = basename(__FILE__, ".php") . ".dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$newpath = create_include_path();
set_include_path($newpath);
runtest();
+
$newpath = generate_next_path();
set_include_path($newpath);
runtest();
$extraDir = "extraDir";
mkdir($dir1.'/'.$extraDir);
+ mkdir($extraDir);
- $tmpfile = $extraDir.'/fopen_variation17.tmp';
+ $tmpfile = $extraDir.'/ basename(__FILE__, ".php") . ".tmp"';
$h = fopen($tmpfile, "w+", true);
- fwrite($h, "This is the test file");
+ fwrite($h, (binary) "This is the test file");
fclose($h);
- $h = fopen($dir1.'/'.$tmpfile, "r");
+ $h = @fopen($dir1.'/'.$tmpfile, "r");
if ($h === false) {
echo "Not created in dir1\n";
}
echo "could not find file for reading\n";
}
else {
- echo "found file again in dir1\n";
+ echo "found file for reading\n";
fclose($h);
}
- unlink($dir1.'/'.$tmpfile);
- rmdir($dir1.'/'.$extraDir);
+ unlink($tmpfile);
+ rmdir($dir1.'/'.$extraDir);
+ rmdir($extraDir);
}
?>
===DONE===
--EXPECT--
-*** Testing fopen() : variation ***
-created in dir1
-found file again in dir1
-created in dir1
-found file again in dir1
+Not created in dir1
+found file for reading
+Not created in dir1
+found file for reading
===DONE===
--TEST--
Test fopen() function : variation: use include path and stream context (absolute directories in path)
---XFAIL--
-Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
-echo "*** Testing fopen() : variation ***\n";
//create the include directory structure
-$thisTestDir = "fopenVariation5.dir";
+$thisTestDir = basename(__FILE__, ".php") . ".dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$workingDir = "workdir";
-$filename = "afile.txt";
+$filename = basename(__FILE__, ".php") . ".tmp";
$scriptDir = dirname(__FILE__);
$baseDir = getcwd();
$secondFile = $baseDir."/dir2/".$filename;
// create a file in the middle directory
$h = fopen($secondFile, "w");
- fwrite($h, "in dir2");
+ fwrite($h, (binary) "in dir2");
fclose($h);
echo "\n** testing with mode=$mode **\n";
//create a file in dir1
$h = fopen($firstFile, "w");
- fwrite($h, "in dir1");
+ fwrite($h, (binary) "in dir1");
fclose($h);
//should now read dir1 file
// create a file in working directory
$h = fopen($filename, "w");
- fwrite($h, "in working dir");
+ fwrite($h, (binary) "in working dir");
fclose($h);
//should still read dir1 file
unlink($firstFile);
unlink($secondFile);
- //should fail to read the file
+ //should read the file in working dir
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
// create a file in the script directory
$h = fopen($scriptFile, "w");
- fwrite($h, "in script dir");
+ fwrite($h, (binary) "in script dir");
fclose($h);
//should read the file in script dir
?>
===DONE===
--EXPECTF--
-*** Testing fopen() : variation ***
--- testing include path ---
in dir2
in dir1
in dir1
-
-Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
-
-Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
-
-Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
-
+in working dir
in script dir
** testing with mode=r+ **
in dir2
in dir1
in dir1
-
-Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
-
-Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
-
-Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
-
+in working dir
in script dir
** testing with mode=rt **
in dir2
in dir1
in dir1
-
-Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
-
-Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
-
-Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
-
+in working dir
in script dir
===DONE===
--TEST--
Test fopen() function : variation: use include path create a file (relative)
---XFAIL--
-Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
require_once('fopen_include_path.inc');
-echo "*** Testing fopen() : variation ***\n";
-$thisTestDir = "fopenVariation7.dir";
+$thisTestDir = basename(__FILE__, ".php") . ".dir";
mkdir($thisTestDir);
chdir($thisTestDir);
function runtest() {
global $dir1;
- $tmpfile = 'fopen_variation7.tmp';
+ $tmpfile = basename(__FILE__, ".php") . ".tmp";
$h = fopen($tmpfile, "w", true);
- fwrite($h, "This is the test file");
+ fwrite($h, (binary)"This is the test file");
fclose($h);
unlink($tmpfile);
}
- $h = fopen($dir1.'/'.$tmpfile, "r");
+ $h = @fopen($dir1.'/'.$tmpfile, "r");
if ($h === false) {
echo "Not created in dir1\n";
}
?>
===DONE===
--EXPECT--
-*** Testing fopen() : variation ***
-Not created in working dir
-created in dir1
-Not created in working dir
-created in dir1
+created in working dir
+Not created in dir1
+created in working dir
+Not created in dir1
===DONE===
--TEST--
Test fopen() function : variation: use include path and stream context (relative directories in path)
---XFAIL--
-Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
-echo "*** Testing fopen() : variation ***\n";
-$thisTestDir = "fopenVariation8.dir";
+$thisTestDir = basename(__FILE__, ".php") . ".dir";
mkdir($thisTestDir);
chdir($thisTestDir);
//create the include directory structure
$workingDir = "workdir";
-$filename = "afile.txt";
+$filename = basename(__FILE__, ".php") . ".tmp";
$scriptDir = dirname(__FILE__);
$baseDir = getcwd();
$secondFile = $baseDir."/dir2/".$filename;
// create a file in the middle directory
$h = fopen($secondFile, "w");
- fwrite($h, "in dir2");
+ fwrite($h, (binary) "in dir2");
fclose($h);
echo "\n** testing with mode=$mode **\n";
//create a file in dir1
$h = fopen($firstFile, "w");
- fwrite($h, "in dir1");
+ fwrite($h, (binary) "in dir1");
fclose($h);
//should now read dir1 file
// create a file in working directory
$h = fopen($filename, "w");
- fwrite($h, "in working dir");
+ fwrite($h, (binary) "in working dir");
fclose($h);
- //should still read dir1 file
+ //should read the dir1 file
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
unlink($firstFile);
unlink($secondFile);
- //should fail to read the file
+ //should read the working dir file
$h = fopen($filename, $mode, true);
fpassthru($h);
fclose($h);
// create a file in the script directory
$h = fopen($scriptFile, "w");
- fwrite($h, "in script dir");
+ fwrite($h, (binary) "in script dir");
fclose($h);
//should read the file in script dir
?>
===DONE===
--EXPECTF--
-*** Testing fopen() : variation ***
--- testing include path ---
in dir2
in dir1
in dir1
-
-Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
-
-Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
-
-Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
-
+in working dir
in script dir
** testing with mode=r+ **
in dir2
in dir1
in dir1
-
-Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
-
-Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
-
-Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
-
+in working dir
in script dir
** testing with mode=rt **
in dir2
in dir1
in dir1
-
-Warning: fopen(afile.txt): failed to open stream: No such file or directory in %s on line %d
-
-Warning: fpassthru(): supplied argument is not a valid stream resource in %s on line %d
-
-Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
-
+in working dir
in script dir
===DONE===
--TEST--
Test fopen() function : variation: use include path and stream context create a file, relative path
---XFAIL--
-Pending completion of Unicode streams
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--FILE--
require_once('fopen_include_path.inc');
-echo "*** Testing fopen() : variation ***\n";
-$thisTestDir = "fopenVariation9.dir";
+$thisTestDir = basename(__FILE__, ".php") . ".dir";
mkdir($thisTestDir);
chdir($thisTestDir);
$newpath = relative_include_path();
set_include_path($newpath);
runtest();
+
$newpath = generate_next_rel_path();
set_include_path($newpath);
runtest();
rmdir($thisTestDir);
function runtest() {
- $tmpfile = 'fopen_variation7.tmp';
+ $tmpfile = basename(__FILE__, ".php") . ".tmp";
$h = fopen($tmpfile, "w", true);
- fwrite($h, "This is the test file");
+ fwrite($h, (binary) "This is the test file");
fclose($h);
unlink($tmpfile);
}
- $h = fopen('dir1/'.$tmpfile, "r");
+ $h = @fopen('dir1/'.$tmpfile, "r");
if ($h === false) {
echo "Not created in dir1\n";
}
?>
===DONE===
--EXPECT--
-*** Testing fopen() : variation ***
-Not created in working dir
-created in dir1
-Not created in working dir
-created in dir1
+created in working dir
+Not created in dir1
+created in working dir
+Not created in dir1
===DONE===