mirror of
https://github.com/php/php-src.git
synced 2025-08-20 01:14:28 +02:00
Some fileinfo tests
This commit is contained in:
parent
6476e43eef
commit
ef8ae4dfc5
10 changed files with 12767 additions and 0 deletions
53
ext/fileinfo/tests/finfo_buffer_basic.phpt
Normal file
53
ext/fileinfo/tests/finfo_buffer_basic.phpt
Normal file
|
@ -0,0 +1,53 @@
|
|||
--TEST--
|
||||
Test finfo_buffer() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string finfo_buffer(resource finfo, char *string [, int options [, resource context]])
|
||||
* Description: Return infromation about a string buffer.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
$options = array(
|
||||
FILEINFO_NONE,
|
||||
FILEINFO_MIME,
|
||||
);
|
||||
|
||||
$buffers = array(
|
||||
"Regular string here",
|
||||
"\177ELF",
|
||||
"\000\000\0001\000\000\0000\000\000\0000\000\000\0002\000\000\0000\000\000\0000\000\000\0003",
|
||||
"\x55\x7A\x6E\x61",
|
||||
"id=ImageMagick",
|
||||
"RIFFüîò^BAVI LISTv",
|
||||
);
|
||||
|
||||
echo "*** Testing finfo_buffer() : basic functionality ***\n";
|
||||
|
||||
foreach( $options as $option ) {
|
||||
$finfo = finfo_open( $option, $magicFile );
|
||||
foreach( $buffers as $string ) {
|
||||
var_dump( finfo_buffer( $finfo, $string, $option ) );
|
||||
}
|
||||
finfo_close( $finfo );
|
||||
}
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_buffer() : basic functionality ***
|
||||
string(36) "ASCII text, with no line terminators"
|
||||
string(3) "ELF"
|
||||
string(22) "old ACE/gr binary file"
|
||||
string(12) "xo65 object,"
|
||||
string(15) "MIFF image data"
|
||||
string(25) "RIFF (little-endian) data"
|
||||
string(27) "text/plain charset=us-ascii"
|
||||
string(25) "text/plain charset=ebcdic"
|
||||
string(24) "application/octet-stream"
|
||||
string(27) "text/plain charset=us-ascii"
|
||||
string(27) "text/plain charset=us-ascii"
|
||||
string(24) "text/plain charset=utf-8"
|
||||
===DONE===
|
43
ext/fileinfo/tests/finfo_buffer_error.phpt
Normal file
43
ext/fileinfo/tests/finfo_buffer_error.phpt
Normal file
|
@ -0,0 +1,43 @@
|
|||
--TEST--
|
||||
Test finfo_buffer() function : error conditions
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string finfo_buffer(resource finfo, char *string [, int options [, resource context]])
|
||||
* Description: Return infromation about a string buffer.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
echo "*** Testing finfo_buffer() : error conditions ***\n";
|
||||
|
||||
$finfo = finfo_open( FILEINFO_NONE, $magicFile );
|
||||
|
||||
//Test finfo_buffer with one more than the expected number of arguments
|
||||
echo "\n-- Testing finfo_buffer() function with more than expected no. of arguments --\n";
|
||||
|
||||
$context = stream_context_get_default();
|
||||
$extra_arg = 10;
|
||||
var_dump( finfo_buffer($finfo, "foobar", FILEINFO_MIME, $context, $extra_arg) );
|
||||
|
||||
// Testing finfo_buffer with one less than the expected number of arguments
|
||||
echo "\n-- Testing finfo_buffer() function with less than expected no. of arguments --\n";
|
||||
|
||||
var_dump( finfo_buffer($finfo) );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_buffer() : error conditions ***
|
||||
|
||||
-- Testing finfo_buffer() function with more than expected no. of arguments --
|
||||
|
||||
Warning: finfo_buffer() expects at most 4 parameters, 5 given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Testing finfo_buffer() function with less than expected no. of arguments --
|
||||
|
||||
Warning: finfo_buffer() expects at least 2 parameters, 1 given in %s on line %d
|
||||
bool(false)
|
||||
===DONE===
|
52
ext/fileinfo/tests/finfo_buffer_variation1.phpt
Normal file
52
ext/fileinfo/tests/finfo_buffer_variation1.phpt
Normal file
|
@ -0,0 +1,52 @@
|
|||
--TEST--
|
||||
Test finfo_buffer() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string finfo_buffer(resource finfo, char *string [, int options [, resource context]])
|
||||
* Description: Return infromation about a string buffer.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
$options = array(
|
||||
FILEINFO_NONE,
|
||||
FILEINFO_MIME,
|
||||
);
|
||||
|
||||
$buffers = array(
|
||||
"Regular string here",
|
||||
"\177ELF",
|
||||
"\000\000\0001\000\000\0000\000\000\0000\000\000\0002\000\000\0000\000\000\0000\000\000\0003",
|
||||
"\x55\x7A\x6E\x61",
|
||||
"id=ImageMagick",
|
||||
"RIFFüîò^BAVI LISTv",
|
||||
);
|
||||
|
||||
echo "*** Testing finfo_buffer() : variation functionality with oo interface ***\n";
|
||||
|
||||
foreach( $options as $option ) {
|
||||
$finfo = new finfo( $option, $magicFile );
|
||||
foreach( $buffers as $string ) {
|
||||
var_dump( $finfo->buffer( $string, $option ) );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_buffer() : variation functionality with oo interface ***
|
||||
string(36) "ASCII text, with no line terminators"
|
||||
string(3) "ELF"
|
||||
string(22) "old ACE/gr binary file"
|
||||
string(12) "xo65 object,"
|
||||
string(15) "MIFF image data"
|
||||
string(25) "RIFF (little-endian) data"
|
||||
string(27) "text/plain charset=us-ascii"
|
||||
string(25) "text/plain charset=ebcdic"
|
||||
string(24) "application/octet-stream"
|
||||
string(27) "text/plain charset=us-ascii"
|
||||
string(27) "text/plain charset=us-ascii"
|
||||
string(24) "text/plain charset=utf-8"
|
||||
===DONE===
|
33
ext/fileinfo/tests/finfo_close_basic.phpt
Normal file
33
ext/fileinfo/tests/finfo_close_basic.phpt
Normal file
|
@ -0,0 +1,33 @@
|
|||
--TEST--
|
||||
Test finfo_close() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : resource finfo_close(resource finfo)
|
||||
* Description: Close fileinfo resource.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
echo "*** Testing finfo_close() : basic functionality ***\n";
|
||||
|
||||
$magicFile = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
$finfo = finfo_open( FILEINFO_MIME, $magicFile );
|
||||
var_dump( $finfo );
|
||||
|
||||
// Calling finfo_close() with all possible arguments
|
||||
var_dump( finfo_close($finfo) );
|
||||
|
||||
$finfo = new finfo( FILEINFO_MIME, $magicFile );
|
||||
var_dump( $finfo );
|
||||
unset( $finfo );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_close() : basic functionality ***
|
||||
resource(%d) of type (file_info)
|
||||
bool(true)
|
||||
object(finfo)#%d (%d) {
|
||||
}
|
||||
===DONE===
|
28
ext/fileinfo/tests/finfo_file_basic.phpt
Normal file
28
ext/fileinfo/tests/finfo_file_basic.phpt
Normal file
|
@ -0,0 +1,28 @@
|
|||
--TEST--
|
||||
Test finfo_file() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string finfo_file(resource finfo, char *file_name [, int options [, resource context]])
|
||||
* Description: Return information about a file.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
$finfo = finfo_open( FILEINFO_MIME );
|
||||
|
||||
echo "*** Testing finfo_file() : basic functionality ***\n";
|
||||
|
||||
// Calling finfo_file() with all possible arguments
|
||||
var_dump( finfo_file( $finfo, __FILE__) );
|
||||
var_dump( finfo_file( $finfo, __FILE__, FILEINFO_CONTINUE ) );
|
||||
var_dump( finfo_file( $finfo, $magicFile ) );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_file() : basic functionality ***
|
||||
string(25) "text/x-c charset=us-ascii"
|
||||
string(15) "PHP script text"
|
||||
string(26) "text/plain charset=unknown"
|
||||
===DONE===
|
45
ext/fileinfo/tests/finfo_open_basic.phpt
Normal file
45
ext/fileinfo/tests/finfo_open_basic.phpt
Normal file
|
@ -0,0 +1,45 @@
|
|||
--TEST--
|
||||
Test finfo_open() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : resource finfo_open([int options [, string arg]])
|
||||
* Description: Create a new fileinfo resource.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
echo "*** Testing finfo_open() : basic functionality ***\n";
|
||||
|
||||
// Calling finfo_open() with different options
|
||||
var_dump( finfo_open( FILEINFO_MIME, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_NONE, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_SYMLINK, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_COMPRESS, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_DEVICES, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_CONTINUE, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_PRESERVE_ATIME, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_RAW, $magicFile ) );
|
||||
|
||||
// OO inteface to finfo
|
||||
var_dump( new finfo( FILEINFO_MIME, $magicFile ) );
|
||||
var_dump( new finfo() );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_open() : basic functionality ***
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
object(finfo)#%d (%d) {
|
||||
}
|
||||
object(finfo)#%d (%d) {
|
||||
}
|
||||
===DONE===
|
43
ext/fileinfo/tests/finfo_open_error.phpt
Normal file
43
ext/fileinfo/tests/finfo_open_error.phpt
Normal file
|
@ -0,0 +1,43 @@
|
|||
--TEST--
|
||||
Test finfo_open() function : error functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : resource finfo_open([int options [, string arg]])
|
||||
* Description: Create a new fileinfo resource.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
echo "*** Testing finfo_open() : error functionality ***\n";
|
||||
|
||||
var_dump( finfo_open( FILEINFO_MIME, 'foobarfile' ) );
|
||||
var_dump( finfo_open( array(), $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_MIME, $magicFile, 'extraArg' ) );
|
||||
var_dump( finfo_open( PHP_INT_MAX - 1, $magicFile ) );
|
||||
var_dump( finfo_open( 'foobar' ) );
|
||||
|
||||
var_dump( new finfo('foobar') );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_open() : error functionality ***
|
||||
bool(false)
|
||||
|
||||
Warning: finfo_open() expects parameter 1 to be long, array given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: finfo_open() expects at most 2 parameters, 3 given in %s on line %d
|
||||
bool(false)
|
||||
unknown, 0: Warning: using regular magic file `%s'
|
||||
resource(%d) of type (file_info)
|
||||
|
||||
Warning: finfo_open() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: finfo::finfo() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d
|
||||
object(finfo)#%d (%d) {
|
||||
}
|
||||
===DONE===
|
27
ext/fileinfo/tests/finfo_open_variation1.phpt
Normal file
27
ext/fileinfo/tests/finfo_open_variation1.phpt
Normal file
|
@ -0,0 +1,27 @@
|
|||
--TEST--
|
||||
Test finfo_open() function : variations in opening
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : resource finfo_open([int options [, string arg]])
|
||||
* Description: Create a new fileinfo resource.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
|
||||
echo "*** Testing finfo_open() : variations in opening ***\n";
|
||||
|
||||
// Calling finfo_open() with different options
|
||||
var_dump( finfo_open( FILEINFO_MIME | FILEINFO_SYMLINK, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_COMPRESS | FILEINFO_PRESERVE_ATIME, $magicFile ) );
|
||||
var_dump( finfo_open( FILEINFO_DEVICES | FILEINFO_RAW, $magicFile ) );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_open() : variations in opening ***
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
resource(%d) of type (file_info)
|
||||
===DONE===
|
40
ext/fileinfo/tests/finfo_set_flags_basic.phpt
Normal file
40
ext/fileinfo/tests/finfo_set_flags_basic.phpt
Normal file
|
@ -0,0 +1,40 @@
|
|||
--TEST--
|
||||
Test finfo_set_flags() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : bool finfo_set_flags(resource finfo, int options)
|
||||
* Description: Set libmagic configuration options.
|
||||
* Source code: ext/fileinfo/fileinfo.c
|
||||
* Alias to functions:
|
||||
*/
|
||||
|
||||
$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
|
||||
$finfo = finfo_open( FILEINFO_MIME, $magicFile );
|
||||
|
||||
echo "*** Testing finfo_set_flags() : basic functionality ***\n";
|
||||
|
||||
var_dump( finfo_set_flags( $finfo, FILEINFO_NONE ) );
|
||||
var_dump( finfo_set_flags( $finfo, FILEINFO_SYMLINK ) );
|
||||
var_dump( finfo_set_flags() );
|
||||
|
||||
finfo_close( $finfo );
|
||||
|
||||
// OO way
|
||||
$finfo = new finfo( FILEINFO_NONE, $magicFile );
|
||||
var_dump( $finfo->set_flags( FILEINFO_MIME ) );
|
||||
var_dump( $finfo->set_flags() );
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing finfo_set_flags() : basic functionality ***
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: finfo_set_flags() expects exactly 2 parameters, 0 given in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
|
||||
Warning: finfo::set_flags() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
bool(false)
|
||||
===DONE===
|
12403
ext/fileinfo/tests/magic
Normal file
12403
ext/fileinfo/tests/magic
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue