xref: /plugin/bpmnio/_test/syntax_plugin_bpmnio_bpmnio.test.php (revision 242a8e5c8fdb14becaae50d3af24fc80cf14b6f4)
1<?php
2/**
3 * @group plugin_bpmnio
4 * @group plugins
5 */
6class syntax_plugin_bpmnio_test extends DokuWikiTest {
7
8    protected $pluginsEnabled = array('bpmnio');
9
10    public function test_syntax_bpmn() {
11        $info = array();
12        $expected = <<<OUT
13        <div class="plugin-bpmnio" id="__bpmn_js_1"><div class="bpmn_js_data">
14            ClhNTC4uLgo=
15        </div><div class="bpmn_js_canvas sectionedit1">
16            <div class="bpmn_js_container"></div>
17        </div><!-- EDIT{&quot;target&quot;:&quot;plugin_bpmnio_bpmn&quot;,&quot;secid&quot;:1,&quot;range&quot;:&quot;21-29&quot;} --></div>
18        OUT;
19
20        $input = <<<IN
21        <bpmnio type="bpmn">
22        XML...
23        </bpmnio>
24        IN;
25
26        $instructions = p_get_instructions($input);
27        $xhtml = p_render('xhtml', $instructions, $info);
28
29        $this->assertEquals($expected, $xhtml);
30    }
31
32    public function test_syntax_dmn() {
33        $info = array();
34        $expected = <<<OUT
35        <div class="plugin-bpmnio" id="__dmn_js_1"><div class="dmn_js_data">
36            ClhNTC4uLgo=
37        </div><div class="dmn_js_canvas sectionedit1">
38            <div class="dmn_js_container"></div>
39        </div><!-- EDIT{&quot;target&quot;:&quot;plugin_bpmnio_dmn&quot;,&quot;secid&quot;:1,&quot;range&quot;:&quot;20-28&quot;} --></div>
40        OUT;
41
42        $input = <<<IN
43        <bpmnio type="dmn">
44        XML...
45        </bpmnio>
46        IN;
47
48        $instructions = p_get_instructions($input);
49        $xhtml = p_render('xhtml', $instructions, $info);
50
51        $this->assertEquals($expected, $xhtml);
52    }
53
54    /**
55     * Test that type defaults to bpmn when not specified
56     */
57    public function test_syntax_default_type() {
58        $info = array();
59
60        $input = <<<IN
61        <bpmnio>
62        XML...
63        </bpmnio>
64        IN;
65
66        $instructions = p_get_instructions($input);
67        $xhtml = p_render('xhtml', $instructions, $info);
68
69        $this->assertStringContainsString('bpmn_js_data', $xhtml);
70        $this->assertStringContainsString('bpmn_js_canvas', $xhtml);
71        $this->assertStringContainsString('bpmn_js_container', $xhtml);
72    }
73
74    /**
75     * Test empty content between tags
76     */
77    public function test_syntax_empty_content() {
78        $info = array();
79
80        $input = <<<IN
81        <bpmnio type="bpmn">
82        </bpmnio>
83        IN;
84
85        $instructions = p_get_instructions($input);
86        $xhtml = p_render('xhtml', $instructions, $info);
87
88        // Should still produce the structure, with base64 of whitespace/empty
89        $this->assertStringContainsString('plugin-bpmnio', $xhtml);
90        $this->assertStringContainsString('bpmn_js_data', $xhtml);
91    }
92
93    /**
94     * Test that multiline XML content is properly base64-encoded
95     */
96    public function test_syntax_multiline_content() {
97        $info = array();
98
99        $input = <<<IN
100        <bpmnio type="bpmn">
101        <?xml version="1.0"?>
102        <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">
103        </definitions>
104        </bpmnio>
105        IN;
106
107        $instructions = p_get_instructions($input);
108        $xhtml = p_render('xhtml', $instructions, $info);
109
110        $this->assertStringContainsString('bpmn_js_data', $xhtml);
111        // Verify the data section contains valid base64
112        preg_match('/<div class="bpmn_js_data">\s*(.*?)\s*<\/div>/s', $xhtml, $matches);
113        $this->assertNotEmpty($matches[1]);
114        $decoded = base64_decode(trim($matches[1]), true);
115        $this->assertNotFalse($decoded, 'Content should be valid base64');
116        $this->assertStringContainsString('definitions', $decoded);
117    }
118
119    /**
120     * Test that the plugin produces section edit markers for inline content
121     */
122    public function test_syntax_section_edit_bpmn() {
123        $info = array();
124
125        $input = <<<IN
126        <bpmnio type="bpmn">
127        Content
128        </bpmnio>
129        IN;
130
131        $instructions = p_get_instructions($input);
132        $xhtml = p_render('xhtml', $instructions, $info);
133
134        $this->assertStringContainsString('sectionedit', $xhtml);
135        $this->assertStringContainsString('plugin_bpmnio_bpmn', $xhtml);
136    }
137
138    /**
139     * Test that the plugin produces section edit markers for DMN inline content
140     */
141    public function test_syntax_section_edit_dmn() {
142        $info = array();
143
144        $input = <<<IN
145        <bpmnio type="dmn">
146        Content
147        </bpmnio>
148        IN;
149
150        $instructions = p_get_instructions($input);
151        $xhtml = p_render('xhtml', $instructions, $info);
152
153        $this->assertStringContainsString('sectionedit', $xhtml);
154        $this->assertStringContainsString('plugin_bpmnio_dmn', $xhtml);
155    }
156
157    /**
158     * Test that unrecognized text outside <bpmnio> is not affected
159     */
160    public function test_syntax_no_interference() {
161        $info = array();
162
163        $input = <<<IN
164        Hello World
165        <bpmnio type="bpmn">
166        XML...
167        </bpmnio>
168        Goodbye World
169        IN;
170
171        $instructions = p_get_instructions($input);
172        $xhtml = p_render('xhtml', $instructions, $info);
173
174        $this->assertStringContainsString('Hello World', $xhtml);
175        $this->assertStringContainsString('Goodbye World', $xhtml);
176        $this->assertStringContainsString('plugin-bpmnio', $xhtml);
177    }
178
179    /**
180     * Test the handle method directly for ENTER state
181     */
182    public function test_handle_enter_state() {
183        $plugin = plugin_load('syntax', 'bpmnio_bpmnio');
184        $this->assertNotNull($plugin, 'Plugin should be loadable');
185
186        $handler = new Doku_Handler();
187        $result = $plugin->handle('<bpmnio type="bpmn">', DOKU_LEXER_ENTER, 0, $handler);
188
189        $this->assertEquals(DOKU_LEXER_ENTER, $result[0]);
190        $this->assertEquals('bpmn', $result[1]);
191    }
192
193    /**
194     * Test the handle method directly for EXIT state
195     */
196    public function test_handle_exit_state() {
197        $plugin = plugin_load('syntax', 'bpmnio_bpmnio');
198        $handler = new Doku_Handler();
199        $result = $plugin->handle('</bpmnio>', DOKU_LEXER_EXIT, 0, $handler);
200
201        $this->assertEquals(DOKU_LEXER_EXIT, $result[0]);
202    }
203
204    /**
205     * Test that the plugin is correctly registered
206     */
207    public function test_plugin_registration() {
208        $plugin = plugin_load('syntax', 'bpmnio_bpmnio');
209        $this->assertNotNull($plugin, 'Plugin should be loadable');
210        $this->assertEquals('block', $plugin->getPType());
211        $this->assertEquals('protected', $plugin->getType());
212        $this->assertEquals(0, $plugin->getSort());
213    }
214