MediaWiki  1.23.12
MediaWikiTest.php
Go to the documentation of this file.
1 <?php
2 
4  protected function setUp() {
5  parent::setUp();
6 
7  $this->setMwGlobals( array(
8  'wgServer' => 'http://example.org',
9  'wgScriptPath' => '/w',
10  'wgScript' => '/w/index.php',
11  'wgArticlePath' => '/wiki/$1',
12  'wgActionPaths' => array(),
13  ) );
14  }
15 
16  public static function provideTryNormaliseRedirect() {
17  return array(
18  array(
19  // View: Canonical
20  'url' => 'http://example.org/wiki/Foo_Bar',
21  'query' => array(),
22  'title' => 'Foo_Bar',
23  'redirect' => false,
24  ),
25  array(
26  // View: Escaped title
27  'url' => 'http://example.org/wiki/Foo%20Bar',
28  'query' => array(),
29  'title' => 'Foo_Bar',
30  'redirect' => 'http://example.org/wiki/Foo_Bar',
31  ),
32  array(
33  // View: Script path
34  'url' => 'http://example.org/w/index.php?title=Foo_Bar',
35  'query' => array( 'title' => 'Foo_Bar' ),
36  'title' => 'Foo_Bar',
37  'redirect' => false,
38  ),
39  array(
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' ),
43  'title' => 'Foo_Bar',
44  'redirect' => false,
45  ),
46  array(
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' ),
50  'title' => 'Foo_Bar',
51  'redirect' => false,
52  ),
53  array(
54  // View: Script path without title
55  'url' => 'http://example.org/w/index.php',
56  'query' => array(),
57  'title' => 'Main_Page',
58  'redirect' => 'http://example.org/wiki/Main_Page',
59  ),
60  array(
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',
66  ),
67  array(
68  // View: Index with escaped title
69  'url' => 'http://example.org/w/index.php?title=Foo%20Bar',
70  'query' => array( 'title' => 'Foo Bar' ),
71  'title' => 'Foo_Bar',
72  'redirect' => 'http://example.org/wiki/Foo_Bar',
73  ),
74  array(
75  // View: Script path with escaped title
76  'url' => 'http://example.org/w/?title=Foo_Bar',
77  'query' => array( 'title' => 'Foo_Bar' ),
78  'title' => 'Foo_Bar',
79  'redirect' => false,
80  ),
81  array(
82  // View: Root path with escaped title
83  'url' => 'http://example.org/?title=Foo_Bar',
84  'query' => array( 'title' => 'Foo_Bar' ),
85  'title' => 'Foo_Bar',
86  'redirect' => false,
87  ),
88  array(
89  // View: Canonical with redundant query
90  'url' => 'http://example.org/wiki/Foo_Bar?action=view',
91  'query' => array( 'action' => 'view' ),
92  'title' => 'Foo_Bar',
93  'redirect' => false,
94  ),
95  array(
96  // Edit: Canonical view url with action query
97  'url' => 'http://example.org/wiki/Foo_Bar?action=edit',
98  'query' => array( 'action' => 'edit' ),
99  'title' => 'Foo_Bar',
100  'redirect' => false,
101  ),
102  array(
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' => false,
108  ),
109  array(
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',
114  'redirect' => false,
115  ),
116  );
117  }
118 
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;
127 
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();
132 
133  $titleObj = Title::newFromText( $title );
134 
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 );
139 
140  $mw = new MediaWiki( $context );
141 
142  $method = new ReflectionMethod( $mw, 'tryNormaliseRedirect' );
143  $method->setAccessible( true );
144  $ret = $method->invoke( $mw, $titleObj );
145 
146  $this->assertEquals(
147  $expectedRedirect !== false,
148  $ret,
149  'Return true only when redirecting'
150  );
151 
152  $this->assertEquals(
153  $expectedRedirect ?: '',
154  $context->getOutput()->getRedirect()
155  );
156  }
157 }
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
Definition: MediaWikiTest.php:3
$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:4
MediaWikiTest\provideTryNormaliseRedirect
static provideTryNormaliseRedirect()
Definition: MediaWikiTest.php:16
MediaWikiTest\testTryNormaliseRedirect
testTryNormaliseRedirect( $url, $query, $title, $expectedRedirect=false)
@dataProvider provideTryNormaliseRedirect @covers MediaWiki::tryNormaliseRedirect
Definition: MediaWikiTest.php:123
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