MediaWiki REL1_33
SpecialPageTest.php
Go to the documentation of this file.
1<?php
2
3use Wikimedia\TestingAccessWrapper;
4
13
14 protected function setUp() {
15 parent::setUp();
16
17 $this->setContentLang( 'en' );
18 $this->setMwGlobals( [
19 'wgScript' => '/index.php',
20 ] );
21 }
22
26 public function testGetTitleFor( $expectedName, $name ) {
27 $title = SpecialPage::getTitleFor( $name );
28 $expected = Title::makeTitle( NS_SPECIAL, $expectedName );
29 $this->assertEquals( $expected, $title );
30 }
31
32 public function getTitleForProvider() {
33 return [
34 [ 'UserLogin', 'Userlogin' ]
35 ];
36 }
37
41 public function testInvalidGetTitleFor() {
42 $title = SpecialPage::getTitleFor( 'cat' );
43 $expected = Title::makeTitle( NS_SPECIAL, 'Cat' );
44 $this->assertEquals( $expected, $title );
45 }
46
51 public function testGetTitleForWithWarning( $expected, $name ) {
52 $title = SpecialPage::getTitleFor( $name );
53 $this->assertEquals( $expected, $title );
54 }
55
57 return [
58 [ Title::makeTitle( NS_SPECIAL, 'UserLogin' ), 'UserLogin' ]
59 ];
60 }
61
65 public function testRequireLoginAnon( $expected, $reason, $title ) {
66 $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
67
69 $specialPage->getContext()->setUser( $user );
70 $specialPage->getContext()->setLanguage( Language::factory( 'en' ) );
71
72 $this->setExpectedException( UserNotLoggedIn::class, $expected );
73
74 // $specialPage->requireLogin( [ $reason [, $title ] ] )
75 call_user_func_array(
76 [ $specialPage, 'requireLogin' ],
77 array_filter( [ $reason, $title ] )
78 );
79 }
80
81 public function requireLoginAnonProvider() {
82 $lang = 'en';
83
84 $expected1 = wfMessage( 'exception-nologin-text' )->inLanguage( $lang )->text();
85 $expected2 = wfMessage( 'about' )->inLanguage( $lang )->text();
86
87 return [
88 [ $expected1, null, null ],
89 [ $expected2, 'about', null ],
90 [ $expected2, 'about', 'about' ],
91 ];
92 }
93
94 public function testRequireLoginNotAnon() {
95 $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
96
97 $user = User::newFromName( "UTSysop" );
98 $specialPage->getContext()->setUser( $user );
99
100 $specialPage->requireLogin();
101
102 // no exception thrown, logged in use can access special page
103 $this->assertTrue( true );
104 }
105
107 yield [ 0, 20, false, false ];
108 yield [ 17, 20, false, false ];
109 yield [ 0, 17, false, false ];
110 yield [ 0, 20, true, 'Foo' ];
111 yield [ 17, 20, true, 'Föö_Bär' ];
112 }
113
117 public function testBuildPrevNextNavigation( $offset, $limit, $atEnd, $subPage ) {
118 $this->setUserLang( Language::factory( 'qqx' ) ); // disable i18n
119
120 $specialPage = new SpecialPage( 'Watchlist' );
121 $specialPage = TestingAccessWrapper::newFromObject( $specialPage );
122
123 $html = $specialPage->buildPrevNextNavigation(
124 $offset,
125 $limit,
126 [ 'x' => 25 ],
127 $atEnd,
128 $subPage
129 );
130
131 $this->assertStringStartsWith( '(viewprevnext:', $html );
132
133 preg_match_all( '!<a.*?</a>!', $html, $m, PREG_PATTERN_ORDER );
134 $links = $m[0];
135
136 foreach ( $links as $a ) {
137 if ( $subPage ) {
138 $this->assertContains( 'Special:Watchlist/' . wfUrlencode( $subPage ), $a );
139 } else {
140 $this->assertContains( 'Special:Watchlist', $a );
141 $this->assertNotContains( 'Special:Watchlist/', $a );
142 }
143 $this->assertContains( 'x=25', $a );
144 }
145
146 $i = 0;
147
148 if ( $offset > 0 ) {
149 $this->assertContains(
150 'limit=' . $limit . '&amp;offset=' . max( 0, $offset - $limit ) . '&amp;',
151 $links[ $i ]
152 );
153 $this->assertContains( 'title="(prevn-title: ' . $limit . ')"', $links[$i] );
154 $this->assertContains( 'class="mw-prevlink"', $links[$i] );
155 $this->assertContains( '>(prevn: ' . $limit . ')<', $links[$i] );
156 $i += 1;
157 }
158
159 if ( !$atEnd ) {
160 $this->assertContains(
161 'limit=' . $limit . '&amp;offset=' . ( $offset + $limit ) . '&amp;',
162 $links[ $i ]
163 );
164 $this->assertContains( 'title="(nextn-title: ' . $limit . ')"', $links[$i] );
165 $this->assertContains( 'class="mw-nextlink"', $links[$i] );
166 $this->assertContains( '>(nextn: ' . $limit . ')<', $links[$i] );
167 $i += 1;
168 }
169
170 $this->assertCount( 5 + $i, $links );
171
172 $this->assertContains( 'limit=20&amp;offset=' . $offset, $links[$i] );
173 $this->assertContains( 'title="(shown-title: 20)"', $links[$i] );
174 $this->assertContains( 'class="mw-numlink"', $links[$i] );
175 $this->assertContains( '>20<', $links[$i] );
176 $i += 4;
177
178 $this->assertContains( 'limit=500&amp;offset=' . $offset, $links[$i] );
179 $this->assertContains( 'title="(shown-title: 500)"', $links[$i] );
180 $this->assertContains( 'class="mw-numlink"', $links[$i] );
181 $this->assertContains( '>500<', $links[$i] );
182 }
183
184}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
testBuildPrevNextNavigation( $offset, $limit, $atEnd, $subPage)
provideBuildPrevNextNavigation
testInvalidGetTitleFor()
PHPUnit_Framework_Error_Notice.
testGetTitleForWithWarning( $expected, $name)
PHPUnit_Framework_Error_Notice getTitleForWithWarningProvider.
testGetTitleFor( $expectedName, $name)
getTitleForProvider
testRequireLoginAnon( $expected, $reason, $title)
requireLoginAnonProvider
Parent class for all special pages.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:585
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition User.php:609
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const NS_SPECIAL
Definition Defines.php:62
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition hooks.txt:783
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
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 just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition hooks.txt:2011
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:271
return true to allow those checks to and false if checking is done & $user
Definition hooks.txt:1510
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
if(!isset( $args[0])) $lang