MediaWiki  1.23.14
MediaWikiTest.php
Go to the documentation of this file.
1 <?php
2 
7  protected function setUp() {
8  parent::setUp();
9 
10  $this->setMwGlobals( array(
11  'wgServer' => 'http://example.org',
12  'wgScriptPath' => '/w',
13  'wgScript' => '/w/index.php',
14  'wgArticlePath' => '/wiki/$1',
15  'wgActionPaths' => array(),
16  ) );
17  }
18 
19  public static function provideTryNormaliseRedirect() {
20  return array(
21  array(
22  // View: Canonical
23  'url' => 'http://example.org/wiki/Foo_Bar',
24  'query' => array(),
25  'title' => 'Foo_Bar',
26  'redirect' => false,
27  ),
28  array(
29  // View: Escaped title
30  'url' => 'http://example.org/wiki/Foo%20Bar',
31  'query' => array(),
32  'title' => 'Foo_Bar',
33  'redirect' => 'http://example.org/wiki/Foo_Bar',
34  ),
35  array(
36  // View: Script path
37  'url' => 'http://example.org/w/index.php?title=Foo_Bar',
38  'query' => array( 'title' => 'Foo_Bar' ),
39  'title' => 'Foo_Bar',
40  'redirect' => 'http://example.org/wiki/Foo_Bar',
41  ),
42  array(
43  // View: Script path with implicit title from page id
44  'url' => 'http://example.org/w/index.php?curid=123',
45  'query' => array( 'curid' => '123' ),
46  'title' => 'Foo_Bar',
47  'redirect' => false,
48  ),
49  array(
50  // View: Script path with implicit title from revision id
51  'url' => 'http://example.org/w/index.php?oldid=123',
52  'query' => array( 'oldid' => '123' ),
53  'title' => 'Foo_Bar',
54  'redirect' => false,
55  ),
56  array(
57  // View: Script path without title
58  'url' => 'http://example.org/w/index.php',
59  'query' => array(),
60  'title' => 'Main_Page',
61  'redirect' => 'http://example.org/wiki/Main_Page',
62  ),
63  array(
64  // View: Script path with empty title
65  'url' => 'http://example.org/w/index.php?title=',
66  'query' => array( 'title' => '' ),
67  'title' => 'Main_Page',
68  'redirect' => 'http://example.org/wiki/Main_Page',
69  ),
70  array(
71  // View: Index with escaped title
72  'url' => 'http://example.org/w/index.php?title=Foo%20Bar',
73  'query' => array( 'title' => 'Foo Bar' ),
74  'title' => 'Foo_Bar',
75  'redirect' => 'http://example.org/wiki/Foo_Bar',
76  ),
77  array(
78  // View: Script path with escaped title
79  'url' => 'http://example.org/w/?title=Foo_Bar',
80  'query' => array( 'title' => 'Foo_Bar' ),
81  'title' => 'Foo_Bar',
82  'redirect' => 'http://example.org/wiki/Foo_Bar',
83  ),
84  array(
85  // View: Root path with escaped title
86  'url' => 'http://example.org/?title=Foo_Bar',
87  'query' => array( 'title' => 'Foo_Bar' ),
88  'title' => 'Foo_Bar',
89  'redirect' => 'http://example.org/wiki/Foo_Bar',
90  ),
91  array(
92  // View: Canonical with redundant query
93  'url' => 'http://example.org/wiki/Foo_Bar?action=view',
94  'query' => array( 'action' => 'view' ),
95  'title' => 'Foo_Bar',
96  'redirect' => 'http://example.org/wiki/Foo_Bar',
97  ),
98  array(
99  // Edit: Canonical view url with action query
100  'url' => 'http://example.org/wiki/Foo_Bar?action=edit',
101  'query' => array( 'action' => 'edit' ),
102  'title' => 'Foo_Bar',
103  'redirect' => false,
104  ),
105  array(
106  // View: Index with action query
107  'url' => 'http://example.org/w/index.php?title=Foo_Bar&action=view',
108  'query' => array( 'title' => 'Foo_Bar', 'action' => 'view' ),
109  'title' => 'Foo_Bar',
110  'redirect' => 'http://example.org/wiki/Foo_Bar',
111  ),
112  array(
113  // Edit: Index with action query
114  'url' => 'http://example.org/w/index.php?title=Foo_Bar&action=edit',
115  'query' => array( 'title' => 'Foo_Bar', 'action' => 'edit' ),
116  'title' => 'Foo_Bar',
117  'redirect' => false,
118  ),
119  );
120  }
121 
126  public function testTryNormaliseRedirect( $url, $query, $title, $expectedRedirect = false ) {
127  // Set SERVER because interpolateTitle() doesn't use getRequestURL(),
128  // whereas tryNormaliseRedirect does().
129  $_SERVER['REQUEST_URI'] = $url;
130 
131  $req = new FauxRequest( $query );
132  $req->setRequestURL( $url );
133  // This adds a virtual 'title' query parameter. Normally called from Setup.php
134  $req->interpolateTitle();
135 
136  $titleObj = Title::newFromText( $title );
137 
138  // Set global context since some involved code paths don't yet have context
139  $context = RequestContext::getMain();
140  $context->setRequest( $req );
141  $context->setTitle( $titleObj );
142 
143  $mw = new MediaWiki( $context );
144 
145  $method = new ReflectionMethod( $mw, 'tryNormaliseRedirect' );
146  $method->setAccessible( true );
147  $ret = $method->invoke( $mw, $titleObj );
148 
149  $this->assertEquals(
150  $expectedRedirect !== false,
151  $ret,
152  'Return true only when redirecting'
153  );
154 
155  $this->assertEquals(
156  $expectedRedirect ?: '',
157  $context->getOutput()->getRedirect()
158  );
159  }
160 }
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: WebRequest.php:1275
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
MediaWikiTest
@group Broken
Definition: MediaWikiTest.php:6
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
MediaWikiTest\setUp
setUp()
Definition: MediaWikiTest.php:7
MediaWikiTest\provideTryNormaliseRedirect
static provideTryNormaliseRedirect()
Definition: MediaWikiTest.php:19
MediaWikiTest\testTryNormaliseRedirect
testTryNormaliseRedirect( $url, $query, $title, $expectedRedirect=false)
@dataProvider provideTryNormaliseRedirect @covers MediaWiki::tryNormaliseRedirect
Definition: MediaWikiTest.php:126
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
MediaWiki
This document describes the state of Postgres support in MediaWiki
Definition: postgres.txt:4
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
RequestContext\getMain
static getMain()
Static methods.
Definition: RequestContext.php:420
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105