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