ILIAS  release_8 Revision v8.24
class.ilMathJaxTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once __DIR__ . '/ilMathJaxBaseTest.php';
22
27{
28 public function testInstanceCanBeCreated(): void
29 {
30 $config = $this->getEmptyConfig();
31 $mathjax = ilMathJax::getIndependent($this->getEmptyConfig(), $this->getFactoryMock());
32 $this->assertInstanceOf('ilMathJax', $mathjax);
33 }
34
39 public function testClientSideRendering(int $limiter, string $input, ?string $start, ?string $end, string $expected): 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 }
46
47 public function clientSideData(): 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 }
69
74 public function testServerSideRendering(string $purpose, ?string $imagefile, string $expected): 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 }
89
90 public function serverSideData(): 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 }
99}
Base class for al tests.
getFactoryMock(?string $imagefile=null)
Get a factory mockup that will deliver other mockups.
getEmptyConfig()
Get a config without active settings.
Testing the MathJax class.
testServerSideRendering(string $purpose, ?string $imagefile, string $expected)
@depends testInstanceCanBeCreated @dataProvider serverSideData
testClientSideRendering(int $limiter, string $input, ?string $start, ?string $end, string $expected)
@depends testInstanceCanBeCreated @dataProvider clientSideData
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