1<?php
2
3require_once(__DIR__ . '/../webcomponent.php');
4
5/**
6 * Test the component plugin
7 *
8 * @group plugin_webcomponent
9 * @group plugins
10 */
11class plugin_webcomponent_math_test extends DokuWikiTest
12{
13
14    protected $pluginsEnabled = [webcomponent::PLUGIN_NAME];
15
16
17    public function test_component_name()
18    {
19
20        $componentName = syntax_plugin_webcomponent_math::getComponentName();
21
22        $this->assertEquals('math', $componentName);
23
24    }
25
26    /**
27     * Do we protect the math syntax fully
28     */
29    public function test_syntax_base()
30    {
31
32        $elements = syntax_plugin_webcomponent_math::getElements();
33        // The element is protecting, therefore a dokuwiki link should not be converted to a <a> Html element
34        $content = '[[link]]';
35        $info = array();
36        foreach ($elements as $element) {
37            $doku_text = '<' . $element . '>' . $content . '</' . $element . '>';
38            $instructions = p_get_instructions($doku_text);
39            $xhtml = p_render('xhtml', $instructions, $info);
40            $expected = DOKU_LF.
41                '<p>'.DOKU_LF.
42                '&lt;'.$element.'&gt;[[link]]&lt;/'.$element.'&gt;'.DOKU_LF.
43                '</p>'.DOKU_LF;
44            $this->assertEquals($expected, $xhtml);
45        }
46
47    }
48
49
50    /**
51     * Test if the MathJs library were not added
52     */
53    public function test_library_not_added()
54    {
55
56        global $conf;
57        $conf['template'] = 'bootie';
58
59        $pageId = webcomponent::getNameSpace() . 'test_library_base';
60        $doku_text = 'whatever without math element';
61        saveWikiText($pageId, $doku_text, 'test_indexer test library base');
62        idx_addPage($pageId);
63        $testRequest = new TestRequest();
64        $testResponse = $testRequest->get(array('id' => $pageId));
65        $divId = webcomponent::PLUGIN_NAME . '_' . syntax_plugin_webcomponent_math::getComponentName();
66        $mathJaxDiv = $testResponse->queryHTML('#' . $divId)->elements;
67        $expected = 0;
68        $this->assertEquals($expected, sizeof($mathJaxDiv));
69
70
71    }
72
73    /**
74     * Test if the MathJs library were added
75     */
76    public function test_library_added()
77    {
78
79        global $conf;
80        $conf['template'] = 'bootie';
81
82        $pageId = webcomponent::getNameSpace() . 'test_library_added';
83        $doku_text = '<math>x^2</math>';
84        saveWikiText($pageId, $doku_text, 'test_indexer test library added');
85        idx_addPage($pageId);
86        $testRequest = new TestRequest();
87        $testResponse = $testRequest->get(array('id' => $pageId));
88        $divId = webcomponent::PLUGIN_NAME . '_' . syntax_plugin_webcomponent_math::getComponentName();
89        $mathJaxDiv = $testResponse->queryHTML('#' . $divId)->elements;
90        $expected = 1;
91        $this->assertEquals($expected, sizeof($mathJaxDiv));
92
93
94    }
95
96
97}
98