1<?php 2 3/** 4 * @group plugin_bpmnio 5 * @group plugins 6 */ 7class action_plugin_bpmnio_editor_test_form 8{ 9 public array $hiddenFields = []; 10 public string $html = ''; 11 12 public function setHiddenField($name, $value) 13 { 14 $this->hiddenFields[$name] = $value; 15 } 16 17 public function addHTML($html) 18 { 19 $this->html .= $html; 20 } 21} 22 23class action_plugin_bpmnio_editor_test extends DokuWikiTest 24{ 25 protected $pluginsEnabled = array('bpmnio'); 26 27 /** 28 * Test that the editor plugin can be loaded 29 */ 30 public function test_plugin_load() 31 { 32 $plugin = plugin_load('action', 'bpmnio_editor'); 33 $this->assertNotNull($plugin, 'Editor action plugin should be loadable'); 34 } 35 36 /** 37 * Test section edit button for BPMN target 38 */ 39 public function test_section_edit_button_bpmn() 40 { 41 $plugin = plugin_load('action', 'bpmnio_editor'); 42 43 $data = ['target' => 'plugin_bpmnio_bpmn', 'name' => '']; 44 $event = new \dokuwiki\Extension\Event('HTML_SECEDIT_BUTTON', $data); 45 46 $plugin->sectionEditButton($event); 47 48 $this->assertNotEmpty($data['name'], 'Button name should be set for BPMN target'); 49 } 50 51 /** 52 * Test section edit button for DMN target 53 */ 54 public function test_section_edit_button_dmn() 55 { 56 $plugin = plugin_load('action', 'bpmnio_editor'); 57 58 $data = ['target' => 'plugin_bpmnio_dmn', 'name' => '']; 59 $event = new \dokuwiki\Extension\Event('HTML_SECEDIT_BUTTON', $data); 60 61 $plugin->sectionEditButton($event); 62 63 $this->assertNotEmpty($data['name'], 'Button name should be set for DMN target'); 64 } 65 66 /** 67 * Test section edit button ignores non-bpmnio targets 68 */ 69 public function test_section_edit_button_ignores_other() 70 { 71 $plugin = plugin_load('action', 'bpmnio_editor'); 72 73 $data = ['target' => 'section', 'name' => '']; 74 $event = new \dokuwiki\Extension\Event('HTML_SECEDIT_BUTTON', $data); 75 76 $plugin->sectionEditButton($event); 77 78 $this->assertEmpty($data['name'], 'Button name should not be set for non-bpmnio targets'); 79 } 80 81 /** 82 * Test handlePost does nothing when plugin data not in POST 83 */ 84 public function test_handle_post_noop_without_data() 85 { 86 $plugin = plugin_load('action', 'bpmnio_editor'); 87 88 global $TEXT; 89 $TEXT = 'original'; 90 global $INPUT; 91 92 $data = 'edit'; 93 $event = new \dokuwiki\Extension\Event('ACTION_ACT_PREPROCESS', $data); 94 95 $plugin->handlePost($event); 96 97 $this->assertEquals('original', $TEXT, '$TEXT should not change when plugin data is not posted'); 98 } 99 100 public function test_handle_form_generates_balanced_editor_markup() 101 { 102 $plugin = plugin_load('action', 'bpmnio_editor'); 103 104 global $TEXT; 105 global $RANGE; 106 107 $TEXT = '<xml />'; 108 $RANGE = '1-2'; 109 110 $form = new action_plugin_bpmnio_editor_test_form(); 111 $data = [ 112 'target' => 'plugin_bpmnio_bpmn', 113 'form' => $form, 114 ]; 115 $event = new \dokuwiki\Extension\Event('EDIT_FORM_ADDTEXTAREA', $data); 116 117 $plugin->handleForm($event); 118 119 $this->assertArrayHasKey('plugin_bpmnio_data', $form->hiddenFields); 120 $this->assertStringContainsString('id="plugin_bpmnio__bpmn_editor"', $form->html); 121 $this->assertStringContainsString('<div class="bpmn_js_canvas">', $form->html); 122 $this->assertSame(4, substr_count($form->html, '<div')); 123 $this->assertSame(4, substr_count($form->html, '</div>')); 124 } 125} 126