1<?php
2
3/**
4 * Renderer tests for the latexit plugin
5 * Almost all the tests are testing just insertion to $this->doc variable.
6 *
7 * @group plugin_latexit
8 * @group plugins
9 */
10class renderer_plugin_latexit_test extends DokuWikiTest {
11
12    /**
13     * These plugins will be loaded for testing. Additional ones added in constructor
14     * @var array
15     */
16    protected $pluginsEnabled = array('latexit');
17
18    /**
19     * Variable to store the instance of the renderer.
20     * @var renderer_plugin_latexit
21     */
22    protected $r;
23
24    /**
25     * Enable additional plugins if available
26     */
27    public function __construct() {
28        if(is_dir(DOKUWIKI_PLUGIN.'mathjax')) $this->pluginsEnabled[] = 'mathjax';
29        if(is_dir(DOKUWIKI_PLUGIN.'imagereference')) $this->pluginsEnabled[] = 'imaereference';
30        if(is_dir(DOKUWIKI_PLUGIN.'zotero')) $this->pluginsEnabled[] = 'zotero';
31    }
32
33    /**
34     * Prepares the testing environment
35     */
36    public function setUp() {
37        parent::setUp();
38
39        $this->r = new renderer_plugin_latexit();
40        //this function inicializes all variables
41        $this->r->document_start();
42        //but we dont want to have the header of document in tests
43        $this->clearDoc();
44    }
45
46    /**
47     * Clears the document variable.
48     */
49    protected function clearDoc() {
50        $this->r->doc = '';
51    }
52
53    /**
54     * Testing canRender method.
55     */
56    public function test_canRender() {
57        $this->assertTrue($this->r->canRender('latex'));
58        $this->assertFalse($this->r->canRender('xhtml'));
59        $this->assertFalse($this->r->canRender('affsd'));
60    }
61
62    /**
63     * Testing getFormat method.
64     */
65    public function test_getFormat() {
66        $this->assertEquals('latex', $this->r->getFormat());
67    }
68
69    /**
70     * Testing isSingleton method.
71     */
72    public function test_isSingleton() {
73        $this->assertFalse($this->r->isSingleton());
74    }
75
76    /**
77     * Testing document_start method.
78     */
79    public function test_document_start() {
80        $this->r->document_start();
81        $string = "\begin{document}\n\n";
82
83        $this->assertEquals($string, $this->r->doc);
84    }
85
86    /**
87     * Testing test_header method.
88     * It tests all the possible levels of a header.
89     */
90    public function test_header() {
91        $this->r->header("header", 1, 5);
92        $string = "\n\n\section{\\texorpdfstring{header}{header}}\n\label{sec:header}\n";
93        $this->assertEquals($string, $this->r->doc);
94        $this->clearDoc();
95
96        $this->r->header("Nadpis", 2, 245);
97        $string = "\n\n\subsection{\\texorpdfstring{Nadpis}{Nadpis}}\n\label{sec:nadpis}\n";
98        $this->assertEquals($string, $this->r->doc);
99        $this->clearDoc();
100
101        $this->r->header("Článek 5", 3, 575);
102        $string = "\n\n\subsubsection{\\texorpdfstring{Článek 5}{Clanek 5}}\n\label{sec:clanek_5}\n";
103        $this->assertEquals($string, $this->r->doc);
104        $this->clearDoc();
105
106        $this->r->header("sdfsdfsdk sdf ", 4, 7525);
107        $string = "\n\n\paragraph{\\texorpdfstring{sdfsdfsdk sdf }{sdfsdfsdk sdf }}\n\label{sec:sdfsdfsdk_sdf_}\n";
108        $this->assertEquals($string, $this->r->doc);
109        $this->clearDoc();
110
111        $this->r->header("Nadpis", 5, 4525);
112        $string = "\n\n\subparagraph{\\texorpdfstring{Nadpis}{Nadpis}}\n\label{sec:nadpis2}\n";
113        $this->assertEquals($string, $this->r->doc);
114        $this->clearDoc();
115
116        $this->r->header("Nadpis", 6, 4525);
117        $string = "\n\n~\\newline\n\\textbf{Nadpis}\n\label{sec:nadpis3}\n";
118        $this->assertEquals($string, $this->r->doc);
119    }
120
121    /**
122     * Testing cdata method.
123     */
124    public function test_cdata() {
125        $this->r->cdata("text");
126        $string = "text";
127        $this->assertEquals($string, $this->r->doc);
128        $this->clearDoc();
129
130        //test special characters
131        $this->r->cdata('\{}&%$#_~^<>');
132        $string = '\textbackslash{}\{\}\&\%\$\#\_\textasciitilde{}\textasciicircum{}\textless \textgreater ';
133        $this->assertEquals($string, $this->r->doc);
134    }
135
136    /**
137     * Testing p_open method.
138     */
139    public function test_p_open() {
140        $this->r->p_open();
141        $this->assertEquals("\n\n", $this->r->doc);
142    }
143
144    /**
145     * Testing linebreak method.
146     */
147    public function test_linebreak() {
148        $this->r->linebreak();
149        $this->assertEquals("\\\\", $this->r->doc);
150    }
151
152    /**
153     * Testing hr method.
154     */
155    public function test_hr() {
156        $this->r->hr();
157        $string = "\n\n\\begin{center}\n\\line(1,0){250}\n\\end{center}\n\n";
158        $this->assertEquals($string, $this->r->doc);
159    }
160
161    /**
162     * Testing strong_open method.
163     */
164    public function test_strong_open() {
165        $this->r->strong_open();
166        $this->assertEquals("\\textbf{", $this->r->doc);
167    }
168
169    /**
170     * Testing emphasis_open method.
171     */
172    public function test_emphasis_open() {
173        $this->r->emphasis_open();
174        $this->assertEquals("\\emph{", $this->r->doc);
175    }
176
177    /**
178     * Testing underline_open method.
179     */
180    public function test_underline_open() {
181        $this->r->underline_open();
182        $this->assertEquals("\\underline{", $this->r->doc);
183    }
184
185    /**
186     * Testing monospace_open method.
187     */
188    public function test_monospace_open() {
189        $this->r->monospace_open();
190        $this->assertEquals("\\texttt{", $this->r->doc);
191    }
192
193    /**
194     * Testing subscript_open method.
195     */
196    public function test_subscript_open() {
197        $this->r->subscript_open();
198        $this->assertEquals("\\textsubscript{", $this->r->doc);
199    }
200
201    /**
202     * Testing superscript_open method.
203     */
204    public function test_superscript_open() {
205        $this->r->superscript_open();
206        $this->assertEquals("\\textsuperscript{", $this->r->doc);
207    }
208
209    /**
210     * Testing deleted_open method.
211     */
212    public function test_deleted_open() {
213        $this->r->deleted_open();
214        $this->assertEquals("\\sout{", $this->r->doc);
215    }
216
217    /**
218     * Testing footnote_open method.
219     */
220    public function test_footnote_open() {
221        $this->r->footnote_open();
222        $this->assertEquals("\\footnote{", $this->r->doc);
223    }
224
225    /**
226     * Testing strong_close method.
227     */
228    public function test_strong_close() {
229        $this->r->strong_close();
230        $this->assertEquals("}", $this->r->doc);
231    }
232
233    /**
234     * Testing emphasis_close method.
235     */
236    public function test_emphasis_close() {
237        $this->r->emphasis_close();
238        $this->assertEquals("}", $this->r->doc);
239    }
240
241    /**
242     * Testing underline_close method.
243     */
244    public function test_underline_close() {
245        $this->r->underline_close();
246        $this->assertEquals("}", $this->r->doc);
247    }
248
249    /**
250     * Testing monospace_close method.
251     */
252    public function test_monospace_close() {
253        $this->r->monospace_close();
254        $this->assertEquals("}", $this->r->doc);
255    }
256
257    /**
258     * Testing subscript_close method.
259     */
260    public function test_subscript_close() {
261        $this->r->subscript_close();
262        $this->assertEquals("}", $this->r->doc);
263    }
264
265    /**
266     * Testing superscript_close method.
267     */
268    public function test_superscript_close() {
269        $this->r->superscript_close();
270        $this->assertEquals("}", $this->r->doc);
271    }
272
273    /**
274     * Testing deleted_close method.
275     */
276    public function test_deleted_close() {
277        $this->r->deleted_close();
278        $this->assertEquals("}", $this->r->doc);
279    }
280
281    /**
282     * Testing footnote_close method.
283     */
284    public function test_footnote_close() {
285        $this->r->footnote_close();
286        $this->assertEquals("}", $this->r->doc);
287    }
288
289    /**
290     * Testing listu_open method.
291     */
292    public function test_listu_open() {
293        $this->r->listu_open();
294        $this->assertEquals("\n\\begin{itemize}\n", $this->r->doc);
295    }
296
297    /**
298     * Testing listo_open method.
299     */
300    public function test_listo_open() {
301        $this->r->listo_open();
302        $this->assertEquals("\n\\begin{enumerate}\n", $this->r->doc);
303    }
304
305    /**
306     * Testing listu_close method.
307     */
308    public function test_listu_close() {
309        $this->r->listu_close();
310        $this->assertEquals("\\end{itemize}\n", $this->r->doc);
311    }
312
313    /**
314     * Testing listo_close method.
315     */
316    public function test_listo_close() {
317        $this->r->listo_close();
318        $this->assertEquals("\\end{enumerate}\n", $this->r->doc);
319    }
320
321    /**
322     * Testing listitem_open method.
323     * It tests different item levels.
324     */
325    public function test_listitem_open() {
326        $this->r->listitem_open(1);
327        $this->assertEquals("  \\item", $this->r->doc);
328        $this->clearDoc();
329
330        $this->r->listitem_open(2);
331        $this->assertEquals("    \\item", $this->r->doc);
332    }
333
334    /**
335     * Testing listcontent_close method.
336     */
337    public function test_listcontent_close() {
338        $this->r->listcontent_close();
339        $this->assertEquals("\n", $this->r->doc);
340    }
341
342    /**
343     * Testing unformatted method.
344     * It tests even with special characters.
345     */
346    public function test_unformatted() {
347        $this->r->unformatted("text");
348        $string = "text";
349        $this->assertEquals($string, $this->r->doc);
350        $this->clearDoc();
351
352        $this->r->unformatted('\{}&%$#_~^<>');
353        $string = '\textbackslash{}\{\}\&\%\$\#\_\textasciitilde{}\textasciicircum{}\textless \textgreater ';
354        $this->assertEquals($string, $this->r->doc);
355    }
356
357    /**
358     * Testing php method.
359     */
360    public function test_php() {
361        $this->r->php("echo \"test\";");
362        $string = "\\lstset{frame=single, language=PHP}\n\\begin{lstlisting}\necho \"test\";\\end{lstlisting}\n\n";
363        $this->assertEquals($string, $this->r->doc);
364    }
365
366    /**
367     * Testing phpblock method.
368     */
369    public function test_phpblock() {
370        $this->r->phpblock("echo \"test\";");
371        $string = "\\lstset{frame=single, language=PHP}\n\\begin{lstlisting}\necho \"test\";\\end{lstlisting}\n\n";
372        $this->assertEquals($string, $this->r->doc);
373    }
374
375    /**
376     * Testing html method.
377     */
378    public function test_html() {
379        $this->r->html("<html><b>Hello World!</b></html>");
380        $string = "\\lstset{frame=single, language=HTML}\n\\begin{lstlisting}\n<html><b>Hello World!</b></html>\\end{lstlisting}\n\n";
381        $this->assertEquals($string, $this->r->doc);
382    }
383
384    /**
385     * Testing htmlblock method.
386     */
387    public function test_htmlblock() {
388        $this->r->htmlblock("<html><b>Hello World!</b></html>");
389        $string = "\\lstset{frame=single, language=HTML}\n\\begin{lstlisting}\n<html><b>Hello World!</b></html>\\end{lstlisting}\n\n";
390        $this->assertEquals($string, $this->r->doc);
391    }
392
393    /**
394     * Testing preformatted method.
395     */
396    public function test_preformatted() {
397        $this->r->preformatted("    no format a a    ");
398        $string = "\n\\begin{verbatim}\n    no format a a    \n\\end{verbatim}\n";
399        $this->assertEquals($string, $this->r->doc);
400    }
401
402    /**
403     * Testing quote_open method.
404     */
405    public function test_quote_open() {
406        $this->r->quote_open();
407        $this->assertEquals("\n\\begin{quote}\n", $this->r->doc);
408    }
409
410    /**
411     * Testing quote_close method.
412     */
413    public function test_quote_close() {
414        $this->r->quote_close();
415        $this->assertEquals("\n\\end{quote}\n", $this->r->doc);
416    }
417
418    /**
419     * Testing file method.
420     */
421    public function test_file() {
422        $this->r->file("std::cout \"Hello world!\";", "C++");
423        $string = "\\lstset{frame=single, language=C++}\n\\begin{lstlisting}\nstd::cout \"Hello world!\";\\end{lstlisting}\n\n";
424        $this->assertEquals($string, $this->r->doc);
425        $this->clearDoc();
426
427        $this->r->file("std::cout \"Hello world!\";", "C++", "script.cpp");
428        $string = "\\lstset{frame=single, language=C++, title=script.cpp}\n\\begin{lstlisting}\nstd::cout \"Hello world!\";\\end{lstlisting}\n\n";
429        $this->assertEquals($string, $this->r->doc);
430    }
431
432    /**
433     * Testing code method.
434     */
435    public function test_code() {
436        $this->r->code("std::cout \"Hello world!\";", "C++");
437        $string = "\\lstset{frame=single, language=C++}\n\\begin{lstlisting}\nstd::cout \"Hello world!\";\\end{lstlisting}\n\n";
438        $this->assertEquals($string, $this->r->doc);
439        $this->clearDoc();
440
441        $this->r->code("std::cout \"Hello world!\";", "C++", "script.cpp");
442        $string = "\\lstset{frame=single, language=C++, title=script.cpp}\n\\begin{lstlisting}\nstd::cout \"Hello world!\";\\end{lstlisting}\n\n";
443        $this->assertEquals($string, $this->r->doc);
444    }
445
446    /**
447     * Testing acronym method.
448     * Even with special characters.
449     */
450    public function test_acronym() {
451        $this->r->acronym("text");
452        $string = "text";
453        $this->assertEquals($string, $this->r->doc);
454        $this->clearDoc();
455
456        $this->r->acronym('\{}&%$#_~^<>');
457        $string = '\textbackslash{}\{\}\&\%\$\#\_\textasciitilde{}\textasciicircum{}\textless \textgreater ';
458        $this->assertEquals($string, $this->r->doc);
459    }
460
461    /**
462     * Testing smiley method.
463     * Even with some special cases.
464     */
465    public function test_smiley() {
466        $this->r->smiley("text");
467        $string = "text";
468        $this->assertEquals($string, $this->r->doc);
469        $this->clearDoc();
470
471        $this->r->smiley('\{}&%$#_~^<>');
472        $string = '\textbackslash{}\{\}\&\%\$\#\_\textasciitilde{}\textasciicircum{}\textless \textgreater ';
473        $this->assertEquals($string, $this->r->doc);
474        $this->clearDoc();
475
476        $this->r->smiley(':-)');
477        $string = ':-)';
478        $this->assertEquals($string, $this->r->doc);
479        $this->clearDoc();
480
481        $this->r->smiley('FIXME');
482        $string = 'FIXME';
483        $this->assertEquals($string, $this->r->doc);
484    }
485
486    /**
487     * Testing entity method.
488     * It tests all possible entities.
489     */
490    public function test_entity() {
491        $this->r->entity("->");
492        $string = "///ENTITYSTART///";
493        $string .= '$\rightarrow$';
494        $string .= '///ENTITYEND///';
495        $this->assertEquals($string, $this->r->doc);
496        $this->clearDoc();
497
498        $this->r->entity("<-");
499        $string = "///ENTITYSTART///";
500        $string .= '$\leftarrow$';
501        $string .= '///ENTITYEND///';
502        $this->assertEquals($string, $this->r->doc);
503        $this->clearDoc();
504
505        $this->r->entity("<->");
506        $string = "///ENTITYSTART///";
507        $string .= '$\leftrightarrow$';
508        $string .= '///ENTITYEND///';
509        $this->assertEquals($string, $this->r->doc);
510        $this->clearDoc();
511
512        $this->r->entity("=>");
513        $string = "///ENTITYSTART///";
514        $string .= '$\Rightarrow$';
515        $string .= '///ENTITYEND///';
516        $this->assertEquals($string, $this->r->doc);
517        $this->clearDoc();
518
519        $this->r->entity("<=");
520        $string = "///ENTITYSTART///";
521        $string .= '$\Leftarrow$';
522        $string .= '///ENTITYEND///';
523        $this->assertEquals($string, $this->r->doc);
524        $this->clearDoc();
525
526        $this->r->entity("<=>");
527        $string = "///ENTITYSTART///";
528        $string .= '$\Leftrightarrow$';
529        $string .= '///ENTITYEND///';
530        $this->assertEquals($string, $this->r->doc);
531        $this->clearDoc();
532
533        $this->r->entity("(c)");
534        $string = "///ENTITYSTART///";
535        $string .= '\copyright ';
536        $string .= '///ENTITYEND///';
537        $this->assertEquals($string, $this->r->doc);
538        $this->clearDoc();
539
540        $this->r->entity("(tm)");
541        $string = "///ENTITYSTART///";
542        $string .= '\texttrademark ';
543        $string .= '///ENTITYEND///';
544        $this->assertEquals($string, $this->r->doc);
545        $this->clearDoc();
546
547        $this->r->entity("(r)");
548        $string = "///ENTITYSTART///";
549        $string .= '\textregistered ';
550        $string .= '///ENTITYEND///';
551        $this->assertEquals($string, $this->r->doc);
552        $this->clearDoc();
553
554        $this->r->entity('\{}&%$#_~^<>');
555        $string = "///ENTITYSTART///";
556        $string .= '\textbackslash{}\{\}\&\%\$\#\_\textasciitilde{}\textasciicircum{}\textless \textgreater ';
557        $string .= '///ENTITYEND///';
558        $this->assertEquals($string, $this->r->doc);
559        $this->clearDoc();
560    }
561
562    /**
563     * Testing multiplyentity method.
564     * Even with special characters.
565     */
566    public function test_multiplyentity() {
567        $this->r->multiplyentity('\{}&%$', '#_~^<>');
568        $string = "///ENTITYSTART///";
569        $string .= '$\textbackslash{}\{\}\&\%\$ \times \#\_\textasciitilde{}\textasciicircum{}\textless \textgreater $';
570        $string .= '///ENTITYEND///';
571        $this->assertEquals($string, $this->r->doc);
572    }
573
574    /**
575     * Testing singlequoteopening method.
576     */
577    public function test_singlequoteopening() {
578        $this->r->singlequoteopening();
579        $this->assertEquals('`', $this->r->doc);
580    }
581
582    /**
583     * Testing singlequoteclosing method.
584     */
585    public function test_singlequoteclosing() {
586        $this->r->singlequoteclosing();
587        $this->assertEquals('\'', $this->r->doc);
588    }
589
590    /**
591     * Testing apostrophe method.
592     */
593    public function test_apostrophe() {
594        $this->r->apostrophe();
595        $this->assertEquals('\'', $this->r->doc);
596    }
597
598    /**
599     * Testing doublequoteopening method.
600     */
601    public function test_doublequoteopening() {
602        $this->r->doublequoteopening();
603        $this->assertEquals(',,', $this->r->doc);
604    }
605
606    /**
607     * Testing doublequoteclosing method.
608     */
609    public function test_doublequoteclosing() {
610        $this->r->doublequoteclosing();
611        $this->assertEquals('"', $this->r->doc);
612    }
613
614    /**
615     * Testing internallink method.
616     * It unfortunatelly tests only non-existing link.
617     * I was not successful simulating whole DW behaviour for this function.
618     */
619    public function test_internallink() {
620        $this->r->internallink("NotExistingCamelCase", "NotExistingCamelCase");
621        $this->assertEquals('NotExistingCamelCase', $this->r->doc);
622    }
623
624    /**
625     * Testing locallink method.
626     */
627    public function test_locallink() {
628        $this->r->locallink("section", "Odkaz");
629        $this->assertEquals("Odkaz (\\autoref{sec:section})", $this->r->doc);
630        $this->clearDoc();
631
632        $this->r->locallink("section");
633        $this->assertEquals("section (\\autoref{sec:section})", $this->r->doc);
634    }
635
636    /**
637     * Testing externallink method.
638     */
639    public function test_externallink() {
640        $this->r->externallink("http://url.com", "Odkaz");
641        $this->assertEquals("\\href{http://url.com}{Odkaz}", $this->r->doc);
642        $this->clearDoc();
643
644        $this->r->externallink("http://url.com");
645        $this->assertEquals("\\url{http://url.com}", $this->r->doc);
646    }
647
648    /**
649     * Testing interwikilink method.
650     * It unfortunately does not load intewiki settings, so testing only default.
651     */
652    public function test_interwikilink() {
653        $this->r->interwikilink("doku>Interwiki", NULL, "doku", "Interwiki");
654        $this->assertEquals("\\href{http://www.google.com/search?q=Interwiki\&amp;btnI=lucky}{Interwiki}", $this->r->doc);
655    }
656
657    /**
658     * Testing filelink method.
659     */
660    public function test_filelink() {
661        $this->r->filelink("file:///P:/Manuals/UserManual.pdf", "text");
662        $this->assertEquals("\\href{file:///P:/Manuals/UserManual.pdf}{text}", $this->r->doc);
663        $this->clearDoc();
664
665        $this->r->filelink("file:///P:/Manuals/UserManual.pdf");
666        $this->assertEquals("\\url{file:///P:/Manuals/UserManual.pdf}", $this->r->doc);
667    }
668
669    /**
670     * Testing windowssharelink method.
671     */
672    public function test_windowssharelink() {
673        $this->r->windowssharelink("\\server\share", "text");
674        $this->assertEquals("\\href{\\\\server\\\\share}{text}", $this->r->doc);
675        $this->clearDoc();
676
677        $this->r->windowssharelink("\\server\share");
678        $this->assertEquals("\\url{\\\\server\\\\share}", $this->r->doc);
679    }
680
681    /**
682     * Testing emaillink method.
683     */
684    public function test_emaillink() {
685        $this->r->emaillink("email@domain.com", "Email");
686        $this->assertEquals("\\href{mailto:email@domain.com}{Email}", $this->r->doc);
687        $this->clearDoc();
688
689        $this->r->emaillink("email@domain.com");
690        $this->assertEquals("\\href{mailto:email@domain.com}{email@domain.com}", $this->r->doc);
691    }
692
693    /**
694     * Testing internalmedia method.
695     * It does not test packaging of media itself, just insertion of commands.
696     * It tests different parameters.
697     */
698    public function test_internalmedia() {
699        $this->r->internalmedia("pic:picture.png", "aaa", "left");
700        $string = "\\raggedleft\\includegraphics[keepaspectratio=true,width=0.8\\textwidth]{picture}\n";
701        $this->assertEquals($string, $this->r->doc);
702        $this->clearDoc();
703
704        $this->r->internalmedia("pic:picture.png", "aaa", "center");
705        $string = "\\centering\\includegraphics[keepaspectratio=true,width=0.8\\textwidth]{picture}\n";
706        $this->assertEquals($string, $this->r->doc);
707        $this->clearDoc();
708
709        $this->r->internalmedia("pic:picture.png", "aaa", "right");
710        $string = "\\raggedright\\includegraphics[keepaspectratio=true,width=0.8\\textwidth]{picture}\n";
711        $this->assertEquals($string, $this->r->doc);
712    }
713
714    public function test_internalmedia_nons() {
715        $this->r->internalmedia("picture.png", "aaa", "left");
716        $string = "\\raggedleft\\includegraphics[keepaspectratio=true,width=0.8\\textwidth]{picture}\n";
717        $this->assertEquals($string, $this->r->doc);
718        $this->clearDoc();
719
720        $this->r->internalmedia("picture.png", "aaa", "center");
721        $string = "\\centering\\includegraphics[keepaspectratio=true,width=0.8\\textwidth]{picture}\n";
722        $this->assertEquals($string, $this->r->doc);
723        $this->clearDoc();
724
725        $this->r->internalmedia("picture.png", "aaa", "right");
726        $string = "\\raggedright\\includegraphics[keepaspectratio=true,width=0.8\\textwidth]{picture}\n";
727        $this->assertEquals($string, $this->r->doc);
728    }
729
730    /**
731     * Testing externalmedia method.
732     * It does not test packaging of media itself, just insertion of commands.
733     * It tests different parameters.
734     */
735    public function test_externalmedia() {
736        $this->r->externalmedia("http://url.com/picture.png", "aaa", "left");
737        $string = "\\raggedleft\\includegraphics[keepaspectratio=true,width=0.8\\textwidth]{picture}\n";
738        $this->assertEquals($string, $this->r->doc);
739        $this->clearDoc();
740
741        $this->r->externalmedia("http://url.com/picture.png", "aaa", "center");
742        $string = "\\centering\\includegraphics[keepaspectratio=true,width=0.8\\textwidth]{picture}\n";
743        $this->assertEquals($string, $this->r->doc);
744        $this->clearDoc();
745
746        $this->r->externalmedia("http://url.com/picture.png", "aaa", "right");
747        $string = "\\raggedright\\includegraphics[keepaspectratio=true,width=0.8\\textwidth]{picture}\n";
748        $this->assertEquals($string, $this->r->doc);
749    }
750
751    /**
752     * Testing table_open method.
753     */
754    public function test_table_open() {
755        $this->r->table_open(5);
756        $string = "\\begin{longtable}{|l|l|l|l|l|}\n\\hline\n";
757        $this->assertEquals($string, $this->r->doc);
758        $this->clearDoc();
759
760        $this->r->table_open(3);
761        $string = "\\begin{longtable}{|l|l|l|}\n\\hline\n";
762        $this->assertEquals($string, $this->r->doc);
763    }
764
765    /**
766     * Testing table_close method.
767     */
768    public function test_table_close() {
769        $this->r->table_close();
770        $string = "\\end{longtable}\n\n";
771        $this->assertEquals($string, $this->r->doc);
772    }
773
774    /**
775     * Testing tablerow_close method.
776     */
777    public function test_tablerow_close() {
778        $this->r->tablerow_close();
779        $string = " \\\\ \n\\hline\n \n";
780        $this->assertEquals($string, $this->r->doc);
781    }
782
783    /**
784     * Testing tableheader_open method.
785     */
786    public function test_tableheader_open() {
787        $this->r->tableheader_open(1, "r", 1);
788        $string = "\\multicolumn{1}{|r|}{\\textbf{";
789        $this->assertEquals($string, $this->r->doc);
790        $this->clearDoc();
791
792        $this->r->tableheader_open(1, NULL, 1);
793        $string = "\\textbf{";
794        $this->assertEquals($string, $this->r->doc);
795        $this->clearDoc();
796
797        $this->r->tableheader_open(2, NULL, 1);
798        $string = "\\multicolumn{2}{|l|}{\\textbf{";
799        $this->assertEquals($string, $this->r->doc);
800        $this->clearDoc();
801
802        $this->r->tableheader_open(1, NULL, 2);
803        $string = "\\multirow{2}{*}{\\textbf{";
804        $this->assertEquals($string, $this->r->doc);
805        $this->clearDoc();
806        //remove the rowspan
807        $this->setUp();
808
809        $this->r->tableheader_open(2, NULL, 2);
810        $string = "\\multicolumn{2}{|l|}{\\multirow{2}{*}{\\textbf{";
811        $this->assertEquals($string, $this->r->doc);
812    }
813
814    /**
815     * Testing tableheader_close method.
816     */
817    public function test_tableheader_close() {
818        $this->r->tableheader_open();
819        $this->clearDoc();
820        $this->r->tableheader_close();
821        $this->assertEquals("} & ", $this->r->doc);
822        $this->clearDoc();
823
824        $this->r->tableheader_open(2);
825        $this->clearDoc();
826        $this->r->tableheader_close();
827        $this->assertEquals("}} & ", $this->r->doc);
828        $this->clearDoc();
829        $this->setUp();
830
831        $this->r->tableheader_open(1, "r");
832        $this->clearDoc();
833        $this->r->tableheader_close();
834        $this->assertEquals("}} & ", $this->r->doc);
835        $this->clearDoc();
836        $this->setUp();
837
838        $this->r->tableheader_open(1, "l", 2);
839        $this->clearDoc();
840        $this->r->tableheader_close();
841        $this->assertEquals("}} & ", $this->r->doc);
842        $this->clearDoc();
843        $this->setUp();
844
845        $this->r->tableheader_open(2, "l", 2);
846        $this->clearDoc();
847        $this->r->tableheader_close();
848        $this->assertEquals("}}} & ", $this->r->doc);
849        $this->clearDoc();
850        $this->setUp();
851    }
852
853    /**
854     * Testing tablecell_open method.
855     */
856    public function test_tablecell_open() {
857        $this->r->tablecell_open(1, "r", 1);
858        $string = "\\multicolumn{1}{|r|}{";
859        $this->assertEquals($string, $this->r->doc);
860        $this->clearDoc();
861
862        $this->r->tablecell_open(1, NULL, 1);
863        $string = "";
864        $this->assertEquals($string, $this->r->doc);
865        $this->clearDoc();
866
867        $this->r->tablecell_open(2, NULL, 1);
868        $string = "\\multicolumn{2}{|l|}{";
869        $this->assertEquals($string, $this->r->doc);
870        $this->clearDoc();
871
872        $this->r->tablecell_open(1, NULL, 2);
873        $string = "\\multirow{2}{*}{";
874        $this->assertEquals($string, $this->r->doc);
875        $this->clearDoc();
876        $this->setUp();
877
878        $this->r->tablecell_open(2, NULL, 2);
879        $string = "\\multicolumn{2}{|l|}{\\multirow{2}{*}{";
880        $this->assertEquals($string, $this->r->doc);
881    }
882
883    /**
884     * Testing tablecell_close method.
885     */
886    public function test_tablecell_close() {
887        $this->r->tablecell_open();
888        $this->clearDoc();
889        $this->r->tablecell_close();
890        $this->assertEquals(" & ", $this->r->doc);
891        $this->clearDoc();
892
893        $this->r->tablecell_open(2);
894        $this->clearDoc();
895        $this->r->tablecell_close();
896        $this->assertEquals("} & ", $this->r->doc);
897        $this->clearDoc();
898        $this->setUp();
899
900        $this->r->tablecell_open(1, "r");
901        $this->clearDoc();
902        $this->r->tablecell_close();
903        $this->assertEquals("} & ", $this->r->doc);
904        $this->clearDoc();
905        $this->setUp();
906
907        $this->r->tablecell_open(1, "l", 2);
908        $this->clearDoc();
909        $this->r->tablecell_close();
910        $this->assertEquals("} & ", $this->r->doc);
911        $this->clearDoc();
912        $this->setUp();
913
914        $this->r->tablecell_open(2, "l", 2);
915        $this->clearDoc();
916        $this->r->tablecell_close();
917        $this->assertEquals("}} & ", $this->r->doc);
918        $this->clearDoc();
919        $this->setUp();
920    }
921
922    /**
923     * Testing _mathMode method.
924     */
925    public function test__mathMode() {
926        $this->r->_mathMode("$\lnot$");
927        $this->assertEquals("$\\lnot$", $this->r->doc);
928        $this->clearDoc();
929
930        $this->r->_mathMode("$-> <- <-> => <= <=> ... −$");
931        $string = '$\rightarrow \leftarrow \leftrightarrow \Rightarrow \Leftarrow \Leftrightarrow \ldots -$';
932        $this->assertEquals($string, $this->r->doc);
933    }
934
935}
936