Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_formatinvisiblecollection.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 namespace Dcp\Pu;
8 /**
9  * @author Anakeen
10  * @package Dcp\Pu
11  */
12 
13 require_once 'PU_testcase_dcp_commonfamily.php';
15 {
16  /**
17  * import TST_FMTCOL
18  * @static
19  * @return string
20  */
21  protected static function getCommonImportFile()
22  {
23  return array(
24  "PU_data_dcp_invisible.ods"
25  );
26  }
27 
28  protected $famName = 'tst_invisiblefamily1';
29  /**
30  * @dataProvider dataRenderInvisibleCollection
31  */
32  public function testRenderInvisibleCollection($login, $docName, array $expectedValues)
33  {
34  $this->sudo($login);
35  $s = new \SearchDoc(self::$dbaccess, $this->famName);
36  $s->setObjectReturn();
37  $dl = $s->search()->getDocumentList();
38 
39  $fc = new \FormatCollection();
40  $fc->useCollection($dl);
41  $fc->relationNoAccessText = 'no grant';
42  $fc->addProperty($fc::propName);
43  foreach ($expectedValues as $aid => $value) {
44  $fc->addAttribute($aid);
45  }
46 
47  $r = $fc->render();
48  foreach ($expectedValues as $aid => $value) {
49  $this->assertTrue($this->getRenderValue($r, $docName, $aid) !== null, "$aid not found");
50  $this->assertEquals($value, $this->getRenderValue($r, $docName, $aid)->displayValue, sprintf("%s [%s]<>\n%s", $aid, $value, print_r($this->getRenderValue($r, $docName, $aid) , true)));
51  }
52  $this->exitSudo();
53  }
54  /**
55  * @dataProvider dataRenderNoVerifyAccessCollection
56  */
57  public function testRenderNoVerifyAccessCollection($login, $docName, array $expectedValues)
58  {
59  $this->sudo($login);
60  $s = new \SearchDoc(self::$dbaccess, $this->famName);
61  $s->setObjectReturn();
62  $dl = $s->search()->getDocumentList();
63 
64  $fc = new \FormatCollection();
65  $fc->setVerifyAttributeAccess(false);
66  $fc->useCollection($dl);
67  $fc->relationNoAccessText = 'no grant';
68  $fc->addProperty($fc::propName);
69  foreach ($expectedValues as $aid => $value) {
70  $fc->addAttribute($aid);
71  }
72 
73  $r = $fc->render();
74  foreach ($expectedValues as $aid => $value) {
75  $this->assertTrue($this->getRenderValue($r, $docName, $aid) !== null, "$aid not found");
76  $this->assertEquals($value, $this->getRenderValue($r, $docName, $aid)->displayValue, sprintf("%s [%s]<>\n%s", $aid, $value, print_r($this->getRenderValue($r, $docName, $aid) , true)));
77  }
78  $this->exitSudo();
79  }
80  /**
81  * @dataProvider dataExportNoVerifyAccessCollection
82  */
83  public function testExportNoVerifyAccessCollection($login, array $expectedValues)
84  {
85  $this->sudo($login);
86 
87  $outFile = tempnam(getTmpDir() , 'tstexport');
88  $s = new \SearchDoc(self::$dbaccess, $this->famName);
89  $s->setObjectReturn();
90  $dl = $s->search()->getDocumentList();
91 
92  $ec = new \Dcp\ExportCollection();
93  $ec->setVerifyAttributeAccess(false);
94  $ec->setDocumentlist($dl);
95  $separator = ',';
96  $enclosure = '"';
97  $ec->setCvsEnclosure($enclosure);
98  $ec->setCvsSeparator($separator);
99  $ec->setOutputFilePath($outFile);
100  $ec->export();
101 
102  $this->verifyCsvContains($outFile, $separator, $enclosure, $expectedValues, 2);
103 
104  $this->exitSudo();
105  }
106  /**
107  * @dataProvider dataExportVerifyAccessCollection
108  */
109  public function testExportVerifyAccessCollection($login, array $expectedValues)
110  {
111  $this->sudo($login);
112 
113  $outFile = tempnam(getTmpDir() , 'tstexport');
114  $s = new \SearchDoc(self::$dbaccess, $this->famName);
115  $s->setObjectReturn();
116  $dl = $s->search()->getDocumentList();
117 
118  $ec = new \Dcp\ExportCollection();
119  $ec->setVerifyAttributeAccess(true);
120  $ec->setDocumentlist($dl);
121  $separator = ',';
122  $enclosure = '"';
123  $ec->setCvsEnclosure($enclosure);
124  $ec->setCvsSeparator($separator);
125  $ec->setOutputFilePath($outFile);
126  $ec->export();
127 
128  $this->verifyCsvContains($outFile, $separator, $enclosure, $expectedValues, 2);
129 
130  $this->exitSudo();
131  }
132 
133  protected function verifyCsvContains($outFile, $separator, $enclosure, $expectedData, $columnId)
134  {
135  $results = fopen($outFile, "r");
136  $resultData = array();
137  while (($data = fgetcsv($results, 1000, $separator, $enclosure)) !== FALSE) {
138 
139  $docName = $data[$columnId];
140  $resultData[$docName] = $data;
141  }
142  fclose($results);
143  foreach ($expectedData as $docName => $docValues) {
144  $this->assertTrue(isset($resultData[$docName]) , sprintf("%s document not found : %s", $docName, print_r($resultData, true)));
145  foreach ($docValues as $index => $value) {
146  if (strpos($value, "*") === false) {
147  $this->assertEquals($value, $resultData[$docName][$index], sprintf("%s (index %s) : %s \n %s", $docName, $index, print_r($resultData, true) , $outFile));
148  } else {
149  $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));
150  }
151  }
152  }
153  }
154  /**
155  * @dataProvider dataExportXmlSingle
156  */
157  public function testExportXmlSingle($login, array $expectedData)
158  {
159  $this->sudo($login);
160  $outFile = tempnam(getTmpDir() , 'tstexport');
161  $s = new \SearchDoc(self::$dbaccess, $this->famName);
162  $s->setObjectReturn();
163  $s->search();
164 
165  $this->assertEmpty($s->searchError() , sprintf("Error in search %s", print_r($s->getSearchInfo() , true)));
166 
167  $ec = new \Dcp\ExportCollection();
168 
169  $ec->setOutputFilePath($outFile);
170  $ec->setOutputFormat(\Dcp\ExportCollection::xmlFileOutputFormat);
171  $ec->setDocumentlist($s->getDocumentList());
172  $ec->setVerifyAttributeAccess(true);
173  $ec->export();
174 
175  $this->assertTrue(filesize($outFile) > 0, sprintf("\"%s\" file not produced", $outFile));
176 
177  $dom = new \DOMDocument();
178  $dom->load($outFile);
179 
180  $this->XPathTesting($dom, $expectedData);
181  $this->exitSudo();
182  }
183  protected function XPathTesting(\DOMDocument $dom, array $expectedValues)
184  {
185 
186  $xp = new \DOMXpath($dom);
187  foreach ($expectedValues as $path => $value) {
188  $entries = $xp->query($path);
189  $found = 0;
190  $foundValues = array();
191 
192  foreach ($entries as $entry) {
193  if ($entry->nodeValue == $value) $found++;
194  $foundValues[] = $entry->nodeValue;
195  }
196  $this->assertGreaterThan(0, $found, sprintf("Item \"%s\" not found in %s path, found \n\t%s\n", $value, $path, implode("\n\t", $foundValues)));
197  }
198  }
199  /**
200  * @param array $r
201  * @param $docName
202  * @param $attrName
203  * @return \StandardAttributeValue
204  */
205  private function getRenderValue(array $r, $docName, $attrName)
206  {
207  foreach ($r as $format) {
208  if ($format["properties"]["name"] == $docName) {
209  if ($format["attributes"][$attrName] === null) {
210  return new \StandardAttributeValue("", null);
211  } else {
212  return $format["attributes"][$attrName];
213  }
214  }
215  }
216  return null;
217  }
218 
219  public function dataExportXmlSingle()
220  {
221  return array(
222  array(
223  "uinvisible_1",
224  array(
225  $this->famName . '[@name = "TST_INVISIBLE_DOC1"]/tst_frame1/tst_number' => "1",
226  $this->famName . '[@name = "TST_INVISIBLE_DOC1"]/tst_frame1/tst_text[@granted = "false"]' => "",
227  $this->famName . '[@name = "TST_INVISIBLE_DOC1"]/tst_tab_i/tst_frame2/tst_decimal[@granted = "false"]' => "",
228 
229  $this->famName . '[@name = "TST_INVISIBLE_DOC2"]/tst_frame1/tst_number[@granted = "false"]' => "",
230  $this->famName . '[@name = "TST_INVISIBLE_DOC2"]/tst_frame1/tst_text[@granted = "false"]' => "",
231  $this->famName . '[@name = "TST_INVISIBLE_DOC2"]/tst_tab_i/tst_frame2/tst_decimal' => "2.2",
232 
233  $this->famName . '[@name = "TST_INVISIBLE_DOC3"]/tst_frame1/tst_number' => "3",
234  $this->famName . '[@name = "TST_INVISIBLE_DOC3"]/tst_frame1/tst_text[@granted = "false"]' => "",
235  $this->famName . '[@name = "TST_INVISIBLE_DOC3"]/tst_tab_i/tst_frame2/tst_decimal[@granted = "false"]' => "",
236  )
237  ) ,
238  array(
239  "uinvisible_2",
240  array(
241 
242  $this->famName . '[@name = "TST_INVISIBLE_DOC3"]/tst_frame1/tst_number[@granted = "false"]' => "",
243  $this->famName . '[@name = "TST_INVISIBLE_DOC3"]/tst_frame1/tst_text[@granted = "false"]' => "",
244  $this->famName . '[@name = "TST_INVISIBLE_DOC3"]/tst_tab_i/tst_frame2/tst_decimal' => "3.3",
245  )
246  )
247  );
248  }
249 
251  {
252  return array(
253  array(
254  "uinvisible_1",
255  array(
256  "TST_INVISIBLE_DOC1" => array(
257  4 => "Titre 1", // title
258  5 => "1", // number
259  6 => \FormatCollection::noAccessText, // text
260  7 => \FormatCollection::noAccessText, // decimal
261  8 => \FormatCollection::noAccessText, // longtext
263  // docid
264 
265  ) ,
266  "TST_INVISIBLE_DOC2" => array(
267  4 => "Titre 2",
270  7 => "2.2",
271  8 => "Deux long",
272  9 => "TST_INVISIBLE_DOC1"
273  ) ,
274  "TST_INVISIBLE_DOC3" => array(
275  4 => "Titre 3",
276  5 => "3", // number
277  6 => \FormatCollection::noAccessText, // text
278  7 => \FormatCollection::noAccessText, // decimal
280  // longtext
281 
282  )
283  )
284  )
285  );
286  }
288  {
289  return array(
290  array(
291  "uinvisible_1",
292  array(
293  "TST_INVISIBLE_DOC1" => array(
294  4 => "Titre 1",
295  5 => "1",
296  6 => "Un",
297  7 => "1.1",
298  8 => "Un long"
299  ) ,
300  "TST_INVISIBLE_DOC2" => array(
301  4 => "Titre 2",
302  5 => "2",
303  6 => "Deux",
304  7 => "2.2",
305  8 => "Deux long",
306  9 => "TST_INVISIBLE_DOC1"
307  ) ,
308  "TST_INVISIBLE_DOC3" => array(
309  4 => "Titre 3",
310  9 => "TST_INVISIBLE_DOC1\nTST_INVISIBLE_DOC2"
311  )
312  )
313  )
314  );
315  }
316 
318  {
319  return array(
320  array( // MASK TST_INVMASK_E1
321  "uinvisible_1",
322  "TST_INVISIBLE_DOC1",
323  array(
324  "tst_title" => "Titre 1",
325  "tst_text" => \FormatCollection::noAccessText,
326  "tst_number" => "1",
327  "tst_longtext" => \FormatCollection::noAccessText,
328  "tst_decimal" => \FormatCollection::noAccessText,
329  "tst_docid" => \FormatCollection::noAccessText
330  )
331  ) ,
332  array( // MASK TST_INVMASK_E2
333  "uinvisible_1",
334  "TST_INVISIBLE_DOC2",
335  array(
336  "tst_title" => "Titre 2",
337  "tst_text" => \FormatCollection::noAccessText,
338  "tst_number" => \FormatCollection::noAccessText,
339  "tst_longtext" => "Deux long",
340  "tst_decimal" => "2,2"
341  )
342  ) ,
343  array( // MASK TST_INVMASK_E1
344  "uinvisible_1",
345  "TST_INVISIBLE_DOC3",
346  array(
347  "tst_title" => "Titre 3",
348  "tst_text" => \FormatCollection::noAccessText,
349  "tst_number" => "3",
350  "tst_longtext" => \FormatCollection::noAccessText,
351  "tst_decimal" => \FormatCollection::noAccessText
352  )
353  ) ,
354  array( // MASK TST_INVMASK_E1
355  "uinvisible_1",
356  "TST_INVISIBLE_DOC4",
357  array(
358  "tst_title" => "Titre 4",
359  "tst_text" => \FormatCollection::noAccessText,
360  "tst_number" => "4",
361  "tst_longtext" => \FormatCollection::noAccessText,
362  "tst_decimal" => \FormatCollection::noAccessText
363  )
364  ) ,
365  array( // MASK TST_INVMASK_E1
366  "uinvisible_1",
367  "TST_INVISIBLE_DOC5",
368  array(
369  "tst_title" => "Titre 5",
370  "tst_text" => \FormatCollection::noAccessText,
371  "tst_number" => \FormatCollection::noAccessText,
372  "tst_longtext" => \FormatCollection::noAccessText,
373  "tst_decimal" => \FormatCollection::noAccessText
374  )
375  ) ,
376  array( // MASK TST_INVMASK_E2
377  "uinvisible_2",
378  "TST_INVISIBLE_DOC3",
379  array(
380  "tst_title" => "Titre 3",
381  "tst_text" => \FormatCollection::noAccessText,
382  "tst_number" => \FormatCollection::noAccessText,
383  "tst_longtext" => "Trois long",
384  "tst_decimal" => "3,3"
385  )
386  ) ,
387  array( // MASK TST_INVMASK_E2
388  "uinvisible_2",
389  "TST_INVISIBLE_DOC4",
390  array(
391  "tst_title" => "Titre 4",
392  "tst_text" => \FormatCollection::noAccessText,
393  "tst_number" => \FormatCollection::noAccessText,
394  "tst_longtext" => "Quatre long",
395  "tst_decimal" => "4,4"
396  )
397  ) ,
398  array( // MASK TST_INVMASK_E1
399  "uinvisible_3",
400  "TST_INVISIBLE_DOC3",
401  array(
402  "tst_title" => "Titre 3",
403  "tst_text" => \FormatCollection::noAccessText,
404  "tst_number" => "3",
405  "tst_longtext" => \FormatCollection::noAccessText,
406  "tst_decimal" => \FormatCollection::noAccessText
407  )
408  ) ,
409  array( // MASK TST_INVMASK_E4
410  "uinvisible_3",
411  "TST_INVISIBLE_DOC4",
412  array(
413  "tst_title" => "Titre 4",
414  "tst_text" => "Quatre",
415  "tst_number" => "4",
416  "tst_longtext" => "Quatre long",
417  "tst_decimal" => "4,4"
418  )
419  ) ,
420  array( // no mask
421  "uinvisible_4",
422  "TST_INVISIBLE_DOC3",
423  array(
424  "tst_title" => "Titre 3",
425  "tst_text" => \FormatCollection::noAccessText,
426  "tst_number" => \FormatCollection::noAccessText,
427  "tst_longtext" => \FormatCollection::noAccessText,
428  "tst_decimal" => \FormatCollection::noAccessText
429  )
430  ) ,
431  array( // MASK TST_INVMASK_E4
432  "uinvisible_4",
433  "TST_INVISIBLE_DOC4",
434  array(
435  "tst_title" => "Titre 4",
436  "tst_text" => "Quatre",
437  "tst_number" => "4",
438  "tst_longtext" => "Quatre long",
439  "tst_decimal" => "4,4"
440  )
441  )
442  );
443  }
444 
446  {
447  return array(
448  array( // MASK TST_INVMASK_E1
449  "uinvisible_1",
450  "TST_INVISIBLE_DOC1",
451  array(
452  "tst_title" => "Titre 1",
453  "tst_text" => "Un",
454  "tst_number" => "1",
455  "tst_longtext" => "Un long",
456  "tst_decimal" => "1,1"
457  )
458  ) ,
459  array( // MASK TST_INVMASK_E2
460  "uinvisible_1",
461  "TST_INVISIBLE_DOC2",
462  array(
463  "tst_title" => "Titre 2",
464  "tst_text" => "Deux",
465  "tst_number" => "2",
466  "tst_longtext" => "Deux long",
467  "tst_decimal" => "2,2"
468  )
469  ) ,
470  array( // MASK TST_INVMASK_E1
471  "uinvisible_1",
472  "TST_INVISIBLE_DOC3",
473  array(
474  "tst_title" => "Titre 3",
475  "tst_text" => "Trois",
476  "tst_number" => "3",
477  "tst_longtext" => "Trois long",
478  "tst_decimal" => "3,3"
479  )
480  ) ,
481  array( // MASK TST_INVMASK_E1
482  "uinvisible_1",
483  "TST_INVISIBLE_DOC4",
484  array(
485  "tst_title" => "Titre 4",
486  "tst_text" => "Quatre",
487  "tst_number" => "4",
488  "tst_longtext" => "Quatre long",
489  "tst_decimal" => "4,4"
490  )
491  ) ,
492  array( // MASK TST_INVMASK_E1
493  "uinvisible_1",
494  "TST_INVISIBLE_DOC5",
495  array(
496  "tst_title" => "Titre 5",
497  "tst_text" => "Cinq",
498  "tst_number" => "5",
499  "tst_longtext" => "Cinq long",
500  "tst_decimal" => "5,5"
501  )
502  ) ,
503  array( // MASK TST_INVMASK_E2
504  "uinvisible_2",
505  "TST_INVISIBLE_DOC3",
506  array(
507  "tst_title" => "Titre 3",
508  "tst_text" => "Trois",
509  "tst_number" => "3",
510  "tst_longtext" => "Trois long",
511  "tst_decimal" => "3,3"
512  )
513  ) ,
514  array( // MASK TST_INVMASK_E2
515  "uinvisible_2",
516  "TST_INVISIBLE_DOC4",
517  array(
518  "tst_title" => "Titre 4",
519  "tst_text" => "Quatre",
520  "tst_number" => "4",
521  "tst_longtext" => "Quatre long",
522  "tst_decimal" => "4,4"
523  )
524  ) ,
525  array( // MASK TST_INVMASK_E1
526  "uinvisible_3",
527  "TST_INVISIBLE_DOC3",
528  array(
529  "tst_title" => "Titre 3",
530  "tst_text" => "Trois",
531  "tst_number" => "3",
532  "tst_longtext" => "Trois long",
533  "tst_decimal" => "3,3"
534  )
535  ) ,
536  array( // MASK TST_INVMASK_E4
537  "uinvisible_3",
538  "TST_INVISIBLE_DOC4",
539  array(
540  "tst_title" => "Titre 4",
541  "tst_text" => "Quatre",
542  "tst_number" => "4",
543  "tst_longtext" => "Quatre long",
544  "tst_decimal" => "4,4"
545  )
546  ) ,
547  array( // no mask
548  "uinvisible_4",
549  "TST_INVISIBLE_DOC3",
550  array(
551  "tst_title" => "Titre 3",
552  "tst_text" => "Trois",
553  "tst_number" => "3",
554  "tst_longtext" => "Trois long",
555  "tst_decimal" => "3,3"
556  )
557  ) ,
558  array( // MASK TST_INVMASK_E4
559  "uinvisible_4",
560  "TST_INVISIBLE_DOC4",
561  array(
562  "tst_title" => "Titre 4",
563  "tst_text" => "Quatre",
564  "tst_number" => "4",
565  "tst_longtext" => "Quatre long",
566  "tst_decimal" => "4,4"
567  )
568  )
569  );
570  }
571 }
572 ?>
static sudo($login)
XPathTesting(\DOMDocument $dom, array $expectedValues)
if($famId) $s
testRenderNoVerifyAccessCollection($login, $docName, array $expectedValues)
testExportNoVerifyAccessCollection($login, array $expectedValues)
$path
Definition: dav.php:39
$login
Definition: dav.php:40
verifyCsvContains($outFile, $separator, $enclosure, $expectedData, $columnId)
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
$dbaccess
Definition: checkVault.php:17
testRenderInvisibleCollection($login, $docName, array $expectedValues)
$value
$data
← centre documentaire © anakeen