Makes wikilinks nicer when possible
[mediawiki.git] / tests / phpunit / includes / TitleTest.php
blob37044bc5a354930afb3239eddbd94a240dcafeec
1 <?php
3 class TitleTest extends MediaWikiTestCase {
5 function testLegalChars() {
6 $titlechars = Title::legalChars();
8 foreach ( range( 1, 255 ) as $num ) {
9 $chr = chr( $num );
10 if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
11 $this->assertFalse( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is not a valid titlechar" );
12 } else {
13 $this->assertTrue( (bool)preg_match( "/[$titlechars]/", $chr ), "chr($num) = $chr is a valid titlechar" );
18 /**
19 * Helper to test getLocalURL
21 * @cover Title:getLocalURL
23 function assertGetLocalURL( $expected, $dbkey, $query, $articlepath, $actionpaths = array(), $variant = false )
25 global $wgArticlePath;
26 $wgArticlePath = $articlepath;
27 global $wgActionPaths;
28 $wgActionPaths = $actionpaths;
30 $t = Title::newFromDBKey( $dbkey );
32 $this->assertEquals( $expected, $t->getLocalURL( $query, $variant ) );
35 /**
36 * @dataProvider provider1
37 * @cover Title:getLocalURL
39 function testGetLocalUrl( $expected, $dbkey, $query )
41 $this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/$1' );
44 function provider1()
46 return array(
47 array( '/wiki/Recentchanges', 'Recentchanges', '' ),
48 array( '/wiki/Recentchanges?foo=2', 'Recentchanges', 'foo=2' ),
49 array( '/wiki/Recentchanges?foo=A&bar=1', 'Recentchanges', 'foo=A&bar=1' ),
54 /**
55 * @dataProvider provider2
56 * @cover Title:getLocalURL
58 function testGetLocalUrlWithArticlePath( $expected, $dbkey, $query, $actions )
60 $this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/view/$1', $actions );
63 function provider2()
65 return array(
66 array( '/wiki/view/Recentchanges', 'Recentchanges', '', array( ) ),
67 array( '/wiki/view/Recentchanges', 'Recentchanges', '', array( 'view' => 'OH MEN' ) ),
68 array( '/wiki/view/Recentchanges', 'Recentchanges', '', array( 'view' => '/wiki/view/$1' ) ),
69 array( '/wiki/view/Recentchanges?foo=2', 'Recentchanges', 'foo=2', array( 'view' => '/wiki/view/$1' ) ),
70 array( '/wiki/view/Recentchanges?foo=A&bar=1', 'Recentchanges', 'foo=A&bar=1', array() ),
75 /**
76 * @dataProvider provider3
77 * @cover Title:getLocalURL
79 function testGetLocalUrlWithActionPaths( $expected, $dbkey, $query )
81 $actions = array( 'edit' => '/wiki/edit/$1' );
82 $this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/view/$1', $actions );
85 function provider3() {
86 return array(
87 array( '/wiki/view/Recentchanges', 'Recentchanges', ''),
88 array( '/wiki/edit/Recentchanges', 'Recentchanges', 'action=edit' ),
89 array( '/wiki/edit/Recentchanges?foo=2', 'Recentchanges', 'action=edit&foo=2' ),
90 array( '/wiki/edit/Recentchanges?foo=2', 'Recentchanges', 'foo=2&action=edit' ),
91 array( '/wiki/view/Recentchanges?foo=A&bar=1', 'Recentchanges', 'foo=A&bar=1' ),
92 array( '/wiki/edit/Recentchanges?foo=A&bar=1', 'Recentchanges', 'foo=A&bar=1&action=edit' ),
93 array( '/wiki/edit/Recentchanges?foo=A&bar=1', 'Recentchanges', 'foo=A&action=edit&bar=1' ),
94 array( '/wiki/edit/Recentchanges?foo=A&bar=1', 'Recentchanges', 'action=edit&foo=A&bar=1' ),
96 # FIXME The next two are equals but need investigation:
97 array( '/wiki/edit/Recentchanges', 'Recentchanges', 'action=view&action=edit' ),
98 array( '/wiki/view/Recentchanges?action=edit&action=view', 'Recentchanges', 'action=edit&action=view' ),
103 * @dataProvider provider4
104 * @cover Title:getLocalURL
106 function testGetLocalUrlWithVariantArticlePaths( $expected, $dbkey, $query )
108 # FIXME find a language with variants!
109 $this->markTestIncomplete();
111 $actions = array( 'edit' => '/wiki/edit/$1' );
112 $this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/view/$1', array(), '/$2/$1' );
115 function provider4() {
116 return array(
117 array( '/wiki/view/Recentchanges', 'Recentchanges', '', ),