xref: /PHP-7.1/ext/phar/tests/phar_extract2.phpt (revision cdf5d201)
1--TEST--
2Phar: Phar::extractTo() - .phar safety
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9
10$fname = dirname(__FILE__) . '/tempmanifest2.phar.php';
11$pname = 'phar://' . $fname;
12
13$phar = new Phar($fname);
14$phar->setDefaultStub();
15$phar->setAlias('fred');
16$phar['file1.txt'] = 'hi';
17$phar['file2.txt'] = 'hi2';
18$phar['subdir/ectory/file.txt'] = 'hi3';
19$phar->mount($pname . '/mount2', __FILE__);
20$phar->addEmptyDir('one/level');
21
22$phar->extractTo(dirname(__FILE__) . '/extract2', 'mount2');
23$phar->extractTo(dirname(__FILE__) . '/extract2');
24$out = array();
25
26foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/extract2', 0x00003000), RecursiveIteratorIterator::CHILD_FIRST) as $path => $file) {
27	$extracted[] = $path;
28}
29
30sort($extracted);
31
32foreach ($extracted as $out) {
33	echo "$out\n";
34}
35
36?>
37===DONE===
38--CLEAN--
39<?php
40@unlink(dirname(__FILE__) . '/tempmanifest2.phar.php');
41$dir = dirname(__FILE__) . '/extract2/';
42@unlink($dir . 'file1.txt');
43@unlink($dir . 'file2.txt');
44@unlink($dir . 'subdir/ectory/file.txt');
45@rmdir($dir . 'subdir/ectory');
46@rmdir($dir . 'subdir');
47@rmdir($dir . 'one/level');
48@rmdir($dir . 'one');
49@rmdir($dir);
50$dir = dirname(__FILE__) . '/extract1/';
51@rmdir($dir);
52?>
53--EXPECTF--
54%sextract2%cfile1.txt
55%sextract2%cfile2.txt
56%sextract2%cone
57%sextract2%csubdir
58%sextract2%csubdir%cectory
59%sextract2%csubdir%cectory%cfile.txt
60===DONE===
61