Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_ooolayout.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_oooLayout.ods");
37  }
38  public static function tearDownAfterClass()
39  {
40  self::rollbackTransaction();
41  TestSuiteDcp::addMessage(sprintf("Results for %s in file://%s", __CLASS__, self::$outputDir));
42  }
43 
44  protected function saveFileResult($file, $name)
45  {
46  copy($file, self::$outputDir . '/' . $name);
47  }
48  /**
49  * @dataProvider dataErrorXML
50  * @param string $layoutFile
51  * @param array $data
52  * @return void
53  */
54  public function testErrorXML($layoutFile, array $data, $expectedCode)
55  {
56  $l = new \OOoLayout(sprintf("DCPTEST/Layout/%s", $layoutFile));
57  foreach ($data as $k => $v) {
58  $l->set($k, $v);
59  }
60  try {
61  $f = $l->gen();
62  $this->fail(sprintf("Generate %s", $f));
63  }
64  catch(\Dcp\Layout\Exception $e) {
65  $this->assertEquals($expectedCode, $e->getDcpCode() , "not correct code");
66  $this->assertNotEmpty($e->getCorruptedFile());
67  }
68  }
69  /**
70  * @dataProvider dataSimpleLayout
71  * @param string $instances
72  * @param string $lname
73  * @param array $templates
74  */
75  public function testSimpleLayout($instances, $lname, array $templates)
76  {
77  $df = new_doc(self::$dbaccess, "TST_OOOLAYOUT");
78  $this->assertTrue($df->isAlive() , "family TST_OOOLAYOUT is not alive");
79  $this->importDocument($instances);
80 
81  $instance = new_doc(self::$dbaccess, $lname);
82  $this->assertTrue($instance->isAlive() , "document $lname is not alive");
83 
84  foreach ($templates as $template) {
85  $file = '';
86  try {
87  $file = $instance->viewDoc("DCPTEST:" . $template . ":B");
88  }
89  catch(\Dcp\Layout\exception $e) {
90  $this->fail(sprintf("%s, \n file: %s", $e->getMessage() , $e->getCorruptedFile()));
91  }
92  $this->assertTrue(file_exists($file) , "fail layout $template : $file");
93  // print "ooffice $file\n";
94  $this->saveFileResult($file, sprintf("%s_%s.odt", str_replace('.odt', '', $template) , $lname));
95  }
96  //print_r($instance->getValues());
97 
98  }
99  /**
100  * @dataProvider dataErrorHtmlLayout
101  * @param string $instances
102  * @param string $lname
103  * @param array $templates
104  * @param string $expectedCode
105  * @return void
106  */
107  public function testErrorHtmlLayout($instances, $lname, array $templates, $expectedCode)
108  {
109  $df = new_doc(self::$dbaccess, "TST_OOOLAYOUT");
110  $this->assertTrue($df->isAlive() , "family TST_OOOLAYOUT is not alive");
111  $this->importDocument($instances);
112 
113  $instance = new_doc(self::$dbaccess, $lname);
114  $this->assertTrue($instance->isAlive() , "document $lname is not alive");
115  foreach ($templates as $template) {
116  $file = '';
117  try {
118  $file = $instance->viewDoc("DCPTEST:" . $template . ":B");
119  $this->fail(sprintf("No error detected. Need find %s code", $expectedCode));
120  }
121  catch(\Dcp\Layout\exception $e) {
122  $this->assertEquals($expectedCode, $e->getDcpCode() , sprintf("%s, \n corrupted file is : %s", $e->getMessage() , $e->getCorruptedFile()));
123  $this->assertNotEmpty($e->getCorruptedFile() , "no corrupted file found");
124  }
125  }
126  }
127  /**
128  * @dataProvider dataGoodXML
129  * @param string $layoutFile
130  * @param array $data
131  * @return void
132  */
133  public function testGoodXML($layoutFile, array $data)
134  {
135  $l = new \OOoLayout(sprintf("DCPTEST/Layout/%s", $layoutFile));
136  foreach ($data as $k => $v) {
137  $l->set($k, $v);
138  }
139  $f = $l->gen();
140  $this->assertNotEmpty($f, "file is not produced");
141  }
142  /**
143  * @dataProvider dataInvalidXMLChars
144  */
145  public function testInvalidXMLChars($data)
146  {
147  $err = '';
148  $doc = createTmpDoc(self::$dbaccess, $data['family']);
149  foreach ($data['setValue'] as $k => $v) {
150  $err.= $doc->setValue($k, $v);
151  }
152  $out = '';
153  $exceptionMessage = '';
154  try {
155  $out = $doc->viewDoc("DCPTEST:" . $data['template'] . ":B");
156  }
157  catch(\Exception $e) {
158  $exceptionMessage = $e->getMessage();
159  }
160  $this->assertTrue(is_file($out) , sprintf("Unexpected error from viewDoc(): %s", $out));
161  $this->assertEmpty($exceptionMessage, sprintf("Unexpected exception from viewDoc(): %s", $exceptionMessage));
162  }
163 
164  public function dataErrorXML()
165  {
166  return array(
167  array(
168  "PU_dcp_data_customOooLayout.odt",
169  array(
170  "X" => "Tree & Two",
171  "Y" => "Two",
172  "Z" => "One"
173  ) ,
174  "LAY0004"
175  ) ,
176  array(
177  "PU_dcp_data_customOooLayout.odt",
178  array(
179  "X" => "Tree <Two>",
180  "Y" => "Two",
181  "Z" => "One"
182  ) ,
183  "LAY0004"
184  ) ,
185  array(
186  "PU_dcp_data_customOooLayout.odt",
187  array(
188  "X" => "Tree 'test &zou;",
189  "Y" => "Two",
190  "Z" => "One"
191  ) ,
192  "LAY0004"
193  ) ,
194  array(
195  "PU_dcp_data_customOooLayout_no_automatic-styles.odt",
196  array() ,
197  "LAY0009"
198  )
199  );
200  }
201 
202  public function dataGoodXML()
203  {
204  return array(
205  array(
206  "PU_dcp_data_customOooLayout.odt",
207  array(
208  "X" => "Tree",
209  "Y" => "Two",
210  "Z" => "One"
211  )
212  ) ,
213  array(
214  "PU_dcp_data_customOooLayout.odt",
215  array(
216  "X" => "Tree <text:line-break/>",
217  "Y" => "<text:span>Two</text:span>",
218  "Z" => '<text:span text:style-name="Tbold">One</text:span>"'
219  )
220  ) ,
221  array(
222  "PU_dcp_data_customOooLayout.odt",
223  array(
224  "X" => "Tree &amp; Two",
225  "Y" => "&lt;One&gt;"
226  )
227  )
228  );
229  }
230  public function dataErrorHtmlLayout()
231  {
232  return array(
233  array(
234  "PU_dcp_data_simpleOooLayout.xml",
235  "TST_SIMPLEODT",
236  array(
237  "PU_dcp_data_errorInlineOooLayout.odt"
238  ) ,
239  "LAY0005"
240  ) ,
241 
242  array(
243  "PU_dcp_data_simpleOooLayout.xml",
244  "TST_SIMPLEODT",
245  array(
246  "PU_dcp_data_errorPuceHtmlOooLayout.odt"
247  ) ,
248  "LAY0002"
249  )
250  );
251  }
252  public function dataSimpleLayout()
253  {
254  return array(
255  array(
256  "PU_dcp_data_simpleOooLayout.xml",
257  "TST_SIMPLEODT",
258  array(
259  "PU_dcp_data_simpleOooLayout.odt",
260  "PU_dcp_data_repeatMulti.odt",
261  "PU_dcp_data_repeatOne.odt",
262  "PU_dcp_data_repeatOooLayout.odt",
263  "PU_dcp_data_rowOooLayout.odt",
264  "PU_dcp_data_ifOooLayout.odt"
265  )
266  ) ,
267  array(
268  "PU_dcp_data_multipleOooLayout.xml",
269  "TST_MULTIPLEODT",
270  array(
271  "PU_dcp_data_multipleOooLayout.odt"
272  )
273  ) ,
274  array(
275  "PU_dcp_data_simpleOooLayout.xml",
276  "TST_TABLEODT",
277  array(
278  "PU_dcp_data_simpleOooLayout.odt",
279  "PU_dcp_data_puceOooLayout.odt"
280  )
281  ) ,
282  array(
283  "PU_dcp_data_simpleOooLayout.xml",
284  "TST_PUCEODT",
285  array(
286  "PU_dcp_data_simpleOooLayout.odt",
287  "PU_dcp_data_puceOooLayout.odt"
288  )
289  )
290  );
291  }
292  public function dataInvalidXMLChars()
293  {
294  return array(
295  /* PCDATA invalid Char value 1 in Entity */
296  array(
297  array(
298  "family" => "TST_OOOLAYOUT",
299  "setValue" => array(
300  "TST_TITLE" => "(SOH: \x01)"
301  ) ,
302  "template" => "PU_dcp_data_simple1.odt"
303  )
304  ) ,
305  array(
306  array(
307  "family" => "TST_OOOLAYOUT",
308  "setValue" => array(
309  "HTML_MULTI" => "(SOH: \x01)"
310  ) ,
311  "template" => "PU_dcp_data_simple1.odt"
312  )
313  ) ,
314  /* Char 0xFFFE out of allowed range in Entity + PCDATA invalid Char value 65534 in Entity */
315  array(
316  array(
317  "family" => "TST_OOOLAYOUT",
318  "setValue" => array(
319  "TST_TITLE" => "(\xef\xbf\xbe)"
320  ) ,
321  "template" => "PU_dcp_data_simple1.odt"
322  )
323  ) ,
324  array(
325  array(
326  "family" => "TST_OOOLAYOUT",
327  "setValue" => array(
328  "HTML_MULTI" => "(\xef\xbf\xbe)"
329  ) ,
330  "template" => "PU_dcp_data_simple1.odt"
331  )
332  )
333  );
334  }
335 }
Layout is a template generator.
testErrorXML($layoutFile, array $data, $expectedCode)
static addMessage($msg)
Definition: PU_dcp.php:44
testSimpleLayout($instances, $lname, array $templates)
testGoodXML($layoutFile, array $data)
$file
static importDocument($file)
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
testErrorHtmlLayout($instances, $lname, array $templates, $expectedCode)
$dbaccess
Definition: checkVault.php:17
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
if($file) if($subject==""&&$file) if($subject=="") $err
$data
← centre documentaire © anakeen