1*1e28e406SAndreas Gohr<?php 2*1e28e406SAndreas Gohr 3*1e28e406SAndreas Gohrnamespace dokuwiki\test\Parsing\Helpers; 4*1e28e406SAndreas Gohr 5*1e28e406SAndreas Gohruse dokuwiki\Parsing\Helpers\Link; 6*1e28e406SAndreas Gohr 7*1e28e406SAndreas Gohr/** 8*1e28e406SAndreas Gohr * Tests for URL classification shared between Internallink and GfmLink. 9*1e28e406SAndreas Gohr */ 10*1e28e406SAndreas Gohrclass LinkTest extends \DokuWikiTest 11*1e28e406SAndreas Gohr{ 12*1e28e406SAndreas Gohr function testClassifyInternalPageDefault() 13*1e28e406SAndreas Gohr { 14*1e28e406SAndreas Gohr $this->assertSame( 15*1e28e406SAndreas Gohr ['internallink', ['some:page', 'Label']], 16*1e28e406SAndreas Gohr Link::classify('some:page', 'Label') 17*1e28e406SAndreas Gohr ); 18*1e28e406SAndreas Gohr } 19*1e28e406SAndreas Gohr 20*1e28e406SAndreas Gohr function testClassifyExternalHttp() 21*1e28e406SAndreas Gohr { 22*1e28e406SAndreas Gohr $this->assertSame( 23*1e28e406SAndreas Gohr ['externallink', ['http://example.com', null]], 24*1e28e406SAndreas Gohr Link::classify('http://example.com', null) 25*1e28e406SAndreas Gohr ); 26*1e28e406SAndreas Gohr } 27*1e28e406SAndreas Gohr 28*1e28e406SAndreas Gohr function testClassifyExternalCustomScheme() 29*1e28e406SAndreas Gohr { 30*1e28e406SAndreas Gohr // Any `scheme://...` matches — the ladder does not validate against 31*1e28e406SAndreas Gohr // the configured schemes list; that's the renderer's job. 32*1e28e406SAndreas Gohr $this->assertSame( 33*1e28e406SAndreas Gohr ['externallink', ['ftp://files.example.com/x', 'F']], 34*1e28e406SAndreas Gohr Link::classify('ftp://files.example.com/x', 'F') 35*1e28e406SAndreas Gohr ); 36*1e28e406SAndreas Gohr } 37*1e28e406SAndreas Gohr 38*1e28e406SAndreas Gohr function testClassifyInterwikiLink() 39*1e28e406SAndreas Gohr { 40*1e28e406SAndreas Gohr $this->assertSame( 41*1e28e406SAndreas Gohr ['interwikilink', ['wp>Callback', 'cb', 'wp', 'Callback']], 42*1e28e406SAndreas Gohr Link::classify('wp>Callback', 'cb') 43*1e28e406SAndreas Gohr ); 44*1e28e406SAndreas Gohr } 45*1e28e406SAndreas Gohr 46*1e28e406SAndreas Gohr function testClassifyInterwikiPrefixLowercased() 47*1e28e406SAndreas Gohr { 48*1e28e406SAndreas Gohr [$call, $args] = Link::classify('IW>SomePage', 'T'); 49*1e28e406SAndreas Gohr $this->assertSame('interwikilink', $call); 50*1e28e406SAndreas Gohr $this->assertSame('iw', $args[2], 'interwiki prefix must be lowercased'); 51*1e28e406SAndreas Gohr $this->assertSame('SomePage', $args[3], 'interwiki target must be preserved'); 52*1e28e406SAndreas Gohr } 53*1e28e406SAndreas Gohr 54*1e28e406SAndreas Gohr function testClassifyWindowsShare() 55*1e28e406SAndreas Gohr { 56*1e28e406SAndreas Gohr $this->assertSame( 57*1e28e406SAndreas Gohr ['windowssharelink', ['\\\\server\\share', null]], 58*1e28e406SAndreas Gohr Link::classify('\\\\server\\share', null) 59*1e28e406SAndreas Gohr ); 60*1e28e406SAndreas Gohr } 61*1e28e406SAndreas Gohr 62*1e28e406SAndreas Gohr function testClassifyEmail() 63*1e28e406SAndreas Gohr { 64*1e28e406SAndreas Gohr $this->assertSame( 65*1e28e406SAndreas Gohr ['emaillink', ['user@example.com', 'Mail']], 66*1e28e406SAndreas Gohr Link::classify('user@example.com', 'Mail') 67*1e28e406SAndreas Gohr ); 68*1e28e406SAndreas Gohr } 69*1e28e406SAndreas Gohr 70*1e28e406SAndreas Gohr function testClassifyLocalAnchorStripsHash() 71*1e28e406SAndreas Gohr { 72*1e28e406SAndreas Gohr $this->assertSame( 73*1e28e406SAndreas Gohr ['locallink', ['section', 'Here']], 74*1e28e406SAndreas Gohr Link::classify('#section', 'Here') 75*1e28e406SAndreas Gohr ); 76*1e28e406SAndreas Gohr } 77*1e28e406SAndreas Gohr 78*1e28e406SAndreas Gohr function testClassifyInterwikiWinsOverEmail() 79*1e28e406SAndreas Gohr { 80*1e28e406SAndreas Gohr // An interwiki prefix containing `>` before an `@` still goes 81*1e28e406SAndreas Gohr // interwiki. Order of the ladder is load-bearing. 82*1e28e406SAndreas Gohr [$call, ] = Link::classify('wiki>user@host', 'x'); 83*1e28e406SAndreas Gohr $this->assertSame('interwikilink', $call); 84*1e28e406SAndreas Gohr } 85*1e28e406SAndreas Gohr 86*1e28e406SAndreas Gohr function testClassifyArrayLabelForMediaInTitle() 87*1e28e406SAndreas Gohr { 88*1e28e406SAndreas Gohr // Internallink supports a parsed-media array as the label; the 89*1e28e406SAndreas Gohr // helper must pass it through untouched. 90*1e28e406SAndreas Gohr $media = ['type' => 'internalmedia', 'src' => 'img.gif']; 91*1e28e406SAndreas Gohr [, $args] = Link::classify('some:page', $media); 92*1e28e406SAndreas Gohr $this->assertSame($media, $args[1]); 93*1e28e406SAndreas Gohr } 94*1e28e406SAndreas Gohr} 95