Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_ooosimplelayout.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_document.php';
14 
16 {
17  protected static $outputDir;
18 
19  protected function tearDown()
20  {
21  }
22 
23  protected function setUp()
24  {
25  }
26 
27  public static function setUpBeforeClass()
28  {
29  parent::setUpBeforeClass();
30  // self::$outputDir = uniqid(getTmpDir() . "/oootest-");
31  self::$outputDir = (getTmpDir() . "/oootest");
32  if (!is_dir(self::$outputDir)) mkdir(self::$outputDir);
33  self::connectUser();
34  self::beginTransaction();
35 
36  self::importDocument("PU_data_dcp_oooSimpleLayout.ods");
37  self::importDocument("PU_data_dcp_oooSimpleLayout.xml");
38  // replace real img reference into document testing
39  $img = new_doc(self::$dbaccess, "TST_HTMLIMAGE");
40  self::assertTrue($img->isAlive() , "no found reference image");
41 
42  $htmlImage = new_doc(self::$dbaccess, "TST_OOOS5");
43  self::assertTrue($htmlImage->isAlive() , "no found reference html");
44  $imgInfo = $img->getFileInfo($img->getRawValue("img_file"));
45  $htmlImage->setValue("tst_html", str_replace("1234567", $imgInfo["id_file"], $htmlImage->getRawValue("tst_html")));
46  $htmlImage->modify();
47  }
48 
49  public static function tearDownAfterClass()
50  {
51  self::rollbackTransaction();
52  TestSuiteDcp::addMessage(sprintf("Results for %s in file://%s", __CLASS__, self::$outputDir));
53  }
54 
55  protected function saveFileResult($file, $name)
56  {
57  copy($file, self::$outputDir . '/' . $name);
58  }
59 
60  protected function extractFile($docName, $template, $extractName)
61  {
62  $doc = new_doc(self::$dbaccess, $docName);
63  $this->assertTrue($doc->isAlive() , sprintf("document %s is not alive", $docName));
64 
65  $file = $doc->viewDoc("DCPTEST:" . $template . ":B");
66  $this->assertTrue(file_exists($file) , "fail layout $template");
67 
68  $copyFileName = sprintf("%s_%s.odt", str_replace('.odt', '', $template) , $docName);
69  $this->saveFileResult($file, $copyFileName);
70 
71  $cmd = sprintf('cd %s;rm -f %s;unzip -q %s %s', self::$outputDir, $extractName, $copyFileName, $extractName);
72 
73  system($cmd, $status);
74  $this->assertEquals(0, $status);
75  $extractFile = sprintf('%s/%s', self::$outputDir, $extractName);
76  return $extractFile;
77  }
78 
79  protected function XPathTesting(\DOMDocument $dom, array $expectedValues)
80  {
81 
82  $xp = new \DOMXpath($dom);
83  foreach ($expectedValues as $pathValue) {
84  list($path, $value) = $pathValue;
85  $entries = $xp->query($path);
86  $found = 0;
87  $foundValues = array();
88  foreach ($entries as $entry) {
89  if ($entry->nodeValue == $value) $found++;
90  $foundValues[] = $entry->nodeValue;
91  }
92 
93  $this->assertGreaterThan(0, $found, sprintf("Item \"%s\" not found in %s path, found \n\t%s\n", print_r($value, true) , $path, implode("\n\t", $foundValues)));
94  }
95  }
96  /**
97  * @dataProvider dataContent
98  * @param string $docName
99  * @param string $template
100  * @param array $expectedValues
101  */
102  public function testContent($docName, $template, array $expectedValues)
103  {
104 
105  $contentFile = $this->extractFile($docName, $template, 'content.xml');
106  $dom = new \DOMDocument();
107  $dom->load($contentFile);
108  $this->XPathTesting($dom, $expectedValues);
109  }
110  /**
111  * @dataProvider dataMeta
112  * @param string $docName
113  * @param string $template
114  * @param array $expectedValues
115  */
116  public function testMeta($docName, $template, array $expectedValues)
117  {
118 
119  $metaFile = $this->extractFile($docName, $template, 'meta.xml');
120  $dom = new \DOMDocument();
121  $dom->load($metaFile);
122  $this->XPathTesting($dom, $expectedValues);
123  }
124 
125  public function dataMeta()
126  {
127  return array(
128  array(
129  "TST_OOOS1",
130  "PU_dcp_data_simple1.odt",
131  array(
132  array(
133  "office:meta//dc:title",
134  "First Test"
135  ) ,
136  array(
137  "office:meta//meta:keyword",
138  "40.00 %"
139  )
140  )
141  ) ,
142  array(
143  "TST_OOOS2",
144  "PU_dcp_data_simple1.odt",
145  array(
146  array(
147  "office:meta//dc:title",
148  "Second Test"
149  ) ,
150  array(
151  "office:meta//meta:keyword",
152  "3.14 %"
153  )
154  )
155  )
156  );
157  }
158 
159  public function dataContent()
160  {
161  return array(
162  array(
163  "TST_OOOS1",
164  "PU_dcp_data_simple1.odt",
165  array(
166  array(
167  "office:body/office:text/text:p/text:span",
168  "First Test"
169  ) ,
170  array(
171  "office:body/office:text/text:p/text:span",
172  "40.00 %"
173  ) ,
174  array(
175  "office:body/office:text/text:p/text:span",
176  "rouge"
177  ) ,
178  array(
179  "office:body/office:text/text:section//text:span",
180  "Bold"
181  ) ,
182  array(
183  "office:body/office:text/text:section//text:span[@text:style-name='Tbold']",
184  "Bold"
185  )
186  )
187  ) ,
188  array(
189  "TST_OOOS2",
190  "PU_dcp_data_simple1.odt",
191  array(
192  array(
193  "office:body/office:text/text:p/text:span",
194  "Second Test"
195  ) ,
196  array(
197  "office:body/office:text/text:p/text:span",
198  "3.14 %"
199  ) ,
200  array(
201  "office:body/office:text/text:p/text:span",
202  "jaune"
203  ) ,
204  array(
205  "office:body/office:text/text:section//text:span",
206  "Italique"
207  ) ,
208  array(
209  "office:body/office:text/text:section//text:span[@text:style-name='Titalics']",
210  "Italique"
211  ) ,
212  array(
213  "office:body//table:table/table:table-row[1]/table:table-cell[1]//text:p/text:span",
214  "Html colonne"
215  ) , // first row
216  array(
217  "office:body//table:table/table:table-row[1]/table:table-cell[2]//text:p/text:span",
218  "Texte colonne"
219  ) ,
220  array(
221  "office:body//table:table/table:table-row[2]/table:table-cell[1]//text:section/text:p/text:span[@text:style-name='Tbold']",
222  "Bold one"
223  ) ,
224  array(
225  "office:body//table:table/table:table-row[3]/table:table-cell[1]//text:section/text:p/text:span[@text:style-name='Titalics']",
226  "Italique two"
227  ) , // second row (after header row)
228  array(
229  "office:body//table:table/table:table-row[4]/table:table-cell[1]//text:section/text:p/text:span[@text:style-name='Punderline']",
230  "Underline three"
231  ) ,
232  array(
233  "office:body//table:table/table:table-row[5]/table:table-cell[1]//text:section/text:p/text:span[@text:style-name='Tbold']",
234  "bold four"
235  ) ,
236  array(
237  "office:body//table:table/table:table-row[5]/table:table-cell[1]//text:section/text:p/text:span[@text:style-name='Titalics']",
238  "italic four"
239  ) ,
240  array(
241  "office:body//table:table/table:table-row[5]/table:table-cell[1]//text:section/text:p/text:span[@text:style-name='Punderline']",
242  "underline four"
243  ) ,
244  array(
245  "office:body//table:table/table:table-row[2]/table:table-cell[2]//text:p/text:span",
246  "Column one"
247  ) ,
248  array(
249  "office:body//table:table/table:table-row[3]/table:table-cell[2]//text:p/text:span",
250  "Column two"
251  ) ,
252  array(
253  "office:body//table:table/table:table-row[4]/table:table-cell[2]//text:p/text:span",
254  "Column 'three"
255  ) ,
256  array(
257  "office:body//table:table/table:table-row[5]/table:table-cell[2]//text:p/text:span",
258  "Column <four>"
259  )
260  )
261  ) ,
262  array(
263  "TST_OOOS3",
264  "PU_dcp_data_simple1.odt",
265  array(
266  array(
267  "office:body/office:text/text:p/text:span",
268  '$Third Test$'
269  ) ,
270  array(
271  "office:body/office:text/text:p/text:span",
272  "42.00 %"
273  ) ,
274  array(
275  "office:body/office:text/text:p/text:span",
276  "rouge"
277  ) ,
278  array(
279  "office:body/office:text/text:section//text:span",
280  "Bold"
281  ) ,
282  array(
283  "office:body/office:text/text:section//text:span[@text:style-name='Tbold']",
284  "Bold"
285  )
286  )
287  ) ,
288  array(
289  "TST_OOOS4",
290  "PU_dcp_data_simple1.odt",
291  array(
292  array(
293  "office:body//table:table/table:table-row[1]/table:table-cell[1]//text:p/text:span",
294  "Html colonne"
295  ) ,
296  array(
297  "office:body//table:table/table:table-row[2]/table:table-cell[1]//text:section/text:p",
298  "C'est un test <<\"hivers\" & \"été\">>"
299  )
300  )
301  ) ,
302  array(
303  "TST_OOOS5",
304  "PU_dcp_data_simple1.odt",
305  array(
306  array(
307  "office:body/office:text/text:section/text:p",
308  "Texte"
309  ) ,
310  array(
311  "office:body/office:text/text:section/text:p/draw:frame[@draw:name='htmlgraphic']",
312  ""
313  ) ,
314  array(
315  "office:body/office:text/text:section/text:p/draw:frame[@svg:width='20mm']",
316  ""
317  ) ,
318  array(
319  "office:body/office:text/text:section/text:p/draw:frame[@svg:height='30mm']",
320  ""
321  ) ,
322  array(
323  "office:body/office:text/text:section/text:p/draw:frame[@draw:name='htmlgraphic']/draw:image[contains(@xlink:href,'Pictures/dcp')]",
324  ""
325  )
326  )
327  ) ,
328  array(
329  "TST_OOOS6",
330  "PU_dcp_data_simple1.odt",
331  array(
332  array(
333  "office:body/office:text/text:section/text:p",
334  "Débutet fin."
335  ) ,
336  array(
337  "office:body/office:text/text:section/text:p/draw:frame[@draw:name='htmlgraphic']",
338  ""
339  ) ,
340  array(
341  "office:body/office:text/text:section/text:p/draw:frame[@svg:width='48mm']",
342  ""
343  ) ,
344  array(
345  "office:body/office:text/text:section/text:p/draw:frame[@svg:height='35mm']",
346  ""
347  ) ,
348  array(
349  "office:body/office:text/text:section/text:p/draw:frame[@draw:name='htmlgraphic']/draw:image[contains(@xlink:href,'Pictures/dcp')]",
350  ""
351  )
352  )
353  ) ,
354  array(
355  "TST_OOOS7",
356  "PU_dcp_data_simple1.odt",
357  array(
358 
359  array(
360  "office:body/office:text/text:section//table:table[1]/table:table-row[1]//table:table-cell/text:p/draw:frame[@draw:name='htmlgraphic']",
361  ""
362  ) ,
363  array(
364  "office:body/office:text/text:section//table:table[1]/table:table-row[2]//table:table-cell/text:p/draw:frame[@draw:name='htmlgraphic']",
365  ""
366  ) ,
367  array(
368  "office:body/office:text/text:section/table:table[1]/table:table-row[1]//table:table-cell/text:p/text:span[@text:style-name='Tbold']",
369  "Gras"
370  )
371  )
372  ) ,
373  array(
374  "TST_OOOS8",
375  "PU_dcp_data_simple1.odt",
376  array(
377 
378  array(
379  "office:body/office:text/text:section//table:table[1]/table:table-row[1]//table:table-cell[1]/text:p/text:span[@text:style-name='Tbold']",
380  "GrasP"
381  ) ,
382  array(
383  "office:body/office:text/text:section//table:table[1]/table:table-row[1]//table:table-cell[2]/text:p/text:span[@text:style-name='Tbold']",
384  "GrasO"
385  ) ,
386  array(
387  "office:body/office:text/text:section//table:table[1]/table:table-row[1]//table:table-cell[1]/text:p/text:span[@text:style-name='Titalics']",
388  "ItaliqueP"
389  ) ,
390  array(
391  "office:body/office:text/text:section//table:table[1]/table:table-row[1]//table:table-cell[2]/text:p/text:span[@text:style-name='Titalics']",
392  "ItaliqueO"
393  ) ,
394  array(
395  "office:body/office:text/text:section//table:table[1]/table:table-row[1]//table:table-cell[3]/text:p",
396  "Single text 'voilà'"
397  ) ,
398  array(
399  "office:body/office:text/text:section//table:table[1]/table:table-row[2]//table:table-cell[1]/text:p",
400  "Balise ignorée"
401  ) ,
402  array(
403  "office:body/office:text/text:section//table:table[1]/table:table-row[2]//table:table-cell[2]/text:p/text:span[@text:style-name='Punderline']",
404  "Souligné"
405  ) ,
406  array(
407  "office:body/office:text/text:section//table:table[1]/table:table-row[2]//table:table-cell[3]/text:p",
408  "Paragraphe normal."
409  ) ,
410  array(
411  "office:body/office:text/text:section//table:table[1]/table:table-row[2]//table:table-cell[4]/text:p",
412  "Là"
413  ) ,
414  array(
415  "office:body/office:text/text:section//table:table[1]/table:table-row[3]//table:table-cell[1]/text:p/text:span[@text:style-name='Tsub']",
416  "Delta"
417  ) ,
418  array(
419  "office:body/office:text/text:section//table:table[1]/table:table-row[3]//table:table-cell[1]/text:p/text:span[@text:style-name='Tbold']",
420  "Gros"
421  ) ,
422  array(
423  "office:body/office:text/text:section//table:table[1]/table:table-row[3]//table:table-cell[1]/text:p/text:span[@text:style-name='Titalics']",
424  "mince"
425  ) ,
426  array(
427  "office:body/office:text/text:section//table:table[1]/table:table-row[3]//table:table-cell[2]/text:p/text:span[@text:style-name='Tsuper']",
428  "2"
429  ) ,
430  array(
431  "office:body/office:text/text:section//table:table[1]/table:table-row[3]//table:table-cell[3]/text:p/text:span[@text:style-name='Tsub']",
432  "d"
433  ) ,
434  array(
435  "office:body/office:text/text:section//table:table[1]/table:table-row[3]//table:table-cell[4]/text:p/text:span[@text:style-name='Tsub']",
436  "g"
437  ) ,
438  array(
439  "office:body/office:text/text:section//table:table[1]/table:table-row[3]//table:table-cell[4]/text:p/text:span[@text:style-name='Tsuper']",
440  "f"
441  ) ,
442  array(
443  "office:body/office:text/text:section//table:table[1]/table:table-row[3]//table:table-cell[2]/text:p",
444  "Y2S"
445  ) ,
446  array(
447  "office:body/office:text/text:section//table:table[1]/table:table-row[3]//table:table-cell[3]/text:p",
448  "Wd"
449  ) ,
450  array(
451  "office:body/office:text/text:section//table:table[1]/table:table-row[3]//table:table-cell[4]/text:p",
452  "Gg, Ff"
453  ) ,
454  array(
455  "office:body/office:text/text:section//table:table[1]/table:table-row[3]//table:table-cell[1]/text:p",
456  "XDelta Très Gros et mince"
457  ) ,
458  array(
459  "office:body/office:text/text:section//table:table[1]/table:table-row[1]//table:table-cell[4]/text:p/text:a",
460  "Goto"
461  ) ,
462  array(
463  "office:body/office:text/text:section//table:table[1]//table:table-column[@table:number-columns-repeated='4']",
464  ""
465  ) ,
466  array(
467  "office:body/office:text/text:section//table:table[1]/table:table-header-rows//table:table-cell[1]/text:p/text:span[@text:style-name='Tbold']",
468  "HGrasP"
469  ) ,
470  array(
471  "office:body/office:text/text:section//table:table[1]/table:table-header-rows//table:table-cell[2]/text:p/text:span[@text:style-name='Tbold']",
472  "HGrasO"
473  ) ,
474  array(
475  "office:body/office:text/text:section//table:table[1]/table:table-header-rows//table:table-cell[1]/text:p/text:span[@text:style-name='Titalics']",
476  "HItaliqueP"
477  ) ,
478  array(
479  "office:body/office:text/text:section//table:table[1]/table:table-header-rows//table:table-cell[2]/text:p/text:span[@text:style-name='Titalics']",
480  "HItaliqueO"
481  ) ,
482  array(
483  "office:body/office:text/text:section//table:table[1]/table:table-header-rows//table:table-cell[3]/text:p",
484  "Hingle text 'voilà'"
485  ) ,
486  array(
487  "office:body/office:text/text:section//table:table[1]/table:table-header-rows//table:table-cell[4]/text:p/text:a",
488  "Hoto"
489  ) ,
490  )
491  )
492  );
493  }
494 }
495 ?>
$status
Definition: index.php:30
testContent($docName, $template, array $expectedValues)
static addMessage($msg)
Definition: PU_dcp.php:44
$file
extractFile($docName, $template, $extractName)
foreach($argv as $arg) $cmd
testMeta($docName, $template, array $expectedValues)
$path
Definition: dav.php:39
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
XPathTesting(\DOMDocument $dom, array $expectedValues)
$dbaccess
Definition: checkVault.php:17
$value
← centre documentaire © anakeen