1<?php 2 3/** 4 * @group plugin_bpmnio 5 * @group plugins 6 */ 7class plugin_bpmnio_link_processor_test extends DokuWikiTest 8{ 9 protected $pluginsEnabled = array('bpmnio'); 10 11 private function loadLinkProcessor(): void 12 { 13 require_once __DIR__ . '/../inc/link_processor.php'; 14 } 15 16 /** 17 * XML with a declaration at position 0 (clean input as provided after source trim) 18 * must be successfully parsed so that wikilinks are resolved. 19 */ 20 public function test_build_payload_xml_declaration_at_start(): void 21 { 22 $this->loadLinkProcessor(); 23 24 io_mkdir_p(dirname(wikiFN('test:target'))); 25 io_saveFile(wikiFN('test:target'), 'Target page'); 26 27 $xml = '<?xml version="1.0" encoding="UTF-8"?>' 28 . '<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">' 29 . '<process id="Process_1">' 30 . '<task id="Task_1" name="[[test:target|Go there]]" />' 31 . '</process>' 32 . '</definitions>'; 33 34 $result = plugin_bpmnio_link_processor::buildPayload($xml); 35 36 // XML was parsed successfully: wikilink markup is stripped from name 37 $this->assertStringNotContainsString('[[', $result['xml']); 38 $this->assertStringContainsString('name="Go there"', $result['xml']); 39 // XML declaration is preserved in output 40 $this->assertStringContainsString('<?xml', $result['xml']); 41 // Link map contains the resolved entry 42 $this->assertArrayHasKey('Task_1', $result['links']); 43 $this->assertEquals('test:target', $result['links']['Task_1']['target']); 44 } 45 46 /** 47 * Empty input returns empty xml and no links without crashing. 48 */ 49 public function test_build_payload_empty_input(): void 50 { 51 $this->loadLinkProcessor(); 52 53 $result = plugin_bpmnio_link_processor::buildPayload(''); 54 55 $this->assertSame('', $result['xml']); 56 $this->assertSame([], $result['links']); 57 } 58 59 /** 60 * XML without wikilinks returns the processed XML and an empty link map. 61 */ 62 public function test_build_payload_no_links(): void 63 { 64 $this->loadLinkProcessor(); 65 66 $xml = '<?xml version="1.0" encoding="UTF-8"?>' 67 . '<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">' 68 . '<process id="Process_1">' 69 . '<task id="Task_1" name="Plain Task" />' 70 . '</process>' 71 . '</definitions>'; 72 73 $result = plugin_bpmnio_link_processor::buildPayload($xml); 74 75 $this->assertStringContainsString('Plain Task', $result['xml']); 76 $this->assertSame([], $result['links']); 77 } 78 79 /** 80 * Malformed XML returns the original string unchanged and no links. 81 */ 82 public function test_build_payload_malformed_xml(): void 83 { 84 $this->loadLinkProcessor(); 85 86 $xml = '<unclosed>'; 87 88 $result = plugin_bpmnio_link_processor::buildPayload($xml); 89 90 $this->assertSame($xml, $result['xml']); 91 $this->assertSame([], $result['links']); 92 } 93} 94