diff options
author | SVN Migration <svn@php.net> | 2008-05-12 21:03:49 +0000 |
---|---|---|
committer | SVN Migration <svn@php.net> | 2008-05-12 21:03:49 +0000 |
commit | 16b4d8e0e1108564fa042520171d9091af708d83 (patch) | |
tree | ed242b98e845ea9c045ad6e10b9e9a083b569dd5 /ext/phar/tests/tar | |
parent | e35c45791383ac9337adcd37255895f396001557 (diff) | |
download | php-git-16b4d8e0e1108564fa042520171d9091af708d83.tar.gz |
This commit was manufactured by cvs2svn to create branch 'PHP_5_3'.
Diffstat (limited to 'ext/phar/tests/tar')
114 files changed, 3571 insertions, 0 deletions
diff --git a/ext/phar/tests/tar/033.phpt b/ext/phar/tests/tar/033.phpt new file mode 100644 index 0000000000..29223e49e3 --- /dev/null +++ b/ext/phar/tests/tar/033.phpt @@ -0,0 +1,50 @@ +--TEST-- +Phar::chmod tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://hio'; + +$phar = new Phar($fname); +$phar['a.php'] = '<?php echo "This is a\n"; include "'.$alias.'/b.php"; ?>'; +$phar->setAlias('hio'); +$phar->addEmptyDir('test'); +$phar->stopBuffering(); + +try { + var_dump($phar['a.php']->isExecutable()); + $phar['a.php']->chmod(0777); + var_dump($phar['a.php']->isExecutable()); + $phar['a.php']->chmod(0666); + var_dump($phar['a.php']->isExecutable()); + echo "test dir\n"; + var_dump($phar['test']->isReadable()); + $phar['test']->chmod(0000); + var_dump($phar['test']->isReadable()); + $phar['test']->chmod(0666); + var_dump($phar['test']->isReadable()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +?> +--EXPECTF-- +bool(false) +bool(true) +bool(false) +test dir +bool(true) +bool(false) +bool(true) +===DONE=== diff --git a/ext/phar/tests/tar/033a.phpt b/ext/phar/tests/tar/033a.phpt new file mode 100644 index 0000000000..09b5446aec --- /dev/null +++ b/ext/phar/tests/tar/033a.phpt @@ -0,0 +1,45 @@ +--TEST-- +Phar::chmod tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://hio'; + +$phar = new Phar($fname); +$phar['a.php'] = '<?php echo "This is a\n"; include "'.$alias.'/b.php"; ?>'; +$phar->setAlias('hio'); +$phar->addEmptyDir('test'); +$phar->stopBuffering(); +ini_set('phar.readonly', 1); + +try { + var_dump($phar['a.php']->isExecutable()); + $phar['a.php']->chmod(0777); + var_dump($phar['a.php']->isExecutable()); + $phar['a.php']->chmod(0666); + var_dump($phar['a.php']->isExecutable()); + echo "test dir\n"; + var_dump($phar['test']->isReadable()); + $phar['test']->chmod(0000); + var_dump($phar['test']->isReadable()); + $phar['test']->chmod(0666); + var_dump($phar['test']->isReadable()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +?> +--EXPECTF-- +bool(false) +Cannot modify permissions for file "a.php" in phar "%s033a.phar.tar", write operations are prohibited +===DONE=== diff --git a/ext/phar/tests/tar/alias_acrobatics.phpt b/ext/phar/tests/tar/alias_acrobatics.phpt new file mode 100644 index 0000000000..d08dc0467c --- /dev/null +++ b/ext/phar/tests/tar/alias_acrobatics.phpt @@ -0,0 +1,46 @@ +--TEST-- +Phar: alias edge cases +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.tar'; + +$p = new Phar($fname); + +$p->setAlias('foo'); +$p['unused'] = 'hi'; +try { +$a = new Phar($fname2, 0, 'foo'); +} catch (Exception $e) { +echo $e->getMessage(),"\n"; +} +copy($fname, $fname2); +echo "2\n"; +try { +$a = new Phar($fname2); +} catch (Exception $e) { +echo $e->getMessage(),"\n"; +} +try { +$b = new Phar($fname, 0, 'another'); +} catch (Exception $e) { +echo $e->getMessage(),"\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar'); +?> +--EXPECTF-- +alias "foo" is already used for archive "%salias_acrobatics.phar.tar" cannot be overloaded with "%salias_acrobatics.2.phar.tar" +2 +phar error: Unable to add tar-based phar "%salias_acrobatics.2.phar.tar", alias is already in use +alias "another" is already used for archive "%salias_acrobatics.phar.tar" cannot be overloaded with "%salias_acrobatics.phar.tar" +===DONE=== diff --git a/ext/phar/tests/tar/badalias.phpt b/ext/phar/tests/tar/badalias.phpt new file mode 100644 index 0000000000..441fc03ae7 --- /dev/null +++ b/ext/phar/tests/tar/badalias.phpt @@ -0,0 +1,25 @@ +--TEST-- +Phar: invalid aliases +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("zlib")) die("skip no zlib"); ?> +<?php if (!extension_loaded("bz2")) die("skip no bz2"); ?> +--FILE-- +<?php +$e = dirname(__FILE__) . '/files/'; +for ($i = 1; $i <= 5; $i++) { +try { +new Phar($e . "badalias$i.phar.tar"); +} catch (Exception $ee) { +echo $ee->getMessage(), "\n"; +} +} +?> +===DONE=== +--EXPECTF-- +phar error: invalid alias "hi/thereaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." in tar-based phar "%sbadalias1.phar.tar" +phar error: invalid alias "hi\there" in tar-based phar "%sbadalias2.phar.tar" +phar error: invalid alias "hi;there" in tar-based phar "%sbadalias3.phar.tar" +phar error: invalid alias "hi:there" in tar-based phar "%sbadalias4.phar.tar" +phar error: tar-based phar "%sbadalias5.phar.tar" has alias that is larger than 511 bytes, cannot process +===DONE=== diff --git a/ext/phar/tests/tar/badchecksum.phpt b/ext/phar/tests/tar/badchecksum.phpt new file mode 100644 index 0000000000..fae19b153d --- /dev/null +++ b/ext/phar/tests/tar/badchecksum.phpt @@ -0,0 +1,30 @@ +--TEST-- +Phar: tar with bad checksum +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--FILE-- +<?php +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar'; +$pname = 'phar://' . $fname; + +include dirname(__FILE__) . '/files/corrupt_tarmaker.php.inc'; +$a = new corrupt_tarmaker($fname, 'none'); +$a->init(); +$a->addFile('hithere', 'contents', null, 'checksum'); +$a->close(); + +try { + $p = new PharData($fname); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); +?> +--EXPECTF-- +phar error: "%sbadchecksum.tar" is a corrupted tar file (checksum mismatch of file "hithere") +===DONE=== diff --git a/ext/phar/tests/tar/bignames.phpt b/ext/phar/tests/tar/bignames.phpt new file mode 100644 index 0000000000..19d5f638e1 --- /dev/null +++ b/ext/phar/tests/tar/bignames.phpt @@ -0,0 +1,35 @@ +--TEST-- +Phar: tar with huge filenames +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--FILE-- +<?php +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar'; +$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.tar'; +$pname = 'phar://' . $fname; + +$p1 = new PharData($fname); +$p1[str_repeat('a', 101)] = 'hi'; +$p1[str_repeat('a', 255)] = 'hi2'; +copy($fname, $fname2); +$p2 = new PharData($fname2); +echo $p2[str_repeat('a', 101)]->getContent() . "\n"; +echo $p2[str_repeat('a', 255)]->getContent() . "\n"; + +try { + $p2[str_repeat('a', 400)] = 'yuck'; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.tar'); +?> +--EXPECTF-- +hi +hi2 +tar-based phar "%sbignames.2.tar" cannot be created, filename "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" is too long for tar file format +===DONE=== diff --git a/ext/phar/tests/tar/create_new_and_modify.phpt b/ext/phar/tests/tar/create_new_and_modify.phpt new file mode 100644 index 0000000000..8062fda769 --- /dev/null +++ b/ext/phar/tests/tar/create_new_and_modify.phpt @@ -0,0 +1,45 @@ +--TEST-- +Phar: create and modify tar-based phar +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.php'; +$pname = 'phar://' . $fname; + +@unlink($fname); + +file_put_contents($pname . '/a.php', "brand new!\n"); + +$phar = new Phar($fname); +var_dump($phar->isFileFormat(Phar::TAR)); +$sig1 = md5_file($fname); + +include $pname . '/a.php'; + +file_put_contents($pname .'/a.php', "modified!\n"); +file_put_contents($pname .'/b.php', "another!\n"); + +$phar = new Phar($fname); +$sig2 = md5_file($fname); + +var_dump($sig1 != $sig2); + +include $pname . '/a.php'; +include $pname . '/b.php'; + +?> +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.php'); ?> +--EXPECTF-- +bool(true) +brand new! +bool(true) +modified! +another! +===DONE=== diff --git a/ext/phar/tests/tar/create_new_phar_b.phpt b/ext/phar/tests/tar/create_new_phar_b.phpt new file mode 100644 index 0000000000..a608be4705 --- /dev/null +++ b/ext/phar/tests/tar/create_new_phar_b.phpt @@ -0,0 +1,27 @@ +--TEST-- +Phar: create a completely new tar-based phar +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=1 +phar.require_hash=1 +--FILE-- +<?php + +file_put_contents('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar/a.php', + 'brand new!'); +include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar/a.php'; +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- + +Warning: file_put_contents(phar://%screate_new_phar_b.phar.tar/a.php): failed to open stream: phar error: write operations disabled by INI setting in %screate_new_phar_b.php on line %d + +Warning: include(phar://%screate_new_phar_b.phar.tar/a.php): failed to open stream: %s in %screate_new_phar_b.php on line %d + +Warning: include(): Failed opening 'phar://%screate_new_phar_b.phar.tar/a.php' for inclusion (include_path='%s') in %screate_new_phar_b.php on line %d + +===DONE=== diff --git a/ext/phar/tests/tar/delete.phpt b/ext/phar/tests/tar/delete.phpt new file mode 100644 index 0000000000..32b2b1e28b --- /dev/null +++ b/ext/phar/tests/tar/delete.phpt @@ -0,0 +1,32 @@ +--TEST-- +Phar: delete test, tar-based phar +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; +$stub = "<?php +Phar::mapPhar('hio'); +__HALT_COMPILER(); ?>"; + +$phar = new Phar($fname); +$phar['a'] = 'a'; +$phar->setStub($stub); +$phar->stopBuffering(); + +echo file_get_contents($alias . '/a') . "\n"; +$phar->delete('a'); +echo file_get_contents($alias . '/a') . "\n"; + +?> +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- +a + +Warning: file_get_contents(phar://%sdelete.phar.tar/a): failed to open stream: phar error: "a" is not a file in phar "%sdelete.phar.tar" in %sdelete.php on line %d
\ No newline at end of file diff --git a/ext/phar/tests/tar/delete_in_phar.phpt b/ext/phar/tests/tar/delete_in_phar.phpt new file mode 100644 index 0000000000..91ef4a2046 --- /dev/null +++ b/ext/phar/tests/tar/delete_in_phar.phpt @@ -0,0 +1,49 @@ +--TEST-- +Phar: delete a file within a tar-based .phar +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$phar = new Phar($fname); +$phar['a.php'] = '<?php echo "This is a\n"; ?>'; +$phar['b.php'] = '<?php echo "This is b\n"; ?>'; +$phar['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +$phar->setStub('<?php __HALT_COMPILER(); ?>'); +$phar->stopBuffering(); + +include $alias . '/a.php'; +include $alias . '/b.php'; +include $alias . '/b/c.php'; +unlink($alias . '/b/c.php'); + +?> +===AFTER=== +<?php +include $alias . '/a.php'; +include $alias . '/b.php'; +include $alias . '/b/c.php'; +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- +This is a +This is b +This is b/c +===AFTER=== +This is a +This is b + +Warning: include(%sdelete_in_phar.phar.tar/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar.phar.tar" in %sdelete_in_phar.php on line %d + +Warning: include(): Failed opening 'phar://%sdelete_in_phar.phar.tar/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar.php on line %d + +===DONE=== diff --git a/ext/phar/tests/tar/delete_in_phar_b.phpt b/ext/phar/tests/tar/delete_in_phar_b.phpt new file mode 100644 index 0000000000..2af1c66deb --- /dev/null +++ b/ext/phar/tests/tar/delete_in_phar_b.phpt @@ -0,0 +1,49 @@ +--TEST-- +Phar: delete a file within a tar-based .phar +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$phar = new Phar($fname); +$phar['a.php'] = '<?php echo "This is a\n"; ?>'; +$phar['b.php'] = '<?php echo "This is b\n"; ?>'; +$phar['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +$phar->setStub('<?php __HALT_COMPILER(); ?>'); +$phar->stopBuffering(); +ini_set('phar.readonly', 1); + +include $alias . '/a.php'; +include $alias . '/b.php'; +include $alias . '/b/c.php'; +unlink($alias . '/b/c.php'); + +?> +===AFTER=== +<?php +include $alias . '/a.php'; +include $alias . '/b.php'; +include $alias . '/b/c.php'; +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- +This is a +This is b +This is b/c + +Warning: unlink(): phar error: write operations disabled by INI setting in %sdelete_in_phar_b.php on line %d +===AFTER=== +This is a +This is b +This is b/c + +===DONE=== diff --git a/ext/phar/tests/tar/delete_in_phar_confirm.phpt b/ext/phar/tests/tar/delete_in_phar_confirm.phpt new file mode 100644 index 0000000000..707bcbd0ed --- /dev/null +++ b/ext/phar/tests/tar/delete_in_phar_confirm.phpt @@ -0,0 +1,52 @@ +--TEST-- +Phar: delete a file within a tar-based .phar (confirm disk file is changed) +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$phar = new Phar($fname); +$phar['a.php'] = '<?php echo "This is a\n"; ?>'; +$phar['b.php'] = '<?php echo "This is b\n"; ?>'; +$phar['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +$phar->setStub('<?php __HALT_COMPILER(); ?>'); +$phar->stopBuffering(); + +include $alias . '/a.php'; +include $alias . '/b.php'; +include $alias . '/b/c.php'; +$md5 = md5_file($fname); +unlink($alias . '/b/c.php'); +clearstatcache(); +$md52 = md5_file($fname); +if ($md5 == $md52) echo 'file was not modified'; +?> +===AFTER=== +<?php +include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar/a.php'; +include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar/b.php'; +include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar/b/c.php'; +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- +This is a +This is b +This is b/c +===AFTER=== +This is a +This is b + +Warning: include(%sdelete_in_phar_confirm.phar.tar/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar_confirm.phar.tar" in %sdelete_in_phar_confirm.php on line %d + +Warning: include(): Failed opening 'phar://%sdelete_in_phar_confirm.phar.tar/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar_confirm.php on line %d + +===DONE=== diff --git a/ext/phar/tests/tar/dir.phpt b/ext/phar/tests/tar/dir.phpt new file mode 100644 index 0000000000..53bf65f9a7 --- /dev/null +++ b/ext/phar/tests/tar/dir.phpt @@ -0,0 +1,43 @@ +--TEST-- +Phar: mkdir/rmdir test tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.php'; +$pname = 'phar://' . $fname; +$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.1.phar.php'; +$pname2 = 'phar://' . $fname2; +$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.php'; +$pname3 = 'phar://' . $fname3; +$phar = new Phar($fname); +var_dump($phar->isFileFormat(Phar::TAR)); + +$phar->addEmptyDir('test'); +var_dump($phar['test']->isDir()); +var_dump($phar['test/']->isDir()); +copy($fname, $fname2); +mkdir($pname . '/another/dir/'); +var_dump($phar['another/dir']->isDir()); +rmdir($pname . '/another/dir/'); +copy($fname, $fname3); +clearstatcache(); +var_dump(file_exists($pname . '/another/dir/')); +var_dump(file_exists($pname2 . '/test/')); +var_dump(file_exists($pname3 . '/another/dir/')); +?> +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.php'); ?> +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php'); ?> +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php'); ?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(true) +bool(false) diff --git a/ext/phar/tests/tar/exists_as_phar.phpt b/ext/phar/tests/tar/exists_as_phar.phpt new file mode 100644 index 0000000000..9a8cfc81f0 --- /dev/null +++ b/ext/phar/tests/tar/exists_as_phar.phpt @@ -0,0 +1,38 @@ +--TEST-- +Phar: phar-based phar named with ".tar" fails +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar'; +$tname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://hio'; + +$phar = new Phar($fname); +$phar['a.php'] = '<?php echo "This is a\n"; include "'.$alias.'/b.php"; ?>'; +$phar->setAlias('hio'); +$phar->addEmptyDir('test'); +$phar->stopBuffering(); +copy($fname, $tname); +$phar->setAlias('hio2'); + +try { + $p = new Phar($tname); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); +?> +--EXPECTF-- +phar tar error: "%sexists_as_phar.phar.tar" already exists as a regular phar and must be deleted from disk prior to creating as a tar-based phar +===DONE=== diff --git a/ext/phar/tests/tar/files/badalias1.phar.tar b/ext/phar/tests/tar/files/badalias1.phar.tar Binary files differnew file mode 100644 index 0000000000..6cd4716d8f --- /dev/null +++ b/ext/phar/tests/tar/files/badalias1.phar.tar diff --git a/ext/phar/tests/tar/files/badalias2.phar.tar b/ext/phar/tests/tar/files/badalias2.phar.tar Binary files differnew file mode 100644 index 0000000000..5face85827 --- /dev/null +++ b/ext/phar/tests/tar/files/badalias2.phar.tar diff --git a/ext/phar/tests/tar/files/badalias3.phar.tar b/ext/phar/tests/tar/files/badalias3.phar.tar Binary files differnew file mode 100644 index 0000000000..ab36e1f343 --- /dev/null +++ b/ext/phar/tests/tar/files/badalias3.phar.tar diff --git a/ext/phar/tests/tar/files/badalias4.phar.tar b/ext/phar/tests/tar/files/badalias4.phar.tar Binary files differnew file mode 100644 index 0000000000..c54e31d4fc --- /dev/null +++ b/ext/phar/tests/tar/files/badalias4.phar.tar diff --git a/ext/phar/tests/tar/files/badalias5.phar.tar b/ext/phar/tests/tar/files/badalias5.phar.tar Binary files differnew file mode 100644 index 0000000000..dd52b6ac7d --- /dev/null +++ b/ext/phar/tests/tar/files/badalias5.phar.tar diff --git a/ext/phar/tests/tar/files/biglink.tar b/ext/phar/tests/tar/files/biglink.tar Binary files differnew file mode 100644 index 0000000000..43bbf58423 --- /dev/null +++ b/ext/phar/tests/tar/files/biglink.tar diff --git a/ext/phar/tests/tar/files/corrupt_tarmaker.php.inc b/ext/phar/tests/tar/files/corrupt_tarmaker.php.inc new file mode 100644 index 0000000000..b0eba6cc69 --- /dev/null +++ b/ext/phar/tests/tar/files/corrupt_tarmaker.php.inc @@ -0,0 +1,177 @@ +<?php +// stolen from PEAR2_Pyrus_Developer_Creator_Tar by Greg Beaver, the original author, for use in unit tests +class corrupt_tarmaker +{ + /** + * Path to archive file + * + * @var string + */ + protected $archive; + /** + * Temporary stream used for creating the archive + * + * @var stream + */ + protected $tmp; + protected $path; + protected $compress; + function __construct($path, $compress = 'zlib') + { + $this->compress = $compress; + if ($compress === 'bz2' && !function_exists('bzopen')) { + throw new PEAR2_Pyrus_Developer_Creator_Exception( + 'bzip2 extension not available'); + } + if ($compress === 'zlib' && !function_exists('gzopen')) { + throw new PEAR2_Pyrus_Developer_Creator_Exception( + 'zlib extension not available'); + } + $this->path = $path; + } + + /** + * save a file inside this package + * + * This code is modified from Vincent Lascaux's File_Archive + * package, which is licensed under the LGPL license. + * @param string relative path within the package + * @param string|resource file contents or open file handle + */ + function addFile($path, $fileOrStream, $stat = null, $corrupt = null) + { + clearstatcache(); + if ($stat === null) { + if (is_resource($fileOrStream)) { + $stat = fstat($fileOrStream); + } else { + $stat = array( + 'mode' => 0x8000 + 0644, + 'uid' => 0, + 'gid' => 0, + 'size' => strlen($fileOrStream), + 'mtime' => time(), + ); + } + } + + $link = null; + if ($stat['mode'] & 0xA000 && $corrupt === 'symlink') { + $type = 2; // Symbolic Link + $link = $fileOrStream; + $stat['size'] = 0; + $fileOrStream = ''; + } else if ($stat['mode'] & 0xA000) { + $type = 1; // Link + $link = $fileOrStream; + $stat['size'] = 0; + $fileOrStream = ''; + } else if ($stat['mode'] & 0x4000) { + $type = 5; // Directory + } else if ($stat['mode'] & 0x8000) { + $type = 0; // Regular + } else { + $type = 9; // Unknown + } + + $filePrefix = ''; + if (strlen($path) > 255) { + throw new Exception( + "$path is too long, must be 255 characters or less" + ); + } else if (strlen($path) > 100) { + $filePrefix = substr($path, 0, strlen($path)-100); + $path = substr($path, -100); + } + + $block = pack('a100a8a8a8a12A12', + $path, + decoct($stat['mode']), + sprintf('%6s ',decoct($stat['uid'])), + sprintf('%6s ',decoct($stat['gid'])), + sprintf('%11s ',decoct($stat['size'])), + sprintf('%11s ',decoct($stat['mtime'])) + ); + + $blockend = pack('a1a100a6a2a32a32a8a8a155a12', + $type, + $link, + 'ustar', + '00', + 'Pyrus', + 'Pyrus', + '', + '', + $filePrefix, + ''); + + $checkheader = array_merge(str_split($block), str_split($blockend)); + if (!function_exists('_pear2tarchecksum')) { + function _pear2tarchecksum($a, $b) {return $a + ord($b);} + } + $checksum = 256; // 8 * ord(' '); + $checksum += array_reduce($checkheader, '_pear2tarchecksum'); + + if ($corrupt === 'checksum') $checksum++; + $checksum = pack('a8', sprintf('%6s ', decoct($checksum))); + + fwrite($this->tmp, $block . $checksum . $blockend, 512); + if (is_resource($fileOrStream)) { + stream_copy_to_stream($fileOrStream, $this->tmp); + if ($stat['size'] % 512) { + fwrite($this->tmp, str_repeat("\0", 512 - $stat['size'] % 512)); + } + } else { + fwrite($this->tmp, $fileOrStream); + if (strlen($fileOrStream) && !isset($link) && strlen($fileOrStream) % 512) { + fwrite($this->tmp, str_repeat("\0", 512 - strlen($fileOrStream) % 512)); + } + } + } + + /** + * Initialize the package creator + */ + function init() + { + switch ($this->compress) { + case 'zlib' : + $this->tmp = gzopen($this->path, 'wb'); + break; + case 'bz2' : + $this->tmp = bzopen($this->path, 'w'); + break; + case 'none' : + $this->tmp = fopen($this->path, 'wb'); + break; + default : + throw new Exception( + 'unknown compression type ' . $this->compress); + } + } + + /** + * Create an internal directory, creating parent directories as needed + * + * @param string $dir + */ + function mkdir($dir) + { + $this->addFile($dir, "", array( + 'mode' => 0x4000 + 0644, + 'uid' => 0, + 'gid' => 0, + 'size' => 0, + 'mtime' => time(), + )); + } + + /** + * Finish saving the package + */ + function close() + { + fwrite($this->tmp, pack('a1024', '')); + fclose($this->tmp); + } +}
\ No newline at end of file diff --git a/ext/phar/tests/tar/files/frontcontroller.phar.inc b/ext/phar/tests/tar/files/frontcontroller.phar.inc new file mode 100644 index 0000000000..6f426e8864 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller.phar.inc @@ -0,0 +1,13 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller.phar.tar'); +$a['a.php'] = 'hio'; +$a['a.jpg'] = 'hio'; +$a['a.phps'] = '<?php function hio(){}'; +$a['index.php'] = 'here is my index'; +$a->setStub('<?php +Phar::webPhar(); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller.phar.tar b/ext/phar/tests/tar/files/frontcontroller.phar.tar Binary files differnew file mode 100644 index 0000000000..522d097845 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller.phar.tar diff --git a/ext/phar/tests/tar/files/frontcontroller10.phar.inc b/ext/phar/tests/tar/files/frontcontroller10.phar.inc new file mode 100644 index 0000000000..5b132fa117 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller10.phar.inc @@ -0,0 +1,20 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller10.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller10.phar.tar'); +$a['index.php'] = '<?php +var_dump($_SERVER["PHP_SELF"]); +var_dump($_SERVER["SCRIPT_NAME"]); +var_dump($_SERVER["SCRIPT_FILENAME"]); +var_dump($_SERVER["REQUEST_URI"]); +var_dump($_SERVER["PHAR_PHP_SELF"]); +var_dump($_SERVER["PHAR_SCRIPT_NAME"]); +var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]); +var_dump($_SERVER["PHAR_REQUEST_URI"]); +'; +$a->setStub('<?php +Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI", "OOPSIE")); +Phar::webPhar(); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller10.phar.tar b/ext/phar/tests/tar/files/frontcontroller10.phar.tar Binary files differnew file mode 100644 index 0000000000..d43ed916a1 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller10.phar.tar diff --git a/ext/phar/tests/tar/files/frontcontroller11.phar.inc b/ext/phar/tests/tar/files/frontcontroller11.phar.inc new file mode 100644 index 0000000000..2fa15f097e --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller11.phar.inc @@ -0,0 +1,20 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller11.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller11.phar.tar'); +$a['index.php'] = '<?php +var_dump($_SERVER["PHP_SELF"]); +var_dump($_SERVER["SCRIPT_NAME"]); +var_dump($_SERVER["SCRIPT_FILENAME"]); +var_dump($_SERVER["REQUEST_URI"]); +var_dump($_SERVER["PHAR_PHP_SELF"]); +var_dump($_SERVER["PHAR_SCRIPT_NAME"]); +var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]); +var_dump($_SERVER["PHAR_REQUEST_URI"]); +'; +$a->setStub('<?php +Phar::mungServer(array(array(), "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI")); +Phar::webPhar(); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller11.phar.tar b/ext/phar/tests/tar/files/frontcontroller11.phar.tar Binary files differnew file mode 100644 index 0000000000..c8f98a1e78 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller11.phar.tar diff --git a/ext/phar/tests/tar/files/frontcontroller12.phar.inc b/ext/phar/tests/tar/files/frontcontroller12.phar.inc new file mode 100644 index 0000000000..693ef0aa01 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller12.phar.inc @@ -0,0 +1,20 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller12.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller12.phar.tar'); +$a['index.php'] = '<?php +var_dump($_SERVER["PHP_SELF"]); +var_dump($_SERVER["SCRIPT_NAME"]); +var_dump($_SERVER["SCRIPT_FILENAME"]); +var_dump($_SERVER["REQUEST_URI"]); +var_dump($_SERVER["PHAR_PHP_SELF"]); +var_dump($_SERVER["PHAR_SCRIPT_NAME"]); +var_dump($_SERVER["PHAR_SCRIPT_FILENAME"]); +var_dump($_SERVER["PHAR_REQUEST_URI"]); +'; +$a->setStub('<?php +Phar::mungServer(array("PHP_SELF", "SCRIPT_NAME", "SCRIPT_FILENAME", "REQUEST_URI")); +Phar::webPhar(); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller12.phar.tar b/ext/phar/tests/tar/files/frontcontroller12.phar.tar Binary files differnew file mode 100644 index 0000000000..06e7e59b03 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller12.phar.tar diff --git a/ext/phar/tests/tar/files/frontcontroller2.phar.inc b/ext/phar/tests/tar/files/frontcontroller2.phar.inc new file mode 100644 index 0000000000..8ae1171a38 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller2.phar.inc @@ -0,0 +1,12 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller2.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller2.phar.tar'); +$a['a.php'] = 'hio'; +$a['a.jpg'] = 'hio'; +$a['a.phps'] = '<?php function hio(){}'; +$a->setStub('<?php +Phar::webPhar("whatever", "a.php"); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller2.phar.tar b/ext/phar/tests/tar/files/frontcontroller2.phar.tar Binary files differnew file mode 100644 index 0000000000..857b116890 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller2.phar.tar diff --git a/ext/phar/tests/tar/files/frontcontroller3.phar.inc b/ext/phar/tests/tar/files/frontcontroller3.phar.inc new file mode 100644 index 0000000000..9729d0065b --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller3.phar.inc @@ -0,0 +1,18 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller3.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller3.phar.tar'); +$a['a.php'] = 'hio'; +$a['a.jpg'] = 'hio'; +$a['a.phps'] = '<?php function hio(){}'; +$a->setStub('<?php +function s($a) +{ + static $b = array("/hi" => "a.phps"); + if (isset($b[$a])) return $b[$a]; + return $a; +} +Phar::webPhar("whatever", "/index.php", null, array(), "s"); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller3.phar.tar b/ext/phar/tests/tar/files/frontcontroller3.phar.tar Binary files differnew file mode 100644 index 0000000000..f733884d12 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller3.phar.tar diff --git a/ext/phar/tests/tar/files/frontcontroller4.phar.inc b/ext/phar/tests/tar/files/frontcontroller4.phar.inc new file mode 100644 index 0000000000..eb1d56f0d4 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller4.phar.inc @@ -0,0 +1,18 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller4.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller4.phar.tar'); +$a['a.php'] = 'hio'; +$a['a.jpg'] = 'hio'; +$a['a.phps'] = '<?php function hio(){}'; +$a->setStub('<?php +function s($a) +{ + static $b = array("/hi" => false); + if (isset($b[$a])) return $b[$a]; + return $a; +} +Phar::webPhar("whatever", "index.php", null, array(), "s"); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller4.phar.tar b/ext/phar/tests/tar/files/frontcontroller4.phar.tar Binary files differnew file mode 100644 index 0000000000..5d11af499c --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller4.phar.tar diff --git a/ext/phar/tests/tar/files/frontcontroller5.phar.inc b/ext/phar/tests/tar/files/frontcontroller5.phar.inc new file mode 100644 index 0000000000..d6204c7d97 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller5.phar.inc @@ -0,0 +1,12 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller5.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller5.phar.tar'); +$a['a.php'] = 'hio'; +$a['a.jpg'] = 'hio'; +$a['a.phps'] = '<?php function hio(){}'; +$a->setStub('<?php +Phar::webPhar("whatever", "index.php", null, array(0 => "oops")); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller5.phar.tar b/ext/phar/tests/tar/files/frontcontroller5.phar.tar Binary files differnew file mode 100644 index 0000000000..e6e9015bf8 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller5.phar.tar diff --git a/ext/phar/tests/tar/files/frontcontroller6.phar.inc b/ext/phar/tests/tar/files/frontcontroller6.phar.inc new file mode 100644 index 0000000000..66212d82e8 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller6.phar.inc @@ -0,0 +1,12 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller6.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller6.phar.tar'); +$a['a.php'] = 'hio'; +$a['a.jpg'] = 'hio'; +$a['a.phps'] = '<?php function hio(){}'; +$a->setStub('<?php +Phar::webPhar("whatever", "index.php", null, array("blah" => 100)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller6.phar.tar b/ext/phar/tests/tar/files/frontcontroller6.phar.tar Binary files differnew file mode 100644 index 0000000000..d30b7ab9eb --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller6.phar.tar diff --git a/ext/phar/tests/tar/files/frontcontroller7.phar.inc b/ext/phar/tests/tar/files/frontcontroller7.phar.inc new file mode 100644 index 0000000000..74adf2c008 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller7.phar.inc @@ -0,0 +1,12 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller7.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller7.phar.tar'); +$a['a.php'] = 'hio'; +$a['a.jpg'] = 'hio'; +$a['a.phps'] = '<?php function hio(){}'; +$a->setStub('<?php +Phar::webPhar("whatever", "index.php", null, array("blah" => null)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller7.phar.tar b/ext/phar/tests/tar/files/frontcontroller7.phar.tar Binary files differnew file mode 100644 index 0000000000..c7ccc940c1 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller7.phar.tar diff --git a/ext/phar/tests/tar/files/frontcontroller8.phar.inc b/ext/phar/tests/tar/files/frontcontroller8.phar.inc new file mode 100644 index 0000000000..f51a762806 --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller8.phar.inc @@ -0,0 +1,13 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller8.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller8.phar.tar'); +$a['a.phps'] = 'hio1'; +$a['a.jpg'] = 'hio2'; +$a['a.php'] = '<?php function hio(){}'; +$a['fronk.gronk'] = 'hio3'; +$a->setStub('<?php +Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller8.phar.tar b/ext/phar/tests/tar/files/frontcontroller8.phar.tar Binary files differnew file mode 100644 index 0000000000..98495717ce --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller8.phar.tar diff --git a/ext/phar/tests/tar/files/frontcontroller9.phar.inc b/ext/phar/tests/tar/files/frontcontroller9.phar.inc new file mode 100644 index 0000000000..758ce4ff4e --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller9.phar.inc @@ -0,0 +1,14 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller9.phar.tar'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller9.phar.tar'); +$a['a.phps'] = 'hio1'; +$a['a.jpg'] = 'hio2'; +$a['a.php'] = '<?php function hio(){}'; +$a['fronk.gronk'] = 'hio3'; +$a->setStub('<?php +Phar::mungServer(array()); +Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/tar/files/frontcontroller9.phar.tar b/ext/phar/tests/tar/files/frontcontroller9.phar.tar Binary files differnew file mode 100644 index 0000000000..481864c1cf --- /dev/null +++ b/ext/phar/tests/tar/files/frontcontroller9.phar.tar diff --git a/ext/phar/tests/tar/files/links.tar b/ext/phar/tests/tar/files/links.tar Binary files differnew file mode 100644 index 0000000000..6cd22df2bc --- /dev/null +++ b/ext/phar/tests/tar/files/links.tar diff --git a/ext/phar/tests/tar/files/make_invalid_tar.php.inc b/ext/phar/tests/tar/files/make_invalid_tar.php.inc new file mode 100644 index 0000000000..c18bd199b3 --- /dev/null +++ b/ext/phar/tests/tar/files/make_invalid_tar.php.inc @@ -0,0 +1,9 @@ +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +class corrupter extends tarmaker { +function close() +{ + fwrite($this->tmp, 'oopsie'); + fclose($this->tmp); +} +}
\ No newline at end of file diff --git a/ext/phar/tests/tar/files/subdirlink.tar b/ext/phar/tests/tar/files/subdirlink.tar Binary files differnew file mode 100644 index 0000000000..5463a4942d --- /dev/null +++ b/ext/phar/tests/tar/files/subdirlink.tar diff --git a/ext/phar/tests/tar/files/tarmaker.php.inc b/ext/phar/tests/tar/files/tarmaker.php.inc new file mode 100644 index 0000000000..902507881a --- /dev/null +++ b/ext/phar/tests/tar/files/tarmaker.php.inc @@ -0,0 +1,169 @@ +<?php +// stolen from PEAR2_Pyrus_Developer_Creator_Tar by Greg Beaver, the original author, for use in unit tests +class tarmaker +{ + /** + * Path to archive file + * + * @var string + */ + protected $archive; + /** + * Temporary stream used for creating the archive + * + * @var stream + */ + protected $tmp; + protected $path; + protected $compress; + function __construct($path, $compress = 'zlib') + { + $this->compress = $compress; + if ($compress === 'bz2' && !function_exists('bzopen')) { + throw new PEAR2_Pyrus_Developer_Creator_Exception( + 'bzip2 extension not available'); + } + if ($compress === 'zlib' && !function_exists('gzopen')) { + throw new PEAR2_Pyrus_Developer_Creator_Exception( + 'zlib extension not available'); + } + $this->path = $path; + } + + /** + * save a file inside this package + * + * This code is modified from Vincent Lascaux's File_Archive + * package, which is licensed under the LGPL license. + * @param string relative path within the package + * @param string|resource file contents or open file handle + */ + function addFile($path, $fileOrStream, $stat = null) + { + clearstatcache(); + if ($stat === null) { + if (is_resource($fileOrStream)) { + $stat = fstat($fileOrStream); + } else { + $stat = array( + 'mode' => 0x8000 + 0644, + 'uid' => 0, + 'gid' => 0, + 'size' => strlen($fileOrStream), + 'mtime' => time(), + ); + } + } + + $link = null; + if ($stat['mode'] & 0x4000) { + $type = 5; // Directory + } else if ($stat['mode'] & 0x8000) { + $type = 0; // Regular + } else if ($stat['mode'] & 0xA000) { + $type = 1; // Link + $link = @readlink($current); + } else { + $type = 9; // Unknown + } + + $filePrefix = ''; + if (strlen($path) > 255) { + throw new Exception( + "$path is too long, must be 255 characters or less" + ); + } else if (strlen($path) > 100) { + $filePrefix = substr($path, 0, strlen($path)-100); + $path = substr($path, -100); + } + + $block = pack('a100a8a8a8a12A12', + $path, + decoct($stat['mode']), + sprintf('%6s ',decoct($stat['uid'])), + sprintf('%6s ',decoct($stat['gid'])), + sprintf('%11s ',decoct($stat['size'])), + sprintf('%11s ',decoct($stat['mtime'])) + ); + + $blockend = pack('a1a100a6a2a32a32a8a8a155a12', + $type, + $link, + 'ustar', + '00', + 'Pyrus', + 'Pyrus', + '', + '', + $filePrefix, + ''); + + $checkheader = array_merge(str_split($block), str_split($blockend)); + if (!function_exists('_pear2tarchecksum')) { + function _pear2tarchecksum($a, $b) {return $a + ord($b);} + } + $checksum = 256; // 8 * ord(' '); + $checksum += array_reduce($checkheader, '_pear2tarchecksum'); + + $checksum = pack('a8', sprintf('%6s ', decoct($checksum))); + + fwrite($this->tmp, $block . $checksum . $blockend, 512); + if (is_resource($fileOrStream)) { + stream_copy_to_stream($fileOrStream, $this->tmp); + if ($stat['size'] % 512) { + fwrite($this->tmp, str_repeat("\0", 512 - $stat['size'] % 512)); + } + } else { + fwrite($this->tmp, $fileOrStream); + if (strlen($fileOrStream) % 512) { + fwrite($this->tmp, str_repeat("\0", 512 - strlen($fileOrStream) % 512)); + } + } + } + + /** + * Initialize the package creator + */ + function init() + { + switch ($this->compress) { + case 'zlib' : + $this->tmp = gzopen($this->path, 'wb'); + break; + case 'bz2' : + $this->tmp = bzopen($this->path, 'w'); + break; + case 'none' : + $this->tmp = fopen($this->path, 'wb'); + break; + default : + throw new Exception( + 'unknown compression type ' . $this->compress); + } + } + + /** + * Create an internal directory, creating parent directories as needed + * + * @param string $dir + */ + function mkdir($dir) + { + $this->addFile($dir, "", array( + 'mode' => 0x4000 + 0644, + 'uid' => 0, + 'gid' => 0, + 'size' => 0, + 'mtime' => time(), + )); + } + + /** + * Finish saving the package + */ + function close() + { + fwrite($this->tmp, pack('a1024', '')); + fclose($this->tmp); + } +}
\ No newline at end of file diff --git a/ext/phar/tests/tar/files/tinylink.tar b/ext/phar/tests/tar/files/tinylink.tar Binary files differnew file mode 100644 index 0000000000..741b56c2f5 --- /dev/null +++ b/ext/phar/tests/tar/files/tinylink.tar diff --git a/ext/phar/tests/tar/files/trunc.tar b/ext/phar/tests/tar/files/trunc.tar Binary files differnew file mode 100644 index 0000000000..2156b5c623 --- /dev/null +++ b/ext/phar/tests/tar/files/trunc.tar diff --git a/ext/phar/tests/tar/frontcontroller1.phar.phpt b/ext/phar/tests/tar/frontcontroller1.phar.phpt new file mode 100644 index 0000000000..77158169bb --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller1.phar.phpt @@ -0,0 +1,15 @@ +--TEST-- +Phar front controller other tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller1.phar.php +REQUEST_URI=/frontcontroller1.phar.php/a.jpg +PATH_INFO=/a.jpg +--FILE_EXTERNAL-- +files/frontcontroller.phar.tar +--EXPECTHEADERS-- +Content-type: image/jpeg +Content-length: 3 +--EXPECT-- +hio diff --git a/ext/phar/tests/tar/frontcontroller10.phar.phpt b/ext/phar/tests/tar/frontcontroller10.phar.phpt new file mode 100644 index 0000000000..0ca67b3d3e --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller10.phar.phpt @@ -0,0 +1,22 @@ +--TEST-- +Phar front controller rewrite array invalid tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller10.phar.php +REQUEST_URI=/frontcontroller10.phar.php/hi +PATH_INFO=/hi +--FILE_EXTERNAL-- +files/frontcontroller4.phar.tar +--EXPECTHEADERS-- +Content-type: text/html +Status: 403 Access Denied +--EXPECT-- +<html> + <head> + <title>Access Denied</title> + </head> + <body> + <h1>403 - File /hi Access Denied</h1> + </body> +</html>
\ No newline at end of file diff --git a/ext/phar/tests/tar/frontcontroller11.phar.phpt b/ext/phar/tests/tar/frontcontroller11.phar.phpt new file mode 100644 index 0000000000..3a420f6c85 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller11.phar.phpt @@ -0,0 +1,18 @@ +--TEST-- +Phar front controller mime type extension is not a string tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller11.phar.php +REQUEST_URI=/frontcontroller11.phar.php/a.php +PATH_INFO=/a.php +--FILE_EXTERNAL-- +files/frontcontroller5.phar.tar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECTF-- +Fatal error: Uncaught exception 'PharException' with message 'Key of MIME type overrides array must be a file extension, was "0"' in %sfrontcontroller11.phar.php:2 +Stack trace: +#0 %sfrontcontroller11.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#1 {main} + thrown in %sfrontcontroller11.phar.php on line 2
\ No newline at end of file diff --git a/ext/phar/tests/tar/frontcontroller12.phar.phpt b/ext/phar/tests/tar/frontcontroller12.phar.phpt new file mode 100644 index 0000000000..e659434e07 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller12.phar.phpt @@ -0,0 +1,18 @@ +--TEST-- +Phar front controller mime type unknown int tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller12.phar.php +REQUEST_URI=/frontcontroller12.phar.php/a.php +PATH_INFO=/a.php +--FILE_EXTERNAL-- +files/frontcontroller6.phar.tar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECTF-- +Fatal error: Uncaught exception 'PharException' with message 'Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed' in %sfrontcontroller12.phar.php:2 +Stack trace: +#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#1 {main} + thrown in %sfrontcontroller12.phar.php on line 2
\ No newline at end of file diff --git a/ext/phar/tests/tar/frontcontroller13.phar.phpt b/ext/phar/tests/tar/frontcontroller13.phar.phpt new file mode 100644 index 0000000000..0b9d3e3895 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller13.phar.phpt @@ -0,0 +1,18 @@ +--TEST-- +Phar front controller mime type not string/int tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller13.phar.php +REQUEST_URI=/frontcontroller13.phar.php/a.php +PATH_INFO=/a.php +--FILE_EXTERNAL-- +files/frontcontroller7.phar.tar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECTF-- +Fatal error: Uncaught exception 'PharException' with message 'Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed' in %sfrontcontroller13.phar.php:2 +Stack trace: +#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#1 {main} + thrown in %sfrontcontroller13.phar.php on line 2
\ No newline at end of file diff --git a/ext/phar/tests/tar/frontcontroller14.phar.phpt b/ext/phar/tests/tar/frontcontroller14.phar.phpt new file mode 100644 index 0000000000..c40f9b6c34 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller14.phar.phpt @@ -0,0 +1,15 @@ +--TEST-- +Phar front controller mime type override, other tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller14.phar.php +REQUEST_URI=/frontcontroller14.phar.php/a.jpg +PATH_INFO=/a.jpg +--FILE_EXTERNAL-- +files/frontcontroller8.phar.tar +--EXPECTHEADERS-- +Content-type: foo/bar +Content-length: 4 +--EXPECT-- +hio2 diff --git a/ext/phar/tests/tar/frontcontroller15.phar.phpt b/ext/phar/tests/tar/frontcontroller15.phar.phpt new file mode 100644 index 0000000000..154117fda4 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller15.phar.phpt @@ -0,0 +1,18 @@ +--TEST-- +Phar front controller mime type override, Phar::PHPS tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller15.phar.php +REQUEST_URI=/frontcontroller15.phar.php/a.php +PATH_INFO=/a.php +--FILE_EXTERNAL-- +files/frontcontroller8.phar.tar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- +<code><span style="color: #000000"> +<span style="color: #0000BB"><?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span> +</span> +</code> + diff --git a/ext/phar/tests/tar/frontcontroller16.phar.phpt b/ext/phar/tests/tar/frontcontroller16.phar.phpt new file mode 100644 index 0000000000..042a695eb3 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller16.phar.phpt @@ -0,0 +1,15 @@ +--TEST-- +Phar front controller mime type override, Phar::PHP tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller16.phar.php +REQUEST_URI=/frontcontroller16.phar.php/a.phps +PATH_INFO=/a.phps +--FILE_EXTERNAL-- +files/frontcontroller8.phar.tar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- +hio1 + diff --git a/ext/phar/tests/tar/frontcontroller17.phar.phpt b/ext/phar/tests/tar/frontcontroller17.phar.phpt new file mode 100644 index 0000000000..17d04baf30 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller17.phar.phpt @@ -0,0 +1,16 @@ +--TEST-- +Phar front controller mime type unknown tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller17.phar.php +REQUEST_URI=/frontcontroller17.phar.php/fronk.gronk +PATH_INFO=/fronk.gronk +--FILE_EXTERNAL-- +files/frontcontroller8.phar.tar +--EXPECTHEADERS-- +Content-type: application/octet-stream +Content-length: 4 +--EXPECT-- +hio3 + diff --git a/ext/phar/tests/tar/frontcontroller18.phar.phpt b/ext/phar/tests/tar/frontcontroller18.phar.phpt new file mode 100644 index 0000000000..c52ce291c7 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller18.phar.phpt @@ -0,0 +1,16 @@ +--TEST-- +Phar front controller $_SERVER munging failure tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller18.phar.php +REQUEST_URI=/frontcontroller18.phar.php/fronk.gronk +PATH_INFO=/fronk.gronk +--FILE_EXTERNAL-- +files/frontcontroller9.phar.tar +--EXPECTF-- +Fatal error: Uncaught exception 'PharException' with message 'No values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller18.phar.php:2 +Stack trace: +#0 %sfrontcontroller18.phar.php(2): Phar::mungServer(Array) +#1 {main} + thrown in %sfrontcontroller18.phar.php on line 2 diff --git a/ext/phar/tests/tar/frontcontroller19.phar.phpt b/ext/phar/tests/tar/frontcontroller19.phar.phpt new file mode 100644 index 0000000000..6b07438787 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller19.phar.phpt @@ -0,0 +1,16 @@ +--TEST-- +Phar front controller $_SERVER munging failure 2 tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller19.phar.php +REQUEST_URI=/frontcontroller19.phar.php/ +PATH_INFO=/ +--FILE_EXTERNAL-- +files/frontcontroller10.phar.tar +--EXPECTF-- +Fatal error: Uncaught exception 'PharException' with message 'Too many values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller19.phar.php:2 +Stack trace: +#0 %sfrontcontroller19.phar.php(2): Phar::mungServer(Array) +#1 {main} + thrown in %sfrontcontroller19.phar.php on line 2 diff --git a/ext/phar/tests/tar/frontcontroller2.phar.phpt b/ext/phar/tests/tar/frontcontroller2.phar.phpt new file mode 100644 index 0000000000..a6b1c780fd --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller2.phar.phpt @@ -0,0 +1,14 @@ +--TEST-- +Phar front controller PHP test tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller2.phar.php +REQUEST_URI=/frontcontroller2.phar.php/a.php +PATH_INFO=/a.php +--FILE_EXTERNAL-- +files/frontcontroller.phar.tar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- +hio diff --git a/ext/phar/tests/tar/frontcontroller20.phar.phpt b/ext/phar/tests/tar/frontcontroller20.phar.phpt new file mode 100644 index 0000000000..3cc470d41b --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller20.phar.phpt @@ -0,0 +1,16 @@ +--TEST-- +Phar front controller $_SERVER munging failure 3 tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller20.phar.php +REQUEST_URI=/frontcontroller20.phar.php/ +PATH_INFO=/ +--FILE_EXTERNAL-- +files/frontcontroller11.phar.tar +--EXPECTF-- +Fatal error: Uncaught exception 'PharException' with message 'Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller20.phar.php:2 +Stack trace: +#0 %sfrontcontroller20.phar.php(2): Phar::mungServer(Array) +#1 {main} + thrown in %sfrontcontroller20.phar.php on line 2 diff --git a/ext/phar/tests/tar/frontcontroller21.phar.phpt b/ext/phar/tests/tar/frontcontroller21.phar.phpt new file mode 100644 index 0000000000..eb21897226 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller21.phar.phpt @@ -0,0 +1,22 @@ +--TEST-- +Phar front controller $_SERVER munging success tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller21.phar.php +REQUEST_URI=/frontcontroller21.phar.php/index.php?test=hi +PATH_INFO=/index.php +QUERY_STRING=test=hi +--FILE_EXTERNAL-- +files/frontcontroller12.phar.tar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECTF-- +string(10) "/index.php" +string(10) "/index.php" +string(%d) "phar://%sfrontcontroller21.phar.php/index.php" +string(18) "/index.php?test=hi" +string(37) "/frontcontroller21.phar.php/index.php" +string(27) "/frontcontroller21.phar.php" +string(%d) "%sfrontcontroller21.phar.php" +string(45) "/frontcontroller21.phar.php/index.php?test=hi"
\ No newline at end of file diff --git a/ext/phar/tests/tar/frontcontroller3.phar.phpt b/ext/phar/tests/tar/frontcontroller3.phar.phpt new file mode 100644 index 0000000000..dee16ee2b2 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller3.phar.phpt @@ -0,0 +1,17 @@ +--TEST-- +Phar front controller phps tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller3.phar.php +REQUEST_URI=/frontcontroller3.phar.php/a.phps +PATH_INFO=/a.phps +--FILE_EXTERNAL-- +files/frontcontroller.phar.tar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- +<code><span style="color: #000000"> +<span style="color: #0000BB"><?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span> +</span> +</code> diff --git a/ext/phar/tests/tar/frontcontroller4.phar.phpt b/ext/phar/tests/tar/frontcontroller4.phar.phpt new file mode 100644 index 0000000000..db4846c69b --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller4.phar.phpt @@ -0,0 +1,13 @@ +--TEST-- +Phar front controller index.php relocate (no /) tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller4.phar.php +REQUEST_URI=/frontcontroller4.phar.php +--FILE_EXTERNAL-- +files/frontcontroller.phar.tar +--EXPECTHEADERS-- +Status: 301 Moved Permanently +Location: /frontcontroller4.phar.php/index.php +--EXPECT-- diff --git a/ext/phar/tests/tar/frontcontroller5.phar.phpt b/ext/phar/tests/tar/frontcontroller5.phar.phpt new file mode 100644 index 0000000000..534e66a1e3 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller5.phar.phpt @@ -0,0 +1,14 @@ +--TEST-- +Phar front controller index.php relocate tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller5.phar.php +REQUEST_URI=/frontcontroller5.phar.php/ +PATH_INFO=/ +--FILE_EXTERNAL-- +files/frontcontroller.phar.tar +--EXPECTHEADERS-- +Status: 301 Moved Permanently +Location: /frontcontroller5.phar.php/index.php +--EXPECT-- diff --git a/ext/phar/tests/tar/frontcontroller6.phar.phpt b/ext/phar/tests/tar/frontcontroller6.phar.phpt new file mode 100644 index 0000000000..5375beef8c --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller6.phar.phpt @@ -0,0 +1,21 @@ +--TEST-- +Phar front controller 404 tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller6.phar.php +REQUEST_URI=/frontcontroller6.phar.php/notfound.php +PATH_INFO=/notfound.php +--FILE_EXTERNAL-- +files/frontcontroller.phar.tar +--EXPECTHEADERS-- +Status: 404 Not Found +--EXPECT-- +<html> + <head> + <title>File Not Found</title> + </head> + <body> + <h1>404 - File /notfound.php Not Found</h1> + </body> +</html>
\ No newline at end of file diff --git a/ext/phar/tests/tar/frontcontroller7.phar.phpt b/ext/phar/tests/tar/frontcontroller7.phar.phpt new file mode 100644 index 0000000000..3b73f2075c --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller7.phar.phpt @@ -0,0 +1,14 @@ +--TEST-- +Phar front controller alternate index file tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller7.phar.php +REQUEST_URI=/frontcontroller7.phar.php/ +PATH_INFO=/ +--FILE_EXTERNAL-- +files/frontcontroller2.phar.tar +--EXPECTHEADERS-- +Status: 301 Moved Permanently +Location: /frontcontroller7.phar.php/a.php +--EXPECT-- diff --git a/ext/phar/tests/tar/frontcontroller8.phar.phpt b/ext/phar/tests/tar/frontcontroller8.phar.phpt new file mode 100644 index 0000000000..19844cb199 --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller8.phar.phpt @@ -0,0 +1,21 @@ +--TEST-- +Phar front controller no index file 404 tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller8.phar.php +REQUEST_URI=/frontcontroller8.phar.php/ +PATH_INFO=/ +--FILE_EXTERNAL-- +files/frontcontroller3.phar.tar +--EXPECTHEADERS-- +Status: 404 Not Found +--EXPECT-- +<html> + <head> + <title>File Not Found</title> + </head> + <body> + <h1>404 - File /index.php Not Found</h1> + </body> +</html>
\ No newline at end of file diff --git a/ext/phar/tests/tar/frontcontroller9.phar.phpt b/ext/phar/tests/tar/frontcontroller9.phar.phpt new file mode 100644 index 0000000000..080db58f8f --- /dev/null +++ b/ext/phar/tests/tar/frontcontroller9.phar.phpt @@ -0,0 +1,17 @@ +--TEST-- +Phar front controller rewrite array tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller9.phar.php +REQUEST_URI=/frontcontroller9.phar.php/hi +PATH_INFO=/hi +--FILE_EXTERNAL-- +files/frontcontroller3.phar.tar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- +<code><span style="color: #000000"> +<span style="color: #0000BB"><?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span> +</span> +</code>
\ No newline at end of file diff --git a/ext/phar/tests/tar/links.phpt b/ext/phar/tests/tar/links.phpt new file mode 100644 index 0000000000..73e257b8be --- /dev/null +++ b/ext/phar/tests/tar/links.phpt @@ -0,0 +1,33 @@ +--TEST-- +Phar: tar with hard link and symbolic link +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--FILE-- +<?php +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar'; +copy(dirname(__FILE__) . '/files/links.tar', $fname); +try { + $p = new PharData($fname); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +var_dump($p['testit/link']->getContent()); +var_dump($p['testit/hard']->getContent()); +var_dump($p['testit/file']->getContent()); +$p['testit/link'] = 'overwriting'; +var_dump($p['testit/link']->getContent()); +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); +?> +--EXPECT-- +string(3) "hi +" +string(3) "hi +" +string(3) "hi +" +string(11) "overwriting" +===DONE=== diff --git a/ext/phar/tests/tar/links2.phpt b/ext/phar/tests/tar/links2.phpt new file mode 100644 index 0000000000..1939e002bd --- /dev/null +++ b/ext/phar/tests/tar/links2.phpt @@ -0,0 +1,35 @@ +--TEST-- +Phar: tar with hard link to nowhere +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--FILE-- +<?php +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar'; +$pname = 'phar://' . $fname; + +include dirname(__FILE__) . '/files/corrupt_tarmaker.php.inc'; +$a = new corrupt_tarmaker($fname, 'none'); +$a->init(); +$a->addFile('hardlink', 'internal/file.txt', array( + 'mode' => 0xA000 + 0644, + 'uid' => 0, + 'gid' => 0, + 'size' => 0, + 'mtime' => time(), + )); +$a->close(); + +try { + $p = new PharData($fname); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); +?> +--EXPECTF-- +phar error: "%slinks2.tar" is a corrupted tar file - hard link to non-existent file "internal/file.txt" +===DONE=== diff --git a/ext/phar/tests/tar/links3.phpt b/ext/phar/tests/tar/links3.phpt new file mode 100644 index 0000000000..2241081660 --- /dev/null +++ b/ext/phar/tests/tar/links3.phpt @@ -0,0 +1,19 @@ +--TEST-- +Phar: tar with link to absolute path +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--FILE-- +<?php +try { + $p = new PharData(dirname(__FILE__) . '/files/biglink.tar'); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +echo $p['file.txt']->getContent(); +echo $p['my/file']->getContent(); +?> +===DONE=== +--EXPECT-- +my file +my file +===DONE=== diff --git a/ext/phar/tests/tar/links4.phpt b/ext/phar/tests/tar/links4.phpt new file mode 100644 index 0000000000..d0783e84ac --- /dev/null +++ b/ext/phar/tests/tar/links4.phpt @@ -0,0 +1,19 @@ +--TEST-- +Phar: tar with link to root directory file from root directory file +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--FILE-- +<?php +try { + $p = new PharData(dirname(__FILE__) . '/files/tinylink.tar'); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +echo $p['file.txt']->getContent(); +echo $p['link.txt']->getContent(); +?> +===DONE=== +--EXPECT-- +hi +hi +===DONE=== diff --git a/ext/phar/tests/tar/links5.phpt b/ext/phar/tests/tar/links5.phpt new file mode 100644 index 0000000000..262d41d841 --- /dev/null +++ b/ext/phar/tests/tar/links5.phpt @@ -0,0 +1,19 @@ +--TEST-- +Phar: tar with relative link to subdirectory file from subdirectory file +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--FILE-- +<?php +try { + $p = new PharData(dirname(__FILE__) . '/files/subdirlink.tar'); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +echo $p['hi/test.txt']->getContent(); +echo $p['hi/link.txt']->getContent(); +?> +===DONE=== +--EXPECT-- +hi +hi +===DONE=== diff --git a/ext/phar/tests/tar/open_for_write_existing.phpt b/ext/phar/tests/tar/open_for_write_existing.phpt new file mode 100644 index 0000000000..641e5ce21d --- /dev/null +++ b/ext/phar/tests/tar/open_for_write_existing.phpt @@ -0,0 +1,42 @@ +--TEST-- +Phar: fopen a .phar for writing (existing file) tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$phar = new Phar($fname); +$phar->setStub("<?php __HALT_COMPILER(); ?>"); + +$files = array(); + +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; + +foreach ($files as $n => $file) { + $phar[$n] = $file; +} + +$phar->stopBuffering(); + +$fp = fopen($alias . '/b/c.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); + +include $alias . '/b/c.php'; + +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECT-- +extra +===DONE=== diff --git a/ext/phar/tests/tar/open_for_write_existing_b.phpt b/ext/phar/tests/tar/open_for_write_existing_b.phpt new file mode 100755 index 0000000000..54ec5855fb --- /dev/null +++ b/ext/phar/tests/tar/open_for_write_existing_b.phpt @@ -0,0 +1,56 @@ +--TEST-- +Phar: fopen a .phar for writing (existing file) tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$phar = new Phar($fname); +$phar->setStub("<?php __HALT_COMPILER(); ?>"); + +$files = array(); + +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; + +foreach ($files as $n => $file) { + $phar[$n] = $file; +} + +$phar->stopBuffering(); +ini_set('phar.readonly', 1); + +function err_handler($errno, $errstr, $errfile, $errline) { + echo "Catchable fatal error: $errstr in $errfile on line $errline\n"; +} + +set_error_handler("err_handler", E_RECOVERABLE_ERROR); + +$fp = fopen($alias . '/b/c.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); + +include $alias . '/b/c.php'; + +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- + +Warning: fopen(phar://%sopen_for_write_existing_b.phar.tar/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_b.php on line %d + +Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_b.php on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d +This is b/c + +===DONE=== diff --git a/ext/phar/tests/tar/open_for_write_existing_c.phpt b/ext/phar/tests/tar/open_for_write_existing_c.phpt new file mode 100755 index 0000000000..0e5a181e65 --- /dev/null +++ b/ext/phar/tests/tar/open_for_write_existing_c.phpt @@ -0,0 +1,50 @@ +--TEST-- +Phar: fopen a .phar for writing (existing file) tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$phar = new Phar($fname); +$phar->setStub("<?php __HALT_COMPILER(); ?>"); + +$files = array(); + +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; + +foreach ($files as $n => $file) { + $phar[$n] = $file; +} + +$phar->stopBuffering(); +ini_set('phar.readonly', 1); + +$fp = fopen($alias . '/b/c.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); + +include $alias . '/b/c.php'; + +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- + +Warning: fopen(phar://%sopen_for_write_existing_c.phar.tar/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_c.php on line %d + +Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d +This is b/c + +===DONE=== diff --git a/ext/phar/tests/tar/open_for_write_newfile.phpt b/ext/phar/tests/tar/open_for_write_newfile.phpt new file mode 100644 index 0000000000..31e9d4a7e9 --- /dev/null +++ b/ext/phar/tests/tar/open_for_write_newfile.phpt @@ -0,0 +1,44 @@ +--TEST-- +Phar: fopen a .phar for writing (new file) tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$phar = new Phar($fname); +$phar->setStub("<?php __HALT_COMPILER(); ?>"); + +$files = array(); + +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; + +foreach ($files as $n => $file) { + $phar[$n] = $file; +} + +$phar->stopBuffering(); + +$fp = fopen($alias . '/b/new.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); + +include $alias . '/b/c.php'; +include $alias . '/b/new.php'; + +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECT-- +This is b/c +extra +===DONE=== diff --git a/ext/phar/tests/tar/open_for_write_newfile_b.phpt b/ext/phar/tests/tar/open_for_write_newfile_b.phpt new file mode 100755 index 0000000000..d3a21b4caf --- /dev/null +++ b/ext/phar/tests/tar/open_for_write_newfile_b.phpt @@ -0,0 +1,61 @@ +--TEST-- +Phar: fopen a .phar for writing (new file) tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$phar = new Phar($fname); +$phar->setStub("<?php __HALT_COMPILER(); ?>"); + +$files = array(); + +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; + +foreach ($files as $n => $file) { + $phar[$n] = $file; +} + +$phar->stopBuffering(); +ini_set('phar.readonly', 1); + +function err_handler($errno, $errstr, $errfile, $errline) { + echo "Catchable fatal error: $errstr in $errfile on line $errline\n"; +} + +set_error_handler("err_handler", E_RECOVERABLE_ERROR); + +$fp = fopen($alias . '/b/new.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); + +include $alias . '/b/c.php'; +include $alias . '/b/new.php'; + +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- + +Warning: fopen(phar://%sopen_for_write_newfile_b.phar.tar/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_b.php on line %d + +Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d +This is b/c + +Warning: include(phar://%sopen_for_write_newfile_b.phar.tar/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_b.phar.tar" in %sopen_for_write_newfile_b.php on line %d + +Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_b.phar.tar/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_b.php on line %d + +===DONE=== diff --git a/ext/phar/tests/tar/open_for_write_newfile_c.phpt b/ext/phar/tests/tar/open_for_write_newfile_c.phpt new file mode 100755 index 0000000000..231241c8ad --- /dev/null +++ b/ext/phar/tests/tar/open_for_write_newfile_c.phpt @@ -0,0 +1,54 @@ +--TEST-- +Phar: fopen a .phar for writing (new file) tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$phar = new Phar($fname); +$phar->setStub("<?php __HALT_COMPILER(); ?>"); + +$files = array(); + +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; + +foreach ($files as $n => $file) { + $phar[$n] = $file; +} + +$phar->stopBuffering(); +ini_set('phar.readonly', 1); + +$fp = fopen($alias . '/b/new.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); +include $alias . '/b/c.php'; +include $alias . '/b/new.php'; + +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- + +Warning: fopen(phar://%sopen_for_write_newfile_c.phar.tar/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_c.php on line %d + +Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d +This is b/c + +Warning: include(phar://%sopen_for_write_newfile_c.phar.tar/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_c.phar.tar" in %sopen_for_write_newfile_c.php on line %d + +Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_c.phar.tar/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_c.php on line %d + +===DONE===
\ No newline at end of file diff --git a/ext/phar/tests/tar/phar_begin_setstub_commit.phpt b/ext/phar/tests/tar/phar_begin_setstub_commit.phpt new file mode 100755 index 0000000000..c990ff9b98 --- /dev/null +++ b/ext/phar/tests/tar/phar_begin_setstub_commit.phpt @@ -0,0 +1,51 @@ +--TEST-- +Phar::startBuffering()/setStub()/stopBuffering() tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php +$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.tar', 0, 'brandnewphar.phar'); +var_dump($p->isFileFormat(Phar::TAR)); +//var_dump($p->getStub()); +var_dump($p->isBuffering()); +$p->startBuffering(); +var_dump($p->isBuffering()); +$p['a.php'] = '<?php var_dump("Hello");'; +$p->setStub('<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>'); +include 'phar://brandnewphar.phar/a.php'; +var_dump($p->getStub()); +$p['b.php'] = '<?php var_dump("World");'; +$p->setStub('<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER();'); +include 'phar://brandnewphar.phar/b.php'; +var_dump($p->getStub()); +$p->stopBuffering(); +echo "===COMMIT===\n"; +var_dump($p->isBuffering()); +include 'phar://brandnewphar.phar/a.php'; +include 'phar://brandnewphar.phar/b.php'; +var_dump($p->getStub()); +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/brandnewphar.phar.tar'); +?> +--EXPECT-- +bool(true) +bool(true) +bool(false) +string(5) "Hello" +string(84) "<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?> +" +string(5) "World" +string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?> +" +===COMMIT=== +bool(true) +string(5) "Hello" +string(5) "World" +string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?> +" +===DONE=== diff --git a/ext/phar/tests/tar/phar_buildfromiterator4.phpt b/ext/phar/tests/tar/phar_buildfromiterator4.phpt new file mode 100644 index 0000000000..b7d6d56f64 --- /dev/null +++ b/ext/phar/tests/tar/phar_buildfromiterator4.phpt @@ -0,0 +1,66 @@ +--TEST-- +Phar::buildFromIterator() iterator, 1 file passed in tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +class myIterator implements Iterator +{ + var $a; + function __construct(array $a) + { + $this->a = $a; + } + function next() { + echo "next\n"; + return next($this->a); + } + function current() { + echo "current\n"; + return current($this->a); + } + function key() { + echo "key\n"; + return key($this->a); + } + function valid() { + echo "valid\n"; + return current($this->a); + } + function rewind() { + echo "rewind\n"; + return reset($this->a); + } +} +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar'); + var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . 'phpt')))); + var_dump($phar->isFileFormat(Phar::TAR)); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar'); +__HALT_COMPILER(); +?> +--EXPECTF-- +rewind +valid +current +key +next +valid +array(1) { + ["a"]=> + string(%d) "%sphar_buildfromiterator4.phpt" +} +bool(true) +===DONE=== diff --git a/ext/phar/tests/tar/phar_buildfromiterator5.phpt b/ext/phar/tests/tar/phar_buildfromiterator5.phpt new file mode 100644 index 0000000000..600bd2ee5c --- /dev/null +++ b/ext/phar/tests/tar/phar_buildfromiterator5.phpt @@ -0,0 +1,59 @@ +--TEST-- +Phar::buildFromIterator() iterator, iterator returns non-string tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +class myIterator implements Iterator +{ + var $a; + function __construct(array $a) + { + $this->a = $a; + } + function next() { + echo "next\n"; + return next($this->a); + } + function current() { + echo "current\n"; + return current($this->a); + } + function key() { + echo "key\n"; + return key($this->a); + } + function valid() { + echo "valid\n"; + return current($this->a); + } + function rewind() { + echo "rewind\n"; + return reset($this->a); + } +} +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar'); + var_dump($phar->buildFromIterator(new myIterator(array('a' => new stdClass)))); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar'); +__HALT_COMPILER(); +?> +--EXPECTF-- +rewind +valid +current +string(24) "UnexpectedValueException" +Iterator myIterator returned an invalid value (must return a string) +===DONE=== diff --git a/ext/phar/tests/tar/phar_buildfromiterator6.phpt b/ext/phar/tests/tar/phar_buildfromiterator6.phpt new file mode 100644 index 0000000000..e891a5d065 --- /dev/null +++ b/ext/phar/tests/tar/phar_buildfromiterator6.phpt @@ -0,0 +1,60 @@ +--TEST-- +Phar::buildFromIterator() iterator, key is int tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +class myIterator implements Iterator +{ + var $a; + function __construct(array $a) + { + $this->a = $a; + } + function next() { + echo "next\n"; + return next($this->a); + } + function current() { + echo "current\n"; + return current($this->a); + } + function key() { + echo "key\n"; + return key($this->a); + } + function valid() { + echo "valid\n"; + return current($this->a); + } + function rewind() { + echo "rewind\n"; + return reset($this->a); + } +} +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar'); + var_dump($phar->buildFromIterator(new myIterator(array(basename(__FILE__, 'php') . 'phpt')))); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar'); +__HALT_COMPILER(); +?> +--EXPECTF-- +rewind +valid +current +key +string(24) "UnexpectedValueException" +Iterator myIterator returned an invalid key (must return a string) +===DONE=== diff --git a/ext/phar/tests/tar/phar_buildfromiterator7.phpt b/ext/phar/tests/tar/phar_buildfromiterator7.phpt new file mode 100644 index 0000000000..d64c032d71 --- /dev/null +++ b/ext/phar/tests/tar/phar_buildfromiterator7.phpt @@ -0,0 +1,60 @@ +--TEST-- +Phar::buildFromIterator() iterator, file can't be opened tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +class myIterator implements Iterator +{ + var $a; + function __construct(array $a) + { + $this->a = $a; + } + function next() { + echo "next\n"; + return next($this->a); + } + function current() { + echo "current\n"; + return current($this->a); + } + function key() { + echo "key\n"; + return key($this->a); + } + function valid() { + echo "valid\n"; + return current($this->a); + } + function rewind() { + echo "rewind\n"; + return reset($this->a); + } +} +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar'); + var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . '/oopsie/there.phpt')))); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar'); +__HALT_COMPILER(); +?> +--EXPECT-- +rewind +valid +current +key +string(24) "UnexpectedValueException" +Iterator myIterator returned a file that could not be opened "phar_buildfromiterator7./oopsie/there.phpt" +===DONE=== diff --git a/ext/phar/tests/tar/phar_buildfromiterator8.phpt b/ext/phar/tests/tar/phar_buildfromiterator8.phpt new file mode 100644 index 0000000000..f42640f692 --- /dev/null +++ b/ext/phar/tests/tar/phar_buildfromiterator8.phpt @@ -0,0 +1,73 @@ +--TEST-- +Phar::buildFromIterator() iterator, SplFileInfo as current tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar'); + $a = $phar->buildFromIterator(new RegexIterator(new DirectoryIterator('.'), '/^frontcontroller\d{0,2}\.phar\.phpt\\z|^\.\\z|^\.\.\\z/'), dirname(__FILE__) . DIRECTORY_SEPARATOR); + asort($a); + var_dump($a); + var_dump($phar->isFileFormat(Phar::TAR)); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar'); +__HALT_COMPILER(); +?> +--EXPECTF-- +array(21) { + ["frontcontroller1.phar.phpt"]=> + string(%d) "%sfrontcontroller1.phar.phpt" + ["frontcontroller10.phar.phpt"]=> + string(%d) "%sfrontcontroller10.phar.phpt" + ["frontcontroller11.phar.phpt"]=> + string(%d) "%sfrontcontroller11.phar.phpt" + ["frontcontroller12.phar.phpt"]=> + string(%d) "%sfrontcontroller12.phar.phpt" + ["frontcontroller13.phar.phpt"]=> + string(%d) "%sfrontcontroller13.phar.phpt" + ["frontcontroller14.phar.phpt"]=> + string(%d) "%sfrontcontroller14.phar.phpt" + ["frontcontroller15.phar.phpt"]=> + string(%d) "%sfrontcontroller15.phar.phpt" + ["frontcontroller16.phar.phpt"]=> + string(%d) "%sfrontcontroller16.phar.phpt" + ["frontcontroller17.phar.phpt"]=> + string(%d) "%sfrontcontroller17.phar.phpt" + ["frontcontroller18.phar.phpt"]=> + string(%d) "%sfrontcontroller18.phar.phpt" + ["frontcontroller19.phar.phpt"]=> + string(%d) "%sfrontcontroller19.phar.phpt" + ["frontcontroller2.phar.phpt"]=> + string(%d) "%sfrontcontroller2.phar.phpt" + ["frontcontroller20.phar.phpt"]=> + string(%d) "%sfrontcontroller20.phar.phpt" + ["frontcontroller21.phar.phpt"]=> + string(%d) "%sfrontcontroller21.phar.phpt" + ["frontcontroller3.phar.phpt"]=> + string(%d) "%sfrontcontroller3.phar.phpt" + ["frontcontroller4.phar.phpt"]=> + string(%d) "%sfrontcontroller4.phar.phpt" + ["frontcontroller5.phar.phpt"]=> + string(%d) "%sfrontcontroller5.phar.phpt" + ["frontcontroller6.phar.phpt"]=> + string(%d) "%sfrontcontroller6.phar.phpt" + ["frontcontroller7.phar.phpt"]=> + string(%d) "%sfrontcontroller7.phar.phpt" + ["frontcontroller8.phar.phpt"]=> + string(%d) "%sfrontcontroller8.phar.phpt" + ["frontcontroller9.phar.phpt"]=> + string(%d) "%sfrontcontroller9.phar.phpt" +} +bool(true) +===DONE=== diff --git a/ext/phar/tests/tar/phar_buildfromiterator9.phpt b/ext/phar/tests/tar/phar_buildfromiterator9.phpt new file mode 100644 index 0000000000..f9deef4d9f --- /dev/null +++ b/ext/phar/tests/tar/phar_buildfromiterator9.phpt @@ -0,0 +1,65 @@ +--TEST-- +Phar::buildFromIterator() iterator, 1 file resource passed in tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +class myIterator implements Iterator +{ + var $a; + function __construct(array $a) + { + $this->a = $a; + } + function next() { + echo "next\n"; + return next($this->a); + } + function current() { + echo "current\n"; + return current($this->a); + } + function key() { + echo "key\n"; + return key($this->a); + } + function valid() { + echo "valid\n"; + return current($this->a); + } + function rewind() { + echo "rewind\n"; + return reset($this->a); + } +} +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar'); + var_dump($phar->buildFromIterator(new myIterator(array('a' => $a = fopen(basename(__FILE__, 'php') . 'phpt', 'r'))))); + fclose($a); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar.tar'); +__HALT_COMPILER(); +?> +--EXPECTF-- +rewind +valid +current +key +next +valid +array(1) { + ["a"]=> + string(%d) "[stream]" +} +===DONE=== diff --git a/ext/phar/tests/tar/phar_commitwrite.phpt b/ext/phar/tests/tar/phar_commitwrite.phpt new file mode 100644 index 0000000000..b926b9a081 --- /dev/null +++ b/ext/phar/tests/tar/phar_commitwrite.phpt @@ -0,0 +1,44 @@ +--TEST-- +Phar::setStub()/stopBuffering() tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.tar', 0, 'brandnewphar.phar'); +$p['file1.txt'] = 'hi'; +$p->stopBuffering(); +var_dump($p->getStub()); +$p->setStub("<?php +function __autoload(\$class) +{ + include 'phar://' . str_replace('_', '/', \$class); +} +Phar::mapPhar('brandnewphar.phar'); +include 'phar://brandnewphar.phar/startup.php'; +__HALT_COMPILER(); +?>"); +var_dump($p->getStub()); +var_dump($p->isFileFormat(Phar::TAR)); +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/brandnewphar.phar.tar'); +?> +--EXPECT-- +string(60) "<?php // tar-based phar archive stub file +__HALT_COMPILER();" +string(200) "<?php +function __autoload($class) +{ + include 'phar://' . str_replace('_', '/', $class); +} +Phar::mapPhar('brandnewphar.phar'); +include 'phar://brandnewphar.phar/startup.php'; +__HALT_COMPILER(); ?> +" +bool(true) +===DONE===
\ No newline at end of file diff --git a/ext/phar/tests/tar/phar_convert_phar.phpt b/ext/phar/tests/tar/phar_convert_phar.phpt new file mode 100644 index 0000000000..6a7d78ea8b --- /dev/null +++ b/ext/phar/tests/tar/phar_convert_phar.phpt @@ -0,0 +1,58 @@ +--TEST-- +Phar::convertToPhar() from tar +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar'; +$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar'; +$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.3.phar'; + +$phar = new Phar($fname); +$phar['a.txt'] = 'some text'; +$phar->stopBuffering(); +var_dump($phar->isFileFormat(Phar::TAR)); +var_dump(strlen($phar->getStub())); + +$phar = $phar->convertToExecutable(Phar::TAR); +var_dump($phar->isFileFormat(Phar::TAR)); +var_dump($phar->getStub()); + +$phar['a'] = 'hi there'; + +$phar = $phar->convertToExecutable(Phar::PHAR, Phar::NONE, '.3.phar'); +var_dump($phar->isFileFormat(Phar::PHAR)); +var_dump(strlen($phar->getStub())); + +copy($fname3, $fname2); + +$phar = new Phar($fname2); +var_dump($phar->isFileFormat(Phar::PHAR)); +var_dump(strlen($phar->getStub())); + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.3.phar'); +__HALT_COMPILER(); +?> +--EXPECT-- +bool(false) +int(6651) +bool(true) +string(60) "<?php // tar-based phar archive stub file +__HALT_COMPILER();" +bool(true) +int(6651) +bool(true) +int(6651) +===DONE=== diff --git a/ext/phar/tests/tar/phar_convert_phar2.phpt b/ext/phar/tests/tar/phar_convert_phar2.phpt new file mode 100644 index 0000000000..496948b14c --- /dev/null +++ b/ext/phar/tests/tar/phar_convert_phar2.phpt @@ -0,0 +1,62 @@ +--TEST-- +Phar::convertToPhar() gzipped +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("zlib")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar'; +$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar'; + +$phar = new Phar($fname); +$phar['a.txt'] = 'some text'; +$phar->stopBuffering(); +var_dump($phar->isFileFormat(Phar::TAR)); +var_dump(strlen($phar->getStub())); + +$phar = $phar->convertToExecutable(Phar::TAR); +var_dump($phar->isFileFormat(Phar::TAR)); +var_dump($phar->getStub()); + +$phar['a'] = 'hi there'; + +$phar = $phar->convertToExecutable(Phar::PHAR, Phar::GZ); +var_dump($phar->isFileFormat(Phar::PHAR)); +var_dump($phar->isCompressed()); +var_dump(strlen($phar->getStub())); + +copy($fname . '.gz', $fname2); + +$phar = new Phar($fname2); +var_dump($phar->isFileFormat(Phar::PHAR)); +var_dump($phar->isCompressed() == Phar::GZ); +var_dump(strlen($phar->getStub())); + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.gz'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.gz'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar'); +__HALT_COMPILER(); +?> +--EXPECT-- +bool(false) +int(6651) +bool(true) +string(60) "<?php // tar-based phar archive stub file +__HALT_COMPILER();" +bool(true) +int(4096) +int(6651) +bool(true) +bool(true) +int(6651) +===DONE=== diff --git a/ext/phar/tests/tar/phar_convert_phar3.phpt b/ext/phar/tests/tar/phar_convert_phar3.phpt new file mode 100644 index 0000000000..f4768194d1 --- /dev/null +++ b/ext/phar/tests/tar/phar_convert_phar3.phpt @@ -0,0 +1,62 @@ +--TEST-- +Phar::convertToPhar() bzipped +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("bz2")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar'; +$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar'; + +$phar = new Phar($fname); +$phar['a.txt'] = 'some text'; +$phar->stopBuffering(); +var_dump($phar->isFileFormat(Phar::TAR)); +var_dump(strlen($phar->getStub())); + +$phar = $phar->convertToExecutable(Phar::TAR); +var_dump($phar->isFileFormat(Phar::TAR)); +var_dump($phar->getStub()); + +$phar['a'] = 'hi there'; + +$phar = $phar->convertToExecutable(Phar::PHAR, Phar::BZ2); +var_dump($phar->isFileFormat(Phar::PHAR)); +var_dump($phar->isCompressed()); +var_dump(strlen($phar->getStub())); + +copy($fname . '.bz2', $fname2); + +$phar = new Phar($fname2); +var_dump($phar->isFileFormat(Phar::PHAR)); +var_dump($phar->isCompressed() == Phar::BZ2); +var_dump(strlen($phar->getStub())); + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.bz2'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.bz2'); +__HALT_COMPILER(); +?> +--EXPECT-- +bool(false) +int(6651) +bool(true) +string(60) "<?php // tar-based phar archive stub file +__HALT_COMPILER();" +bool(true) +int(8192) +int(6651) +bool(true) +bool(true) +int(6651) +===DONE=== diff --git a/ext/phar/tests/tar/phar_copy.phpt b/ext/phar/tests/tar/phar_copy.phpt new file mode 100644 index 0000000000..ed5cdac8bc --- /dev/null +++ b/ext/phar/tests/tar/phar_copy.phpt @@ -0,0 +1,56 @@ +--TEST-- +Phar: copy() tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=1 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.php'; +$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar.php'; + +$pname = 'phar://'.$fname; +$iname = '/file.txt'; +$ename = '/error/..'; + +$p = new Phar($fname); + +try +{ + $p['a'] = 'hi'; + $p->startBuffering(); + $p->copy('a', 'b'); + echo file_get_contents($p['b']->getPathName()); + $p->copy('b', 'c'); + $p->stopBuffering(); + echo file_get_contents($p['c']->getPathName()); + copy($fname, $fname2); + var_dump($p->isFileFormat(Phar::TAR)); + $p->copy('a', $ename); +} +catch(Exception $e) +{ + echo $e->getMessage() . "\n"; +} +ini_set('phar.readonly',1); +$p2 = new Phar($fname2); +var_dump($p2->isFileFormat(Phar::TAR)); +echo "\n"; +echo 'a: ' , file_get_contents($p2['a']->getPathName()); +echo 'b: ' ,file_get_contents($p2['b']->getPathName()); +echo 'c: ' ,file_get_contents($p2['c']->getPathName()); +?> +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.php'); ?> +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.php'); ?> +--EXPECTF-- +hihibool(true) +file "/error/.." contains invalid characters upper directory reference, cannot be copied from "a" in phar %s +bool(true) + +a: hib: hic: hi===DONE===
\ No newline at end of file diff --git a/ext/phar/tests/tar/phar_magic.phpt b/ext/phar/tests/tar/phar_magic.phpt new file mode 100644 index 0000000000..1bb336f96c --- /dev/null +++ b/ext/phar/tests/tar/phar_magic.phpt @@ -0,0 +1,33 @@ +--TEST-- +Phar: include/fopen magic tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.php'; +$p = new Phar($fname); +var_dump($p->isFileFormat(Phar::TAR)); +$p['a'] = '<?php include "b/c.php";' . "\n"; +$p['b/c.php'] = '<?php echo "in b\n";$a = fopen("a", "r", true);echo stream_get_contents($a);fclose($a);include dirname(__FILE__) . "/../d";'; +$p['d'] = "in d\n"; +$p->setStub('<?php +set_include_path("phar://" . __FILE__); +include "phar://" . __FILE__ . "/a"; +__HALT_COMPILER();'); +include $fname; +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.php'); +__HALT_COMPILER(); +?> +--EXPECTF-- +bool(true) +in b +<?php include "b/c.php"; +in d +===DONE=== diff --git a/ext/phar/tests/tar/phar_setalias.phpt b/ext/phar/tests/tar/phar_setalias.phpt new file mode 100644 index 0000000000..a1bc51154c --- /dev/null +++ b/ext/phar/tests/tar/phar_setalias.phpt @@ -0,0 +1,51 @@ +--TEST-- +Phar::setAlias() tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar.tar'; + +$phar = new Phar($fname); +$phar->setStub('<?php echo "first stub\n"; __HALT_COMPILER(); ?>'); +$phar->setAlias('hio'); + +$files = array(); + +$files['a'] = 'a'; +$files['b'] = 'b'; +$files['c'] = 'c'; + +foreach ($files as $n => $file) { + $phar[$n] = $file; +} + +$phar->stopBuffering(); + +echo $phar->getAlias() . "\n"; +$phar->setAlias('test'); +echo $phar->getAlias() . "\n"; + +copy($fname, $fname2); +$phar->setAlias('unused'); +$a = new Phar($fname2); +echo $a->getAlias() . "\n"; + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.tar'); +__HALT_COMPILER(); +?> +--EXPECT-- +hio +test +test +===DONE=== diff --git a/ext/phar/tests/tar/phar_setalias2.phpt b/ext/phar/tests/tar/phar_setalias2.phpt new file mode 100644 index 0000000000..a44cc397c2 --- /dev/null +++ b/ext/phar/tests/tar/phar_setalias2.phpt @@ -0,0 +1,53 @@ +--TEST-- +Phar::setAlias() error tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; + +$phar = new Phar($fname); +$phar->setStub('<?php echo "first stub\n"; __HALT_COMPILER(); ?>'); +$phar->setAlias('hio'); + +$files = array(); + +$files['a'] = 'a'; +$files['b'] = 'b'; +$files['c'] = 'c'; + +foreach ($files as $n => $file) { + $phar[$n] = $file; +} + +$phar->stopBuffering(); + +echo $phar->getAlias() . "\n"; +$phar->setAlias('test'); +echo $phar->getAlias() . "\n"; +$b = $phar; +$phar = new Phar(dirname(__FILE__) . '/notphar.phar'); + +try { + $phar->setAlias('test'); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.tar'); +__HALT_COMPILER(); +?> +--EXPECTF-- +hio +test +alias "test" is already used for archive "%sphar_setalias2.phar.tar" and cannot be used for other archives +===DONE=== diff --git a/ext/phar/tests/tar/phar_setdefaultstub.phpt b/ext/phar/tests/tar/phar_setdefaultstub.phpt new file mode 100644 index 0000000000..c1e6642a17 --- /dev/null +++ b/ext/phar/tests/tar/phar_setdefaultstub.phpt @@ -0,0 +1,80 @@ +--TEST-- +Phar: Phar::setDefaultStub() with and without arg, tar-based phar +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; + +$phar = new Phar($fname); +$phar['a.php'] = '<php echo "this is a\n"; ?>'; +$phar['b.php'] = '<php echo "this is b\n"; ?>'; +$phar->setStub('<?php echo "Hello World\n"; __HALT_COMPILER(); ?>'); + +var_dump($phar->getStub()); + +echo "============================================================================\n"; +echo "============================================================================\n"; + +try { + $phar->setDefaultStub(); + $phar->stopBuffering(); +} catch(Exception $e) { + echo $e->getMessage(). "\n"; +} + +var_dump($phar->getStub()); + +echo "============================================================================\n"; +echo "============================================================================\n"; + +try { + $phar->setDefaultStub('my/custom/thingy.php'); + $phar->stopBuffering(); +} catch(Exception $e) { + echo $e->getMessage(). "\n"; +} + +var_dump($phar->getStub()); + +echo "============================================================================\n"; +echo "============================================================================\n"; + +try { + $phar->setDefaultStub('my/custom/thingy.php', 'the/web.php'); + $phar->stopBuffering(); +} catch(Exception $e) { + echo $e->getMessage(). "\n"; +} + +var_dump($phar->getStub()); + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +?> +--EXPECTF-- +string(51) "<?php echo "Hello World\n"; __HALT_COMPILER(); ?> +" +============================================================================ +============================================================================ +string(60) "<?php // tar-based phar archive stub file +__HALT_COMPILER();" +============================================================================ +============================================================================ + +Warning: Phar::setDefaultStub(): method accepts no arguments for a tar- or zip-based phar stub, 1 given in %sphar_setdefaultstub.php on line %d +string(60) "<?php // tar-based phar archive stub file +__HALT_COMPILER();" +============================================================================ +============================================================================ + +Warning: Phar::setDefaultStub(): method accepts no arguments for a tar- or zip-based phar stub, 2 given in %sphar_setdefaultstub.php on line %d +string(60) "<?php // tar-based phar archive stub file +__HALT_COMPILER();" +===DONE=== diff --git a/ext/phar/tests/tar/phar_stub.phpt b/ext/phar/tests/tar/phar_stub.phpt new file mode 100644 index 0000000000..e0d728f6f8 --- /dev/null +++ b/ext/phar/tests/tar/phar_stub.phpt @@ -0,0 +1,75 @@ +--TEST-- +Phar::setStub() (tar-based) +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.tar.php'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar.php'; +$pname = 'phar://' . $fname; +$pname2 = 'phar://' . $fname2; + +$p = new Phar($pname2); +$p->setStub('<?php echo "first stub\n"; __HALT_COMPILER(); ?>'); +$p['a'] = 'a'; +$p['b'] = 'b'; +$p['c'] = 'c'; +copy($fname2, $fname); + +$phar = new Phar($fname); +echo $phar->getStub(); + +$file = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>'; + +//// 2 +$phar->setStub($file); +echo $phar->getStub(); + +$fname3 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phartmp.php'; +$file = '<?php echo "third stub\n"; __HALT_COMPILER(); ?>'; +$fp = fopen($fname3, 'wb'); +fwrite($fp, $file); +fclose($fp); +$fp = fopen($fname3, 'rb'); + +//// 3 +$phar->setStub($fp); +fclose($fp); + +echo $phar->getStub(); + +$fp = fopen($fname3, 'ab'); +fwrite($fp, 'booya'); +fclose($fp); +echo file_get_contents($fname3) . "\n"; + +$fp = fopen($fname3, 'rb'); + +//// 4 +$phar->setStub($fp, strlen($file)); +fclose($fp); +echo $phar->getStub(); + +$phar['testing'] = 'hi'; + +echo $phar->getStub(); +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar.php'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.tar.php'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php'); +__HALT_COMPILER(); +?> +--EXPECT-- +<?php echo "first stub\n"; __HALT_COMPILER(); ?> +<?php echo "second stub\n"; __HALT_COMPILER(); ?> +<?php echo "third stub\n"; __HALT_COMPILER(); ?> +<?php echo "third stub\n"; __HALT_COMPILER(); ?>booya +<?php echo "third stub\n"; __HALT_COMPILER(); ?> +<?php echo "third stub\n"; __HALT_COMPILER(); ?> +===DONE=== diff --git a/ext/phar/tests/tar/phar_stub_error.phpt b/ext/phar/tests/tar/phar_stub_error.phpt new file mode 100755 index 0000000000..5d35b932fe --- /dev/null +++ b/ext/phar/tests/tar/phar_stub_error.phpt @@ -0,0 +1,57 @@ +--TEST-- +Phar::setStub()/getStub() tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; + +$phar = new Phar($fname); +$phar->setStub($stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>' ."\r\n"); +$phar->setAlias('hio'); +$phar['a'] = 'a'; +$phar->stopBuffering(); + +var_dump($stub); +var_dump($phar->getStub()); +var_dump($phar->getStub() == $stub); + +$newstub = '<?php echo "second stub\n"; _x_HALT_COMPILER(); ?>'; + +try { + $phar->setStub($newstub); +} catch(exception $e) { + echo 'Exception: ' . $e->getMessage() . "\n"; +} + +var_dump($phar->getStub()); +var_dump($phar->getStub() == $stub); +$phar->stopBuffering(); +var_dump($phar->getStub()); +var_dump($phar->getStub() == $stub); + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +__HALT_COMPILER(); +?> +--EXPECTF-- +string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?> +" +string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?> +" +bool(true) +Exception: illegal stub for tar-based phar "%sphar_stub_error.phar.tar" +string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?> +" +bool(true) +string(50) "<?php echo "first stub\n"; __HALT_COMPILER(); ?> +" +bool(true) +===DONE=== diff --git a/ext/phar/tests/tar/refcount1.phpt b/ext/phar/tests/tar/refcount1.phpt new file mode 100644 index 0000000000..c6808afb63 --- /dev/null +++ b/ext/phar/tests/tar/refcount1.phpt @@ -0,0 +1,74 @@ +--TEST-- +Phar: test that refcounting avoids problems with deleting a file tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +<?php if (version_compare(PHP_VERSION, "5.3", "<")) die("skip requires 5.3 or later"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php +include dirname(__FILE__) . '/files/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$tar = new tarmaker($fname, 'none'); +$tar->init(); +$tar->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>"); + +$files = array(); + +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +$files['.phar/alias.txt'] = 'hio'; + +foreach ($files as $n => $file) { + $tar->addFile($n, $file); +} + +$tar->close(); + +$fp = fopen($alias . '/b/c.php', 'wb'); +fwrite($fp, "extra"); +fclose($fp); +echo "===CLOSE===\n"; +$phar = new Phar($fname); +$b = fopen($alias . '/b/c.php', 'rb'); +$a = $phar['b/c.php']; +var_dump($a); +var_dump(fread($b, 20)); +rewind($b); +echo "===UNLINK===\n"; +unlink($alias . '/b/c.php'); +var_dump($a); +var_dump(fread($b, 20)); +include $alias . '/b/c.php'; + +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- +===CLOSE=== +object(PharFileInfo)#%d (2) { + ["pathName":"SplFileInfo":private]=> + string(%d) "phar://%srefcount1.phar.tar/b" + ["fileName":"SplFileInfo":private]=> + string(%d) "phar://%srefcount1.phar.tar/b/c.php" +} +string(5) "extra" +===UNLINK=== + +Warning: unlink(): phar error: "b/c.php" in phar "%srefcount1.phar.tar", has open file pointers, cannot unlink in %srefcount1.php on line %d +object(PharFileInfo)#%d (2) { + ["pathName":"SplFileInfo":private]=> + string(%d) "phar://%srefcount1.phar.tar/b" + ["fileName":"SplFileInfo":private]=> + string(%s) "phar://%srefcount1.phar.tar/b/c.php" +} +string(5) "extra" +extra +===DONE=== diff --git a/ext/phar/tests/tar/refcount1_5_2.phpt b/ext/phar/tests/tar/refcount1_5_2.phpt new file mode 100755 index 0000000000..18587d91ad --- /dev/null +++ b/ext/phar/tests/tar/refcount1_5_2.phpt @@ -0,0 +1,64 @@ +--TEST-- +Phar: test that refcounting avoids problems with deleting a file tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +<?php if (version_compare(PHP_VERSION, "5.3", ">")) die("skip requires 5.2 or earlier"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$phar = new Phar($fname); +$phar->setStub("<?php __HALT_COMPILER(); ?>"); +$phar->setAlias('hio'); + +$files = array(); + +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; + +foreach ($files as $n => $file) { + $phar[$n] = $file; +} +$phar->stopBuffering(); + +$fp = fopen($alias . '/b/c.php', 'wb'); +fwrite($fp, "extra"); +fclose($fp); + +echo "===CLOSE===\n"; + +$b = fopen($alias . '/b/c.php', 'rb'); +$a = $phar['b/c.php']; +var_dump($a); +var_dump(fread($b, 20)); +rewind($b); +echo "===UNLINK===\n"; +unlink($alias . '/b/c.php'); +var_dump($a); +var_dump(fread($b, 20)); +include $alias . '/b/c.php'; +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- +===CLOSE=== +object(PharFileInfo)#%d (0) { +} +string(5) "extra" +===UNLINK=== + +Warning: unlink(): phar error: "b/c.php" in phar "%sefcount1_5_2.phar.tar", has open file pointers, cannot unlink in %sefcount1_5_2.php on line %d +object(PharFileInfo)#%d (0) { +} +string(5) "extra" +extra +===DONE=== diff --git a/ext/phar/tests/tar/rename.phpt b/ext/phar/tests/tar/rename.phpt new file mode 100644 index 0000000000..96588a6596 --- /dev/null +++ b/ext/phar/tests/tar/rename.phpt @@ -0,0 +1,42 @@ +--TEST-- +Phar: rename test tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php +include dirname(__FILE__) . '/files/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar'; +$alias = 'phar://' . $fname; + +$tar = new tarmaker($fname, 'none'); +$tar->init(); +$tar->addFile('.phar/stub.php', "<?php +Phar::mapPhar('hio'); +__HALT_COMPILER(); ?>"); + +$files = array(); +$files['a'] = 'a'; + +foreach ($files as $n => $file) { + $tar->addFile($n, $file); +} + +$tar->close(); + +include $fname; + +echo file_get_contents($alias . '/a') . "\n"; +rename($alias . '/a', $alias . '/b'); +echo file_get_contents($alias . '/b') . "\n"; +echo file_get_contents($alias . '/a') . "\n"; +?> +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?> +--EXPECTF-- +a +a + +Warning: file_get_contents(phar://%srename.phar.tar/a): failed to open stream: phar error: "a" is not a file in phar "%srename.phar.tar" in %srename.php on line %d diff --git a/ext/phar/tests/tar/tar_001.phpt b/ext/phar/tests/tar/tar_001.phpt new file mode 100644 index 0000000000..500058b70d --- /dev/null +++ b/ext/phar/tests/tar/tar_001.phpt @@ -0,0 +1,31 @@ +--TEST-- +Phar: tar-based phar corrupted +--SKIPIF-- +<?php if (!extension_loaded('phar')) die('skip'); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +--FILE-- +<?php +include dirname(__FILE__) . '/files/make_invalid_tar.php.inc'; + +$tar = new corrupter(dirname(__FILE__) . '/tar_001.phar.tar', 'none'); +$tar->init(); +$tar->addFile('tar_001.phpt', __FILE__); +$tar->close(); + +$tar = fopen('phar://' . dirname(__FILE__) . '/tar_001.phar.tar/tar_001.phpt', 'rb'); +try { + $phar = new Phar(dirname(__FILE__) . '/tar_001.phar.tar'); + echo "should not execute\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +@unlink(dirname(__FILE__) . '/tar_001.phar.tar'); +?> +--EXPECTF-- +Warning: fopen(phar://%star_001.phar.tar/tar_001.phpt): failed to open stream: phar error: "%star_001.phar.tar" is a corrupted tar file (truncated) in %star_001.php on line 9 +phar error: "%star_001.phar.tar" is a corrupted tar file (truncated) +===DONE=== diff --git a/ext/phar/tests/tar/tar_002.phpt b/ext/phar/tests/tar/tar_002.phpt new file mode 100644 index 0000000000..75fc220b40 --- /dev/null +++ b/ext/phar/tests/tar/tar_002.phpt @@ -0,0 +1,34 @@ +--TEST-- +Phar: tar-based phar corrupted 2 +--SKIPIF-- +<?php if (!extension_loaded('phar')) die('skip'); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php +include dirname(__FILE__) . '/files/make_invalid_tar.php.inc'; + +$tar = new corrupter(dirname(__FILE__) . '/tar_002.phar.tar', 'none'); +$tar->init(); +$tar->addFile('tar_002.phpt', __FILE__); +$tar->close(); + +$tar = fopen('phar://' . dirname(__FILE__) . '/tar_002.phar.tar/tar_002.phpt', 'rb'); + +try { + $phar = new Phar(dirname(__FILE__) . '/tar_002.phar.tar'); + echo "should not execute\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +@unlink(dirname(__FILE__) . '/tar_002.phar.tar'); +?> +--EXPECTF-- +Warning: fopen(phar://%star_002.phar.tar/tar_002.phpt): failed to open stream: phar error: "%star_002.phar.tar" is a corrupted tar file (truncated) in %star_002.php on line 9 +phar error: "%star_002.phar.tar" is a corrupted tar file (truncated) +===DONE=== diff --git a/ext/phar/tests/tar/tar_003.phpt b/ext/phar/tests/tar/tar_003.phpt new file mode 100644 index 0000000000..47f1d6ca9b --- /dev/null +++ b/ext/phar/tests/tar/tar_003.phpt @@ -0,0 +1,74 @@ +--TEST-- +Phar: tar-based phar, valid 1 +--SKIPIF-- +<?php if (!extension_loaded('phar')) die('skip'); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php +include dirname(__FILE__) . '/files/tarmaker.php.inc'; + +$fname = dirname(__FILE__) . '/tar_003.phar.tar'; +$alias = 'phar://' . $fname; + +$tar = new tarmaker($fname, 'none'); +$tar->init(); +$tar->addFile('.phar/stub.php', "<?php // tar-based phar archive stub file\n__HALT_COMPILER();"); +$tar->addFile('tar_003.phpt', $g = fopen(__FILE__, 'r')); +$tar->addFile('internal/file/here', "hi there!\n"); +$tar->mkDir('internal/dir'); +$tar->mkDir('dir'); +$tar->close(); + +fclose($g); + +echo file_get_contents($alias . '/internal/file/here'); + +try { +$tar = opendir($alias . '/'); +} catch (Exception $e) { +echo $e->getMessage()."\n"; +} + +while (false !== ($v = readdir($tar))) { + echo (is_file($alias . '/' . $v) ? "file\n" : "dir\n"); + echo $v . "\n"; +} +closedir($tar); + +/* ensure none of the dir tar files were freed */ +echo "second round\n"; +$tar = opendir($alias . '/'); +while (false !== ($v = readdir($tar))) { + echo (is_file($alias . '/' . $v) ? "file\n" : "dir\n"); + echo $v . "\n"; +} +closedir($tar); + +?> +===DONE=== +--CLEAN-- +<?php +@unlink(dirname(__FILE__) . '/tar_003.phar.tar'); +?> +--EXPECT-- +hi there! +dir +.phar +dir +dir +dir +internal +file +tar_003.phpt +second round +dir +.phar +dir +dir +dir +internal +file +tar_003.phpt +===DONE=== diff --git a/ext/phar/tests/tar/tar_004.phpt b/ext/phar/tests/tar/tar_004.phpt new file mode 100644 index 0000000000..2dd7ba169f --- /dev/null +++ b/ext/phar/tests/tar/tar_004.phpt @@ -0,0 +1,38 @@ +--TEST-- +Phar: tar-based phar, tar phar with stub, mapPhar() +--SKIPIF-- +<?php if (!extension_loaded('phar')) die('skip'); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php +include dirname(__FILE__) . '/files/tarmaker.php.inc'; + +$fname = dirname(__FILE__) . '/tar_004.phar.tar'; +$alias = 'phar://' . $fname; + +$tar = new tarmaker($fname, 'none'); +$tar->init(); +$tar->addFile('tar_004.php', '<?php var_dump(__FILE__);'); +$tar->addFile('internal/file/here', "hi there!\n"); +$tar->mkDir('internal/dir'); +$tar->mkDir('dir'); +$tar->addFile('.phar/stub.php', '<?php +Phar::mapPhar(); +var_dump("it worked"); +include "phar://" . __FILE__ . "/tar_004.php"; +'); +$tar->close(); + +include $fname; +?> +===DONE=== +--CLEAN-- +<?php +@unlink(dirname(__FILE__) . '/tar_004.phar.tar'); +?> +--EXPECTF-- +string(9) "it worked" +string(%d) "phar://%star_004.phar.tar/tar_004.php" +===DONE===
\ No newline at end of file diff --git a/ext/phar/tests/tar/tar_bz2.phpt b/ext/phar/tests/tar/tar_bz2.phpt new file mode 100644 index 0000000000..ad14541431 --- /dev/null +++ b/ext/phar/tests/tar/tar_bz2.phpt @@ -0,0 +1,54 @@ +--TEST-- +Phar: tar-based phar, bzipped tar +--SKIPIF-- +<?php if (!extension_loaded('phar')) die('skip'); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +<?php if (!extension_loaded("bz2")) die("skip bz2 not available"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php +include dirname(__FILE__) . '/files/tarmaker.php.inc'; + +$fname = dirname(__FILE__) . '/tar_bz2.phar'; +$alias = 'phar://' . $fname; +$fname2 = dirname(__FILE__) . '/tar_bz2.phar.tar'; +$alias2 = 'phar://' . $fname2; + +$tar = new tarmaker($fname, 'bz2'); +$tar->init(); +$tar->addFile('tar_004.php', '<?php var_dump(__FILE__);'); +$tar->addFile('internal/file/here', "hi there!\n"); +$tar->mkDir('internal/dir'); +$tar->mkDir('dir'); +$tar->addFile('.phar/stub.php', '<?php +Phar::mapPhar(); +var_dump("it worked"); +include "phar://" . __FILE__ . "/tar_004.php"; +'); +$tar->close(); + +include $fname; + +$phar = new Phar($fname); +$phar['test'] = 'hi'; + +copy($fname, $fname2); + +$phar2 = new Phar($fname2); +var_dump($phar2->isFileFormat(Phar::TAR)); +var_dump($phar2->isCompressed() == Phar::BZ2); + +?> +===DONE=== +--CLEAN-- +<?php +@unlink(dirname(__FILE__) . '/tar_bz2.phar'); +@unlink(dirname(__FILE__) . '/tar_bz2.phar.tar'); +?> +--EXPECTF-- +string(9) "it worked" +string(%d) "phar://%star_bz2.phar/tar_004.php" +bool(true) +bool(true) +===DONE===
\ No newline at end of file diff --git a/ext/phar/tests/tar/tar_gzip.phpt b/ext/phar/tests/tar/tar_gzip.phpt new file mode 100644 index 0000000000..8287ee7f06 --- /dev/null +++ b/ext/phar/tests/tar/tar_gzip.phpt @@ -0,0 +1,51 @@ +--TEST-- +Phar: tar-based phar, gzipped tar +--SKIPIF-- +<?php if (!extension_loaded('phar')) die('skip'); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?> +<?php if (version_compare(phpversion(), '5.2.6', '<')) die("skip zlib is buggy in PHP < 5.2.6"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php +include dirname(__FILE__) . '/files/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/tar_gzip.phar'; +$pname = 'phar://' . $fname; +$fname2 = dirname(__FILE__) . '/tar_gzip.phar.tar'; +$pname2 = 'phar://' . $fname2; + +$a = new tarmaker($fname, 'zlib'); +$a->init(); +$a->addFile('tar_004.php', '<?php var_dump(__FILE__);'); +$a->addFile('internal/file/here', "hi there!\n"); +$a->mkDir('internal/dir'); +$a->mkDir('dir'); +$a->addFile('.phar/stub.php', '<?php +Phar::mapPhar(); +var_dump("it worked"); +include "phar://" . __FILE__ . "/tar_004.php"; +'); +$a->close(); + +include $fname; + +$a = new Phar($fname); +$a['test'] = 'hi'; +copy($fname, $fname2); +$b = new Phar($fname2); +var_dump($b->isFileFormat(Phar::TAR)); +var_dump($b->isCompressed() == Phar::GZ); +?> +===DONE=== +--CLEAN-- +<?php +@unlink(dirname(__FILE__) . '/tar_gzip.phar'); +@unlink(dirname(__FILE__) . '/tar_gzip.phar.tar'); +?> +--EXPECTF-- +string(9) "it worked" +string(%d) "phar://%star_gzip.phar/tar_004.php" +bool(true) +bool(true) +===DONE===
\ No newline at end of file diff --git a/ext/phar/tests/tar/tar_makebz2.phpt b/ext/phar/tests/tar/tar_makebz2.phpt new file mode 100644 index 0000000000..f703b46924 --- /dev/null +++ b/ext/phar/tests/tar/tar_makebz2.phpt @@ -0,0 +1,40 @@ +--TEST-- +Phar: tar-based phar, make new bzipped tar +--SKIPIF-- +<?php if (!extension_loaded('phar')) die('skip'); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +<?php if (!extension_loaded("bz2")) die("skip bz2 not available"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/tar_makebz2.phar.tar'; +$fname2 = dirname(__FILE__) . '/tar_makebz2.phar.tar.bz2'; +$fname3 = dirname(__FILE__) . '/tar_makebz2_b.phar.tar.bz2'; + +$phar = new Phar($fname); +$phar['test'] = 'hi'; +var_dump($phar->isFileFormat(Phar::TAR)); +$phar = $phar->compress(Phar::BZ2); + +copy($fname2, $fname3); + +$phar2 = new Phar($fname3); +var_dump($phar2->isFileFormat(Phar::TAR)); +var_dump($phar2->isCompressed() == Phar::BZ2); + +?> +===DONE=== +--CLEAN-- +<?php +@unlink(dirname(__FILE__) . '/tar_makebz2.phar.bz2'); +@unlink(dirname(__FILE__) . '/tar_makebz2.phar.tar'); +@unlink(dirname(__FILE__) . '/tar_makebz2.phar.tar.bz2'); +@unlink(dirname(__FILE__) . '/tar_makebz2_b.phar.tar.bz2'); +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +===DONE=== diff --git a/ext/phar/tests/tar/tar_makegz.phpt b/ext/phar/tests/tar/tar_makegz.phpt new file mode 100644 index 0000000000..46fe177611 --- /dev/null +++ b/ext/phar/tests/tar/tar_makegz.phpt @@ -0,0 +1,41 @@ +--TEST-- +Phar: tar-based phar, make new gzipped tar +--SKIPIF-- +<?php if (!extension_loaded('phar')) die('skip'); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/tar_makegz.phar.tar'; +$fname2 = dirname(__FILE__) . '/tar_makegz.phar.tar.gz'; +$fname3 = dirname(__FILE__) . '/tar_makegz_b.phar.tar.gz'; + +$phar = new Phar($fname); +$phar['test'] = 'hi'; +var_dump($phar->isFileFormat(Phar::TAR)); +$phar = $phar->compress(Phar::GZ); + + +copy($fname2, $fname3); + +$phar2 = new Phar($fname3); +var_dump($phar2->isFileFormat(Phar::TAR)); +var_dump($phar2->isCompressed() == Phar::GZ); + +?> +===DONE=== +--CLEAN-- +<?php +@unlink(dirname(__FILE__) . '/tar_makegz.phar.gz'); +@unlink(dirname(__FILE__) . '/tar_makegz.phar.tar'); +@unlink(dirname(__FILE__) . '/tar_makegz.phar.tar.gz'); +@unlink(dirname(__FILE__) . '/tar_makegz_b.phar.tar.gz'); +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +===DONE===
\ No newline at end of file diff --git a/ext/phar/tests/tar/tar_nostub.phpt b/ext/phar/tests/tar/tar_nostub.phpt new file mode 100644 index 0000000000..a107a37deb --- /dev/null +++ b/ext/phar/tests/tar/tar_nostub.phpt @@ -0,0 +1,48 @@ +--TEST-- +Phar: tar-based phar, third-party tar with no stub, Phar->getStub() +--SKIPIF-- +<?php if (!extension_loaded('phar')) die('skip'); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +--INI-- +phar.readonly=1 +--FILE-- +<?php +include dirname(__FILE__) . '/files/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/tar_004.phar.tar'; +$alias = 'phar://' . $fname; +$fname2 = dirname(__FILE__) . '/tar_004.tar'; + +$tar = new tarmaker($fname, 'none'); +$tar->init(); +$tar->addFile('tar_004.php', '<?php var_dump(__FILE__);'); +$tar->addFile('internal/file/here', "hi there!\n"); +$tar->close(); + +try { + $phar = new Phar($fname); + var_dump($phar->getStub()); +} catch (Exception $e) { + echo $e->getMessage()."\n"; +} + +copy($fname, $fname2); + +try { + $phar = new PharData($fname2); + var_dump($phar->getStub()); +} catch (Exception $e) { + echo $e->getMessage()."\n"; +} + +?> +===DONE=== +--CLEAN-- +<?php +@unlink(dirname(__FILE__) . '/tar_004.phar.tar'); +@unlink(dirname(__FILE__) . '/tar_004.tar'); +?> +--EXPECTF-- +RecursiveDirectoryIterator::__construct(phar://%star_004.phar.tar/): failed to open dir: '%star_004.phar.tar' is not a phar archive. Use PharData::__construct() for a standard zip or tar archive +phar url "phar://%star_004.phar.tar/" is unknown +string(0) "" +===DONE=== diff --git a/ext/phar/tests/tar/truncated.phpt b/ext/phar/tests/tar/truncated.phpt new file mode 100644 index 0000000000..fbcabb7986 --- /dev/null +++ b/ext/phar/tests/tar/truncated.phpt @@ -0,0 +1,22 @@ +--TEST-- +Phar: truncated tar +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--FILE-- +<?php +try { + $p = new PharData(dirname(__FILE__) . '/files/trunc.tar'); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); +?> +--EXPECTF-- +phar error: "%strunc.tar" is a corrupted tar file (truncated) +===DONE=== |