9 require_once
'PU_testcase_dcp.php';
16 "PU_data_dcp_exportfamilyrevision.ods"
23 parent::setUpBeforeClass();
31 $d1->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_title,
"Référence n°2");
34 $d4->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_doc_fixed,
$d1->id);
38 $d2->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_title,
"Identifiant n°2");
41 $d6->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_doc_fixed,
$d2->id);
42 $d5->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_doc_state,
$d2->id);
45 $d2->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_title,
"Identifiant n°3");
48 $d5->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_doc_fixed,
$d2->id);
52 $d5->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_doc_state, $d3->id);
53 $d3->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_title,
"Révision n°2");
56 $d3->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_title,
"Révision n°3");
59 $d6->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_doc_state, $d3->id);
62 $d3->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_title,
"Révision n°4");
65 $d6->setValue(\Dcp\AttributeIdentifiers\tst_export_revision::tst_doc_fixed, $d3->id);
79 $outFile = tempnam(
getTmpDir() ,
'tstexport');
81 $s->setObjectReturn();
84 $this->assertEmpty(
$s->searchError() , sprintf(
"Error in search %s", print_r(
$s->getSearchInfo() ,
true)));
86 $ec = new \Dcp\ExportCollection();
88 $ec->setCvsEnclosure($enclosure);
89 $ec->setCvsSeparator($separator);
90 $ec->setOutputFilePath($outFile);
91 $ec->setDocumentlist(
$s->getDocumentList());
94 $this->assertTrue(filesize($outFile) > 0, sprintf(
"\"%s\" file not produced", $outFile));
106 $outFile = tempnam(
getTmpDir() ,
'tstexport');
108 $s->setObjectReturn();
111 $this->assertEmpty(
$s->searchError() , sprintf(
"Error in search %s", print_r(
$s->getSearchInfo() ,
true)));
113 $ec = new \Dcp\ExportCollection();
116 $ec->setOutputFilePath($outFile);
117 $ec->setDocumentlist(
$s->getDocumentList());
120 $this->assertTrue(filesize($outFile) > 0, sprintf(
"\"%s\" file not produced", $outFile));
122 $dom = new \DOMDocument();
123 $dom->load($outFile);
128 protected function verifyCsvContains($outFile, $separator, $enclosure, $expectedData, $columnId)
130 $results = fopen($outFile,
"r");
131 $resultData = array();
132 while ((
$data = fgetcsv($results, 1000, $separator, $enclosure)) !== FALSE) {
133 $docName =
$data[$columnId];
134 $resultData[$docName] =
$data;
137 foreach ($expectedData as $docName => $docValues) {
138 $this->assertTrue(isset($resultData[$docName]) , sprintf(
"%s document not found : %s", $docName, print_r($resultData,
true)));
139 foreach ($docValues as $index =>
$value) {
141 if (preg_match(
"/([A-Z_0-9]+)#([0-9]+)/",
$value, $reg)) {
142 simpleQuery(
"", sprintf(
"select id from docread where name='%s' and revision=%d", pg_escape_string($reg[1]) , $reg[2]) ,
$value,
true,
true);
143 simpleQuery(
"", sprintf(
"select name, revision from docread where id=%d", $resultData[$docName][$index]) , $revName,
false,
true);
146 if (strpos(
$value,
"*") ===
false) {
147 $this->assertEquals(
$value, $resultData[$docName][$index], sprintf(
"%s (index %s : %s) : %s \n %s \n %s", $docName, $index, $docValues[$index], print_r($revName,
true) , print_r($resultData,
true) , $outFile));
149 $this->assertEquals(preg_match(
'/' .
$value .
'/', $resultData[$docName][$index]) , 1, sprintf(
"expected \"%s\" %s (index %s) : %s \n %s", $docValues[$index], $docName, $index, print_r($resultData,
true) , $outFile));
154 protected function XPathTesting(\DOMDocument $dom, array $expectedValues)
157 $xp = new \DOMXpath($dom);
159 $entries = $xp->query(
$path);
161 $foundValues = array();
163 foreach ($entries as $entry) {
164 if ($entry->nodeValue ==
$value) {
167 $foundValues[] = $entry->nodeValue;
169 $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)));
171 foreach ($entries as $entry) {
172 if ($entry->nodeValue ==
$value) $found++;
173 $foundValues[] = $entry->nodeValue;
175 $this->assertGreaterThan(0, $found, sprintf(
"Item \"%s\" not found in %s path, found \n\t%s\n",
$value,
$path, implode(
"\n\t", $foundValues)));
184 $this->famName .
"[@name = \"TST_EREV1\"]/tst_frame/tst_int" =>
"1",
185 $this->famName .
"[@name = \"TST_EREV2\"]/tst_frame/tst_int" =>
"2",
186 $this->famName .
"[@name = \"TST_EREV3\"]/tst_frame/tst_int" =>
"3",
187 $this->famName .
"[@name = \"TST_EREV4\"]/tst_frame/tst_doc_fixed[@name= \"TST_EREV1\"][@revision = \"1\"]" =>
"Référence n°2",
188 $this->famName .
"[@name = \"TST_EREV5\"]/tst_frame/tst_doc_fixed[@name= \"TST_EREV2\"][@revision = \"2\"]" =>
"Identifiant n°3",
189 $this->famName .
"[@name = \"TST_EREV6\"]/tst_frame/tst_doc_fixed[@name= \"TST_EREV3\"][@revision = \"3\"]" =>
"Révision n°4",
190 $this->famName .
"[@name = \"TST_EREV4\"]/tst_frame/tst_doc_state[@name= \"TST_EREV1\"][@revision = \"state:first\"]" =>
"Référence n°1",
191 $this->famName .
"[@name = \"TST_EREV5\"]/tst_frame/tst_doc_state[@name= \"TST_EREV3\"][@revision = \"state:first\"]" =>
"Révision n°2",
192 $this->famName .
"[@name = \"TST_EREV6\"]/tst_frame/tst_doc_state[@name= \"TST_EREV3\"][@revision = \"state:first\"]" =>
"Révision n°3",
204 "TST_EREV1" => array(
205 4 =>
"Référence n°2",
208 "TST_EREV2" => array(
209 4 =>
"Identifiant n°3",
212 "TST_EREV3" => array(
216 "TST_EREV4" => array(
223 "TST_EREV5" => array(
230 "TST_EREV6" => array(
XPathTesting(\DOMDocument $dom, array $expectedValues)
const xmlFileOutputFormat
static setUpBeforeClass()
testExportRevisionCsv($separator, $enclosure, array $expectedData)
verifyCsvContains($outFile, $separator, $enclosure, $expectedData, $columnId)
testExportRevisionXml(array $expectedData)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
static getCommonImportFile()