1*16999ed1SAndreas Gohr<?php 2*16999ed1SAndreas Gohr 3*16999ed1SAndreas Gohrnamespace dokuwiki\test\Parsing; 4*16999ed1SAndreas Gohr 5*16999ed1SAndreas Gohruse dokuwiki\Parsing\ModeRegistry; 6*16999ed1SAndreas Gohr 7*16999ed1SAndreas Gohr/** 8*16999ed1SAndreas Gohr * The per-parse syntax override: p_get_instructions($text, $syntax) parses 9*16999ed1SAndreas Gohr * under the requested flavour regardless of the configured $conf['syntax']. 10*16999ed1SAndreas Gohr */ 11*16999ed1SAndreas Gohrclass SyntaxOverrideTest extends \DokuWikiTest 12*16999ed1SAndreas Gohr{ 13*16999ed1SAndreas Gohr /** Names of all instruction calls produced for $text under $syntax. */ 14*16999ed1SAndreas Gohr private function callNames(string $text, ?string $syntax): array 15*16999ed1SAndreas Gohr { 16*16999ed1SAndreas Gohr return array_column(p_get_instructions($text, $syntax), 0); 17*16999ed1SAndreas Gohr } 18*16999ed1SAndreas Gohr 19*16999ed1SAndreas Gohr public function testDwOverrideUnderMarkdownConfig() 20*16999ed1SAndreas Gohr { 21*16999ed1SAndreas Gohr global $conf; 22*16999ed1SAndreas Gohr $conf['syntax'] = 'md'; 23*16999ed1SAndreas Gohr 24*16999ed1SAndreas Gohr // [[wiki]] is DokuWiki link syntax; it only parses as a link when the 25*16999ed1SAndreas Gohr // DW internallink mode is loaded, which the 'dw' override forces on. 26*16999ed1SAndreas Gohr $names = $this->callNames('[[wiki:syntax]]', 'dw'); 27*16999ed1SAndreas Gohr $this->assertContains('internallink', $names); 28*16999ed1SAndreas Gohr } 29*16999ed1SAndreas Gohr 30*16999ed1SAndreas Gohr public function testMarkdownOverrideUnderDwConfig() 31*16999ed1SAndreas Gohr { 32*16999ed1SAndreas Gohr global $conf; 33*16999ed1SAndreas Gohr $conf['syntax'] = 'dw'; 34*16999ed1SAndreas Gohr 35*16999ed1SAndreas Gohr // *foo* is GFM emphasis; it only fires when gfm_emphasis is loaded, 36*16999ed1SAndreas Gohr // which the 'md' override forces on even though the wiki prefers DW. 37*16999ed1SAndreas Gohr $names = $this->callNames('a *foo* b', 'md'); 38*16999ed1SAndreas Gohr $this->assertContains('emphasis_open', $names); 39*16999ed1SAndreas Gohr } 40*16999ed1SAndreas Gohr 41*16999ed1SAndreas Gohr public function testNullHonoursConfiguredSyntax() 42*16999ed1SAndreas Gohr { 43*16999ed1SAndreas Gohr global $conf; 44*16999ed1SAndreas Gohr $conf['syntax'] = 'md'; 45*16999ed1SAndreas Gohr 46*16999ed1SAndreas Gohr // Passing null means "use the configured syntax" — so [[wiki]] stays 47*16999ed1SAndreas Gohr // literal because DW internallink is not loaded under 'md'. 48*16999ed1SAndreas Gohr $names = $this->callNames('[[wiki:syntax]]', null); 49*16999ed1SAndreas Gohr $this->assertNotContains('internallink', $names); 50*16999ed1SAndreas Gohr } 51*16999ed1SAndreas Gohr 52*16999ed1SAndreas Gohr public function testTwoRegistriesProduceDifferentModeLists() 53*16999ed1SAndreas Gohr { 54*16999ed1SAndreas Gohr // Catches a singleton regression: building two registries with 55*16999ed1SAndreas Gohr // different syntaxes in one request must yield different mode sets. 56*16999ed1SAndreas Gohr $dw = array_column((new ModeRegistry('dw'))->getModes(), 'mode'); 57*16999ed1SAndreas Gohr $md = array_column((new ModeRegistry('md'))->getModes(), 'mode'); 58*16999ed1SAndreas Gohr 59*16999ed1SAndreas Gohr $this->assertNotEquals($dw, $md); 60*16999ed1SAndreas Gohr $this->assertContains('internallink', $dw); 61*16999ed1SAndreas Gohr $this->assertContains('gfm_emphasis', $md); 62*16999ed1SAndreas Gohr } 63*16999ed1SAndreas Gohr} 64