ILIAS  release_8 Revision v8.24
ilMathJaxTest Class Reference

Testing the MathJax class. More...

+ Inheritance diagram for ilMathJaxTest:
+ Collaboration diagram for ilMathJaxTest:

Public Member Functions

 testInstanceCanBeCreated ()
 
 testClientSideRendering (int $limiter, string $input, ?string $start, ?string $end, string $expected)
 @depends testInstanceCanBeCreated @dataProvider clientSideData More...
 
 clientSideData ()
 
 testServerSideRendering (string $purpose, ?string $imagefile, string $expected)
 @depends testInstanceCanBeCreated @dataProvider serverSideData More...
 
 serverSideData ()
 

Additional Inherited Members

- Protected Member Functions inherited from ilMathJaxBaseTest
 getEmptyConfig ()
 Get a config without active settings. More...
 
 getFactoryMock (?string $imagefile=null)
 Get a factory mockup that will deliver other mockups. More...
 
 getTemplateMock ()
 Get a global template mockup. More...
 
 getImageMock (string $imagefile)
 Get a cached image mockup from an example file. More...
 
 getServerMock ()
 Get a mockup of the class for server calls. More...
 

Detailed Description

Testing the MathJax class.

Definition at line 26 of file class.ilMathJaxTest.php.

Member Function Documentation

◆ clientSideData()

ilMathJaxTest::clientSideData ( )

Definition at line 47 of file class.ilMathJaxTest.php.

47 : array
48 {
49 return [
50 [0, '[tex]e=m*c^2[/tex]', null, null, '\‍(e=m*c^2\‍)'],
51 [1, '[tex]e=m*c^2[/tex]', null, null, '[tex]e=m*c^2[/tex]'],
52 [2, '[tex]e=m*c^2[/tex]', null, null, '<span class="math">e=m*c^2</span>'],
53 [1, '<span class="math">e=m*c^2</span>', '<span class="math">', '</span>', '[tex]e=m*c^2[/tex]'],
54 [0, '[tex]e=m*c^2[/tex][tex]e=m*c^2[/tex]', null, null, '\‍(e=m*c^2\‍)\‍(e=m*c^2\‍)'],
55 // char beween
56 [0, '[tex]e=m*c^2[/tex]#[tex]e=m*c^2[/tex]', null, null, '\‍(e=m*c^2\‍)#\‍(e=m*c^2\‍)'],
57 [0, '#[tex]e=m*c^2[/tex]#[tex]e=m*c^2[/tex]', null, null, '#\‍(e=m*c^2\‍)#\‍(e=m*c^2\‍)'],
58 [0, '#[tex]e=m*c^2[/tex]#[tex]e=m*c^2[/tex]#', null, null, '#\‍(e=m*c^2\‍)#\‍(e=m*c^2\‍)#'],
59 // multibyte char
60 [0, '[tex]e=m*c^2[/tex]♥[tex]e=m*c^2[/tex]', null, null, '\‍(e=m*c^2\‍)♥\‍(e=m*c^2\‍)'],
61 [0, '♥[tex]e=m*c^2[/tex]♥[tex]e=m*c^2[/tex]', null, null, '♥\‍(e=m*c^2\‍)♥\‍(e=m*c^2\‍)'],
62 [0, '♥[tex]e=m*c^2[/tex]♥[tex]e=m*c^2[/tex]♥', null, null, '♥\‍(e=m*c^2\‍)♥\‍(e=m*c^2\‍)♥'],
63 // start ignored until end is found
64 [0, '[tex]e=m*c^2[tex]e=m*c^2[/tex]', null, null, '\‍(e=m*c^2[tex]e=m*c^2\‍)'],
65 // whole expression ignored if no end is found
66 [0, '[tex]e=m*c^2[/tex][tex]e=m*c^2', null, null, '\‍(e=m*c^2\‍)[tex]e=m*c^2'],
67 ];
68 }

◆ serverSideData()

ilMathJaxTest::serverSideData ( )

Definition at line 90 of file class.ilMathJaxTest.php.

90 : array
91 {
92 return [
93 ['browser', 'example.svg', '<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="17.47'],
94 ['export', 'example.svg', '<img src="data:image/svg+xml;base64,PHN2ZyB4bWxuczp4bGluaz0i'],
95 ['pdf', 'example.png', '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYA'],
96 ['deferred_pdf', null, '[tex]f(x)=\int_{-\infty}^x e^{-t^2}dt[/tex]']
97 ];
98 }

◆ testClientSideRendering()

ilMathJaxTest::testClientSideRendering ( int  $limiter,
string  $input,
?string  $start,
?string  $end,
string  $expected 
)

@depends testInstanceCanBeCreated @dataProvider clientSideData

Definition at line 39 of file class.ilMathJaxTest.php.

39 : void
40 {
41 $config = $this->getEmptyConfig()->withClientEnabled(true)->withClientLimiter($limiter);
43 $result = $mathjax->insertLatexImages($input, $start, $end);
44 $this->assertEquals($expected, $result, 'input: ' . $input);
45 }
getFactoryMock(?string $imagefile=null)
Get a factory mockup that will deliver other mockups.
getEmptyConfig()
Get a config without active settings.
static getIndependent(ilMathJaxConfig $config, ilMathJaxFactory $factory)
Get an independent instance with a specific config for use in unit tests or on the mathjax settings p...
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85

References $config, ilMathJaxBaseTest\getEmptyConfig(), ilMathJaxBaseTest\getFactoryMock(), and ilMathJax\getIndependent().

+ Here is the call graph for this function:

◆ testInstanceCanBeCreated()

ilMathJaxTest::testInstanceCanBeCreated ( )

Definition at line 28 of file class.ilMathJaxTest.php.

28 : void
29 {
30 $config = $this->getEmptyConfig();
31 $mathjax = ilMathJax::getIndependent($this->getEmptyConfig(), $this->getFactoryMock());
32 $this->assertInstanceOf('ilMathJax', $mathjax);
33 }

References $config, ilMathJaxBaseTest\getEmptyConfig(), ilMathJaxBaseTest\getFactoryMock(), and ilMathJax\getIndependent().

+ Here is the call graph for this function:

◆ testServerSideRendering()

ilMathJaxTest::testServerSideRendering ( string  $purpose,
?string  $imagefile,
string  $expected 
)

@depends testInstanceCanBeCreated @dataProvider serverSideData

Definition at line 74 of file class.ilMathJaxTest.php.

74 : void
75 {
76 $input = '[tex]f(x)=\int_{-\infty}^x e^{-t^2}dt[/tex]';
77
78 $config = $this->getEmptyConfig()
79 ->withServerEnabled(true)
80 ->withServerForBrowser($purpose == 'browser')
81 ->withServerForExport($purpose == 'export')
82 ->withServerForPdf($purpose == 'pdf');
83
84 $mathjax = ilMathJax::getIndependent($config, $this->getFactoryMock($imagefile))->init($purpose);
85 $result = $mathjax->insertLatexImages($input);
86 $head = substr($result, 0, 60);
87 $this->assertEquals($expected, $head, 'purpose: ' . $purpose);
88 }

References $config, ilMathJaxBaseTest\getEmptyConfig(), ilMathJaxBaseTest\getFactoryMock(), and ilMathJax\getIndependent().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: