merge in prettyURL patch
[lhc/web/wiklou.git] / tests / phpunit / includes / TitleTest.php
1 <?php
2
3 class TitleTest extends MediaWikiTestCase {
4
5 function testLegalChars() {
6 $titlechars = Title::legalChars();
7
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" );
14 }
15 }
16 }
17
18 /**
19 * Helper to test getLocalURL
20 *
21 * @cover Title:getLocalURL
22 */
23 function assertGetLocalURL( $expected, $dbkey, $query, $articlepath, $actionpaths = array(), $variant = false )
24 {
25 global $wgArticlePath;
26 $wgArticlePath = $articlepath;
27 global $wgActionPaths;
28 $wgActionPaths = $actionpaths;
29
30 $t = Title::newFromDBKey( $dbkey );
31
32 $this->assertEquals( $expected, $t->getLocalURL( $query, $variant ) );
33 }
34
35 /**
36 * @dataProvider provider1
37 * @cover Title:getLocalURL
38 */
39 function testGetLocalUrl( $expected, $dbkey, $query )
40 {
41 $this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/$1' );
42 }
43
44 function provider1()
45 {
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' ),
50 );
51 }
52
53
54 /**
55 * @dataProvider provider2
56 * @cover Title:getLocalURL
57 */
58 function testGetLocalUrlWithArticlePath( $expected, $dbkey, $query, $actions )
59 {
60 $this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/view/$1', $actions );
61 }
62
63 function provider2()
64 {
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() ),
71 );
72 }
73
74
75 /**
76 * @dataProvider provider3
77 * @cover Title:getLocalURL
78 */
79 function testGetLocalUrlWithActionPaths( $expected, $dbkey, $query )
80 {
81 $actions = array( 'edit' => '/wiki/edit/$1' );
82 $this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/view/$1', $actions );
83 }
84
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' ),
95
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' ),
99 );
100 }
101
102 /**
103 * @dataProvider provider4
104 * @cover Title:getLocalURL
105 */
106 function testGetLocalUrlWithVariantArticlePaths( $expected, $dbkey, $query )
107 {
108 # FIXME find a language with variants!
109 $this->markTestIncomplete();
110
111 $actions = array( 'edit' => '/wiki/edit/$1' );
112 $this->assertGetLocalURL( $expected, $dbkey, $query, '/wiki/view/$1', array(), '/$2/$1' );
113 }
114
115 function provider4() {
116 return array(
117 array( '/wiki/view/Recentchanges', 'Recentchanges', '', ),
118 );
119 }
120
121
122 }