1e89aeebdSAndreas Gohr<?php 2e89aeebdSAndreas Gohr 3e89aeebdSAndreas Gohrnamespace dokuwiki\test\Parsing\ParserMode; 4e89aeebdSAndreas Gohr 5e89aeebdSAndreas Gohruse dokuwiki\Parsing\ModeRegistry; 6e89aeebdSAndreas Gohruse dokuwiki\Parsing\ParserMode\GfmLink; 7e89aeebdSAndreas Gohruse dokuwiki\Parsing\ParserMode\Internallink; 8e89aeebdSAndreas Gohr 9e89aeebdSAndreas Gohr/** 10e89aeebdSAndreas Gohr * Tests for GFM inline links `[text](url)` dispatching to DokuWiki's 11e89aeebdSAndreas Gohr * internal / external / interwiki / email / windowsshare / local link 12e89aeebdSAndreas Gohr * handler instructions. 13e89aeebdSAndreas Gohr */ 14e89aeebdSAndreas Gohrclass GfmLinkTest extends ParserTestBase 15e89aeebdSAndreas Gohr{ 16e89aeebdSAndreas Gohr public function setUp(): void 17e89aeebdSAndreas Gohr { 18e89aeebdSAndreas Gohr parent::setUp(); 19e89aeebdSAndreas Gohr global $conf; 20e89aeebdSAndreas Gohr $conf['syntax'] = 'markdown'; 21e89aeebdSAndreas Gohr ModeRegistry::reset(); 22e89aeebdSAndreas Gohr } 23e89aeebdSAndreas Gohr 24e89aeebdSAndreas Gohr public function tearDown(): void 25e89aeebdSAndreas Gohr { 26e89aeebdSAndreas Gohr ModeRegistry::reset(); 27e89aeebdSAndreas Gohr parent::tearDown(); 28e89aeebdSAndreas Gohr } 29e89aeebdSAndreas Gohr 30e89aeebdSAndreas Gohr function testInternalPage() 31e89aeebdSAndreas Gohr { 32e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 33e89aeebdSAndreas Gohr $this->P->parse('Foo [text](page) Bar'); 34e89aeebdSAndreas Gohr $calls = [ 35e89aeebdSAndreas Gohr ['document_start', []], 36e89aeebdSAndreas Gohr ['p_open', []], 37e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 38e89aeebdSAndreas Gohr ['internallink', ['page', 'text']], 39e89aeebdSAndreas Gohr ['cdata', [' Bar']], 40e89aeebdSAndreas Gohr ['p_close', []], 41e89aeebdSAndreas Gohr ['document_end', []], 42e89aeebdSAndreas Gohr ]; 43e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 44e89aeebdSAndreas Gohr } 45e89aeebdSAndreas Gohr 46e89aeebdSAndreas Gohr function testInternalPageWithNamespace() 47e89aeebdSAndreas Gohr { 48e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 49e89aeebdSAndreas Gohr $this->P->parse('Foo [Syntax](wiki:syntax#internal) Bar'); 50e89aeebdSAndreas Gohr $calls = [ 51e89aeebdSAndreas Gohr ['document_start', []], 52e89aeebdSAndreas Gohr ['p_open', []], 53e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 54e89aeebdSAndreas Gohr ['internallink', ['wiki:syntax#internal', 'Syntax']], 55e89aeebdSAndreas Gohr ['cdata', [' Bar']], 56e89aeebdSAndreas Gohr ['p_close', []], 57e89aeebdSAndreas Gohr ['document_end', []], 58e89aeebdSAndreas Gohr ]; 59e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 60e89aeebdSAndreas Gohr } 61e89aeebdSAndreas Gohr 62e89aeebdSAndreas Gohr function testExternalLink() 63e89aeebdSAndreas Gohr { 64e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 65e89aeebdSAndreas Gohr $this->P->parse('Foo [Google](http://google.com) Bar'); 66e89aeebdSAndreas Gohr $calls = [ 67e89aeebdSAndreas Gohr ['document_start', []], 68e89aeebdSAndreas Gohr ['p_open', []], 69e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 70e89aeebdSAndreas Gohr ['externallink', ['http://google.com', 'Google']], 71e89aeebdSAndreas Gohr ['cdata', [' Bar']], 72e89aeebdSAndreas Gohr ['p_close', []], 73e89aeebdSAndreas Gohr ['document_end', []], 74e89aeebdSAndreas Gohr ]; 75e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 76e89aeebdSAndreas Gohr } 77e89aeebdSAndreas Gohr 78e89aeebdSAndreas Gohr function testInterwikiLink() 79e89aeebdSAndreas Gohr { 80e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 81e89aeebdSAndreas Gohr $this->P->parse('Foo [callbacks](wp>Callback) Bar'); 82e89aeebdSAndreas Gohr $calls = [ 83e89aeebdSAndreas Gohr ['document_start', []], 84e89aeebdSAndreas Gohr ['p_open', []], 85e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 86e89aeebdSAndreas Gohr ['interwikilink', ['wp>Callback', 'callbacks', 'wp', 'Callback']], 87e89aeebdSAndreas Gohr ['cdata', [' Bar']], 88e89aeebdSAndreas Gohr ['p_close', []], 89e89aeebdSAndreas Gohr ['document_end', []], 90e89aeebdSAndreas Gohr ]; 91e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 92e89aeebdSAndreas Gohr } 93e89aeebdSAndreas Gohr 94e89aeebdSAndreas Gohr function testInterwikiLinkCaseNormalized() 95e89aeebdSAndreas Gohr { 96e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 97e89aeebdSAndreas Gohr $this->P->parse('Foo [Page](IW>somepage) Bar'); 98e89aeebdSAndreas Gohr $calls = [ 99e89aeebdSAndreas Gohr ['document_start', []], 100e89aeebdSAndreas Gohr ['p_open', []], 101e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 102e89aeebdSAndreas Gohr ['interwikilink', ['IW>somepage', 'Page', 'iw', 'somepage']], 103e89aeebdSAndreas Gohr ['cdata', [' Bar']], 104e89aeebdSAndreas Gohr ['p_close', []], 105e89aeebdSAndreas Gohr ['document_end', []], 106e89aeebdSAndreas Gohr ]; 107e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 108e89aeebdSAndreas Gohr } 109e89aeebdSAndreas Gohr 110e89aeebdSAndreas Gohr function testEmailLink() 111e89aeebdSAndreas Gohr { 112e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 113e89aeebdSAndreas Gohr $this->P->parse('Foo [mail](user@example.com) Bar'); 114e89aeebdSAndreas Gohr $calls = [ 115e89aeebdSAndreas Gohr ['document_start', []], 116e89aeebdSAndreas Gohr ['p_open', []], 117e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 118e89aeebdSAndreas Gohr ['emaillink', ['user@example.com', 'mail']], 119e89aeebdSAndreas Gohr ['cdata', [' Bar']], 120e89aeebdSAndreas Gohr ['p_close', []], 121e89aeebdSAndreas Gohr ['document_end', []], 122e89aeebdSAndreas Gohr ]; 123e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 124e89aeebdSAndreas Gohr } 125e89aeebdSAndreas Gohr 126e89aeebdSAndreas Gohr function testLocalAnchor() 127e89aeebdSAndreas Gohr { 128e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 129e89aeebdSAndreas Gohr $this->P->parse('Foo [section](#anchor) Bar'); 130e89aeebdSAndreas Gohr $calls = [ 131e89aeebdSAndreas Gohr ['document_start', []], 132e89aeebdSAndreas Gohr ['p_open', []], 133e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 134e89aeebdSAndreas Gohr ['locallink', ['anchor', 'section']], 135e89aeebdSAndreas Gohr ['cdata', [' Bar']], 136e89aeebdSAndreas Gohr ['p_close', []], 137e89aeebdSAndreas Gohr ['document_end', []], 138e89aeebdSAndreas Gohr ]; 139e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 140e89aeebdSAndreas Gohr } 141e89aeebdSAndreas Gohr 142e89aeebdSAndreas Gohr function testWindowsShare() 143e89aeebdSAndreas Gohr { 144e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 145e89aeebdSAndreas Gohr $this->P->parse('Foo [share](\\\\server\\share) Bar'); 146e89aeebdSAndreas Gohr $calls = [ 147e89aeebdSAndreas Gohr ['document_start', []], 148e89aeebdSAndreas Gohr ['p_open', []], 149e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 150e89aeebdSAndreas Gohr ['windowssharelink', ['\\\\server\\share', 'share']], 151e89aeebdSAndreas Gohr ['cdata', [' Bar']], 152e89aeebdSAndreas Gohr ['p_close', []], 153e89aeebdSAndreas Gohr ['document_end', []], 154e89aeebdSAndreas Gohr ]; 155e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 156e89aeebdSAndreas Gohr } 157e89aeebdSAndreas Gohr 158e89aeebdSAndreas Gohr function testTitleInDoubleQuotesIsDiscarded() 159e89aeebdSAndreas Gohr { 160e89aeebdSAndreas Gohr // GFM allows [text](url "title") but DokuWiki's link handler 161e89aeebdSAndreas Gohr // instructions have no title-attribute slot. The title parses 162e89aeebdSAndreas Gohr // cleanly but is dropped; the resulting handler call is identical 163e89aeebdSAndreas Gohr // to the no-title case. 164e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 165e89aeebdSAndreas Gohr $this->P->parse('Foo [Google](http://google.com "Search engine") Bar'); 166e89aeebdSAndreas Gohr $calls = [ 167e89aeebdSAndreas Gohr ['document_start', []], 168e89aeebdSAndreas Gohr ['p_open', []], 169e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 170e89aeebdSAndreas Gohr ['externallink', ['http://google.com', 'Google']], 171e89aeebdSAndreas Gohr ['cdata', [' Bar']], 172e89aeebdSAndreas Gohr ['p_close', []], 173e89aeebdSAndreas Gohr ['document_end', []], 174e89aeebdSAndreas Gohr ]; 175e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 176e89aeebdSAndreas Gohr } 177e89aeebdSAndreas Gohr 178e89aeebdSAndreas Gohr function testTitleInSingleQuotesIsDiscarded() 179e89aeebdSAndreas Gohr { 180e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 181e89aeebdSAndreas Gohr $this->P->parse("Foo [page](target 'a title') Bar"); 182e89aeebdSAndreas Gohr $calls = [ 183e89aeebdSAndreas Gohr ['document_start', []], 184e89aeebdSAndreas Gohr ['p_open', []], 185e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 186e89aeebdSAndreas Gohr ['internallink', ['target', 'page']], 187e89aeebdSAndreas Gohr ['cdata', [' Bar']], 188e89aeebdSAndreas Gohr ['p_close', []], 189e89aeebdSAndreas Gohr ['document_end', []], 190e89aeebdSAndreas Gohr ]; 191e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 192e89aeebdSAndreas Gohr } 193e89aeebdSAndreas Gohr 194e89aeebdSAndreas Gohr function testSpaceBetweenBracketsAndParensIsNotALink() 195e89aeebdSAndreas Gohr { 196e89aeebdSAndreas Gohr // GFM explicitly forbids whitespace between `]` and `(`. 197e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 198e89aeebdSAndreas Gohr $this->P->parse('[foo] (bar)'); 199e89aeebdSAndreas Gohr $modes = array_column($this->H->calls, 0); 200e89aeebdSAndreas Gohr $this->assertNotContains('internallink', $modes); 201e89aeebdSAndreas Gohr $this->assertNotContains('externallink', $modes); 202e89aeebdSAndreas Gohr } 203e89aeebdSAndreas Gohr 204e89aeebdSAndreas Gohr function testDwDoubleBracketNotConsumedByGfmLink() 205e89aeebdSAndreas Gohr { 206e89aeebdSAndreas Gohr // With both gfm_link and DW internallink loaded (mixed syntax), 207e89aeebdSAndreas Gohr // `[[foo]]` must go to Internallink. GfmLink's `\[(?!\[)` guard 208e89aeebdSAndreas Gohr // refuses single-bracket matches that are actually part of `[[`. 209e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 210e89aeebdSAndreas Gohr $this->P->addMode('internallink', new Internallink()); 211e89aeebdSAndreas Gohr $this->P->parse('Foo [[bar]] Baz'); 212e89aeebdSAndreas Gohr $calls = [ 213e89aeebdSAndreas Gohr ['document_start', []], 214e89aeebdSAndreas Gohr ['p_open', []], 215e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 216e89aeebdSAndreas Gohr ['internallink', ['bar', null]], 217e89aeebdSAndreas Gohr ['cdata', [' Baz']], 218e89aeebdSAndreas Gohr ['p_close', []], 219e89aeebdSAndreas Gohr ['document_end', []], 220e89aeebdSAndreas Gohr ]; 221e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 222e89aeebdSAndreas Gohr } 223e89aeebdSAndreas Gohr 224e89aeebdSAndreas Gohr function testMultibyteLinkText() 225e89aeebdSAndreas Gohr { 226e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 227e89aeebdSAndreas Gohr $this->P->parse('Foo [日本語](page) Bar'); 228e89aeebdSAndreas Gohr $calls = [ 229e89aeebdSAndreas Gohr ['document_start', []], 230e89aeebdSAndreas Gohr ['p_open', []], 231e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 232e89aeebdSAndreas Gohr ['internallink', ['page', '日本語']], 233e89aeebdSAndreas Gohr ['cdata', [' Bar']], 234e89aeebdSAndreas Gohr ['p_close', []], 235e89aeebdSAndreas Gohr ['document_end', []], 236e89aeebdSAndreas Gohr ]; 237e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 238e89aeebdSAndreas Gohr } 239e89aeebdSAndreas Gohr 240e89aeebdSAndreas Gohr function testReferenceStyleLinkNotMatched() 241e89aeebdSAndreas Gohr { 242e89aeebdSAndreas Gohr // `[foo][bar]` (reference-style) requires a reference definition 243e89aeebdSAndreas Gohr // we do not support; each `[...]` should stay literal text. 244e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 245e89aeebdSAndreas Gohr $this->P->parse('[foo][bar]'); 246e89aeebdSAndreas Gohr $modes = array_column($this->H->calls, 0); 247e89aeebdSAndreas Gohr $this->assertNotContains('internallink', $modes); 248e89aeebdSAndreas Gohr $this->assertNotContains('externallink', $modes); 249e89aeebdSAndreas Gohr } 250e89aeebdSAndreas Gohr 251e89aeebdSAndreas Gohr function testTwoLinksInOneLine() 252e89aeebdSAndreas Gohr { 253e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 254e89aeebdSAndreas Gohr $this->P->parse('Foo [one](a) and [two](b) Bar'); 255e89aeebdSAndreas Gohr $calls = [ 256e89aeebdSAndreas Gohr ['document_start', []], 257e89aeebdSAndreas Gohr ['p_open', []], 258e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 259e89aeebdSAndreas Gohr ['internallink', ['a', 'one']], 260e89aeebdSAndreas Gohr ['cdata', [' and ']], 261e89aeebdSAndreas Gohr ['internallink', ['b', 'two']], 262e89aeebdSAndreas Gohr ['cdata', [' Bar']], 263e89aeebdSAndreas Gohr ['p_close', []], 264e89aeebdSAndreas Gohr ['document_end', []], 265e89aeebdSAndreas Gohr ]; 266e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 267e89aeebdSAndreas Gohr } 268e89aeebdSAndreas Gohr 269e89aeebdSAndreas Gohr function testFragmentInExternalUrl() 270e89aeebdSAndreas Gohr { 271e89aeebdSAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 272e89aeebdSAndreas Gohr $this->P->parse('Foo [x](http://example.com#fragment) Bar'); 273e89aeebdSAndreas Gohr $calls = [ 274e89aeebdSAndreas Gohr ['document_start', []], 275e89aeebdSAndreas Gohr ['p_open', []], 276e89aeebdSAndreas Gohr ['cdata', ["\nFoo "]], 277e89aeebdSAndreas Gohr ['externallink', ['http://example.com#fragment', 'x']], 278e89aeebdSAndreas Gohr ['cdata', [' Bar']], 279e89aeebdSAndreas Gohr ['p_close', []], 280e89aeebdSAndreas Gohr ['document_end', []], 281e89aeebdSAndreas Gohr ]; 282e89aeebdSAndreas Gohr $this->assertCalls($calls, $this->H->calls); 283e89aeebdSAndreas Gohr } 284e89aeebdSAndreas Gohr 285*3440a8c0SAndreas Gohr // ----- image-as-label (`[](target)`) ----- 286*3440a8c0SAndreas Gohr 287*3440a8c0SAndreas Gohr /** 288*3440a8c0SAndreas Gohr * Media descriptor shape GfmLink emits for image-as-label, matching 289*3440a8c0SAndreas Gohr * what Media::parseMedia() returns. 290*3440a8c0SAndreas Gohr */ 291*3440a8c0SAndreas Gohr private function mediaArray(array $overrides): array 292*3440a8c0SAndreas Gohr { 293*3440a8c0SAndreas Gohr return array_merge([ 294*3440a8c0SAndreas Gohr 'type' => 'internalmedia', 295*3440a8c0SAndreas Gohr 'src' => 'wiki:image.png', 296*3440a8c0SAndreas Gohr 'title' => 'alt', 297*3440a8c0SAndreas Gohr 'align' => null, 298*3440a8c0SAndreas Gohr 'width' => null, 299*3440a8c0SAndreas Gohr 'height' => null, 300*3440a8c0SAndreas Gohr 'cache' => 'cache', 301*3440a8c0SAndreas Gohr 'linking' => 'details', 302*3440a8c0SAndreas Gohr ], $overrides); 303*3440a8c0SAndreas Gohr } 304*3440a8c0SAndreas Gohr 305*3440a8c0SAndreas Gohr function testImageAsLabelInternalPageLink() 306*3440a8c0SAndreas Gohr { 307*3440a8c0SAndreas Gohr // The canonical case: image that links to a wiki page. 308*3440a8c0SAndreas Gohr // Markdown equivalent of DW's `[[test:link|{{wiki:image.png}}]]`. 309*3440a8c0SAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 310*3440a8c0SAndreas Gohr $this->P->parse('Foo [](test:link) Bar'); 311*3440a8c0SAndreas Gohr $calls = [ 312*3440a8c0SAndreas Gohr ['document_start', []], 313*3440a8c0SAndreas Gohr ['p_open', []], 314*3440a8c0SAndreas Gohr ['cdata', ["\nFoo "]], 315*3440a8c0SAndreas Gohr ['internallink', ['test:link', $this->mediaArray([])]], 316*3440a8c0SAndreas Gohr ['cdata', [' Bar']], 317*3440a8c0SAndreas Gohr ['p_close', []], 318*3440a8c0SAndreas Gohr ['document_end', []], 319*3440a8c0SAndreas Gohr ]; 320*3440a8c0SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 321*3440a8c0SAndreas Gohr } 322*3440a8c0SAndreas Gohr 323*3440a8c0SAndreas Gohr function testImageAsLabelExternalLink() 324*3440a8c0SAndreas Gohr { 325*3440a8c0SAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 326*3440a8c0SAndreas Gohr $this->P->parse('Foo [](http://example.com) Bar'); 327*3440a8c0SAndreas Gohr $calls = [ 328*3440a8c0SAndreas Gohr ['document_start', []], 329*3440a8c0SAndreas Gohr ['p_open', []], 330*3440a8c0SAndreas Gohr ['cdata', ["\nFoo "]], 331*3440a8c0SAndreas Gohr ['externallink', ['http://example.com', $this->mediaArray([])]], 332*3440a8c0SAndreas Gohr ['cdata', [' Bar']], 333*3440a8c0SAndreas Gohr ['p_close', []], 334*3440a8c0SAndreas Gohr ['document_end', []], 335*3440a8c0SAndreas Gohr ]; 336*3440a8c0SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 337*3440a8c0SAndreas Gohr } 338*3440a8c0SAndreas Gohr 339*3440a8c0SAndreas Gohr function testImageAsLabelWithExternalMedia() 340*3440a8c0SAndreas Gohr { 341*3440a8c0SAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 342*3440a8c0SAndreas Gohr $this->P->parse('Foo [](test:link) Bar'); 343*3440a8c0SAndreas Gohr $calls = [ 344*3440a8c0SAndreas Gohr ['document_start', []], 345*3440a8c0SAndreas Gohr ['p_open', []], 346*3440a8c0SAndreas Gohr ['cdata', ["\nFoo "]], 347*3440a8c0SAndreas Gohr ['internallink', ['test:link', $this->mediaArray([ 348*3440a8c0SAndreas Gohr 'type' => 'externalmedia', 349*3440a8c0SAndreas Gohr 'src' => 'https://example.com/logo.png', 350*3440a8c0SAndreas Gohr 'title' => 'logo', 351*3440a8c0SAndreas Gohr ])]], 352*3440a8c0SAndreas Gohr ['cdata', [' Bar']], 353*3440a8c0SAndreas Gohr ['p_close', []], 354*3440a8c0SAndreas Gohr ['document_end', []], 355*3440a8c0SAndreas Gohr ]; 356*3440a8c0SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 357*3440a8c0SAndreas Gohr } 358*3440a8c0SAndreas Gohr 359*3440a8c0SAndreas Gohr function testImageAsLabelInterwikiLink() 360*3440a8c0SAndreas Gohr { 361*3440a8c0SAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 362*3440a8c0SAndreas Gohr $this->P->parse('Foo [](wp>Example) Bar'); 363*3440a8c0SAndreas Gohr $calls = [ 364*3440a8c0SAndreas Gohr ['document_start', []], 365*3440a8c0SAndreas Gohr ['p_open', []], 366*3440a8c0SAndreas Gohr ['cdata', ["\nFoo "]], 367*3440a8c0SAndreas Gohr ['interwikilink', ['wp>Example', $this->mediaArray([]), 'wp', 'Example']], 368*3440a8c0SAndreas Gohr ['cdata', [' Bar']], 369*3440a8c0SAndreas Gohr ['p_close', []], 370*3440a8c0SAndreas Gohr ['document_end', []], 371*3440a8c0SAndreas Gohr ]; 372*3440a8c0SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 373*3440a8c0SAndreas Gohr } 374*3440a8c0SAndreas Gohr 375*3440a8c0SAndreas Gohr function testImageAsLabelEmailLink() 376*3440a8c0SAndreas Gohr { 377*3440a8c0SAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 378*3440a8c0SAndreas Gohr $this->P->parse('Foo [](user@example.com) Bar'); 379*3440a8c0SAndreas Gohr $calls = [ 380*3440a8c0SAndreas Gohr ['document_start', []], 381*3440a8c0SAndreas Gohr ['p_open', []], 382*3440a8c0SAndreas Gohr ['cdata', ["\nFoo "]], 383*3440a8c0SAndreas Gohr ['emaillink', ['user@example.com', $this->mediaArray([])]], 384*3440a8c0SAndreas Gohr ['cdata', [' Bar']], 385*3440a8c0SAndreas Gohr ['p_close', []], 386*3440a8c0SAndreas Gohr ['document_end', []], 387*3440a8c0SAndreas Gohr ]; 388*3440a8c0SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 389*3440a8c0SAndreas Gohr } 390*3440a8c0SAndreas Gohr 391*3440a8c0SAndreas Gohr function testImageAsLabelMediaParameters() 392*3440a8c0SAndreas Gohr { 393*3440a8c0SAndreas Gohr // Full DW parameter vocabulary works in the nested image slot. 394*3440a8c0SAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 395*3440a8c0SAndreas Gohr $this->P->parse('Foo [](test:link) Bar'); 396*3440a8c0SAndreas Gohr $calls = [ 397*3440a8c0SAndreas Gohr ['document_start', []], 398*3440a8c0SAndreas Gohr ['p_open', []], 399*3440a8c0SAndreas Gohr ['cdata', ["\nFoo "]], 400*3440a8c0SAndreas Gohr ['internallink', ['test:link', $this->mediaArray([ 401*3440a8c0SAndreas Gohr 'align' => 'right', 402*3440a8c0SAndreas Gohr 'width' => '200', 403*3440a8c0SAndreas Gohr 'height' => '100', 404*3440a8c0SAndreas Gohr 'linking' => 'nolink', 405*3440a8c0SAndreas Gohr ])]], 406*3440a8c0SAndreas Gohr ['cdata', [' Bar']], 407*3440a8c0SAndreas Gohr ['p_close', []], 408*3440a8c0SAndreas Gohr ['document_end', []], 409*3440a8c0SAndreas Gohr ]; 410*3440a8c0SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 411*3440a8c0SAndreas Gohr } 412*3440a8c0SAndreas Gohr 413*3440a8c0SAndreas Gohr function testImageAsLabelEmptyAlt() 414*3440a8c0SAndreas Gohr { 415*3440a8c0SAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 416*3440a8c0SAndreas Gohr $this->P->parse('Foo [](test:link) Bar'); 417*3440a8c0SAndreas Gohr $calls = [ 418*3440a8c0SAndreas Gohr ['document_start', []], 419*3440a8c0SAndreas Gohr ['p_open', []], 420*3440a8c0SAndreas Gohr ['cdata', ["\nFoo "]], 421*3440a8c0SAndreas Gohr ['internallink', ['test:link', $this->mediaArray(['title' => null])]], 422*3440a8c0SAndreas Gohr ['cdata', [' Bar']], 423*3440a8c0SAndreas Gohr ['p_close', []], 424*3440a8c0SAndreas Gohr ['document_end', []], 425*3440a8c0SAndreas Gohr ]; 426*3440a8c0SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 427*3440a8c0SAndreas Gohr } 428*3440a8c0SAndreas Gohr 429*3440a8c0SAndreas Gohr function testImageAsLabelBothTitlesDiscarded() 430*3440a8c0SAndreas Gohr { 431*3440a8c0SAndreas Gohr // Titles on both URLs parse cleanly but are dropped — neither 432*3440a8c0SAndreas Gohr // DW's media nor link instructions have a title-attribute slot. 433*3440a8c0SAndreas Gohr $this->P->addMode('gfm_link', new GfmLink()); 434*3440a8c0SAndreas Gohr $this->P->parse('Foo [](test:link "link title") Bar'); 435*3440a8c0SAndreas Gohr $calls = [ 436*3440a8c0SAndreas Gohr ['document_start', []], 437*3440a8c0SAndreas Gohr ['p_open', []], 438*3440a8c0SAndreas Gohr ['cdata', ["\nFoo "]], 439*3440a8c0SAndreas Gohr ['internallink', ['test:link', $this->mediaArray([])]], 440*3440a8c0SAndreas Gohr ['cdata', [' Bar']], 441*3440a8c0SAndreas Gohr ['p_close', []], 442*3440a8c0SAndreas Gohr ['document_end', []], 443*3440a8c0SAndreas Gohr ]; 444*3440a8c0SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 445*3440a8c0SAndreas Gohr } 446*3440a8c0SAndreas Gohr 447e89aeebdSAndreas Gohr function testSortValue() 448e89aeebdSAndreas Gohr { 449e89aeebdSAndreas Gohr $this->assertSame(300, (new GfmLink())->getSort()); 450e89aeebdSAndreas Gohr } 451e89aeebdSAndreas Gohr} 452