/** * simple test that checks that the given filenames and contents can be grepped from the * uncompressed tar file * * No check for format correctness */ public function test_createfile() { $tar = new Tar(); $dir = dirname(__FILE__) . '/tar'; $tdir = ltrim($dir, '/'); $tmp = tempnam(sys_get_temp_dir(), 'dwtartest'); $tar->create($tmp, Tar::COMPRESS_NONE); $tar->AddFile("{$dir}/testdata1.txt"); $tar->AddFile("{$dir}/foobar/testdata2.txt", 'noway/testdata2.txt'); $tar->addData('another/testdata3.txt', 'testcontent3'); $tar->close(); copy($tmp, '/tmp/test.tar'); $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number $data = file_get_contents($tmp); $this->assertTrue(strpos($data, 'testcontent1') !== false, 'Content in TAR'); $this->assertTrue(strpos($data, 'testcontent2') !== false, 'Content in TAR'); $this->assertTrue(strpos($data, 'testcontent3') !== false, 'Content in TAR'); // fullpath might be too long to be stored as full path FS#2802 $this->assertTrue(strpos($data, "{$tdir}") !== false, "Path in TAR '{$tdir}'"); $this->assertTrue(strpos($data, "testdata1.txt") !== false, 'File in TAR'); $this->assertTrue(strpos($data, 'noway/testdata2.txt') !== false, 'Path in TAR'); $this->assertTrue(strpos($data, 'another/testdata3.txt') !== false, 'Path in TAR'); // fullpath might be too long to be stored as full path FS#2802 $this->assertTrue(strpos($data, "{$tdir}/foobar") === false, 'Path not in TAR'); $this->assertTrue(strpos($data, "foobar.txt") === false, 'File not in TAR'); $this->assertTrue(strpos($data, "foobar") === false, 'Path not in TAR'); @unlink($tmp); }