Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_htmlvalue.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 namespace Dcp\Pu;
8 
10 /**
11  * @author Anakeen
12  * @package Dcp\Pu
13  */
14 require_once 'PU_testcase_dcp_commonfamily.php';
15 
17 {
18  public $famName = "TST_FAMGETHTMLVALUE";
19  /**
20  * import TST_FAMSETVALUE family
21  * @static
22  * @return string
23  */
24  protected static function getCommonImportFile()
25  {
26  return "PU_data_dcp_gethtmlvaluefamily.ods";
27  }
28  /**
29  * @dataProvider dataGetHtmlValues
30  */
31  public function testGetHtmlValues($docName, array $setValues, array $expectedValues)
32  {
33  $this->requiresCoreParamEquals('CORE_LANG', 'fr_FR');
34  $d = new_doc(self::$dbaccess, $docName);
35  $this->assertTrue($d->isAlive() , sprintf("cannot access %s document", $docName));
36  foreach ($setValues as $attrid => $newValue) {
37  $d->setAttributeValue($attrid, $newValue);
38  }
39  $d->store(); // verify database record
40  foreach ($expectedValues as $attrid => $expectedValue) {
41  $oriValue = $d->getrawValue($attrid);
42  $value = $d->getHtmlAttrValue($attrid);
43 
44  $this->assertTrue($expectedValue === $value, sprintf("wrong value \"%s\" : \n\texpected \"%s\", \n\thas \"%s\" \n\tRaw is :\"%s\"", $attrid, print_r($expectedValue, true) , print_r($value, true) , print_r($oriValue, true)));
45  }
46  }
47  /**
48  * @dataProvider dataGetHtmlValuesException
49  */
51  {
52  $this->requiresCoreParamEquals('CORE_LANG', 'fr_FR');
53  $d = new_doc(self::$dbaccess, $data['docName']);
54  $this->assertTrue($d->isAlive() , sprintf("cannot access %s document", $data['docName']));
55  foreach ($data['setValues'] as $attrid => $newValue) {
56  $d->setAttributeValue($attrid, $newValue);
57  }
58  $d->store(); // verify database record
59  foreach ($data['expectedExceptionsMatch'] as $attrid => $expectedExceptionMatchRE) {
60  $exceptionMessage = '';
61  try {
62  $value = $d->getHtmlAttrValue($attrid);
63  }
64  catch(\Exception $e) {
65  $exceptionMessage = $e->getMessage();
66  }
67 
68  $this->assertTrue((preg_match($expectedExceptionMatchRE, $exceptionMessage) === 1) , sprintf("Exception '%s' does not match expected exception message '%s'.", $exceptionMessage, $expectedExceptionMatchRE));
69  }
70  }
71  /**
72  * @dataProvider dataHtmlFormat
73  */
74  public function testHtmlFormat($docName, array $setValues, array $expectedValues, $target = "_self", $htmllink = true, $index = - 1, $useEntitities = true, $abstractMode = false)
75  {
76  $this->requiresCoreParamEquals('CORE_LANG', 'fr_FR');
77  $d = new_doc(self::$dbaccess, $docName);
78  $this->assertTrue($d->isAlive() , sprintf("cannot access %s document", $docName));
79  foreach ($setValues as $attrid => $newValue) {
80  $d->setAttributeValue($attrid, $newValue);
81  }
82  $d->store(); // verify database record
83  $ht = new \DocHtmlFormat($d);
84  foreach ($expectedValues as $attrid => $expectedValue) {
85  $oriValue = $d->getrawValue($attrid);
86  $oa = $d->getAttribute(($attrid));
87 
88  if ($index >= 0) {
89  $mValue = $d->getMultipleRawValues($attrid);
90  $oriValue = $mValue[$index];
91  }
92  $value = $ht->getHtmlValue($oa, $oriValue, $target, $htmllink, $index, $useEntitities, $abstractMode);
93 
94  $this->assertTrue($expectedValue === $value, sprintf("wrong value \"%s\" : \n\texpected \"%s\", \n\thas \"%s\" \n\tRaw is :\"%s\"", $attrid, print_r($expectedValue, true) , print_r($value, true) , print_r($oriValue, true)));
95  }
96  }
97 
98  public function dataHtmlFormat()
99  {
100  return array(
101  array(
102  'TST_DOCHTML0',
103  "set" => array() ,
104  "get" => array(
105 
106  "tst_text" => 'no text',
107  "tst_date" => 'no date',
108  "tst_time" => 'no time',
109  "tst_int" => 'no int',
110  "tst_longtext" => "no longtext",
111  "tst_double" => 'no double',
112  "tst_money" => 'no money',
113  "tst_timestamp" => 'no timestamp',
114  "tst_rel" => "no rel",
115  "tst_enum" => "no enum",
116  "tst_color" => 'no color',
117  "tst_enums" => "no enums",
118  "tst_texts" => "no text",
119  "tst_ints" => "no int",
120  "tst_moneys" => "no money",
121  "tst_doubles" => "no double",
122  "tst_times" => "no time",
123  "tst_enumms" => "no enum",
124  "tst_colors" => 'no color',
125  "tst_longtexts" => "no longtext",
126  "tst_ints1" => "",
127  "tst_doubles1" => "",
128 
129  "tst_ftext" => 'no text',
130  "tst_fdate" => 'no date',
131  "tst_ftime" => 'no time',
132  "tst_fint" => 'no int',
133  "tst_fdouble" => 'no double',
134  "tst_fmoney" => 'no money',
135  "tst_ftimestamp" => 'no timestamp',
136  "tst_fltext" => '',
137  ) ,
138  "target" => "_self",
139  "htmllink" => 1,
140  "index" => - 1,
141  "useEntities" => true,
142  "abstractMode" => false
143  ) ,
144  array(
145  'TST_DOCHTML1',
146  "set" => array() ,
147  "get" => array(
148  "tst_text" => 'Document Un',
149  "tst_date" => '20/04/2013',
150  "tst_time" => '01:00',
151  "tst_int" => '1',
152  "tst_longtext" => "Et<br />\nLa suite en &eacute;t&eacute;&lt;b&gt;...",
153  "tst_double" => '3.1415926',
154  "tst_money" => '2,54',
155  "tst_timestamp" => '30/09/2013 10:00',
156  //"tst_rel"=>"x",
157  "tst_enum" => "A",
158  "tst_color" => '<span style="background-color:#f3f">#f3f</span>',
159  "tst_enums" => "A<BR>B<BR>C",
160  "tst_texts" => "Un<BR>Deux",
161  "tst_ints" => "0",
162  "tst_moneys" => "3,00",
163  "tst_doubles" => "-54",
164  "tst_times" => "10:00",
165  "tst_enumms" => "A",
166  "tst_colors" => '<span style="background-color:#ff33ff">#ff33ff</span><BR><span style="background-color:#45e098">#45e098</span>',
167  "tst_longtexts" => "Un<br />\nDeux<BR>Trois<br />\nQuatre",
168  "tst_ints1" => "1<BR>2<BR>3",
169  "tst_doubles1" => "<BR><BR>",
170  "tst_dates" => "20/04/2013",
171 
172  "tst_ftext" => '[Document Un]',
173  "tst_fdate" => 'samedi 20 avril 2013',
174  "tst_ftime" => ' 1h 00min 00s',
175  "tst_fdoubles" => "-54.000",
176  "tst_fint" => '001',
177  "tst_fdouble" => '3.142',
178  "tst_fmoney" => '2,54 €',
179  "tst_fdates" => "samedi 20 avril 2013",
180  "tst_ftimestamp" => 'lundi 30 septembre 2013 10h 00min 00s',
181  "tst_fltext" => '<a target="_self" title="" onmousedown="document.noselect=true;" href="http://www.here.com/Document%20Un.html" >Document Format Un</a>',
182 
183  "tst_ftexts" => "[Un]<BR>[Deux]",
184  ) ,
185  "target" => "_self",
186  "htmllink" => 1,
187  "index" => - 1,
188  "useEntities" => true,
189  "abstractMode" => false
190  ) ,
191  array(
192  'TST_DOCHTML2',
193  "set" => array() ,
194  "get" => array(
195  "tst_text" => 'Document Deux',
196  "tst_date" => '23/05/2020',
197  "tst_time" => '14:17',
198  "tst_int" => '0',
199  "tst_longtext" => "Texte long. Html tag <br />\n.",
200  "tst_double" => '-54',
201  "tst_money" => '3,00',
202  "tst_timestamp" => '30/09/2013 20:10',
203  //"tst_rel"=>"x",
204  "tst_enum" => "C",
205  "tst_color" => '<span style="background-color:#50ED42">#50ED42</span>',
206  "tst_enums" => "C<BR>no enums<BR>B",
207  "tst_texts" => "Un cheval noir<BR>Et un autre rouge",
208  "tst_ints" => "45<BR>3654<BR>-34",
209  "tst_moneys" => "2,54<BR>3,00<BR>2,72",
210  "tst_doubles" => "3.1415926<BR>2.7182818<BR>1.61803398875",
211  "tst_times" => "04:07",
212  "tst_dates" => '23/05/2020<BR>13/04/2017',
213  "tst_enumms" => "C",
214  "tst_colors" => '<span style="background-color:#50ED42">#50ED42</span>',
215  "tst_longtexts" => "Alpha<br />\nB&eacute;ta<BR>A<br />\nB<br />\nC",
216  "tst_ints1" => "3<BR><BR>",
217  "tst_doubles1" => "<BR>5.6<BR>7.8",
218 
219  "tst_ftext" => '[Document Deux]',
220  "tst_fdate" => 'samedi 23 mai 2020',
221  "tst_fdates" => "samedi 23 mai 2020<BR>jeudi 13 avril 2017",
222  "tst_fint" => '000',
223  "tst_ftexts" => '[Un cheval noir]<BR>[Et un autre rouge]',
224  "tst_fmoneys" => '2,54 $<BR>3,00 $<BR>2,72 $',
225  "tst_fdoubles" => "3.142<BR>2.718<BR>1.618",
226  "tst_ftime" => "14h 17min 43s",
227  "tst_fdouble" => '-54.000',
228  "tst_fmoney" => '3,00 €',
229  "tst_ftimestamp" => 'lundi 30 septembre 2013 20h 10min 41s',
230  "tst_fltext" => '<a target="_self" title="" onmousedown="document.noselect=true;" href="http://www.here.com/Document%20Deux.html" >Document Format Deux</a>',
231  ) ,
232  "target" => "_self",
233  "htmllink" => 1,
234  "index" => - 1,
235  "useEntities" => true,
236  "abstractMode" => false
237  ) ,
238 
239  array(
240  'TST_DOCHTML0',
241  "set" => array(
242  "tst_text" => "Two",
243  "tst_fltext" => 'One',
244  ) ,
245  "get" => array(
246  "tst_fltext" => '<a target="_self" title="" onmousedown="document.noselect=true;" href="http://www.here.com/Two.html" >One</a>',
247  ) ,
248  "target" => "_self",
249  "htmllink" => 1,
250  "index" => - 1,
251  "useEntities" => true,
252  "abstractMode" => false
253  ) ,
254  array(
255  'TST_DOCHTML0',
256  "set" => array(
257  "tst_text" => "Two",
258  "tst_fltext" => 'One',
259  ) ,
260  "get" => array(
261  "tst_fltext" => 'One',
262  ) ,
263  "target" => "_self",
264  "htmllink" => 0,
265  "index" => - 1,
266  "useEntities" => true,
267  "abstractMode" => false
268  ) ,
269  array(
270  'TST_DOCHTML0',
271  "set" => array(
272  "tst_text" => "Hétérogénéité",
273  ) ,
274  "get" => array(
275  "tst_text" => 'H&eacute;t&eacute;rog&eacute;n&eacute;it&eacute;',
276  ) ,
277  "target" => "_self",
278  "htmllink" => 0,
279  "index" => - 1,
280  "useEntities" => true,
281  "abstractMode" => false
282  ) ,
283  array(
284  'TST_DOCHTML0',
285  "set" => array(
286  "tst_text" => "Hétérogénéité",
287  ) ,
288  "get" => array(
289  "tst_text" => 'Hétérogénéité',
290  ) ,
291  "target" => "_self",
292  "htmllink" => 0,
293  "index" => - 1,
294  "useEntities" => false,
295  "abstractMode" => false
296  ) ,
297  array(
298  'TST_DOCHTML0',
299  "set" => array(
300  "tst_texts" => array(
301  "Un",
302  "Deux",
303  "Trois"
304  ) ,
305  ) ,
306  "get" => array(
307  "tst_texts" => 'Deux',
308  ) ,
309  "target" => "_self",
310  "htmllink" => 0,
311  "index" => 1,
312  "useEntities" => false,
313  "abstractMode" => false
314  ) ,
315  array(
316  'TST_DOCHTML0',
317  "set" => array(
318  "tst_texts" => array(
319  "Un",
320  "Deux",
321  "Trois"
322  ) ,
323  ) ,
324  "get" => array(
325  "tst_texts" => 'Un',
326  ) ,
327  "target" => "_self",
328  "htmllink" => 0,
329  "index" => 0,
330  "useEntities" => false,
331  "abstractMode" => false
332  )
333  );
334  }
335 
336  public function dataGetHtmlValues()
337  {
338  return array(
339  array(
340  'TST_DOCHTML0',
341  "set" => array() ,
342  "get" => array(
343  "tst_text" => 'no text',
344  "tst_date" => 'no date',
345  "tst_time" => 'no time',
346  "tst_int" => 'no int',
347  "tst_longtext" => "no longtext",
348  "tst_double" => 'no double',
349  "tst_money" => 'no money',
350  "tst_timestamp" => 'no timestamp',
351  "tst_file" => 'no file',
352  "tst_rel" => "no rel",
353  "tst_enum" => "no enum",
354  "tst_color" => 'no color',
355  "tst_enums" => "no enums",
356  "tst_texts" => "no text",
357  "tst_ints" => "no int",
358  "tst_moneys" => "no money",
359  "tst_doubles" => "no double",
360  "tst_times" => "no time",
361  "tst_enumms" => "no enum",
362  "tst_colors" => 'no color',
363  "tst_longtexts" => "no longtext",
364  "tst_ints1" => "",
365  "tst_doubles1" => "",
366 
367  "tst_ftext" => 'no text',
368  "tst_fdate" => 'no date',
369  "tst_ftime" => 'no time',
370  "tst_fint" => 'no int',
371  "tst_fdouble" => 'no double',
372  "tst_fmoney" => 'no money',
373  "tst_ftimestamp" => 'no timestamp',
374  "tst_fltext" => '',
375  )
376  ) ,
377  array(
378  'TST_DOCHTML1',
379  "set" => array() ,
380  "get" => array(
381  "tst_text" => 'Document Un',
382  "tst_date" => '20/04/2013',
383  "tst_time" => '01:00',
384  "tst_int" => '1',
385  "tst_longtext" => "Et<br />\nLa suite en &eacute;t&eacute;&lt;b&gt;...",
386  "tst_double" => '3.1415926',
387  "tst_money" => '2,54',
388  "tst_timestamp" => '30/09/2013 10:00',
389  //"tst_rel"=>"x",
390  "tst_enum" => "A",
391  "tst_color" => '<span style="background-color:#f3f">#f3f</span>',
392  "tst_enums" => "A<BR>B<BR>C",
393  "tst_texts" => "Un<BR>Deux",
394  "tst_ints" => "0",
395  "tst_moneys" => "3,00",
396  "tst_doubles" => "-54",
397  "tst_times" => "10:00",
398  "tst_enumms" => "A",
399  "tst_colors" => '<span style="background-color:#ff33ff">#ff33ff</span><BR><span style="background-color:#45e098">#45e098</span>',
400  "tst_longtexts" => "Un<br />\nDeux<BR>Trois<br />\nQuatre",
401  "tst_ints1" => "1<BR>2<BR>3",
402  "tst_doubles1" => "<BR><BR>",
403  "tst_dates" => "20/04/2013",
404 
405  "tst_ftext" => '[Document Un]',
406  "tst_fdate" => 'samedi 20 avril 2013',
407  "tst_ftime" => ' 1h 00min 00s',
408  "tst_fdoubles" => "-54.000",
409  "tst_fint" => '001',
410  "tst_fdouble" => '3.142',
411  "tst_fmoney" => '2,54 €',
412  "tst_fdates" => "samedi 20 avril 2013",
413  "tst_ftimestamp" => 'lundi 30 septembre 2013 10h 00min 00s',
414  "tst_fltext" => '<a target="_self" title="" onmousedown="document.noselect=true;" href="http://www.here.com/Document%20Un.html" oncontextmenu="popdoc(event,\'http://www.here.com/Document%20Un.html\');return false;" >Document Format Un</a>',
415 
416  "tst_ftexts" => "[Un]<BR>[Deux]",
417  )
418  ) ,
419  array(
420  'TST_DOCHTML2',
421  "set" => array() ,
422  "get" => array(
423  "tst_text" => 'Document Deux',
424  "tst_date" => '23/05/2020',
425  "tst_time" => '14:17',
426  "tst_int" => '0',
427  "tst_longtext" => "Texte long. Html tag <br />\n.",
428  "tst_double" => '-54',
429  "tst_money" => '3,00',
430  "tst_timestamp" => '30/09/2013 20:10',
431  //"tst_rel"=>"x",
432  "tst_enum" => "C",
433  "tst_color" => '<span style="background-color:#50ED42">#50ED42</span>',
434  "tst_enums" => "C<BR>no enums<BR>B",
435  "tst_texts" => "Un cheval noir<BR>Et un autre rouge",
436  "tst_ints" => "45<BR>3654<BR>-34",
437  "tst_moneys" => "2,54<BR>3,00<BR>2,72",
438  "tst_doubles" => "3.1415926<BR>2.7182818<BR>1.61803398875",
439  "tst_times" => "04:07",
440  "tst_dates" => '23/05/2020<BR>13/04/2017',
441  "tst_enumms" => "C",
442  "tst_colors" => '<span style="background-color:#50ED42">#50ED42</span>',
443  "tst_longtexts" => "Alpha<br />\nB&eacute;ta<BR>A<br />\nB<br />\nC",
444  "tst_ints1" => "3<BR><BR>",
445  "tst_doubles1" => "<BR>5.6<BR>7.8",
446 
447  "tst_ftext" => '[Document Deux]',
448  "tst_fdate" => 'samedi 23 mai 2020',
449  "tst_fdates" => "samedi 23 mai 2020<BR>jeudi 13 avril 2017",
450  "tst_fint" => '000',
451  "tst_ftexts" => '[Un cheval noir]<BR>[Et un autre rouge]',
452  "tst_fmoneys" => '2,54 $<BR>3,00 $<BR>2,72 $',
453  "tst_fdoubles" => "3.142<BR>2.718<BR>1.618",
454  "tst_ftime" => "14h 17min 43s",
455  "tst_fdouble" => '-54.000',
456  "tst_fmoney" => '3,00 €',
457  "tst_ftimestamp" => 'lundi 30 septembre 2013 20h 10min 41s',
458  "tst_fltext" => '<a target="_self" title="" onmousedown="document.noselect=true;" href="http://www.here.com/Document%20Deux.html" oncontextmenu="popdoc(event,\'http://www.here.com/Document%20Deux.html\');return false;" >Document Format Deux</a>',
459  )
460  ) ,
461  array(
462  'TST_DOCHTML0',
463  "set" => array(
464 
465  "tst_text" => '\'"a|à|á|â|ã|ä|å|o|ò|ó|ô|õ|ö|ø|e|è|é|ê|ë|c|ç|i|ì|í|î|ï|u|ù|ú|û|ü|y|ÿ|n|ñ|<|>|&',
466  "tst_htmltext" => '<p>été comme hivers</p><br/><p>2&gt;1</p>',
467  ) ,
468  "get" => array(
469  "tst_text" => "'&quot;a|&agrave;|&aacute;|&acirc;|&atilde;|&auml;|&aring;|o|&ograve;|&oacute;|&ocirc;|&otilde;|&ouml;|&oslash;|e|&egrave;|&eacute;|&ecirc;|&euml;|c|&ccedil;|i|&igrave;|&iacute;|&icirc;|&iuml;|u|&ugrave;|&uacute;|&ucirc;|&uuml;|y|&yuml;|n|&ntilde;|&lt;|&gt;|&amp;",
470  "tst_htmltext" => '<div class="htmltext"><p>été comme hivers</p><br><p>2&gt;1</p></div>',
471  )
472  )
473  );
474  }
475  public function dataGetHtmlValuesException()
476  {
477  return array(
478  array(
479  array(
480  'docName' => 'TST_DOCHTML0',
481  'setValues' => array(
482  'tst_text' => 'foo'
483  ) ,
484  'expectedExceptionsMatch' => array(
485  'tst_text' => '/^$/',
486  'tst_non_existing_attribute' => '/{DOC0130}/'
487  )
488  )
489  )
490  );
491  }
492 }
testHtmlFormat($docName, array $setValues, array $expectedValues, $target="_self", $htmllink=true, $index=-1, $useEntitities=true, $abstractMode=false)
$d
Definition: dav.php:77
testGetHtmlValues($docName, array $setValues, array $expectedValues)
$dbaccess
Definition: checkVault.php:17
$value
requiresCoreParamEquals($paramName, $requiredValue, $markTestIncomplete=true)
$data
← centre documentaire © anakeen