9 require_once
'PU_testcase_dcp.php';
16 "PU_data_dcp_exportfamilycsv.ods",
17 "PU_data_dcp_exportdoccsv.ods",
18 "PU_data_dcp_exportdocimage.ods"
30 include_once (
'FDL/exportfld.php');
31 include_once (
'Lib.FileDir.php');
34 $oImport->importDocuments(self::getAction() , $archiveFile,
false,
true);
36 if (
$err)
throw new \Dcp\Exception(
$err);
38 $folderId =
"TEXT_FOLDER_EXPORT_IMAGE";
39 $famid =
"TST_EXPORT_IMAGE";
40 $testFolder = uniqid(
getTmpDir() .
"/testexportimage");
41 $testExtractFolder = uniqid(
getTmpDir() .
"/testexportextractimage");
48 $testarchivefile = $testFolder .
"/fdl.zip";
50 $this->assertEmpty(
$err, sprintf(
"Unexpected error while extracting archive '%s': %s", $testarchivefile,
$err));
53 exec(sprintf(
"ls -R %s", escapeshellarg($testExtractFolder)) , $output);
54 foreach ($needles as $needle) {
55 $this->assertContains($needle, $output, sprintf(
"file %s not found in export archive", $needle));
69 public function testExportFolder($folderId, array $expectDoc, $separator, $enclosure, array $expectedProfil)
71 include_once (
'FDL/exportfld.php');
74 SetHttpVar(
"wprof", ($expectedProfil ?
"Y" :
"N"));
80 $exportOutput = uniqid(
getTmpDir() .
"/testExport") .
".csv";
82 exportfld(self::getAction() , $folderId, 0, $exportOutput);
84 $this->assertTrue(file_exists($exportOutput) , sprintf(
'Export File "%s" nor create', $exportOutput));
86 $exportDocName = array();
87 $h = fopen($exportOutput,
"r");
89 while ((
$data = fgetcsv($h, 0, $separator, $enclosure)) !== FALSE) {
92 $exportDocName[] = $docName;
93 if (isset($expectDoc[$docName])) {
94 $expecDoc = $expectDoc[$docName];
95 foreach ($expecDoc as $k => $v) {
96 $this->assertEquals($v,
$data[$k], sprintf(
"Invalid value for %s column : [%s] : see %s", $k, implode(
"][",
$data) , $exportOutput));
100 if (isset(
$data[0]) &&
$data[0] ===
"PROFIL") {
103 if (isset($expectedProfil[$docName])) {
104 $prof = $expectedProfil[$docName];
106 foreach ($prof as $k => $v) {
107 $this->assertEquals($v,
$data[$k], sprintf(
"Invalid profil value for %s column : [%s]: see %s", $k, implode(
"][",
$data) , $exportOutput));
114 $this->assertEquals(array_keys($expectDoc) , $exportDocName,
"No same exported documents: See $exportOutput");
126 public function testExportamily($familyId, array $expectData, $separator, $enclosure)
128 include_once (
'FDL/exportfld.php');
140 $err = $tmpFolder->add();
141 $err.= $tmpFolder->insertDocument($familyId);
143 $this->assertEmpty(
$err,
"Error when create family folder");
144 $exportOutput = uniqid(
getTmpDir() .
"/testExport") .
".csv";
146 exportfld(self::getAction() , $tmpFolder->id, 0, $exportOutput);
148 $this->assertTrue(file_exists($exportOutput) , sprintf(
'Export File "%s" nor create', $exportOutput));
150 $h = fopen($exportOutput,
"r");
153 while ((
$data = fgetcsv($h, 0, $separator, $enclosure)) !== FALSE) {
154 if (!empty(
$data[0])) {
156 if (isset($expectData[
$data[0]])) {
157 foreach ($expectData[$data[0]] as $k => $v) {
158 $this->assertEquals($v, $data[$k], sprintf(
"Invalid value for %s column : [%s] : see %s", $k, implode(
"][", $data) , $exportOutput));
164 foreach ($expectData as $key => $v) {
165 $this->assertTrue(in_array($key, $keys) ,
"Missing key $key see $exportOutput");
178 include_once (
'FDL/exportfld.php');
184 if (!isset($data[$key])) {
185 throw new \Exception(sprintf(
"Missing key '%s' in test data."));
190 if (!
$doc->isAlive()) {
191 throw new \Exception(sprintf(
"Could not get document with id '%s'.", $data[
'export:doc']));
196 throw new \Exception(sprintf(
"Could not create temporary file in '%s'.",
getTmpDir()));
199 if ($fout ===
false) {
200 throw new \Exception(sprintf(
"Could not create temporary file '%s'.",
$tmpfile));
217 $ed = new \Dcp\ExportDocument();
218 $ed->csvExport(
$doc, $ef, $fout, $wprof, $wfile, $wident, $wutf8, $nopref, $eformat);
223 $lines = preg_split(
"/\n/",
$out);
224 foreach ($lines as & $line) {
225 if (!preg_match(
'/^ORDER;/', $line)) {
228 foreach ($data[
'expect:no:order'] as $column) {
229 $match = preg_match(sprintf(
'/;%s;/', preg_quote($column,
'/')) , $line);
230 $this->assertTrue(($match <= 0) , sprintf(
"Found param '%s' in ORDER line '%s'.", $column, $line));
242 "family" =>
"TST_EXPORT_PARAM",
243 "expectedData" => array(
249 5 =>
"TST_EXPORT_PARAM"
252 1 =>
"TST_PROFFAMEXPORT"
255 1 =>
"TST_PROFEXPORT"
263 "family" =>
"TST_EXPORT_PARAM",
264 "expectedData" => array(
270 5 =>
"TST_EXPORT_PARAM"
273 1 =>
"TST_PROFFAMEXPORT"
276 1 =>
"TST_PROFEXPORT"
289 "folderId" =>
"TST_EXPORT_FOLDER",
290 "expectedDocument" => array(
291 "TST_EXPORT_PARAM_01" => array(
292 4 =>
"L'un et l'autre",
295 "TST_EXPORT_PARAM_02" => array(
296 4 =>
"Déja vu\nUne impression",
299 "TST_EXPORT_PARAM_03" => array(
300 4 =>
'Dicton "Qui élargit son cœur, rétrécit sa bouche"',
309 "folderId" =>
"TST_EXPORT_FOLDER",
310 "expectedDocument" => array(
311 "TST_EXPORT_PARAM_01" => array(
312 4 =>
"L'un et l'autre"
314 "TST_EXPORT_PARAM_02" => array(
315 4 =>
"Déja vu\nUne impression"
317 "TST_EXPORT_PARAM_03" => array(
318 4 =>
'Dicton "Qui élargit son cœur, rétrécit sa bouche"'
326 "folderId" =>
"TST_EXPORT_FOLDER",
327 "expectedDocument" => array(
328 "TST_EXPORT_PARAM_01" => array(
329 4 =>
"L'un et l'autre"
331 "TST_PROFEXPORT" => array(
332 4 =>
"Profil de test, d'exportation"
334 "TST_EXPORT_PARAM_02" => array(
335 4 =>
"Déja vu\nUne impression"
337 "TST_EXPORT_PARAM_03" => array(
338 4 =>
'Dicton "Qui élargit son cœur, rétrécit sa bouche"'
344 "TST_PROFEXPORT" => array(
358 "./DCPTEST/PU_dcp_data_exportcsvimage.zip",
360 "PU_data_dcp_exportdocimageexample.png",
361 "PU_data_dcp_exportdocimage.ods"
372 "export:doc" =>
"TST_EXPORT_PARAM_01",
373 "expect:no:order" => array(
static getCommonImportFile()
exportfld(Action &$action, $aflid="0", $famid="", $outputPath="", $exportInvisibleVisibilities=false)
testExportImage($archiveFile, $needles)
new_Doc($dbaccess, $id= '', $latest=false)
extractTar($tar, $untardir, $mime="")
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
if($file) if($subject==""&&$file) if($subject=="") $err
testExportFolder($folderId, array $expectDoc, $separator, $enclosure, array $expectedProfil)