forked from Wavyzz/dolibarr
Add phpunit to test the rename/move into a corrupted pdf file.
This commit is contained in:
@@ -972,14 +972,14 @@ function dol_move($srcfile, $destfile, $newmask = '0', $overwriteifexists = 1, $
|
|||||||
// Check using filename + antivirus
|
// Check using filename + antivirus
|
||||||
$testvirusarray = dolCheckVirus($newpathofsrcfile, $newpathofdestfile);
|
$testvirusarray = dolCheckVirus($newpathofsrcfile, $newpathofdestfile);
|
||||||
if (count($testvirusarray)) {
|
if (count($testvirusarray)) {
|
||||||
dol_syslog("files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING);
|
dol_syslog("files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check using filename only
|
// Check using filename only
|
||||||
$testvirusarray = dolCheckOnFileName($newpathofsrcfile, $newpathofdestfile);
|
$testvirusarray = dolCheckOnFileName($newpathofsrcfile, $newpathofdestfile);
|
||||||
if (count($testvirusarray)) {
|
if (count($testvirusarray)) {
|
||||||
dol_syslog("files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING);
|
dol_syslog("files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class FilesLibTest extends CommonClassTest
|
|||||||
$langs = $this->savlangs;
|
$langs = $this->savlangs;
|
||||||
$db = $this->savdb;
|
$db = $this->savdb;
|
||||||
|
|
||||||
$file = dirname(__FILE__).'/Example_import_company_1.csv';
|
$file = dirname(__FILE__).'/file_import_company_1.csv';
|
||||||
$result = dol_count_nb_of_line($file);
|
$result = dol_count_nb_of_line($file);
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result."\n";
|
||||||
$this->assertEquals(3, $result);
|
$this->assertEquals(3, $result);
|
||||||
@@ -115,7 +115,7 @@ class FilesLibTest extends CommonClassTest
|
|||||||
$langs = $this->savlangs;
|
$langs = $this->savlangs;
|
||||||
$db = $this->savdb;
|
$db = $this->savdb;
|
||||||
|
|
||||||
$file = dirname(__FILE__).'/Example_import_company_1.csv';
|
$file = dirname(__FILE__).'/file_import_company_1.csv';
|
||||||
|
|
||||||
$result = dol_is_file($file);
|
$result = dol_is_file($file);
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result."\n";
|
||||||
@@ -256,7 +256,11 @@ class FilesLibTest extends CommonClassTest
|
|||||||
$langs = $this->savlangs;
|
$langs = $this->savlangs;
|
||||||
$db = $this->savdb;
|
$db = $this->savdb;
|
||||||
|
|
||||||
$file = dirname(__FILE__).'/Example_import_company_1.csv';
|
$file = dirname(__FILE__).'/file_import_company_1.csv';
|
||||||
|
|
||||||
|
$result = dol_copy($file, '/adir/that/does/not/exists/file.csv');
|
||||||
|
print __METHOD__." result=".$result."\n";
|
||||||
|
$this->assertLessThan(0, $result, "$result".'copy dir that does not exists'); // We should have error
|
||||||
|
|
||||||
$result = dol_copy($file, '/adir/that/does/not/exists/file.csv');
|
$result = dol_copy($file, '/adir/that/does/not/exists/file.csv');
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result."\n";
|
||||||
@@ -310,6 +314,18 @@ class FilesLibTest extends CommonClassTest
|
|||||||
$result = dol_delete_file($conf->admin->dir_temp.'/file with [x]*é.csv');
|
$result = dol_delete_file($conf->admin->dir_temp.'/file with [x]*é.csv');
|
||||||
print __METHOD__." result=".$result."\n";
|
print __METHOD__." result=".$result."\n";
|
||||||
$this->assertTrue($result, 'delete file using glob');
|
$this->assertTrue($result, 'delete file using glob');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$file = dirname(__FILE__).'/file_pdf_with_js.pdf.jpg';
|
||||||
|
|
||||||
|
$result = dol_copy($file, $conf->admin->dir_temp.'/file_pdf_with_js.pdf.jpg');
|
||||||
|
print __METHOD__." result=".$result."\n";
|
||||||
|
$this->assertGreaterThan(0, $result, "$result".' failed to copy pdf file');
|
||||||
|
|
||||||
|
$result = dol_move($conf->admin->dir_temp.'/file_pdf_with_js.pdf.jpg', $conf->admin->dir_temp.'/file_pdf_with_js.pdf');
|
||||||
|
print __METHOD__." dol_move of corrupted file result=".$result."\n";
|
||||||
|
$this->assertFalse($result, "$result".' move of a jpg into a corrupted pdf should fails');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -330,7 +346,7 @@ class FilesLibTest extends CommonClassTest
|
|||||||
print 'testDolCompressUnCompress zip'."\n";
|
print 'testDolCompressUnCompress zip'."\n";
|
||||||
|
|
||||||
$format = 'zip';
|
$format = 'zip';
|
||||||
$filein = dirname(__FILE__).'/Example_import_company_1.csv';
|
$filein = dirname(__FILE__).'/file_import_company_1.csv';
|
||||||
$fileout = $conf->admin->dir_temp.'/test.'.$format;
|
$fileout = $conf->admin->dir_temp.'/test.'.$format;
|
||||||
$dirout = $conf->admin->dir_temp.'/testdir'.$format;
|
$dirout = $conf->admin->dir_temp.'/testdir'.$format;
|
||||||
|
|
||||||
@@ -361,7 +377,7 @@ class FilesLibTest extends CommonClassTest
|
|||||||
print 'testDolCompressUnCompress gz'."\n";
|
print 'testDolCompressUnCompress gz'."\n";
|
||||||
|
|
||||||
$format = 'gz';
|
$format = 'gz';
|
||||||
$filein = dirname(__FILE__).'/Example_import_company_1.csv';
|
$filein = dirname(__FILE__).'/file_import_company_1.csv';
|
||||||
$fileout = $conf->admin->dir_temp.'/test.'.$format;
|
$fileout = $conf->admin->dir_temp.'/test.'.$format;
|
||||||
$dirout = $conf->admin->dir_temp.'/testdir'.$format;
|
$dirout = $conf->admin->dir_temp.'/testdir'.$format;
|
||||||
|
|
||||||
@@ -486,7 +502,7 @@ class FilesLibTest extends CommonClassTest
|
|||||||
// To test a move of empty directory that should work
|
// To test a move of empty directory that should work
|
||||||
$dirsrcpath = $conf->admin->dir_temp.'/directory';
|
$dirsrcpath = $conf->admin->dir_temp.'/directory';
|
||||||
$dirdestpath = $conf->admin->dir_temp.'/directory2';
|
$dirdestpath = $conf->admin->dir_temp.'/directory2';
|
||||||
$file = dirname(__FILE__).'/Example_import_company_1.csv';
|
$file = dirname(__FILE__).'/file_import_company_1.csv';
|
||||||
dol_mkdir($dirsrcpath);
|
dol_mkdir($dirsrcpath);
|
||||||
dol_delete_dir_recursive($dirdestpath, 0, 1);
|
dol_delete_dir_recursive($dirdestpath, 0, 1);
|
||||||
$result = dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1);
|
$result = dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user