9 require_once
'PU_testcase_dcp_commonfamily.php';
15 "PU_data_dcp_exportcollection.ods",
16 "PU_data_dcp_document_exportcollection.xml"
29 $outFile = tempnam(
getTmpDir() ,
'tstexport');
31 $s->setObjectReturn();
34 $this->assertEmpty(
$s->searchError() , sprintf(
"Error in search %s", print_r(
$s->getSearchInfo() ,
true)));
36 $ec = new \Dcp\ExportCollection();
38 $ec->setCvsEnclosure($enclosure);
39 $ec->setCvsSeparator($separator);
40 $ec->setOutputFilePath($outFile);
41 $ec->setDocumentlist(
$s->getDocumentList());
44 $this->assertTrue(filesize($outFile) > 0, sprintf(
"\"%s\" file not produced", $outFile));
57 $outFile = tempnam(
getTmpDir() ,
'tstexport');
59 $s->setObjectReturn();
62 $this->assertEmpty(
$s->searchError() , sprintf(
"Error in search %s", print_r(
$s->getSearchInfo() ,
true)));
64 $ec = new \Dcp\ExportCollection();
66 $ec->setCvsEnclosure($enclosure);
67 $ec->setCvsSeparator($separator);
68 $ec->setOutputFilePath($outFile);
69 $ec->setOutputFormat($format);
70 $ec->setDocumentlist(
$s->getDocumentList());
73 $this->assertTrue(filesize($outFile) > 0, sprintf(
"\"%s\" file not produced", $outFile));
77 protected function verifyCsvContains($outFile, $separator, $enclosure, $expectedData, $columnId)
79 $results = fopen($outFile,
"r");
80 $resultData = array();
81 while ((
$data = fgetcsv($results, 1000, $separator, $enclosure)) !== FALSE) {
82 $docName =
$data[$columnId];
83 $resultData[$docName] =
$data;
86 foreach ($expectedData as $docName => $docValues) {
87 $this->assertTrue(isset($resultData[$docName]) , sprintf(
"%s document not found : %s", $docName, print_r($resultData,
true)));
88 foreach ($docValues as $index =>
$value) {
89 if (strpos(
$value,
"*") ===
false) {
90 $this->assertEquals(
$value, $resultData[$docName][$index], sprintf(
"%s (index %s) : %s \n %s", $docName, $index, print_r($resultData,
true) , $outFile));
92 $this->assertEquals(preg_match(
'/' .
$value .
'/', $resultData[$docName][$index]) , 1, sprintf(
"expected \"%s\" %s (index %s) : %s \n %s",
$value, $docName, $index, print_r($resultData,
true) , $outFile));
102 $outFile = tempnam(
getTmpDir() ,
'tstexport');
104 $s->setObjectReturn();
107 $this->assertEmpty(
$s->searchError() , sprintf(
"Error in search %s", print_r(
$s->getSearchInfo() ,
true)));
109 $ec = new \Dcp\ExportCollection();
111 $ec->setOutputFilePath($outFile);
113 $ec->setDocumentlist(
$s->getDocumentList());
116 $this->assertTrue(filesize($outFile) > 0, sprintf(
"\"%s\" file not produced", $outFile));
118 $dom = new \DOMDocument();
119 $dom->load($outFile);
128 $outFile = tempnam(
getTmpDir() ,
'tstexport');
130 $s->setObjectReturn();
133 $this->assertEmpty(
$s->searchError() , sprintf(
"Error in search %s", print_r(
$s->getSearchInfo() ,
true)));
135 $ec = new \Dcp\ExportCollection();
137 $ec->setOutputFilePath($outFile);
139 $ec->setDocumentlist(
$s->getDocumentList());
142 $this->assertTrue(filesize($outFile) > 0, sprintf(
"\"%s\" file not produced", $outFile));
144 $outDir = tempnam(
getTmpDir() ,
'tstextract');
145 if (is_file($outDir)) {
149 $zip = new \ZipArchive;
150 $res = $zip->open($outFile);
152 $this->assertTrue($res, sprintf(
"\"%s\" cannot unarchive", $outFile));
153 for ($i = 0; $i < $zip->numFiles; $i++) {
154 $stat = $zip->statIndex($i);
155 if (preg_match(
"/" .
$file .
"/", basename($stat[
'name']))) {
156 $file = $stat[
'name'];
161 $zip->extractTo($outDir, array(
166 $xmlFile = sprintf(
"%s/%s", $outDir,
$file);
167 $this->assertTrue(is_file($xmlFile) , sprintf(
"\"%s\" zip content not found", $xmlFile));
169 $dom = new \DOMDocument();
170 $dom->load($xmlFile);
175 protected function XPathTesting(\DOMDocument $dom, array $expectedValues)
178 $xp = new \DOMXpath($dom);
180 $entries = $xp->query(
$path);
182 $foundValues = array();
184 foreach ($entries as $entry) {
185 if ($entry->nodeValue ==
$value) {
188 $foundValues[] = $entry->nodeValue;
190 $this->assertEquals(
$value, $foundValues, sprintf(
"Item \"%s\" not found in %s path, found \n\t%s\n", print_r(
$value,
true) ,
$path, implode(
"\n\t", $foundValues)));
192 foreach ($entries as $entry) {
193 if ($entry->nodeValue ==
$value) $found++;
194 $foundValues[] = $entry->nodeValue;
196 $this->assertGreaterThan(0, $found, sprintf(
"Item \"%s\" not found in %s path, found \n\t%s\n",
$value,
$path, implode(
"\n\t", $foundValues)));
208 $outFile = tempnam(
getTmpDir() ,
'tstexport');
210 $s->setObjectReturn();
213 $this->assertEmpty(
$s->searchError() , sprintf(
"Error in search %s", print_r(
$s->getSearchInfo() ,
true)));
215 $ec = new \Dcp\ExportCollection();
217 $ec->setCvsEnclosure($enclosure);
218 $ec->setCvsSeparator($separator);
219 $ec->setOutputFilePath($outFile);
220 $ec->setDocumentlist(
$s->getDocumentList());
221 $ec->setExportProfil(
true);
223 $this->assertTrue(filesize($outFile) > 0, sprintf(
"\"%s\" file not produced", $outFile));
224 $results = fopen($outFile,
"r");
225 $resultData = array();
226 while ((
$data = fgetcsv($results, 1000, $separator, $enclosure)) !== FALSE) {
227 if (
$data[0] ===
"PROFIL") {
229 $resultData[$docName] =
$data;
233 foreach ($expectedData as $docName => $docValues) {
234 $this->assertTrue(isset($resultData[$docName]) , sprintf(
"%s document not found : %s", $docName, print_r($resultData,
true)));
235 foreach ($docValues as $index =>
$value) {
236 $this->assertEquals(
$value, $resultData[$docName][$index], sprintf(
"%s (index %s) : %s", $docName, $index, print_r($resultData,
true)));
248 $outFile = tempnam(
getTmpDir() ,
'tstexportfile');
250 $s->setObjectReturn();
253 $this->assertEmpty(
$s->searchError() , sprintf(
"Error in search %s", print_r(
$s->getSearchInfo() ,
true)));
255 $ec = new \Dcp\ExportCollection();
257 $ec->setCvsEnclosure($enclosure);
258 $ec->setCvsSeparator($separator);
259 $ec->setOutputFilePath($outFile);
260 $ec->setDocumentlist(
$s->getDocumentList());
261 $ec->setExportFiles(
true);
263 $this->assertTrue(filesize($outFile) > 0, sprintf(
"\"%s\" file not produced", $outFile));
265 $outDir = tempnam(
getTmpDir() ,
'tstextract');
266 if (is_file($outDir)) {
270 $zip = new \ZipArchive;
271 $res = $zip->open($outFile);
273 $this->assertTrue($res, sprintf(
"\"%s\" cannot unarchive", $outFile));
274 for ($i = 0; $i < $zip->numFiles; $i++) {
275 $stat = $zip->statIndex($i);
276 if (preg_match(
"/" .
$file .
"/", basename($stat[
'name']))) {
277 $file = $stat[
'name'];
282 $zip->extractTo($outDir, array(
287 $contentFile = sprintf(
"%s/%s", $outDir,
$file);
288 $this->assertTrue(is_file($contentFile) , sprintf(
"\"%s\" zip content not found", $contentFile));
290 $this->
verifyCsvContains($contentFile, $separator, $enclosure, $expectedData, 2);
300 $outFile = tempnam(
getTmpDir() ,
'tstexport');
302 $s->setObjectReturn();
305 $this->assertEmpty(
$s->searchError() , sprintf(
"Error in search %s", print_r(
$s->getSearchInfo() ,
true)));
307 $ec = new \Dcp\ExportCollection();
309 $ec->setCvsEnclosure($enclosure);
310 $ec->setCvsSeparator($separator);
311 $ec->setOutputFilePath($outFile);
312 $ec->setDocumentlist(
$s->getDocumentList());
315 $this->assertTrue(filesize($outFile) > 0, sprintf(
"\"%s\" file not produced", $outFile));
327 "TST_EXPCOLL_DOC1" => array(
337 "TST_EXPCOLL_DOC2" => array(
345 11 =>
"TST_EXPCOLL_DOC1"
347 "TST_EXPCOLL_DOC3" => array(
349 11 =>
"TST_EXPCOLL_DOC1\nTST_EXPCOLL_DOC2"
363 "TST_EXPCOLL_DOC1" => array(
373 "TST_EXPCOLL_DOC2" => array(
381 13 =>
"TST_EXPCOLL_DOC1"
383 "TST_EXPCOLL_DOC3" => array(
385 13 =>
"TST_EXPCOLL_DOC1\nTST_EXPCOLL_DOC2"
387 "TST_EXPCOLL_DOC6" => array(
389 9 =>
".*\\/Hello.txt",
403 "TST_PRF_EXPCOLL" => array(
405 4 =>
"view=uexpcoll1",
406 5 =>
"edit=uexpcoll2"
408 "TST_EXPCOLL_DOC1" => array(
409 2 =>
"TST_PRF_EXPCOLL"
411 "TST_EXPCOLL_DOC2" => array(
412 2 =>
"TST_PRF_EXPCOLL"
414 "TST_EXPCOLL_DOC3" => array(
415 2 =>
"TST_PRF_EXPCOLL"
417 "TST_EXPCOLL_DOC4" => array(
418 2 =>
"TST_PRF_EXPCOLL"
420 "TST_EXPCOLL_DOC5" => array(
421 2 =>
"TST_PRF_EXPCOLL"
423 "TST_EXPCOLL_DOC6" => array(
424 2 =>
"TST_PRF_EXPCOLL"
436 "tst_frame1/tst_title" =>
"Titre 1",
437 "tst_frame1/tst_number" =>
"1",
438 "tst_frame1/tst_date" =>
"2014-02-23"
444 "tst_frame1/tst_number" =>
"2",
445 "tst_frame1/tst_date" =>
"2014-12-24"
451 "tst_frame1/tst_number" =>
"3",
452 "tst_tab_i/tst_frame2/tst_longtext" =>
"Trois long",
454 "tst_tab_i/tst_frame2/tst_array/tst_othertexts" => array(
455 "Une ligne<BR>avec retour",
467 $this->famName .
"[@name = \"TST_EXPCOLL_DOC1\"]/tst_frame1/tst_number" =>
"1",
468 $this->famName .
"[@name = \"TST_EXPCOLL_DOC1\"]/tst_frame1/tst_date" =>
"2014-02-23",
469 $this->famName .
"[@name = \"TST_EXPCOLL_DOC2\"]/tst_frame1/tst_number" =>
"2"
503 7 =>
"Titre 1\nTitre 2",
504 8 =>
"Une ligne\navec retour\nUne deuxième"
509 \Dcp\ExportCollection::csvDisplayValueOutputFormat,
558 7 =>
"TST_EXPCOLL_DOC1\nTST_EXPCOLL_DOC2",
559 8 =>
"Une ligne<BR>avec retour\nUne deuxième"
572 "TST_EXPCOLL_DOC1" => array(
582 "TST_EXPCOLL_DOC2" => array(
590 11 =>
"TST_EXPCOLL_DOC1"
592 "TST_EXPCOLL_DOC3" => array(
594 11 =>
"TST_EXPCOLL_DOC1\nTST_EXPCOLL_DOC2"
602 "TST_EXPCOLL_DOC1" => array(
611 "TST_EXPCOLL_DOC2" => array(
testExportProfilCsv($separator, $enclosure, array $expectedData)
verifyCsvContains($outFile, $separator, $enclosure, $expectedData, $columnId)
testExportDisplayCsv($format, $separator, $enclosure, array $expectedData)
const xmlArchiveOutputFormat
const xmlFileOutputFormat
testExportXmlSingle(array $expectedData)
const csvRawOnlyDataOutputFormat
testExportFamilyCsv($separator, $enclosure, array $expectedData)
static getCommonImportFile()
testExportFileCsv($separator, $enclosure, $file, array $expectedData)
testExportRawCsv($separator, $enclosure, array $expectedData)
testExportXmlArchive($file, array $xmlPathes)
XPathTesting(\DOMDocument $dom, array $expectedValues)
const csvDisplayValueOutputFormat