*/ /** Test the domframework file part */ class fileTest extends \PHPUnit_Framework_TestCase { public function testinit () { exec ("rm -rf /tmp/testDFFileDir"); } public function testRealPath01 () { $file = new file (); $res = $file->realpath ("/tmp"); $this->assertSame($res, "/tmp"); } public function testRealPath02 () { $file = new file (); $res = $file->realpath ("////tmp"); $this->assertSame($res, "/tmp"); } public function testRealPath03 () { $file = new file (); $res = $file->realpath ("////tmp////"); $this->assertSame($res, "/tmp"); } public function testRealPath04 () { $file = new file (); $res = $file->realpath (".////tmp////"); $this->assertSame($res, "./tmp"); } public function testRealPath05 () { $file = new file (); $res = $file->realpath ("../../../../../tmp/file"); $this->assertSame($res, "/tmp/file"); } public function testRealPath06 () { $file = new file (); $res = $file->realpath ("../../../../../tmp/file/../../../.."); $this->assertSame($res, "/"); } public function testRealPath07 () { $file = new file (); $res = $file->realpath (".././././../tmp/file/../././.."); $this->assertSame($res, "/"); } public function testRealPath11 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->realpath ("/tmp2"); $this->assertSame($res, "/tmp/tmp2"); } public function testRealPath12 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->realpath ("////tmp2"); $this->assertSame($res, "/tmp/tmp2"); } public function testRealPath13 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->realpath ("////tmp2////"); $this->assertSame($res, "/tmp/tmp2"); } public function testRealPath14 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->realpath (".////tmp2////"); $this->assertSame($res, "/tmp/tmp2"); } public function testRealPath15 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->realpath ("../../../../../tmp2/file"); $this->assertSame($res, "/tmp/tmp2/file"); } public function testRealPath16 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->realpath ("../../../../../tmp2/file/../../../.."); $this->assertSame($res, "/tmp"); } public function testRealPath17 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->realpath (".././././../tmp2/file/../././.."); $this->assertSame($res, "/tmp"); } public function testGetcwd1 () { $file = new file (); $res = $file->getcwd (); $this->assertSame($res, "."); } public function testGetcwd2 () { $file = new file (); $file->chdir ("/tmp"); $res = $file->getcwd (); $this->assertSame($res, "/tmp"); } public function testGetcwd3 () { $this->setExpectedException ("Exception", "Path '/NON EXISTS' not found"); $file = new file (); $file->chdir ("/NON EXISTS"); $res = $file->getcwd (); } public function testGetcwd4 () { $file = new file (); $file->chdir ("/../../../tmp"); $res = $file->getcwd (); $this->assertSame($res, "/tmp"); } public function testGetcwd5 () { $file = new file (); $file->chdir ("../../../../../../tmp"); $res = $file->getcwd (); $this->assertSame($res, "/tmp"); } public function testGetcwd6 () { $this->setExpectedException ("Exception", "Path './tmp' not found"); $file = new file (); $file->chdir ("./tmp"); $res = $file->getcwd (); } public function testGetcwd7 () { $this->setExpectedException ("Exception", "Path '/tmp/NON EXISTS' not found"); $file = new file (); $file->chdir ("/tmp/NON EXISTS"); $res = $file->getcwd (); } public function testGetcwd8 () { $this->setExpectedException ("Exception", "Parent Path '/NON EXISTS/' not found"); $file = new file (); $file->chdir ("/NON EXISTS/tmp"); $res = $file->getcwd (); } public function testchroot1 () { $this->setExpectedException ("Exception"); $file = new file (); $res = $file->chroot ("non exists"); } public function testchroot2 () { $file = new file (); $res = $file->chroot ("/tmp"); $this->assertSame($res, true); } // Without chroot public function testMkdir1 () { $file = new file (); $res = $file->mkdir ("/tmp/testmkdir1-".time()); $this->assertSame($res, true); } // With chroot in tmp public function testMkdir2 () { $file = new file (); $res = $file->chroot ("/tmp"); $res = $file->mkdir ("/testmkdir2-".time()); $this->assertSame($res, true); } // Without chroot and relative public function testMkdir3 () { $file = new file (); $res = $file->mkdir ("/tmp/testmkdir3-".time()); $this->assertSame($res, true); } // With chroot in tmp and in relative public function testMkdir4 () { $file = new file (); $res = $file->chroot ("/tmp"); $res = $file->mkdir ("testmkdir4-".time()); $this->assertSame($res, true); } // With chroot in tmp public function testChdir1 () { @rmdir ("/tmp/testDFFileDir"); $file = new file (); $file->chroot ("/tmp"); $file->mkdir ("/testDFFileDir"); $file->chdir ("/testDFFileDir"); $res = $file->getcwd (); $this->assertSame($res, "/testDFFileDir"); } // With chroot in tmp public function testChdir2 () { @rmdir ("/tmp/testDFFileDir"); $file = new file (); $file->chroot ("/tmp"); $file->mkdir ("/testDFFileDir"); $file->chroot ("/"); $file->chdir ("/testDFFileDir"); $res = $file->getcwd (); $this->assertSame($res, "/testDFFileDir"); } // With chroot in tmp public function testChdir3 () { $this->setExpectedException ("Exception", "Path '/tmp/testDFFileDir/NON EXISTS' not found"); @rmdir ("/tmp/testDFFileDir"); $file = new file (); $file->chroot ("/tmp"); $file->mkdir ("/testDFFileDir"); $file->chroot ("/testDFFileDir"); $file->chdir ("/NON EXISTS"); } // With chroot in tmp public function testChdir4 () { $this->setExpectedException ("Exception", "Parent Path '/tmp/tmp/' not found"); @rmdir ("/tmp/testDFFileDir"); $file = new file (); $file->chroot ("/tmp"); $file->mkdir ("/testDFFileDir"); $file->chroot (".."); $file->chdir ("/tmp/testDFFileDir"); } public function testFile_get_contents1 () { $this->setExpectedException ("Exception", "File '/tmp/testDFFileDir' is not a file"); @rmdir ("/tmp/testDFFileDir"); $file = new file (); $file->chroot ("/tmp"); $file->mkdir ("/testDFFileDir"); $res = $file->file_get_contents ("/testDFFileDir"); } public function testFile_get_contents2 () { @rmdir ("/tmp/testDFFileDir"); $file = new file (); $file->chroot ("/tmp"); $file->mkdir ("/testDFFileDir"); $file->touch ("/testDFFileDir/toto"); $res = $file->file_get_contents ("/testDFFileDir/toto"); $this->assertSame($res, ""); } public function testFile_put_contents1 () { $file = new file (); $file->chroot ("/tmp"); $file->file_put_contents ("/testDFFileDir/toto", "content"); $res = $file->file_get_contents ("/testDFFileDir/toto"); $this->assertSame($res, "content"); } public function testFile_put_contents2 () { $this->setExpectedException ("Exception", "File '/tmp/testDFFileDir' is not a file"); $file = new file (); $file->file_put_contents ("/tmp/testDFFileDir", "content"); } public function testFile_put_contents3 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->file_put_contents ("/testDFFileDir/toto", "content"); $this->assertSame($res, 7); } public function testscandir1 () { $file = new file (); $res = $file->scandir ("/tmp/testDFFileDir"); $this->assertSame ($res, array ("toto")); } public function testscandir2 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->scandir ("/testDFFileDir"); $this->assertSame ($res, array ("toto")); } public function testscandir3 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->scandir ("/testDFFileDir/"); $this->assertSame ($res, array ("toto")); } public function testrmdir1 () { // Directory not empty and NOT recursive : return false $file = new file (); $res = $file->rmdir ("/tmp/testDFFileDir"); $this->assertSame ($res, false); } public function testrmdir2 () { // Directory not empty and NOT recursive : return false $file = new file (); $file->chroot ("/tmp"); $res = $file->rmdir ("/testDFFileDir"); $this->assertSame ($res, false); } public function testrmdir3 () { // Directory not empty and recursive : return true $file = new file (); $file->chroot ("/tmp"); $res = $file->rmdir ("/testDFFileDir", true); $this->assertSame ($res, true); } public function testUnlink1 () { @rmdir ("/tmp/testDFFileDir"); $file = new file (); $file->chroot ("/tmp"); $file->mkdir ("/testDFFileDir"); $file->touch ("/testDFFileDir/toto"); $res = $file->unlink ("/testDFFileDir/toto"); $this->assertSame ($res, true); } public function testIsDir1 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->is_dir ("//testDFFileDir"); $this->assertSame ($res, true); } public function testIsDir2 () { $file = new file (); $file->chroot ("/tmp"); $file->touch ("/testDFFileDir/toto"); $res = $file->is_dir ("//testDFFileDir/toto"); $this->assertSame ($res, false); } public function testIsFile1 () { $file = new file (); $file->chroot ("/tmp"); $file->touch ("/testDFFileDir/toto"); $res = $file->is_file ("/testDFFileDir/toto"); $this->assertSame ($res, true); } public function testIsFile2 () { $file = new file (); $file->chroot ("/tmp"); $file->touch ("/testDFFileDir/toto"); $res = $file->is_file ("//testDFFileDir"); $this->assertSame ($res, false); } public function testMkdir5 () { $file = new file (); $file->chroot ("/tmp"); // The parent doesn't exists and not recursive mode : exception $this->expectException (); $res = $file->mkdir ("/testDFFileDir/tptp/titi/poo"); } public function testMkdir6 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->mkdir ("/testDFFileDir/tptp/titi/poo", 0777, true); $this->assertSame ($res, true); } public function test_glob_1 () { $file = new file (); $file->chroot ("/tmp"); $res = $file->glob ("/testDFFileDir/*"); $this->assertSame ($res, array ("/testDFFileDir/toto", "/testDFFileDir/tptp")); } public function test_glob_2 () { $file = new file (); $file->chroot ("/tmp"); $file->chdir ("/testDFFileDir"); $res = $file->glob ("*"); $this->assertSame ($res, array ("toto", "tptp")); } public function test_glob_3 () { $file = new file (); $file->chroot ("/tmp"); $file->chdir ("/testDFFileDir"); $res = $file->glob ("/testDFFileDir/*"); $this->assertSame ($res, array ("/testDFFileDir/toto", "/testDFFileDir/tptp")); } public function test_glob_4 () { $file = new file (); $res = $file->glob ("/tmp/testDFFileDir/*"); $this->assertSame ($res, array ("/tmp/testDFFileDir/toto", "/tmp/testDFFileDir/tptp")); } public function test_glob_5 () { $file = new file (); $file->chdir ("/tmp/testDFFileDir"); $res = $file->glob ("*"); $this->assertSame ($res, array ("toto", "tptp")); } public function test_glob_6 () { $file = new file (); $file->chdir ("/tmp/testDFFileDir"); $res = $file->glob ("/tmp/testDFFileDir/*"); $this->assertSame ($res, array ("/tmp/testDFFileDir/toto", "/tmp/testDFFileDir/tptp")); } }