1*8fed17f3SAndreas Gohr<?php 2*8fed17f3SAndreas Gohr 3*8fed17f3SAndreas Gohrnamespace dokuwiki\plugin\struct\test; 4*8fed17f3SAndreas Gohr 5*8fed17f3SAndreas Gohruse Doku_Event; 6*8fed17f3SAndreas Gohr 7*8fed17f3SAndreas Gohr/** 8*8fed17f3SAndreas Gohr * @group plugin_struct 9*8fed17f3SAndreas Gohr * @group plugins 10*8fed17f3SAndreas Gohr * 11*8fed17f3SAndreas Gohr * @covers \action_plugin_struct_output 12*8fed17f3SAndreas Gohr */ 13*8fed17f3SAndreas Gohrclass OutputTest extends StructTest 14*8fed17f3SAndreas Gohr{ 15*8fed17f3SAndreas Gohr 16*8fed17f3SAndreas Gohr /** @var array add the extra plugins */ 17*8fed17f3SAndreas Gohr protected $pluginsEnabled = ['struct', 'sqlite', 'log', 'include']; 18*8fed17f3SAndreas Gohr 19*8fed17f3SAndreas Gohr public function setUp(): void 20*8fed17f3SAndreas Gohr { 21*8fed17f3SAndreas Gohr parent::setUp(); 22*8fed17f3SAndreas Gohr 23*8fed17f3SAndreas Gohr $this->loadSchemaJSON('schema1'); 24*8fed17f3SAndreas Gohr $this->loadSchemaJSON('schema_3'); 25*8fed17f3SAndreas Gohr 26*8fed17f3SAndreas Gohr $page = 'page01'; 27*8fed17f3SAndreas Gohr $includedPage = 'foo'; 28*8fed17f3SAndreas Gohr $now = time(); 29*8fed17f3SAndreas Gohr $this->saveData( 30*8fed17f3SAndreas Gohr $page, 31*8fed17f3SAndreas Gohr 'schema1', 32*8fed17f3SAndreas Gohr [ 33*8fed17f3SAndreas Gohr 'first' => 'first data', 34*8fed17f3SAndreas Gohr 'second' => ['second data', 'more data', 'even more'], 35*8fed17f3SAndreas Gohr 'third' => 'third data', 36*8fed17f3SAndreas Gohr 'fourth' => 'fourth data' 37*8fed17f3SAndreas Gohr ], 38*8fed17f3SAndreas Gohr $now 39*8fed17f3SAndreas Gohr ); 40*8fed17f3SAndreas Gohr $this->saveData( 41*8fed17f3SAndreas Gohr $page, 42*8fed17f3SAndreas Gohr 'schema_3', 43*8fed17f3SAndreas Gohr [ 44*8fed17f3SAndreas Gohr 'first_field' => 'first data', 45*8fed17f3SAndreas Gohr 'second field' => ['second data', 'more data', 'even more'], 46*8fed17f3SAndreas Gohr 'third%field' => 'third data', 47*8fed17f3SAndreas Gohr 'fourth.field?' => 'fourth data' 48*8fed17f3SAndreas Gohr ], 49*8fed17f3SAndreas Gohr $now 50*8fed17f3SAndreas Gohr ); 51*8fed17f3SAndreas Gohr $this->saveData( 52*8fed17f3SAndreas Gohr $includedPage, 53*8fed17f3SAndreas Gohr 'schema1', 54*8fed17f3SAndreas Gohr [ 55*8fed17f3SAndreas Gohr 'first' => 'first data', 56*8fed17f3SAndreas Gohr 'second' => ['second data', 'more data', 'even more'], 57*8fed17f3SAndreas Gohr 'third' => 'third data', 58*8fed17f3SAndreas Gohr 'fourth' => 'fourth data' 59*8fed17f3SAndreas Gohr ], 60*8fed17f3SAndreas Gohr $now 61*8fed17f3SAndreas Gohr ); 62*8fed17f3SAndreas Gohr } 63*8fed17f3SAndreas Gohr 64*8fed17f3SAndreas Gohr public function test_output() 65*8fed17f3SAndreas Gohr { 66*8fed17f3SAndreas Gohr global $ID; 67*8fed17f3SAndreas Gohr $page = 'page01'; 68*8fed17f3SAndreas Gohr $ID = $page; 69*8fed17f3SAndreas Gohr 70*8fed17f3SAndreas Gohr saveWikiText($page, "====== abc ======\ndef", ''); 71*8fed17f3SAndreas Gohr $instructions = p_cached_instructions(wikiFN($page), false, $page); 72*8fed17f3SAndreas Gohr $this->assertEquals('document_start', $instructions[0][0]); 73*8fed17f3SAndreas Gohr $this->assertEquals('header', $instructions[1][0]); 74*8fed17f3SAndreas Gohr $this->assertEquals('plugin', $instructions[2][0]); 75*8fed17f3SAndreas Gohr $this->assertEquals('struct_output', $instructions[2][1][0]); 76*8fed17f3SAndreas Gohr } 77*8fed17f3SAndreas Gohr 78*8fed17f3SAndreas Gohr public function test_include_missing_output() 79*8fed17f3SAndreas Gohr { 80*8fed17f3SAndreas Gohr global $ID; 81*8fed17f3SAndreas Gohr $page = 'page01'; 82*8fed17f3SAndreas Gohr $includedPage = 'foo'; 83*8fed17f3SAndreas Gohr 84*8fed17f3SAndreas Gohr saveWikiText($page, "====== abc ======\n{{page>foo}}\n", ''); 85*8fed17f3SAndreas Gohr saveWikiText($includedPage, "====== included page ======\nqwe\n", ''); 86*8fed17f3SAndreas Gohr 87*8fed17f3SAndreas Gohr 88*8fed17f3SAndreas Gohr plugin_load('action', 'struct_output', true); 89*8fed17f3SAndreas Gohr $ID = $page; 90*8fed17f3SAndreas Gohr $insMainPage = p_cached_instructions(wikiFN($page), false, $page); 91*8fed17f3SAndreas Gohr $this->assertEquals('document_start', $insMainPage[0][0]); 92*8fed17f3SAndreas Gohr $this->assertEquals('header', $insMainPage[1][0]); 93*8fed17f3SAndreas Gohr $this->assertEquals('plugin', $insMainPage[2][0]); 94*8fed17f3SAndreas Gohr $this->assertEquals('struct_output', $insMainPage[2][1][0]); 95*8fed17f3SAndreas Gohr 96*8fed17f3SAndreas Gohr plugin_load('action', 'struct_output', true); 97*8fed17f3SAndreas Gohr $ID = $includedPage; 98*8fed17f3SAndreas Gohr $insIncludedPage = p_cached_instructions(wikiFN($includedPage), false, $includedPage); 99*8fed17f3SAndreas Gohr $this->assertEquals('document_start', $insIncludedPage[0][0]); 100*8fed17f3SAndreas Gohr $this->assertEquals('header', $insIncludedPage[1][0]); 101*8fed17f3SAndreas Gohr $this->assertEquals('plugin', $insIncludedPage[2][0], 'The struct data of a page that has been included should still be displayed when viewed on its own.'); 102*8fed17f3SAndreas Gohr $this->assertEquals('struct_output', $insIncludedPage[2][1][0]); 103*8fed17f3SAndreas Gohr 104*8fed17f3SAndreas Gohr } 105*8fed17f3SAndreas Gohr 106*8fed17f3SAndreas Gohr public function test_log_conflict() 107*8fed17f3SAndreas Gohr { 108*8fed17f3SAndreas Gohr global $ID; 109*8fed17f3SAndreas Gohr $page = 'page01'; 110*8fed17f3SAndreas Gohr $ID = $page; 111*8fed17f3SAndreas Gohr 112*8fed17f3SAndreas Gohr saveWikiText($page, "====== abc ======\n{{log}}\n", ''); 113*8fed17f3SAndreas Gohr saveWikiText($page . ':log', '====== abc log ====== 114*8fed17f3SAndreas GohrLog for [[page01]]: 115*8fed17f3SAndreas Gohr 116*8fed17f3SAndreas Gohr * 2017-02-24 10:54:13 //Example User//: foo bar', ''); 117*8fed17f3SAndreas Gohr $instructions = p_cached_instructions(wikiFN($page), false, $page); 118*8fed17f3SAndreas Gohr $this->assertEquals('document_start', $instructions[0][0]); 119*8fed17f3SAndreas Gohr $this->assertEquals('header', $instructions[1][0]); 120*8fed17f3SAndreas Gohr $this->assertEquals('plugin', $instructions[2][0], 'The struct data should be rendererd after the first headline'); 121*8fed17f3SAndreas Gohr $this->assertEquals('struct_output', $instructions[2][1][0]); 122*8fed17f3SAndreas Gohr } 123*8fed17f3SAndreas Gohr 124*8fed17f3SAndreas Gohr /** 125*8fed17f3SAndreas Gohr * Replace and clean up template placeholders 126*8fed17f3SAndreas Gohr * provided by a dw2pdf event 127*8fed17f3SAndreas Gohr */ 128*8fed17f3SAndreas Gohr public function test_dw2pdf_replacements() 129*8fed17f3SAndreas Gohr { 130*8fed17f3SAndreas Gohr $page = 'page01'; 131*8fed17f3SAndreas Gohr $replace = ['@ID@' => $page]; 132*8fed17f3SAndreas Gohr $content = <<< HTML 133*8fed17f3SAndreas Gohr<table class="pdffooter"> 134*8fed17f3SAndreas Gohr <tr> 135*8fed17f3SAndreas Gohr <td style="text-align: left">ID: @ID@</td> 136*8fed17f3SAndreas Gohr <td style="text-align: center">Version: @ID@@@PLUGIN_STRUCT_schema_3_version@~@PLUGIN_STRUCT_schema_3_first_field@</td> 137*8fed17f3SAndreas Gohr <td style="text-align: right">Second data: @PLUGIN_STRUCT_schema_3_second field@</td> 138*8fed17f3SAndreas Gohr </tr> 139*8fed17f3SAndreas Gohr</table> 140*8fed17f3SAndreas GohrHTML; 141*8fed17f3SAndreas Gohr $processed = <<< HTML 142*8fed17f3SAndreas Gohr<table class="pdffooter"> 143*8fed17f3SAndreas Gohr <tr> 144*8fed17f3SAndreas Gohr <td style="text-align: left">ID: page01</td> 145*8fed17f3SAndreas Gohr <td style="text-align: center">Version: page01@~first data</td> 146*8fed17f3SAndreas Gohr <td style="text-align: right">Second data: second data, more data, even more</td> 147*8fed17f3SAndreas Gohr </tr> 148*8fed17f3SAndreas Gohr</table> 149*8fed17f3SAndreas GohrHTML; 150*8fed17f3SAndreas Gohr 151*8fed17f3SAndreas Gohr $evdata = ['id' => $page, 'replace' => &$replace, 'content' => &$content]; 152*8fed17f3SAndreas Gohr $event = new Doku_Event('PLUGIN_DW2PDF_REPLACE', $evdata); 153*8fed17f3SAndreas Gohr if ($event->advise_before()) { 154*8fed17f3SAndreas Gohr $content = str_replace(array_keys($replace), array_values($replace), $content); 155*8fed17f3SAndreas Gohr } 156*8fed17f3SAndreas Gohr $event->advise_after(); 157*8fed17f3SAndreas Gohr 158*8fed17f3SAndreas Gohr $this->assertEquals($processed, $content); 159*8fed17f3SAndreas Gohr } 160*8fed17f3SAndreas Gohr} 161