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