2
0
forked from Wavyzz/dolibarr

Add phpunit to test the rename/move into a corrupted pdf file.

This commit is contained in:
Laurent Destailleur
2024-02-17 18:59:57 +01:00
parent fb283fdfe9
commit 8abe663d6f
4 changed files with 24 additions and 8 deletions

View File

@@ -94,7 +94,7 @@ class FilesLibTest extends CommonClassTest
$langs = $this->savlangs;
$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);
print __METHOD__." result=".$result."\n";
$this->assertEquals(3, $result);
@@ -115,7 +115,7 @@ class FilesLibTest extends CommonClassTest
$langs = $this->savlangs;
$db = $this->savdb;
$file = dirname(__FILE__).'/Example_import_company_1.csv';
$file = dirname(__FILE__).'/file_import_company_1.csv';
$result = dol_is_file($file);
print __METHOD__." result=".$result."\n";
@@ -256,7 +256,11 @@ class FilesLibTest extends CommonClassTest
$langs = $this->savlangs;
$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');
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');
print __METHOD__." result=".$result."\n";
$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";
$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;
$dirout = $conf->admin->dir_temp.'/testdir'.$format;
@@ -361,7 +377,7 @@ class FilesLibTest extends CommonClassTest
print 'testDolCompressUnCompress gz'."\n";
$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;
$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
$dirsrcpath = $conf->admin->dir_temp.'/directory';
$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_delete_dir_recursive($dirdestpath, 0, 1);
$result = dol_move_dir($dirsrcpath, $dirdestpath, 1, 1, 1);