3 class MediaWikiTest
extends MediaWikiTestCase
{
4 protected function setUp() {
7 $this->setMwGlobals( array(
8 'wgServer' => 'http://example.org',
9 'wgScriptPath' => '/w',
10 'wgScript' => '/w/index.php',
11 'wgArticlePath' => '/wiki/$1',
12 'wgActionPaths' => array(),
16 public static function provideTryNormaliseRedirect() {
20 'url' => 'http://example.org/wiki/Foo_Bar',
26 // View: Escaped title
27 'url' => 'http://example.org/wiki/Foo%20Bar',
30 'redirect' => 'http://example.org/wiki/Foo_Bar',
34 'url' => 'http://example.org/w/index.php?title=Foo_Bar',
35 'query' => array( 'title' => 'Foo_Bar' ),
37 'redirect' => 'http://example.org/wiki/Foo_Bar',
40 // View: Script path with implicit title from page id
41 'url' => 'http://example.org/w/index.php?curid=123',
42 'query' => array( 'curid' => '123' ),
47 // View: Script path with implicit title from revision id
48 'url' => 'http://example.org/w/index.php?oldid=123',
49 'query' => array( 'oldid' => '123' ),
54 // View: Script path without title
55 'url' => 'http://example.org/w/index.php',
57 'title' => 'Main_Page',
58 'redirect' => 'http://example.org/wiki/Main_Page',
61 // View: Script path with empty title
62 'url' => 'http://example.org/w/index.php?title=',
63 'query' => array( 'title' => '' ),
64 'title' => 'Main_Page',
65 'redirect' => 'http://example.org/wiki/Main_Page',
68 // View: Index with escaped title
69 'url' => 'http://example.org/w/index.php?title=Foo%20Bar',
70 'query' => array( 'title' => 'Foo Bar' ),
72 'redirect' => 'http://example.org/wiki/Foo_Bar',
75 // View: Script path with escaped title
76 'url' => 'http://example.org/w/?title=Foo_Bar',
77 'query' => array( 'title' => 'Foo_Bar' ),
79 'redirect' => 'http://example.org/wiki/Foo_Bar',
82 // View: Root path with escaped title
83 'url' => 'http://example.org/?title=Foo_Bar',
84 'query' => array( 'title' => 'Foo_Bar' ),
86 'redirect' => 'http://example.org/wiki/Foo_Bar',
89 // View: Canonical with redundant query
90 'url' => 'http://example.org/wiki/Foo_Bar?action=view',
91 'query' => array( 'action' => 'view' ),
93 'redirect' => 'http://example.org/wiki/Foo_Bar',
96 // Edit: Canonical view url with action query
97 'url' => 'http://example.org/wiki/Foo_Bar?action=edit',
98 'query' => array( 'action' => 'edit' ),
103 // View: Index with action query
104 'url' => 'http://example.org/w/index.php?title=Foo_Bar&action=view',
105 'query' => array( 'title' => 'Foo_Bar', 'action' => 'view' ),
106 'title' => 'Foo_Bar',
107 'redirect' => 'http://example.org/wiki/Foo_Bar',
110 // Edit: Index with action query
111 'url' => 'http://example.org/w/index.php?title=Foo_Bar&action=edit',
112 'query' => array( 'title' => 'Foo_Bar', 'action' => 'edit' ),
113 'title' => 'Foo_Bar',
120 * @dataProvider provideTryNormaliseRedirect
121 * @covers MediaWiki::tryNormaliseRedirect
123 public function testTryNormaliseRedirect( $url, $query, $title, $expectedRedirect = false ) {
124 // Set SERVER because interpolateTitle() doesn't use getRequestURL(),
125 // whereas tryNormaliseRedirect does().
126 $_SERVER['REQUEST_URI'] = $url;
128 $req = new FauxRequest( $query );
129 $req->setRequestURL( $url );
130 // This adds a virtual 'title' query parameter. Normally called from Setup.php
131 $req->interpolateTitle();
133 $titleObj = Title
::newFromText( $title );
135 // Set global context since some involved code paths don't yet have context
136 $context = RequestContext
::getMain();
137 $context->setRequest( $req );
138 $context->setTitle( $titleObj );
140 $mw = new MediaWiki( $context );
142 $method = new ReflectionMethod( $mw, 'tryNormaliseRedirect' );
143 $method->setAccessible( true );
144 $ret = $method->invoke( $mw, $titleObj );
147 $expectedRedirect !== false,
149 'Return true only when redirecting'
153 $expectedRedirect ?
: '',
154 $context->getOutput()->getRedirect()